MyBytePtr [ 1 ]
BlitzMax Forums/BlitzMax Programming/MyBytePtr [ 1 ]
| ||
So, the title is self- explanatory .. Now its actually the question, whether the pointer value requesting is 'just' syntactical sugar, or consequently usable - e.g. you could do extraction of color parts from the pixel value like: Local MyPixelValue:Int = ReadPixel( .. ) Local MyPixelValuePtr :Byte Ptr = Varptr MyPixelValue Local MyPixelR :Int = MyPixelValuePtr[ 0 ] Local MyPixelG :Int = MyPixelValuePtr[ 1 ] Local MyPixelB :Int = MyPixelValuePtr[ 2 ] Opinions? |
| ||
Well it seems to compile and run on mine, with numbers coming out (can't be bothered to check if they're correct though). |
| ||
it works but note that the way a 32 bit integer is stored is not the same way a byte is accessed. try this code: Local MyPixelValue:Int = $FF88BBCC ' this is format PF_RGBA8888 Local MyPixelValuePtr :Byte Ptr = Varptr MyPixelValue Local MyPixelR :Int = MyPixelValuePtr[ 0 ] Local MyPixelG :Int = MyPixelValuePtr[ 1 ] Local MyPixelB :Int = MyPixelValuePtr[ 2 ] Local MyPixelA :Int = MyPixelValuePtr[ 3 ] Print Hex(MyPixelR)' this will return blue not red Print Hex(MyPixelG)' this will return green Print Hex(MyPixelB)' this will return red not blue Print Hex(MyPixelA)' this will return alpha you are going to have to adopt your code accordingly |
| ||
Ya, you can do that.. Similar code has been posted before |
| ||
One more reason to love blitzmax. Thanks to you all for your answers. |