Night - Day Filter

BlitzPlus Forums/BlitzPlus Programming/Night - Day Filter

Okay...


Function FB_DarkenImage ( image, d%=100 )

     ;convert number into a fraction for multiplication
     percent# = d / 100

	For ix = 0 To ImageWidth( image ) - 1
		For iy = 0 To ImageHeight( image ) - 1
			
                Local rbgc = ReadPixel( ix, iy, ImageBuffer(image) )
		
                ;check if the pixel is a mask color...if so exit to the next pixel...else proceed
                If rbgc = $FFFF00FF then
                        exit
                else
 
                       	Alpha% = (rbgc And $FF000000) Shr 24 
	        	Red% = (rbgc And $00FF0000) Shr 16 
		        Green% = (rbgc And $0000FF00) Shr 8 
		        Blue% = rbgc And $000000FF
			
                        
                        ;modify the color values, MOD ing them by 256 inorder to keep them in the range of 0 to 255
                        Red = (Red * percent) MOD 256
			Green = (Green * percent) MOD 256
			Blue = (Blue * percent) MOD 256
			     
                             ;make sure this modified color isn't the same as the mask color, if so change it else it will be masked
                             If red = 255 and blue = 255 and green = 0 then green = 1

                        
                        ;rebuild the rbgc value and writepixel it to the image
                        rbgc = (Alpha Shl 24) + (Red Shl 16) + (Green Shl 8) + Blue 
			
                      	WritePixel ix,iy,($0),ImageBuffer(image)		
		


                EndIf
		Next
	Next
	
	Return image

End Function 


the D# value works as an percentage in this..if you want the image to be 75% as brite you just call the function like so:

FB_Darkenimage (myimage, 75)

if you want to increase the brightness by 30% then call it like:

FB_Darkenimage (myimage, 130)

Note however then there is no constraining of the values...erm...that is to say if the pixel is fully white (red=255, green=255, blue=255) and you try to increase the brightness it can make the pixel come out very dark grey...if you don't want that to happen then try this instead:



Function coloradjustImage ( image, R% = 100, G% = 100, B% = 100 )

     ;convert number into a fraction for multiplication
     percentred# = R% / 100
     percentgreen# = G% / 100
     percentblue# = B% / 100

	For ix = 0 To ImageWidth( image ) - 1
		For iy = 0 To ImageHeight( image ) - 1
			
                Local rbgc = ReadPixel( ix, iy, ImageBuffer(image) )
		
                ;check if the pixel is a mask color...if so exit to the next pixel...else proceed
                If rbgc = $FFFF00FF then
                        exit
                else
 
                       	Alpha% = (rbgc And $FF000000) Shr 24 
	        	Red% = (rbgc And $00FF0000) Shr 16 
		        Green% = (rbgc And $0000FF00) Shr 8 
		        Blue% = rbgc And $000000FF
			
                        
                        ;modify the color values

                        Red = (Red * percentred)
                            if Red > 255 then Red = 255
                            if Red < 0 then Red = 0 
			
                        Green = (Green * percent)
			    if Green > 255 then Green = 255
                            if Green < 0 then Green = 0
 
                        Blue = (Blue * percent)
			    if Blue > 255 then Blue = 255
                            if Blue < 0 then Blue = 0
 
                             ;make sure this modified color isn't the same as the mask color, if so change it else it will be masked
                             If red = 255 and blue = 255 and green = 0 then green = 1

                        
                        ;rebuild the rbgc value and writepixel it to the image
                        rbgc = (Alpha Shl 24) + (Red Shl 16) + (Green Shl 8) + Blue 
			
                      	WritePixel ix,iy,($0),ImageBuffer(image)		
		


                EndIf
		Next
	Next
	
	Return image

End Function 



works pretty much the same but you can adjust each color seperately...say you wanted to increase the red inorder to use the image on a fire level or somesuch so you would call it like so:

coloradjustimage (myimage, 130,100,95)

which would increase the red by 30% (or set the red to 130%)...the green would stay the same...and the blue is reduced by 5% (or set to 95% of it's current color value)...