can someone explain me how to convert rgb to a 15 bit BBBBBGGGGGRRRRR value? Please use for each color a separate variable (r = : g= : b = ).
Have tried to understand it but i dont have any infos, so i couldnt understand it. Btw, whats the highest val if a col is stored in 5 bit?
each color of rgb is still limited to 255..
RGB to 15bit BBBBBGGGGGRRRRR convert?
Hi,
Assuming RGB is in RGB order and stored in a long variable we call RGB, and we want a 15 bit BGR value:
Assuming RGB is in RGB order and stored in a long variable we call RGB, and we want a 15 bit BGR value:
Code: Select all
r15 = (RGB&%111110000000000000000000)>>19
g15 = (RGB&%1111100000000000)>>6
b15 = (RGB&%11111000)<<7
rgb15.w = r15|g15|b15
El_Choni
- Andre
- PureBasic Team

- Posts: 2148
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Posted on german forum (http://robsite.de/php/pureboard/viewtop ... ght=15+bit) by NicTheQuick:
Code: Select all
Procedure.l RGB32(R.l, G.l, B.l, A.l)
RGBA.l = A << 24 + B << 16 + G << 8 + R
ProcedureReturn RGBA
EndProcedure
Procedure.l R32(RGBA.l)
R.l = RGBA & $FF
ProcedureReturn R
EndProcedure
Procedure.l G32(RGBA.l)
G.l = RGBA >> 8 & $FF
ProcedureReturn G
EndProcedure
Procedure.l B32(RGBA.l)
B.l = RGBA >> 16 & $FF
ProcedureReturn B
EndProcedure
Procedure.l A32(RGBA.l)
A.l = RGBA >> 24
ProcedureReturn A
EndProcedure
Procedure.l RGB24(R.l, G.l, B.l)
RGB.l = B << 16 + G << 8 + R
ProcedureReturn RGB
EndProcedure
Procedure.l R24(RGB.l)
R.l = RGB & $FF
ProcedureReturn R
EndProcedure
Procedure.l G24(RGB.l)
G.l = RGB >> 8 & $FF
ProcedureReturn G
EndProcedure
Procedure.l B24(RGB.l)
B.l = RGB >> 16
ProcedureReturn B
EndProcedure
Procedure.l RGB16(R.l, G.l, B.l)
R >> 3
G >> 2
B >> 3
RGB.l = B << 11 + G << 5 + R
ProcedureReturn RGB
EndProcedure
Procedure.l R16(RGB.l)
R.l = (RGB & $1F) << 3
ProcedureReturn R
EndProcedure
Procedure.l G16(RGB.l)
G.l = (RGB >> 5 & $3F) << 2
ProcedureReturn G
EndProcedure
Procedure.l B16(RGB.l)
B.l = (RGB >> 11 & $1F) << 3
ProcedureReturn B
EndProcedure
Procedure.l RGB15(R.l, G.l, B.l)
R >> 3
G >> 3
B >> 3
RGB.l = B << 10 + G << 5 + R
ProcedureReturn RGB
EndProcedure
Procedure.l R15(RGB.l)
R.l = (RGB & $1F) << 3
ProcedureReturn R
EndProcedure
Procedure.l G15(RGB.l)
G.l = (RGB >> 5 & $1F) << 3
ProcedureReturn G
EndProcedure
Procedure.l B15(RGB.l)
B.l = (RGB >> 10 & $1F) << 3
ProcedureReturn B
EndProcedure
Debug A32(RGB32(1, 2, 3, 4))
Debug R24(RGB24(5, 6, 7))
Debug G16(RGB16(88, 99, 110))
Debug B15(RGB15(63, 127, 255))