Qbasicnews.com

Full Version: color = r or (g shl 8) or (b shl 16)?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the gfxlib doc you can read that if you wanna convert a color to a integer you do:

color = r or (g shl 8) or (b shl 16)

Running this i get a sytax error.

My problem is the following:

Lets say i draw a box and get it
Screen 18,16,0,0

DIM Spr(0, (32*32*2)+2) AS USHORT
Line (0,0)-(31,31),RGB(255,255,255),BF
GET (0, 0)-(31, 31), Spr(0, 0)

Now i simply wanna "peek" a color and draw a new box with that color.

C= Spr(0,2)
R = (C AND &hF800) SHR 11
G = (C AND &h7E0) SHR 5
B = C AND &h1F

Line (40,40)-(60,60),RGB(R,G,B),BF
Won't work cause R = 31, G = 63, B= 31
I understand this, that you for example only have 31 shades of blue to play with. But isn't it stupid that you can enter 255 in the RGB function?

What should i do?
Quote:In the gfxlib doc you can read that if you wanna convert a color to a integer you do:

color = r or (g shl 8) or (b shl 16)

Running this i get a sytax error.

Of course you get an error because COLOR is a KEYWORD and therefore cannot be used as a variable.

Quote:C= Spr(0,2)
R = (C AND &hF800) SHR 11
G = (C AND &h7E0) SHR 5
B = C AND &h1F

Line (40,40)-(60,60),RGB(R,G,B),BF
Won't work cause R = 31, G = 63, B= 31
I understand this, that you for example only have 31 shades of blue to play with. But isn't it stupid that you can enter 255 in the RGB function?

What should i do?

What the heck are you doing there ... and why did you do this?

This is the correct way to extract the R/G/B channels from a RGB value.

Code:
R  = (C SHR 16) AND &HFF
G  = (C SHR 8 ) AND &HFF
B  = (C SHR 0 ) AND &HFF

gfxlib2 always uses 8 bits for R, G, and B (8:8:8) and not RGB with 5:6:5 as you did above.

How did you come to this 5:6:5 stuff?

Regards,
Mark
I'm using 16 bpp mode isn't it 5:6:5 then?

Well i only want to "peek" the color of a sprite and use it.
Quote:Well i only want to "peek" the color of a sprite and use it.
This should work:
Code:
C= Spr(0,2)

' Exract r, g, b as 8 bit:
R = (C AND &hF800) SHR 8
G = (C AND &h7E0) SHR 3
B = (C AND &h1F) SHL 3

Line (40,40)-(60,60),RGB(R,G,B),BF

You should also be able to use POINT to read a pixel from a sprite (the same way you can "PSET Spr, (x, y), col"), but I can't figure out the syntax. That way POINT would convert to 8:8:8 for you.
Quote:You should also be able to use POINT to read a pixel from a sprite (the same way you can "PSET Spr, (x, y), col"), but I can't figure out the syntax. That way POINT would convert to 8:8:8 for you.
Quote:When called with two arguments, the specified (x,y) coordinates are affected
by the most recent WINDOW and VIEW statements; if the pixel lies out of the
current clipping region, POINT returns -1, otherwise a color number in the
same format as used by the COLOR statement.
I tested and it seems like it only returns 0-255 .

FBWiki has no entry regarding the syntax, examples, etc.
http://www.freebasic.net/wiki/wikka.php?...KeyPgPoint
FreeBASIC either uses either 8 bits or 32-bit color. And 8-bit color is simulated. Windows deals with all the 16-bit nastiness, so you don't have to worry about it.