Sub topic 13
sRGB, the Default Colour Space of the Web
This chapter assumes you understand pixels, channels, bit depth, and basic Python arrays. You should also know that gamma encoding stores light values nonlinearly.
What sRGB defines
sRGB is a colour space used by most web images, displays, and browsers. A colour space defines how numerical channel values correspond to visible colours. The three channels are red, green, and blue.
An sRGB pixel such as (128, 64, 32) is not simply three percentages of physical light. Each value is an encoded value. To display the intended colour, software interprets the values using the sRGB specification.
sRGB defines:
- Red, green, and blue primary colours.
- A reference white point, approximately the colour of standard daylight.
- A transfer function, which maps between stored values and linear light.
- The range of colours that the space can represent, called its gamut.
The usual 8-bit representation stores each channel from 0 to 255. For example, (255, 0, 0) represents the brightest sRGB red, while (0, 0, 0) represents black.
sRGB values are gamma encoded
Light behaves linearly: doubling a light signal doubles its physical intensity. Human vision does not respond linearly, and storing dark values with high precision is useful. sRGB therefore uses a transfer function that allocates code values unevenly.
For values above a small threshold, sRGB is approximately a power curve. Decoding an sRGB value produces linear light:
import numpy as np
def srgb_to_linear(value):
c = np.asarray(value, dtype=np.float64) / 255.0
return np.where(
c <= 0.04045,
c / 12.92,
((c + 0.055) / 1.055) ** 2.4,
)
for value in (0, 64, 128, 255):
print(value, round(float(srgb_to_linear(value)), 4))The stored value 128 decodes to about 0.216, not 0.502. This matters when adding light, resizing images, calculating brightness, or blending colours. Those operations should usually happen in linear light. Display and file output commonly use sRGB encoding again.
Why sRGB is a practical default
The web uses sRGB as the assumed colour space when an image has no embedded colour profile. This shared default makes images look reasonably consistent across systems. PNG, JPEG, CSS colours, and canvas workflows commonly use sRGB values.
However, sRGB is not a complete description of a physical display. Two displays can show different colours for the same sRGB numbers because their panels, brightness, and calibration differ.
Common mistakes
- Treating
128as half the light intensity. - Assuming every RGB image is sRGB.
- Mixing sRGB and linear RGB values in one calculation.
- Comparing colours by raw channel distance when the spaces differ.
- Assuming an unprofiled image has a known camera or display colour space.
sRGB is a useful interoperability default. For wide-gamut photography, accurate printing, or colour-critical work, a wider colour space and an embedded ICC profile may be more appropriate.
Exercise
Why should an image-processing program decode sRGB values before physically correct blending?
Show answer
sRGB values are gamma encoded, so their numerical midpoint is not the midpoint of light intensity. Decoding produces linear-light values that can be blended correctly.