semmixcolor and perception

Color resolution

Color resolution, or bit depth, says how many bits store the color of one pixel or one component. It decides how many different colors an image can contain and how smooth its tonal transitions will be.

Bits per pixel and per component

Bits per pixelEncodingColorsExamples
12-color palette2fax, black-and-white icons
416-color palette16EGA, old Windows icons
8256-color palette or 256 grays256GIF, PNG-8
16RGB 5-6-565,536small displays, older phones
24RGB 8-8-816,777,216JPEG, PNG-24, most displays
30RGB 10-10-10over 1 billionHDR, professional monitors
48RGB 16-16-16about 2.8 · 10¹⁴PNG-48, TIFF, photo editing

An alpha channel can be added on top (see transparency): RGBA 8-8-8-8 is 32 bits per pixel.

The 16-bit 5-6-5 format

16 bits do not split evenly into three, so green gets 6 bits and red and blue 5 each. Green, because the eye is most sensitive to it (see luminance). An example for #c85028:

R: 200 → 200 >> 3 = 25 (of 31) → back 25 · 255 / 31 = 206 G: 80 → 80 >> 2 = 20 (of 63) → back 20 · 255 / 63 = 81 B: 40 → 40 >> 3 = 5 (of 31) → back 5 · 255 / 31 = 41 (200, 80, 40) → (206, 81, 41)

When going back to 8 bits, multiply by 255/31 rather than shifting left. A plain shift (25 << 3 = 200) could never produce full white 255.

Banding in gradients

8 bits per component is 256 levels. On a gentle gradient across the whole screen, consecutive levels then form bands a few pixels wide. At 8 bits they are usually invisible, but they appear when:

That is why photos are edited at 16 bits per component and reduced to 8 bits only at the end, often with light dithering (see color palette). HDR images need at least 10 bits because they cover a much larger brightness range.

Color resolution in GIF

The GIF logical screen descriptor has three "color resolution" bits. Despite the name they do not change the number of colors in the file. They state how many bits per component the original had, from which the palette was made (value + 1). The GIF palette always stores each component in a full byte anyway. Software usually writes 7 (8 bits) here and nobody reads the field.

Bit depth and gamut are two different things. More bits split the same range of colors into finer steps. A wider gamut, such as Display P3 instead of sRGB, widens the range itself (see the RGB model). A wide gamut at 8 bits has coarser steps than sRGB at 8 bits.