how do i round a number to the nearest n? (n representing a variable of course)
rounding numbers
Blitz3D Forums/Blitz3D Beginners Area/rounding numbers Ceil() rounds a Float up to the nearest whole number (int) upwords, Floor() rounds down to the nearest Int downwards.
why does rounding rgb's on a picture (yep, that's what i'm doing!) make it look purple and grey? (even rounding to the nearest 1 using your function!, shouldnt affect it should it?)
Here's the code I'm using:
Here's the code I'm using:
Graphics 1280, 1024, 32, 1 Global imageid, image, bias Global r, g, b, av, n, m imageid=Input$("Image name and extension : ") bias=Input$("To what nearest number should the rgb's be rounded to?") ;bias = Float bias ;bias = bias/(bias*10) If bias=0 Then bias=10 image=LoadImage ("image.jpg") Cls DrawImage image, 0, 0 WaitKey() For n=0 To ImageWidth (image) For m=0 To ImageHeight (image) GetColor n, m r=ColorRed() g=ColorGreen() b=ColorRed() r=(round( r, 15)) g=(round( g, 15)) b=(round( b, 15)) ;r=(round( r, 255)) ;g=(round( g, 255)) ;b=(round( b, 255)) ;av = (r + g + b) / 3 ;r = av : g = av : b = av Color r, g, b ;Plot 1280, 0 Rect 1000, 1000, 2, 2, 1 If ImageHeight(image) < 500 Then writepixelsfast Else writepixels EndIf If KeyHit(1) Then Goto endl Next Next Repeat Color 0, 0, 0 Rect 1000, 1000, 280, 24, 1 GetColor MouseX(), MouseY() Text 1000, 1000, "mouse location rgb = " + ColorRed() + " " + ColorGreen() + " " + ColorBlue() Delay 15 Until KeyHit(1) .endl End Function Round( Number , N ) If ( Number Mod N ) >= ( N *.5 ) Number = ( Ceil( Number / N ) + 1 ) * N Else Number = Floor( Number / N ) * N EndIf Return Number End Function Function writepixelsfast() If ImageHeight(image)*2 > 1024 Then WritePixelFast n+ImageWidth(image), m, ReadPixelFast(1000, 1000) Else If ImageWidth*2 > 1280 Then WritePixelFast n, m+ImageHeight (image), ReadPixelFast(1000, 1000) EndIf End Function Function writepixels() If ImageHeight(image)*2 > 1024 Then WritePixel n+ImageWidth(image), m, ReadPixel(1000, 1000) Else If ImageWidth*2 > 1280 Then WritePixel n, m+ImageHeight (image), ReadPixel(1000, 1000) EndIf End Function
I didn't check it in detail, but your false colors may most likely be caused by register overflows, due to up-rounding. Any color, red, green or blue should never be higher than 255.
Probably you should rather try to delete less significant bits to achieve the effect you may be after.
kind of
red=red and %11111000
green=green and %11111000
blue=blue and %11111000
rgb= (red shl 16) or (green shl 8) or blue
this will erase the 3 least significant bits, so a color channel will always be 0,8,16,24... etc.
Probably you should rather try to delete less significant bits to achieve the effect you may be after.
kind of
red=red and %11111000
green=green and %11111000
blue=blue and %11111000
rgb= (red shl 16) or (green shl 8) or blue
this will erase the 3 least significant bits, so a color channel will always be 0,8,16,24... etc.