Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RGB in 16 bpp
#1
I have dealt with this a long time now and want to clear it up for good.
In a post way back i read that fb emulates 16 bit mode so that the rgb value always i 8:8:8. Then i read that it's 5:6:5..
That's the first thing, then i wonder how rgb() works. RGB(255,255,255) will be white even in 16 bit mode were you don't have 255 colors to play with..

I can't get peek and rgb() to work together in 16 bit! I'm going crazy!!!
If i can get the code below to run as desired i will be so thankfull!

SCREEN 15,16,2
SCREENSET 1,1
S1 = SCREENPTR
LINE (0,0)-(400,300),RGB(244,180,55),BF
SLEEP
SCREENSET 0,0
S2 = SCREENPTR

FOR N=0 TO 400 * 300 - 1
C=PEEK(USHORT,S1 + N * 2)
B = C AND &HFF
G = (C AND &HFF00) SHR 8
R = (C AND &HFF0000) SHR 16
POKE USHORT, S2 + N * 2, RGB(R,G,B)
NEXT
PRINT R,G,B
SLEEP
ttp://hem.passagen.se/qb.basta
Reply
#2
Can't anyone help me..

I peek c from the screenbuffer, c is a ushort containing the rgb code for the current color.. example.. RRRRRGGGGGGBBBBB
Well then i try to split it up in 3 parts, and thats what i'm doing wrong, cause these values i get don't match with the original r,g,b..
However, rgb(r,g,b) succesfully match these 3 parts up to the correct color.. My guess is that i'm splitting C wrong.
ttp://hem.passagen.se/qb.basta
Reply
#3
post on http://www.freebasic.net/forum

i have tried to solve your problem, to no avail.
Reply
#4
16-bit mode are 5.6.5, as you said. RGB always returns 8.8.8 (it's just a macro which doesn't depend on the current screen mode).
Reply
#5
I solved it by skipping the RGB(), if anybody's intreseted here it is:

SCREEN 15,16,2
SCREENSET 1,1
S1 = SCREENPTR
LINE (0,0)-(400,300),RGB(255,55,255),BF
SLEEP
SCREENSET 0,0
S2 = SCREENPTR
FOR N=0 TO 400 * 300 - 1
C=PEEK(USHORT,S1 + N * 2)

R = (C AND 63488) SHR 11 'mask: 1111100000000000 = 63488
G = (C AND 2016) SHR 5 'mask: 0000011111100000 = 2016
B = C AND 31 'mask: 0000000000011111 = 31

R = R SHL 11
G = G SHL 5
B = B

C = R Or G Or B

POKE USHORT, S2 + N * 2, C
NEXT
PRINT R SHR 11,G SHR 5, B
PRINT (R SHR 11)*8,(G SHR 5)*4, B*8 'If you want it RGB() friendly
ttp://hem.passagen.se/qb.basta
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)