Why files use gamma encoding

Capture Frame

Why files use gamma encoding

Sensors measure light roughly linearly: twice the photons, roughly twice the code in a linear RAW. Displayed image files usually do not store that linear light. They apply a nonlinear encoding curve — historically called gamma — so that limited bit depth tracks human lightness discrimination instead of wasting codes on bright steps the eye barely notices.

Human vision is compressive for luminance: we notice relative changes more than absolute watt doubles. Equal steps in linear radiance do not look equal. If you store 8-bit linear light from black to white, half of the 256 codes (codes 128–255) cover only the top stop of the range — one doubling below full scale — while the shadows share the remaining codes across many stops. Banding and posterisation then show first in the darks, where perception is still sensitive and codes are scarce.

A power-law encoding of the form V = L^(1/γ) (with γ near 2.2 in common display-referred spaces, plus piecewise sRGB quirks) lifts midtones and shadows in code space. More integer steps land where the eye needs them; highlights share fewer codes because equal lightness steps there correspond to larger linear gaps. The file is not “physically wrong”; it is perceptually budgeted. Rendering intent assumes a matching decode (and a calibrated display) so linear light can be reconstructed when needed for compositing or colour science.

Worked 8-bit intuition: in linear encoding, mid-grey at 18% reflectance sits near code 0.18 × 255 ≈ 46 — only about 18% of the way up the code scale. Under a simple γ = 2.2 encode, the same relative luminance maps near 255 × (0.18)^(1/2.2) ≈ 255 × 0.18^0.455 ≈ 255 × 0.46 ≈ 117 — roughly mid-scale, closer to how “middle” feels. The exact sRGB curve differs slightly from pure 2.2, but the moral holds: gamma redistributes the 256 buckets.

Gamma encoding is not white balance. White balance estimates the illuminant and scales colour channels so a chosen neutral maps toward white. Gamma (or a tone curve) redistributes lightness codes along a nonlinear axis. You can white-balance a linear RAW and still encode to sRGB gamma for delivery; you can mis-balance a JPEG that already carries gamma. Confusing the two mixes chromatic adaptation with perceptual quantization.

A misreading

The misreading is that gamma is the same as white balance. White balance corrects illuminant colour (channel gains / chromatic adaptation). Gamma encoding redistributes tonal codes for perception and display. One fixes “what is white under this light”; the other fixes “how finely we store dark versus bright.”

Keep linear light for math; keep gamma-encoded files for delivery when bit depth is tight. The curve is a budget, not a mood filter and not a Kelvin dial.

Terms

Linear light
Codes proportional to radiance (within noise and sensor limits).
Gamma encoding
Nonlinear mapping that allocates more codes to darker tones for perceptual efficiency.
Display-referred
A file whose codes assume a defined decode and viewing condition.
White balance
Illuminant estimate and channel scaling — independent of the gamma question.

Sources

  1. Imaging science texts contrast scene-linear data with gamma-encoded display spaces such as sRGB.
  2. 8-bit quantization arguments show why equal linear steps undersample shadows relative to perception.
  3. This frame is educational encoding literacy, not a colour-management workflow for a specific app.

Capture check. Before this frame went live, a human capture-pipeline editor confirmed the linear-versus-gamma spacing example, the mid-grey codes, and the separation from white balance.