Skip to content
Part IA Michaelmas Term

Display Encoding and Gamma

The Purpose of Gamma

Display encoding serves two purposes:

  1. Historical: CRT monitors had non-linear response: L=VγL = V^\gamma where γ2.2\gamma \approx 2.2
  2. Perceptual: Human vision is approximately logarithmic; gamma encoding distributes quantisation noise uniformly

Gamma Correction Equations

Forward (Encode for Display)

Vout=Vlinear1/γV_{\text{out}} = V_{\text{linear}}^{1/\gamma}

Inverse (Decode from Storage)

Vlinear=VoutγV_{\text{linear}} = V_{\text{out}}^\gamma

Typical value: γ=2.2\gamma = 2.2 for sRGB.

Gamma curve showing the encoding/decoding relationship

Why Not Linear?

Quantisation Analysis

Without gamma encoding:

  • Need ~12 bits per channel for visually uniform quantisation
  • Dark regions have visible banding

With gamma encoding:

  • 8 bits often sufficient
  • More codes allocated to darker values (where eye is sensitive)

Perceptual Uniformity

Gamma encoding approximately matches human lightness perception:

  • Weber’s law: ΔL/L\Delta L / L \approx constant
  • Logarithmic response gives uniform perceptual steps

sRGB Transfer Function

sRGB uses a piecewise function (not pure gamma):

Encoding (Linear → sRGB)

Vout={12.92VlinearVlinear0.003131.055Vlinear1/2.40.055Vlinear>0.00313V_{\text{out}} = \begin{cases} 12.92 \cdot V_{\text{linear}} & V_{\text{linear}} \leq 0.00313 \\ 1.055 \cdot V_{\text{linear}}^{1/2.4} - 0.055 & V_{\text{linear}} > 0.00313 \end{cases}

Decoding (sRGB → Linear)

Vlinear={Vout/12.92Vout0.04045(Vout+0.0551.055)2.4Vout>0.04045V_{\text{linear}} = \begin{cases} V_{\text{out}} / 12.92 & V_{\text{out}} \leq 0.04045 \\ \left(\frac{V_{\text{out}} + 0.055}{1.055}\right)^{2.4} & V_{\text{out}} > 0.04045 \end{cases}

Why Piecewise?

  • Linear segment near zero avoids numerical issues
  • Better approximation of CRT behaviour
  • Matches perceptual uniformity more closely

EOTF and OETF

EOTF (Electro-Optical Transfer Function)

Converts digital signal to display light output:

StandardEOTF
sRGB/CRTL=V2.2L = V^{2.2}
HDR (PQ)Complex piecewise function
HDR (HLG)Hybrid log-gamma

OETF (Opto-Electronic Transfer Function)

Converts light to digital signal (inverse of EOTF):

StandardOETF
sRGBV=L1/2.2V = L^{1/2.2} (approximately)
Camera logVarious (LogC, S-Log, V-Log)

sRGB in OpenGL

OpenGL can automate sRGB conversion:

glEnable(GL_FRAMEBUFFER_SRGB);
  • When enabled, fragments are automatically gamma-encoded
  • sRGB textures are linearised on sampling
  • Ensures correct gamma handling throughout pipeline

Practical Considerations

Common Mistakes

MistakeConsequence
Applying gamma twiceImage too dark
Not applying gammaImage too bright, banding
Mixing linear and gammaIncorrect blending

Colour Space Awareness

OperationRequire
BlendingLinear
FilteringLinear
LightingLinear
StorageGamma-encoded
DisplayGamma-encoded

Summary

  • Gamma correction encodes linear values for efficient storage
  • sRGB uses a piecewise function for better accuracy
  • All rendering computations must use linear values
  • OpenGL’s GL_FRAMEBUFFER_SRGB automates conversion

Past Paper Questions

2024 Paper 3 Question 3: Why is gamma correction needed? What would happen without it?

2023 Paper 3 Question 4: Explain the sRGB transfer function. Why is it piecewise?

2022 Paper 3 Question 3: What operations require linear colour values?