Skip to main content

SoftCompress

Struct SoftCompress 

Source
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

Source

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 %.

Source

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.

Source

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.

Source

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.

Source

pub fn knee(&self) -> f32

Knee: the fraction of the largest in-gamut chroma where compression starts.

Trait Implementations§

Source§

impl Clone for SoftCompress

Source§

fn clone(&self) -> SoftCompress

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SoftCompress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SoftCompress

Source§

fn eq(&self, other: &SoftCompress) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SoftCompress

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.