Skip to content
Back to blog
Field notes · accessibility

Most CVD Simulators Skip sRGB Gamma. That Makes Red Two Stops Too Dark.

Skip the sRGB gamma decode and Brettel 1997 protanopia turns #FF0000 into #4F4F4F instead of #828282. How to run Brettel, Viénot and Machado in linear light.

7 min readSimon Wong

Take a flat patch of pure red, #FF0000. In sRGB the byte 255 means "the brightest red the display can show," but in linear light — the space where the eye's L, M, S cone responses actually add up — that byte decodes to 1.0, not 255 / 255 = 1.0 after a linear divide-by-255. Skip the IEC 61966-2-1 gamma decode and you simulate cone projections on numbers that are wrong by 1.0 − (255/255)^2.4 ≈ 0 at the white end, but as much as 0.5 − 0.5^2.4 ≈ 0.31 at mid-gray. The error is largest exactly where most photos live.

Feed #FF0000 to the DaltonLens-Python Brettel-1997 reference for protanopia. Correct (sRGB-decoded) result: #828282. Most consumer CVD simulators on Google instead multiply [1, 0, 0] straight through the LMS matrices and re-encode the answer as sRGB, returning #4F4F4F. Same algorithm, same matrices — the only difference is whether (c/255) ** 2.4 was applied before and c ** (1/2.4) after. The gamma-skipping result is about 1.6 stops too dark, and the relative luminance is off by roughly 6×.

This simulator runs Brettel 1997, Viénot 1999, and Machado 2009 inside an sRGB → linear → operate → linear → sRGB pipeline, with decode compiled to a 256-entry Float64 LUT so the per-pixel hot path contains zero calls to Math.pow. It also refuses to run Viénot 1999 on tritanopia, because Viénot's own paper says the single-matrix simplification fails there.

The sRGB Gamma Trap

sRGB is a piecewise function. From IEC 61966-2-1:1999 Annex A, decode:

linear = c / 12.92                        if c <= 0.04045
linear = ((c + 0.055) / 1.055) ** 2.4     otherwise

with c = byte / 255. Encode is the inverse, with breakpoint 0.0031308. The linear toe near zero keeps quantization noise bounded near black. Above 11/255 the curve is the pure 2.4 power law that gives sRGB its perceptual uniformity. WCAG 2 contrast ratios decode with the same function; APCA uses a pure 2.4 power instead.

CVD simulation requires linear light because cone responses are physically linear in retinal photon flux. The Smith-Pokorny LMS basis used by Viénot 1999 and Brettel 1997 is defined on linear-RGB inputs. Applying the LMS matrix to gamma-encoded bytes projects onto cone axes that do not exist in the eye. The output is deterministic, repeatable, and wrong.

The 256-entry decode LUT pays for itself instantly:

export const SRGB_TO_LINEAR_LUT: Float64Array = (() => {
  const lut = new Float64Array(256);
  for (let i = 0; i < 256; i += 1) {
    const c = i / 255;
    lut[i] = c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
  }
  return lut;
})();

A 1080p image is ~6.2M decode operations. Replacing the formula with SRGB_TO_LINEAR_LUT[byte] swaps three FP multiplies and one transcendental for one array index — about 4× the throughput on M1, with Float64 keeping every entry within 1 ULP of the analytical answer. The image color picker builds the same table as the first step of its sRGB → CIELAB conversion.

Viénot 1999 Has a Footnote That Most Implementations Ignore

Viénot, Brettel & Mollon (1999)1520-6378(199908)24:4%3C243::AID-COL5%3E3.0.CO;2-3) published a single-matrix dichromat simulation that is a closed-form linear-RGB → linear-RGB 3×3. It works because the protanopia and deuteranopia confusion lines, projected from LMS through the Smith-Pokorny basis, are nearly co-planar — the two Brettel 1997 half-planes collapse into one matrix with low error. For protan and deutan the simplification is exact enough that nobody runs Brettel for those CVDs anymore.

The paper's own text says plainly that the trick does not work for tritanopia. The two tritan half-planes in LMS are well separated; collapsing them into one matrix produces a discontinuity at the neutral axis and ΔE errors in the high teens on saturated blues. The "Viénot tritan" 3×3 that floats around the web is a mathematical extrapolation the original paper explicitly disclaims.

The simulator codes the rule directly:

export type VienotCVD = "protan" | "deutan";

export function isVienotSupported(cvd: DichromaticCVD): cvd is VienotCVD {
  return cvd === "protan" || cvd === "deutan";
}

The UI surfaces a warning when a user selects Viénot + tritanopia, and the effectiveAlgorithm field auto-falls back to Brettel 1997 for tritan / tritanomaly. The numerical result the user sees is always the algorithm the algorithm's author endorsed for that CVD type. This is the smallest difference between this tool and the simulators on the SERP first page — they will happily apply a Viénot tritan matrix and produce visibly wrong purples, and most of them never tell the user the result is unreliable.

Three Algorithms, Three Different Severity Models

Brettel, Viénot, and Machado are three different recipes, not three flavors of the same one. They differ in how anomalous trichromacy (partial CVD) is modeled.

Brettel 1997 is a dichromat-only projection. Full-strength result is H1 · linear or H2 · linear depending on the sign of dot(separating_plane, linear). Anomaly is faked by lerping in linear-RGB: (1 − s) · input + s · projection. The lerp is equivalent to lerping in LMS because every matrix here is linear.

Viénot 1999 collapses Brettel's two half-planes into one matrix. Same severity lerp, same neutral preservation, with the tritan failure above.

Machado 2009 (IEEE TVCG, DOI 10.1109/TVCG.2009.113) publishes 11 matrices per CVD type — one at each severity 0.0, 0.1, …, 1.0 — derived from a physiological model that interpolates the L (or M, or S) cone's peak sensitivity wavelength. Anomaly is implemented by interpolating the matrix coefficients themselves in linear-RGB, then applying once. Sanity check: deuteranopia at severity 1.0 gives Machado · linear(1, 0, 0) = (0.367322, 0.280085, −0.011820) exactly, from Table 1. The unit test pins this triple.

The tool exposes all three so a user can A/B them — that is how you see that "deuteranopia at severity 50" means three different images depending on which paper you cite.

The Pixel Loop That Inlines

The hot path is shared between main thread and Web Worker; the worker kicks in past 250K pixels (about 500 × 500), measured to keep a 60Hz frame's main-thread budget under 16 ms. Algorithm selection happens once, outside the loop, because V8's inliner gives up past ~30 LOC and an inner branch costs about 1.5× the throughput on a 1080p photo:

const m = VIENOT_MATRICES[dichromat];
const m00 = m[0][0], m01 = m[0][1], m02 = m[0][2];
// ... destructure 9 coefficients into locals
for (let i = 0; i < n; i += 4) {
  const lr = SRGB_TO_LINEAR_LUT[src[i]];
  const lg = SRGB_TO_LINEAR_LUT[src[i + 1]];
  const lb = SRGB_TO_LINEAR_LUT[src[i + 2]];
  const dr = m00 * lr + m01 * lg + m02 * lb;
  // ... two more rows
  dst[i] = linearToSrgb8(or);
  // ... two more channels + alpha passthrough
}

Destructuring the matrix into nine locals reads ugly. It also lets V8 keep the coefficients in registers across the whole loop. The Brettel branch repeats the shape with eighteen locals, and the Machado severity-interpolated matrix is computed once per frame (the same matrix applies to every pixel at the same severity). The encode side is the only Math.pow in the inner loop — no useful LUT exists for it because the input is a Float64 with 2^53 possible values.

Brettel adds one runtime conditional per pixel for the H1/H2 selection. Branch prediction handles it well on M1 since gradient images are spatially coherent in cone space; the throughput penalty vs Viénot is around 8%.

Try It

Open the Color Blindness Simulator.

  • Gamma-skipping demo: paste hex #FF0000, pick Brettel + protanopia. Output: #828282. Sites that skip gamma return #4F4F4F — a 6× relative-luminance difference from the same paper.
  • Neutral invariance: #808080, protanomaly severity 50 → #808080 exactly. All three matrices map the achromatic line to itself.
  • Viénot tritan refusal: select Viénot + tritanopia. The UI warns citing Viénot 1999, and effective algorithm shows brettel. Switch to deuteranopia and the badge returns to vienot.
  • Machado vs Brettel at severity 1.0, deuteranopia: input linear (1, 0, 0). Machado returns (0.367322, 0.280085, −0.011820) exactly, per Table 1. Brettel returns the geometry projection. The two answers disagree by ~12 ΔE76 because the questions are different.
  • Achromatopsia exact: #FF0000 → #363636, #00FF00 → #B6B6B6, #0000FF → #121212. BT.709 luma of each primary, with gamma decode applied first.

The differentiator is mechanical: one IEC standard, one cone-space matrix, one footnote in a 1999 paper that everybody else missed.