Converting a colour to do a WritePixelFast
BlitzPlus Forums/BlitzPlus Programming/Converting a colour to do a WritePixelFast
| ||
How do you convert a colour, say 255,0,255 to an integer to use with WritePixelFast ? okee |
| ||
RGB = ( RED SHL 16 ) + ( GREEN SHL 8 ) + BLUE, so in your example it would be: RGB = ( 255 shl 16 ) + ( 0 shl 8) + 255 |
| ||
Thanks a lot zawran |
| ||
No problem. :) |
| ||
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? |
| ||
you can or instead of + for a "speed boost" if you are crazy like me :) |
| ||
; 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 |
| ||
OR sounds good to me |
| ||
When using ReadPixelFast() it's best to read it as: RGB=ReadPixelFast(x,y) And $FFFFFF Since the alpha channel is not used. |
| ||
thanks snarty |