EGA Palette

From ModdingWiki
Jump to: navigation, search
EGA Palette
Format typePalette
HardwareEGA
Colour depth6-bit
Number of colours16
Games

While the EGA can only display up to 16 colours at a time, those 16 can be chosen from a selection of 64 possible colours. Effectively this allows each of the red, green and blue channels to be independently set at four different levels (off, low, medium and high.)

While it has always been possible to change the EGA palette, very few games ever did. Duke Nukem II is notable as it is an EGA game which changed the VGA Palette instead.

Default Palette

Default EGA 16-Color Palette
Color Name RGB Binary Decimal
0 black #000000 000000 0
1 blue #0000AA 000001 1
2 green #00AA00 000010 2
3 cyan #00AAAA 000011 3
4 red #AA0000 000100 4
5 magenta #AA00AA 000101 5
6 yellow / brown #AA5500 010100 20
7 white / light gray #AAAAAA 000111 7
8 dark gray / bright black (#555555 111000 56
9 bright blue #5555FF 111001 57
10 bright green #55FF55 111010 58
11 bright cyan #55FFFF 111011 59
12 bright red #FF5555 111100 60
13 bright magenta #FF55FF 111101 61
14 bright yellow #FFFF55 111110 62
15 bright white #FFFFFF 111111 63

The default EGA palette found in most DOS games is shown on the right. This is set up to be backwards-compatible with the 16 colours available in text mode on the original CGA. Notice that colour entry #6 (brown) doesn't fit in sequence with the other entries. This is because the CGA had additional circuitry to make this colour appear "more visually pleasing." The introduction of the EGA palette meant this adjustment no longer required additional hardware. Setting palette entry #6 to the in-sequence value of 6 (#AAAA00) instead of 20 reveals the "dark yellow" colour found in cheaper clone CGA monitors lacking the additional circuitry.

The default format

As there are 16 colours to change, it is easiest to write these values out as 16 bytes. In this case, the palette file is only 16 bytes long.

Conversion

To convert from an EGA palette to RGB values, each 2-bit EGA red, green or blue value should be multiplied by 85, to produce the values 0, 85, 170 and 255.

To obtain the 2-bit value, the bits must be extracted as shown in the following table (where -H is the high bit and -L is the low bit, for each colour.)

Bit 7 6 5 4 3 2 1 0
Purpose Unused Unused Red-H Green-H Blue-H Red-L Green-L Blue-L

Or as a formula:

red   = 85 * (((ega >> 4) & 2) | (ega >> 2) & 1)
green = 85 * (((ega >> 3) & 2) | (ega >> 1) & 1)
blue  = 85 * (((ega >> 2) & 2) |  ega       & 1)

Detection

There are not many EGA palettes in existence on account of so few games bothering to change the palette, and any palette is so short detection is difficult. Typically the first entry will be black (0x00) and the 16th white (0x3F) however even this is not guaranteed. Any value larger than 0x3F is invalid and can be used to identify files that are definitely not palettes.

Links