Converting a colour to do a WritePixelFast

BlitzPlus Forums/BlitzPlus Programming/Converting a colour to do a WritePixelFast

okee(Posted 2005) [#1]
How do you convert a colour, say 255,0,255 to an
integer to use with WritePixelFast ?

okee


Bremer(Posted 2005) [#2]
RGB = ( RED SHL 16 ) + ( GREEN SHL 8 ) + BLUE, so in your example it would be: RGB = ( 255 shl 16 ) + ( 0 shl 8) + 255


okee(Posted 2005) [#3]
Thanks a lot zawran


Bremer(Posted 2005) [#4]
No problem. :)


Grey Alien(Posted 2005) [#5]
However, if you say make white (using 255,255,255) like this and compare it to a ReadPixelFast call that has read a white pixel, readpixelfast returns -1 which is not the same! But if you subtract -16777216 (the ARGB value for black) they will match. Note that write pixel fast doesn't mind either type of value but Readpixelfast seems to be limited. Anyone want to explain why?


Rck(Posted 2005) [#6]
you can or instead of + for a "speed boost" if you are crazy like me :)


Rck(Posted 2005) [#7]
; A 32-bit pixel-making function
Function MakePixel(opaque, r%, g%, b%)
	If opaque Then
		Return (255 Shl 24) Or (r Shl 16) Or (g Shl 8) Or b
	Else
		Return (r Shl 16) Or (g Shl 8) Or b
	EndIf
End Function



Grey Alien(Posted 2005) [#8]
OR sounds good to me


Snarty(Posted 2005) [#9]
When using ReadPixelFast() it's best to read it as:

RGB=ReadPixelFast(x,y) And $FFFFFF

Since the alpha channel is not used.


Grey Alien(Posted 2005) [#10]
thanks snarty