Quickie on ReadPixel(x,y)

Blitz3D Forums/Blitz3D Beginners Area/Quickie on ReadPixel(x,y)

Tobo(Posted 2004) [#1]
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


Rob Farley(Posted 2004) [#2]
http://www.blitzbasic.com/codearcs/codearcs.php?code=551


Tobo(Posted 2004) [#3]
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


Rob Farley(Posted 2004) [#4]
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.


_PJ_(Posted 2004) [#5]
Isn't there GetColor or something for this?


Warren(Posted 2004) [#6]
As Rob said,

www.blitzbasic.com/codearcs/codearcs.php?code=551


_PJ_(Posted 2004) [#7]
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???


Rob Farley(Posted 2004) [#8]
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.


Warren(Posted 2004) [#9]
And definitely use the readpixelfast/writepixelfast functions on locked buffers. The speed improvement is NOT insignificant.