0

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 LIGHTMAGENTA 13
#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).

SigGP
  • 716
  • 1
  • 11
  • 24
  • 2nd hit on gxxgle for "*LIGHTGREEN*": http://www.html-color-names.com/ – alk Nov 27 '16 at 18:50
  • You can get the RGB components by looking at the palette of any "paint" type program, perhaps by copy-pasting an image containing every colour. But hex values? What do you mean? A value is a value is a value. Did you mean the 24-bit representation of the components? – Weather Vane Nov 27 '16 at 18:51

2 Answers2

1

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
Bodo Thiesen
  • 2,476
  • 18
  • 32
0

The easiest, but not the best solution for this is to make a switch() based on pixel value and set it to correct hex/rgb value by hard coding it from page like color-hex.com You can find all popular color representation there.