Sub topic 6
Color depth and color modes
This chapter assumes you know that raster images are grids of pixels and that vector images are described by shapes. It also assumes you know what a screen pixel is. Here you will learn how many bits a pixel uses to store color (color depth) and how those bits are interpreted (color mode).
Color depth: bits per pixel
Color depth is the number of bits used to store the color of one pixel. More bits mean more possible colors and a larger file before compression.
| Depth | Bits per pixel | Colors | Typical use |
|---|---|---|---|
| 1-bit | 1 | 2 | Black-and-white line art |
| 8-bit indexed | 8 | 256 | GIF, small PNG-8 graphics |
| 24-bit "true color" | 24 | about 16.7 million | JPEG, standard PNG |
| 32-bit | 24 plus 8 for transparency | 16.7 million plus an alpha channel | PNG with transparency |
| 16 bits per channel | 48 | trillions | Photo editing, RAW workflows |
Depth is often quoted per channel. "8-bit" in a photo editor usually means 8 bits for each of red, green and blue, which is 24 bits per pixel. An indexed image works differently. It stores a palette of up to 256 colors, and each pixel holds a number pointing into that palette.
Low depth causes banding. A smooth sky gradient has to jump between the few colors available, and you see visible stripes. Higher depth gives finer steps. Editing also benefits, because 16 bits per channel leaves room to brighten or darken without creating banding.
Color modes: what the numbers mean
A color mode defines the channels that combine to make a color.
- RGB is additive. Red, green and blue light are added together. All channels at maximum give white, and all at zero give black. Screens use RGB.
- CMYK is subtractive. Cyan, magenta, yellow and black (the "key" plate) inks absorb light from white paper. Commercial printing uses CMYK.
- Grayscale uses one channel for brightness.
- Indexed uses a palette, as described above.
Vector graphics have colors too. An SVG fill such as #2a6fdb is an RGB value, so color modes apply to vector files in the same way.
# A hex color is three 8-bit channels written in base 16.
color = "#2a6fdb"
r = int(color[1:3], 16)
g = int(color[3:5], 16)
b = int(color[5:7], 16)
print(r, g, b) # 42 111 219
# The same pixel stored at three depths per channel
for bits in (8, 16):
levels = 2 ** bits
print(bits, "bits per channel:", levels, "levels,", levels ** 3, "colors")Gamut: why RGB and CMYK differ
A gamut is the range of colors a device or mode can reproduce. A typical RGB screen can show very saturated blues, greens and oranges that CMYK ink cannot. When you convert RGB to CMYK, those colors are mapped to the nearest printable ones. Bright colors look duller as a result.
Color profiles, such as sRGB for the web, describe how channel numbers map to real colors. If the profile is missing or wrong, the same numbers can look different on different screens.
Common errors
- Converting to CMYK too early. Convert once, at the end, and keep an RGB master. Converting back and forth does not restore the lost colors.
- Using an 8-bit indexed format for a photo. The 256-color limit causes banding and blotches. Use a 24-bit format for photos.
- Assuming a file's color mode from its extension. A JPEG can be RGB, CMYK or grayscale. Some browsers display CMYK JPEGs incorrectly, so check the mode before publishing.
- Forgetting the profile. An image saved without sRGB may look oversaturated or dull on other devices.
Exercise
A designer exports a smooth sunset photo as an 8-bit indexed image to save space. The sky shows visible stripes. What is the cause, and what is the fix?
Show answer
An indexed image holds at most 256 colors, so a smooth gradient has to jump between a few palette entries, which shows as banding. Export the photo at 24-bit color (for example JPEG or PNG-24) so each channel has 256 levels.
Exercise
You are sending a brochure to a commercial printer and also posting it on a website. Which color mode should each version use, and when should you convert?
Show answer
Use CMYK for the print version and RGB (sRGB) for the website. Keep an RGB master during editing and convert to CMYK once, at the end, for the print copy.