Quickie on ReadPixel(x,y)
Blitz3D Forums/Blitz3D Beginners Area/Quickie on ReadPixel(x,y)
Wotcha, folks.
Can anyone tell me why the command ReadPixel(x,y) returns numbers like -65536 for red pixels and -16777216 for black pixels?
I was expecting something like 255,0,0 or 0,0,0.
Many thanks.
Tobo
R Tape loading error, 0:1
....ahhh, a Spectrum man.
Cheers, Rob. That'll come in handy, mate.
The original numbers it gives out, do they actually mean anything though?
Tobo
ARGB as a 32 bit number
First 8 bits are alpha (0-255)
Next 8 are red (0-255)
Next 8 are green (0-255)
Next 8 and Blue (0-255)
Hence all the bit shifts in the functions.
Isn't there GetColor or something for this?
As Rob said,
www.blitzbasic.com/codearcs/codearcs.php?code=551
Will those functions work for all cards? I remember Docs saying something about locking buffers to prevent crashing. How can they be altered to Lock buffers???
use readpixelfast and writepixelfast for locked buffers.
I tend to use them using read/writepixelfast, also you might want to combine the read_r/g/b into one function and load the results into 3 globals so you only do a single readpixelfast to get all r,g and b values.
The functions I've put in the code archives are just simplified for ease of use. They can be optimised dramatically.
And definitely use the readpixelfast/writepixelfast functions on locked buffers. The speed improvement is NOT insignificant.