What a pixel number means
A renderer adds contributions from lights, interpolates texture samples and blends layers. These operations have a physical interpretation only after we say what the numbers represent.
Definition 3.6.1
(Linear-light channel and display code)
Here is a normalized, nonnegative linear-light channel: doubling doubles the modeled light in that channel. A stored or displayed code may instead be a nonlinear encoding of . RGB operations below are componentwise in one fixed RGB color space; linearity alone does not make values in different primaries interchangeable. Alpha is a coverage or opacity parameter, not a color channel, and is not passed through a color transfer function.
For a concrete calculation, use the standard sRGB encoding on .
Definition 3.6.2
(sRGB encoding and decoding)
The encoding is
Its conventional approximate inverse, with rounded breakpoints, is
The breakpoint constants are rounded: the two displayed pieces do not meet exactly, and is not an exact inverse in a tiny neighborhood of the join. The concavity argument below applies on a continuous interval, such as the nonlinear branch, rather than across that rounded join. This is an encoding convention, not a claim that every display produces exact light output . Actual color management, display calibration, tone mapping and out-of-range values require additional decisions. A power law is a useful simplified model, but is not the exact sRGB formula.
Why averaging codes changes the result
Suppose a pixel covers two equally large regions with linear intensities . Under a linear area-average model its correct linear value is , and its code is . Averaging the codes instead produces . These are different in general.
Theorem 3.6.3
(Nonlinear encoding does not preserve averages)
Let be continuous and strictly concave on an interval containing distinct . For ,
Thus averaging encoded values and decoding produces a smaller linear result than averaging the original linear values, provided is also strictly increasing.
Proof
(Concavity pulled back through the decoder)
The displayed inequality is the definition of strict concavity. Applying the increasing inverse preserves its direction and yields . The nonlinear branch of sRGB is strictly concave for positive : its second derivative is with , which is negative. On the linear toe the inequality is equality; do not claim it is strict for every possible pair of sRGB values.
Worked example 3.6.4
(Black and white in equal parts)
For equally weighted black and white, linear averaging gives and . Averaging the codes gives , which decodes to . A midpoint in code space therefore has less than half the intended linear intensity in this example. This same distinction applies to texture filtering when the filter represents an average of light-like color values.
Worked example 3.6.5
(Two mid-range regions)
Take and with equal area. The light average is , with code . The codes are and , whose mean is . Decoding that mean gives , in agreement with the theorem: the code average is darker than the light average, though by less than in the black-and-white case because the endpoints are closer together.
Blending and texture data
Concept lensAnalytic
Averaging codes as a different kind of mean
Averaging codes and then decoding is itself an averaging rule, , the mean generated by the encoding. For the power-law model it is the power mean of order , which never exceeds the arithmetic mean and equals it only when . With , the values and give about , close to the found for sRGB, and and give about .
For a foreground with linear color , opacity , and an opaque linear background , the over operation gives . Encode for storage or display only after the blend.
Worked example 3.6.6
(A quarter-opaque white over black)
With , and , the blend is and its code is . Alpha itself remains in either representation; it is not encoded.
Common mistake
(Scaling the code by )
Multiplying the white code by gives code , which decodes to approximately rather than . The blend is linear in light, not in codes; decode first, blend, then encode.
A practical pipeline must know which textures hold encoded color and which hold numerical data.
Common mistake
(Decoding data textures as color)
Normal maps, masks and roughness parameters are not automatically light intensities: applying an sRGB decode to them changes their meaning. The conversion must follow what the stored numbers represent, not merely the fact that they sit in a texture.
A texture format or API can perform some conversions automatically, but only if configured for the intended data and operation; check the actual API and framebuffer settings rather than assuming all samples and blends are linear. Premultiplying a color by alpha also belongs in the chosen linear representation, before encoding for storage if that storage convention calls for encoding. Consult the actual format's contract before interpreting stored premultiplied values.
Counterexample and limits
Averaging two encoded values is not inherently an invalid arithmetic operation: it can be the intended interpolation of codes. It is simply not the same operation as averaging light. For a toy encoding , the encoded midpoint of and is , corresponding to linear intensity , while the light midpoint is .
Counterexample mode
Averaged codes are not always darker
The claim: for every pair of distinct sRGB light values, the average of the codes is strictly below the code of the average. Take and ; both, and their midpoint , lie in the linear toe , where . Then : equality, not a strict inequality. The theorem needs strict concavity on an interval containing both values, and the toe is linear rather than strictly concave.
The error depends on the data and operation, not on a universal fixed correction.
The three channels do not describe every possible spectrum uniquely. Nor does encoding alone account for tone mapping high dynamic range to a display, gamut conversion, clipping, or perceptual uniformity. A numerically correct linear blend may still look different on differently calibrated displays.
Exercises
Quick check
(A pixel covers one quarter white and three quarters black. Find its linear intensity and sRGB code. Why is the code not ?)
Average in linear light, then encode.
Solution · Answer
, so . The code is nonlinear; is the light average, not its encoded representation.
Quick check
(Decode an sRGB code of , then double the resulting linear intensity. Encode the result without clipping. Compare it with doubling the code.)
Use , double, then .
Solution · Answer
, doubled is , and . Doubling the code gives , the code for linear intensity , a different result. Both values stay in range in this example.
Quick check
(Two linear values and have equal weights. Does sRGB encoding commute with this average? Explain.)
Check which branch of contains the inputs and their midpoint.
Solution · Answer
Yes. Both inputs and their midpoint lie in the linear branch, where ; multiplication by a constant commutes with averaging.
Quick check
(A normal-map component and an alpha mask are stored as ordinary numerical values. Should either be decoded as sRGB merely because it is stored in a texture? Explain.)
Ask what the stored number means.
Solution · Answer
No. Their meaning determines the conversion. Treating data as encoded color changes the values; alpha is not sRGB color. The texture format and sampler configuration must agree with that intent.