sRGB (and display-p3) approximation errors

The Electro-Optical Transfer function (EOTF, or informally "gamma") for sRGB, and also for display-p3 which uses the same one, is defined in the sRGB standard, which (like many other broadcast-derived color space standards) uses a linear portion at very dark levels, to limit noise amplification, followed by a power function for medium-dark to lightest levels.

Here is a sample implementation, over the extended range:

function lin_sRGB(RGB) {
  // convert an array of sRGB values
  // where in-gamut values are in the range [0 - 1]
  // to linear light (un-companded) form.
  // https://en.wikipedia.org/wiki/SRGB
  // Extended transfer function:
  // for negative values,  linear portion is extended on reflection of axis,
  // then reflected power function is used.
  return RGB.map(function (val) {
    let sign = val < 0? -1 : 1;
    let abs = Math.abs(val);

    if (abs < 0.04045) {
      return val / 12.92;
    }

    return sign * (Math.pow((abs + 0.055) / 1.055, 2.4));
  });

Some people approximate this transfer function with a simple power law. The best fit (lowest error) is an overall gamma of 2.223. The relative luminance error is then symmetric, and bounded to -0.517% to 0.5127%.

Other people (and this applies to the APCA algorithm) simply copy the 2.4 exponent value from the full sRGB equation, without considering how the piecewise formula affects it, producing much larger errors. The relative luminance error is asymmetric, and bounded by -2.517% to 0%.

Both approximations under-estimate the relative luminance for dark colors. The 2.4 approximation greatly under estimates it for all colors, being worst in the mid range. Here is a graph of the error, over the in-gamut range: The 2.223 approximation is in black, the 2.4 approximation in red. In addition, if the 2.4 approximation is considered as a deliberate midtone shaper, the effect of a (2.4/2.223) power law after conversion to luminance is shown in green.

view source
Download SVG

Further reading

Further information on this hotly debated topic (includes quotes from people like Jack Holm, technical secretary IEC/TC 100/TA 2 which developed the sRGB standard, and noted expert Charles Poynton):

sRGB EOTF: Pure Gamma 2.2 Function or Piece-Wise Function?