pub struct SoftCompress { /* private fields */ }Expand description
Soft chroma compression for one set of primaries.
Below knee times the largest in-gamut chroma at a pixel’s lightness and hue,
colors pass through unchanged. Above it, chroma rolls off along a rational curve
that’s continuous in value and slope at the knee and approaches the boundary.
Hue and lightness are kept. Results stay within about 0.001 of the cube, so a
final clamp is still needed.
Cheap to construct, with no table and no allocation.
§Examples
use zenpixels_convert::tonemap::SoftCompress;
use zenpixels_convert::oklab::OklabSpace;
use zenpixels_convert::Primaries;
let space = OklabSpace::for_primaries(Primaries::Bt709).unwrap();
let compress = SoftCompress::new(&space, SoftCompress::DEFAULT_KNEE);
let mut pixels = [[1.2_f32, 0.05, 0.05]]; // out-of-gamut red
compress.apply_strip(&mut pixels);
assert!(pixels[0].iter().all(|&c| (-1e-3..=1.0 + 1e-3).contains(&c)));Implementations§
Source§impl SoftCompress
impl SoftCompress
Sourcepub const DEFAULT_KNEE: f32 = 0.96
pub const DEFAULT_KNEE: f32 = 0.96
Production default knee: the fraction of the largest in-gamut chroma where the rolloff begins. From a sweep of 76 imazen-26 gain-mapped HDR images on 2026-06-23, the largest value whose corpus-p90 share of pre-clamp out-of-gamut pixels stayed under 0.1 %.
Sourcepub fn new(space: &OklabSpace, knee: f32) -> Self
pub fn new(space: &OklabSpace, knee: f32) -> Self
A compressor for space. knee is in 0.0..=1.0, and 1.0 maps to the
boundary with no rolloff.
Knees under about 0.5 reach far beyond the boundary, where the solve hasn’t been qualified.
Sourcepub fn apply_strip(&self, rgb: &mut [[f32; 3]])
pub fn apply_strip(&self, rgb: &mut [[f32; 3]])
Compress a row of linear RGB pixels in place.
Interior pixels stay bit-identical. Non-finite channels, and magnitudes above about 1e38, pass through unchanged.
Sourcepub fn compress_oklab_planes(
&self,
l: &[f32],
a: &mut [f32],
b: &mut [f32],
) -> Result<(), At<ConvertError>>
pub fn compress_oklab_planes( &self, l: &[f32], a: &mut [f32], b: &mut [f32], ) -> Result<(), At<ConvertError>>
Compress OKLab planes in place, leaving l as is. For pipelines that already
hold planar OKLab. Equivalent to converting to RGB and using
apply_strip, up to rounding.
§Errors
DimensionMismatch when a or b differs in
length from l, leaving both untouched.
Trait Implementations§
Source§impl Clone for SoftCompress
impl Clone for SoftCompress
Source§fn clone(&self) -> SoftCompress
fn clone(&self) -> SoftCompress
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more