RGB color code to color byte?
E-Head
Posts: 13
Hello
I have tried to solve how the backround and foreground colors are set.
For example, I have analysed the driver below.
''***************************************
''* VGA High-Res Text Driver v1.0 *
''* Author: Chip Gracey *
''* Copyright (c) 2006 Parallax, Inc. *
''* See end of file for terms of use. *
''***************************************
There is explained a following thing.
ColorPtr = Pointer to 64 words which define the foreground and background
'' colors for each row. The lower byte of each word contains the
'' foreground RGB data for that row, while the upper byte
'' contains the background RGB data. The RGB data in each byte is
'' arranged as %RRGGBB00 (4 levels each).
''
'' color word example: %%0020_3300 = gold on blue
So, the question I have is when I look a RGB color chart (like www.tayloredmktg.com/rgb/)
there is for example red presented for 255-0-0. I can understand that if I change the 255 to 3 and then
put a color word like %%0020_3000 there will be red on blue. Then if I look blue, the RGB color chart
says that it is 0-0-255 but the example above in ColorPtr says that blue is 0020 so my conclusion with red doesn't work
Well, hopely I explained my problem well that someone maybe could help me. The problem is that I don't understand
how to convert an RGB color code to a RGB data byte %RRGGBB00.
0-0-255 -> %0020
E-Head
I have tried to solve how the backround and foreground colors are set.
For example, I have analysed the driver below.
''***************************************
''* VGA High-Res Text Driver v1.0 *
''* Author: Chip Gracey *
''* Copyright (c) 2006 Parallax, Inc. *
''* See end of file for terms of use. *
''***************************************
There is explained a following thing.
ColorPtr = Pointer to 64 words which define the foreground and background
'' colors for each row. The lower byte of each word contains the
'' foreground RGB data for that row, while the upper byte
'' contains the background RGB data. The RGB data in each byte is
'' arranged as %RRGGBB00 (4 levels each).
''
'' color word example: %%0020_3300 = gold on blue
So, the question I have is when I look a RGB color chart (like www.tayloredmktg.com/rgb/)
there is for example red presented for 255-0-0. I can understand that if I change the 255 to 3 and then
put a color word like %%0020_3000 there will be red on blue. Then if I look blue, the RGB color chart
says that it is 0-0-255 but the example above in ColorPtr says that blue is 0020 so my conclusion with red doesn't work
Well, hopely I explained my problem well that someone maybe could help me. The problem is that I don't understand
how to convert an RGB color code to a RGB data byte %RRGGBB00.
0-0-255 -> %0020
E-Head
Comments
Presuming you can count in binary, there are 4 levels for each color:
00
01
10
11
00 is black
11 is full color
So 11111100 is full red green blue (the last two bits are ignored)
So where you say red green blue 255 0 0 unfortunately we do not have that sort of resolution. 255 is 255 shades of resolution 0 to 255 and we only have 0 to 3 per color. So not nearly so many color choices there.
Fundamentally, this is because there are 2 physical pins devoted to red, two to green and two to blue. Sure, you could devote 8 pins to red, 8 to green and 8 to blue to get 255 bits per color, but then there would hardly be any pins left on the chip for other equally important things like a keyboard or an sd card or sound.
So, say you have a color 0-255 (say red) and you want to convert to a propeller color 0-3. The answer is to divide your color value by 64 and round to the nearest integer.
eg you have a color 100 out of 255. Divide by 64 = 1.56 Closest integer is 2. Binary value is 10. If you had 100-100-100 then it would be 10101000B for the color byte.
I must confess the line " color word example: %%0020_3300 = gold on blue"
does not make sense to me either.
Gold on blue is (binary) screencolor := %00001000_11110000
(just tested that on a real board)
0020_3300 almost looks like Octal to me, especially looking at the binary. Not a base I've ever seen used before...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
But once again, thanks very much [noparse]:)[/noparse]
Btw, is there any good faq for playing propeller with the graphics?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum