Qbasicnews.com

Full Version: gfxlib pixel formats
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've messed around a bit with it, and clearly I do not understand it.
It being how I extract the r g and b components of the pixel formats
How do I do that?
Perhaps an clr2 (r|g|b) function would come in handy...
for BGR:
red = color AND &HFF
green = color AND &HFF00 shr 8
blue = color AND &HFF0000 shr 16

for RGB: simply reverse red and blue's procedures.
Fast reply, good good ^^

I did some stuff with and, shl and shr, that didn't work, well
I suppose I have to test again... Big Grin
Assuming you're working in hi/truecolor mode (color depth > 8 ), for highlevel pixel access (values passed to COLOR, LINE, CIRCLE, PSET, PAINT, etc, and values returned by POINT), the format is always this:

Code:
red = color SHR 16
green = (color SHR 8) AND &hFF
blue = color AND &hFF

So here's an example:

Code:
SCREEN 14, 32 ' Set 320x240x32
PSET(0,0), RGB(255, 0, 0)  ' red pixel
col = POINT(0,0) ' get the pixel color back
red = col SHR 16
green = (col SHR 8) AND &hFF
blue = col AND &hFF
PRINT "Red: ";red;" green: ";green;" blue: ";blue
SLEEP

If you're accessing the screen at lowlevel (via SCREENPTR), the format depends on the current color depth; have a look at appendix C of gfxlib.txt...