Google Answers Logo
View Question
 
Q: Looking for 8-bit RGB values for each of the 16 VGA text mode colors ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: Looking for 8-bit RGB values for each of the 16 VGA text mode colors
Category: Computers > Graphics
Asked by: bigjosh-ga
List Price: $25.00
Posted: 17 Dec 2002 11:52 PST
Expires: 16 Jan 2003 11:52 PST
Question ID: 126097
I need to know the equivalent RGB values for all 16 foreground colors
available in VGA text mode.

Here are the 16 text mode colors...

0  black  8  dark gray  
1  blue  9  bright blue  
2  green  10  bright green  
3  cyan  11  bright cyan  
4  red  12  pink  
5  magenta  13  bright magenta  
6  brown  14  yellow  
7  white  15  bright white  

What are the accocated 8-bit RGB values for each?

(Please don't guess based on the names of the colors- I need to know
the actual values that the VGA card uses)
(Please don't tell me the RGBI values - I need to know the actual 3
values for the Red, Green, and Blue)

thanks,
josh
Answer  
Subject: Re: Looking for 8-bit RGB values for each of the 16 VGA text mode colors
Answered By: seizer-ga on 17 Dec 2002 13:03 PST
Rated:5 out of 5 stars
 
Hi there bigjosh! What a great question - it made me drag up my old
VGA programming skills again.

I wrote a small program to read these values directly from the video
card. In VGA text mode, the RGB triplet is only represented by the
first six bits of the byte, so the range returned is beteen 0 and 63.
If you're looking for values to use in an 8 bit RGB system, the best
you can do is to quadruple these values (not ideal, because bright
white is given as 252, 252, 252, when in fact it should be 255, 255,
255).

If you're interested, the way to retrieve these values when
programming, is as follows:

* Set port 0x3c7 to the value of the colour you want to read
* Read port 0x3c9 three times, one for each colour component

Here are the RGB triplets for VGA text mode:

---
Colour: 0
VGA 6 bit colour: R:0|G:0|B:0
Approximate 8 bit colour: R:0|G:0|B:0
---
Colour: 1
VGA 6 bit colour: R:0|G:0|B:42
Approximate 8 bit colour: R:0|G:0|B:168
---
Colour: 2
VGA 6 bit colour: R:0|G:42|B:0
Approximate 8 bit colour: R:0|G:168|B:0
---
Colour: 3
VGA 6 bit colour: R:0|G:42|B:42
Approximate 8 bit colour: R:0|G:168|B:168
---
Colour: 4
VGA 6 bit colour: R:42|G:0|B:0
Approximate 8 bit colour: R:168|G:0|B:0
---
Colour: 5
VGA 6 bit colour: R:42|G:0|B:42
Approximate 8 bit colour: R:168|G:0|B:168
---
Colour: 6
VGA 6 bit colour: R:42|G:42|B:0
Approximate 8 bit colour: R:168|G:168|B:0
---
Colour: 7
VGA 6 bit colour: R:52|G:52|B:52
Approximate 8 bit colour: R:208|G:208|B:208
---
Colour: 8
VGA 6 bit colour: R:42|G:42|B:42
Approximate 8 bit colour: R:168|G:168|B:168
---
Colour: 9
VGA 6 bit colour: R:0|G:0|B:63
Approximate 8 bit colour: R:0|G:0|B:252
---
Colour: 10
VGA 6 bit colour: R:0|G:63|B:0
Approximate 8 bit colour: R:0|G:252|B:0
---
Colour: 11
VGA 6 bit colour: R:0|G:63|B:63
Approximate 8 bit colour: R:0|G:252|B:252
---
Colour: 12
VGA 6 bit colour: R:63|G:0|B:0
Approximate 8 bit colour: R:252|G:0|B:0
---
Colour: 13
VGA 6 bit colour: R:63|G:0|B:63
Approximate 8 bit colour: R:252|G:0|B:252
---
Colour: 14
VGA 6 bit colour: R:63|G:63|B:0
Approximate 8 bit colour: R:252|G:252|B:0
---
Colour: 15
VGA 6 bit colour: R:63|G:63|B:63
Approximate 8 bit colour: R:252|G:252|B:252
---

I hope this answers your question, and these values prove useful to
you. Please don't hesitate to request clarification before rating this
answer, if you would like me to provide any more detail.

Thanks,

--seizer-ga

No searching required, as I had previous knowledge of VGA programming.

Request for Answer Clarification by bigjosh-ga on 17 Dec 2002 14:09 PST
You methods sound correct and this is exactly the info what I am
looking for.

Alas, the brown (06) is wrong. Using RGB of (168,168,0) it comes out
looking like muddy yellow - not at all like the brown on VGA text
mode.

Everything else looks right on.

Any ideas as to what is going on with brown?

Are you sure you ran you program directly on the real hardware in text
mode, and not in a emulated window? Windows DOS boxes show 06 as the
same muddy yellow...

thanks,
josh

Clarification of Answer by seizer-ga on 17 Dec 2002 14:50 PST
Hello again.

I must agree that "brown" is a loose interpretation of the colour
presented by RGB(168, 168, 0). However:

I ran the program in DOS mode and in Windows, but it yielded the same
colour. I've tested this on two different systems (one using a
GeForce, one using a Trio3D) so it seems to be consistent in this
house, at least. Certainly, though, it's not the same brown that I
recall from when I programmed with a Cirrus Logic card a few years
back.

It is worth noting, however, that the colour looks similarly
constructed when you compare it to the other colours (use of the value
42/168). Perhaps this is how graphics card manufacturers do things
these days?

The only thing I can suggest is to download and run my program for
yourself, in the hope that it will read the "proper" value from your
video card. I've made it available here:

http://xult.org/bigjosh/detect.exe

It should be 35068 bytes in size. It will function in Win32 or DOS
mode. When you run it, you will see no output, but a file called
"output.txt" will be created in the same directory as the program.

Let me know if this clears things up - I'll continue to look into the
matter in the meantime.

Good luck,

--seizer-ga

Clarification of Answer by seizer-ga on 17 Dec 2002 15:32 PST
Thanks for the five star rating!

I'm sorry you could not download my program. I have verified it is
still present at that link, so perhaps the problem is with your ISP?
It might be worth trying again later.

To find the match for brown, you could get a suitable colour present
in a DOS window, then take a screen capture of it using the Print
Screen button on your keyboard. Then, you could paste that screen
capture into an image editor, and use a dropper tool to "pick up" the
colour. Finally, you could examine its RGB code.

A lengthy and inelegant solution, admittedly.

I'm not sure what this is to be used with, but you could change the
colour's value within the video card - perhaps this would be useful?

Write the RGBI colour that you wish to change to 0x3c8
Write the red component to 0x3c9
Write the green component to 0x3c9
Write the blue component to 0x3c9

It will change back upon a reset (or exiting the DOS box), but perhaps
it will come in useful for you?

Thanks again for the rating, and best of luck.

--seizer-ga
bigjosh-ga rated this answer:5 out of 5 stars
Could not download your exe from the link, but I manually read the
values using DEBUG and got 42,42,0 just like you did on a VGA machine
under real DOS.

My only guess is that this pallette is used for text emulation under
graphics modes and not for actual text modes.

I guess I'll just try to find a match for brown using a color detector
and plugging a screen back and forth.

Oh well, let me know if you think of anyother way. Thanks.

Comments  
Subject: Re: Looking for 8-bit RGB values for each of the 16 VGA text mode colors
From: bavi_h-ga on 11 Feb 2003 05:15 PST
 
I acquired this data from programming in BASIC but I'm
not sure how it actually relates to the true colors
used by the VGA card.

When programming in some languages (BASIC), each of the
colors could be assigned a number from the master
palette of 64 colors.

It turns out that this master palette number is really
an encoding for the bits of red, green, and blue, as
follows:

  R0 G0 B0 R1 G1 B1

In this method, red, greeen, and blue are described
using 2 bits (values from 0 to 3). To convert to a
8 bit system (values 0 to 255) I multiplied by 85.


      color          no  2-bit RGB     8-bit RGB
  =================  ==  =========  ===============
   0  black........   0  (0, 0, 0)  (  0,   0,   0)
   1  blue.........   1  (0, 0, 2)  (  0,   0, 170)
   2  green........   2  (0, 2, 0)  (  0, 170,   0)
   3  cyan.........   3  (0, 2, 2)  (  0, 170, 170)
   4  red..........   4  (2, 0, 0)  (170,   0,   0)
   5  magenta......   5  (2, 0, 2)  (170,   0, 170)
   6  brown........  20  (2, 1, 0)  (170,  85,   0)
   7  white........   7  (2, 2, 2)  (170, 170, 170)
   8  gray.........  56  (1, 1, 1)  ( 85,  85,  85)
   9  light blue...  57  (1, 1, 3)  ( 85,  85, 255)
  10  light green..  58  (1, 3, 1)  ( 85, 255,  64)
  11  light cyan...  59  (1, 3, 3)  ( 85, 255, 255)
  12  light red....  60  (3, 1, 1)  (255,  85,  85)
  13  light magenta  61  (3, 1, 3)  (255,  85, 255)
  14  yellow.......  62  (3, 3, 1)  (255, 255,  85)
  15  bright white.  63  (3, 3, 3)  (255, 255, 255)


If instead I multiply by 84, I get values identical
to those in seizer's answer, except I get (168, 84, 0)
for brown.
Subject: Re: Looking for 8-bit RGB values for each of the 16 VGA text mode colors
From: bavi_h-ga on 11 Feb 2003 05:35 PST
 
Oops! light green should be (85, 255, 85)

And looking closer, when I multiply by 84
I get similar values, but my answers do differ
from seizer's... In any case, I think the
method of restircting RGB to 4 levels is the
key here...

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy