Sigger Sigger - 1 year ago 146
C Question

C: conio colors to Hex code/RGB

In my application I use function textbackground() from conio library. I have 16 available colors:

#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LIGHTGRAY 7
#define DARKGRAY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTCYAN 11
#define LIGHTRED 12
#define YELLOW 14
#define WHITE 15

How can I convert these colors to hex code and to RGB, or simply where can i find RGB/hex code for these colors (I have an int 2D array where cells have values from 0 to 15 and these values represent pixels colors. Now I need to save it in BMP and XPM2 format).

Answer Source

Those are the EGA/VGA colors, right?

The problem here is, that EGA did have 2 bits per color, VGA+ had up to 8. And the actual values differ somewhat. But this colors should be ok:

idx 0xrrggbb:
  0 0x000000
  1 0x0000aa
  2 0x00aa00
  3 0x00aaaa
  4 0xaa0000
  5 0xaa00aa
  6 0xaaaa00 // Windows (dark yellow)
  6 0xaa5500 // EGA/VGA (brown)
  7 0xaaaaaa
  8 0x555555
  9 0x5555ff
 10 0x55ff55
 11 0x55ffff
 12 0xff5555
 13 0xff55ff
 14 0xffff55
 15 0xffffff
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download