Skip to main content

Module gamut_compress

Module gamut_compress 

Source
Expand description

Soft gamut compression in OKLch: reduces chroma near and past the boundary of a set of primaries, keeping hue and lightness.

Scaling OKLab chroma by s at constant L and hue is a straight blend in cube-root LMS, x'(s) = L + s (x' - L), because the a and b rows of that matrix sum to zero and the L row sums to one. Each RGB channel is therefore a cubic in s, and the gamut boundary is its first crossing of 0 or 1. That needs no hue, atan2, square root or lookup table, so it vectorizes directly:

  1. A gate in linear RGB passes interior pixels through bit-identical. Only those it rejects reach the solve, packed into full SIMD batches.
  2. A chord from gray to the input starts each lane before its first crossing.
  3. Three Newton steps find the crossing, and a rational knee sets the new chroma.

Measurements and comparisons are in docs/gamut-mapping-survey.md, and the harness is benchmarks/gamut-compress.

Structsยง

SoftCompress
Soft chroma compression for one set of primaries.