Shop OBEX P1 Docs P2 Docs Learn Events
RGB color code to color byte? — Parallax Forums

RGB color code to color byte?

E-HeadE-Head Posts: 13
edited 2010-01-19 17:20 in Propeller 1
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 confused.gifconfused.gifconfused.gif

E-Head

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-01-19 13:33
    I've just been playing around with this. It helps to have a real VGA screeen and to test things.

    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
  • E-HeadE-Head Posts: 13
    edited 2010-01-19 15:09
    Thanks for the answer. Now the whole thing looks more easier. Now I just wondering if I take a color which some RGB value is a full 255. Then if I divide it by 64, I get 3.9 and a closest integer is 4. Am I missing a point? If I understood right and remembered right from my testings, we can't use 4 because there are 4 levels from 0 to 3. So what to do with colors like 255-255-255?


    But once again, thanks very much [noparse]:)[/noparse]

    Btw, is there any good faq for playing propeller with the graphics?
  • ericballericball Posts: 774
    edited 2010-01-19 17:20
    Divide by 64 and truncate. 0-63 -> 0, 64-127 -> 1, 128-191 -> 2, 192-255 -> 3.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
Sign In or Register to comment.