mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
* Add craft-color-transform: RGB spaces, white balance, OkLab, tone curves and PQ tone mapping craft-color-transform builds on craft-color. It holds RGB spaces from primaries and a white point with Bradford adaptation, white balance by correlated color temperature and tint, OkLab and OkLCh for any RGB space, monotone tone curves and 1D lookup tables, and the BT.2408-8 Annex 5 EETF with a maxRGB tone map. The per-pixel functions take f32 and do not allocate, and the crate builds for wasm32-unknown-unknown. Moved from StudioCraft's craft-color-transform (blamejs/StudioCraft crates/craft-color-transform). The README names the LightCraft and FilmCraft modules parts of it started from. * Color transform: compose, interpolate and invert at extreme values Lut1::compose samples the densest grid of at most MAX_LUT entries that holds both tables' points, so a short inner table, or one that crosses an outer peak between its own points, keeps the outer table's points to within one grid step. Lut1::eval weights the two entries in f64, so entries as far apart as -f32::MAX and f32::MAX no longer give NaN or infinity. MonotoneCurve::new compares the tangent pair's length with 3|d|, so a subnormal secant next to a normal one no longer gives a NaN tangent. Mat3::inverse divides the matrix by its largest entry before taking the determinant, so diag(1e110) and diag(1e-200) invert. OkLab::for_space falls back to XYZ_TO_LMS when a matrix has no inverse or an entry beyond f32. * Color transform: build the matrix arithmetic on craft_cms::math craft_cms::math gains the two hardened functions the color transforms need, and craft-color-transform calls them instead of carrying its own copies. - math::inverse divides the matrix by its largest entry before taking the determinant, so a matrix whose own determinant overflows or underflows still inverts, and it returns None for NaN, infinite or all-zero input and for an inverse beyond f64. math::invert keeps its absolute 1e-12 floor, which profile construction uses to validate ICC matrices. - math::bradford_checked returns None when a white's cone response is not finite or not above 0, or the ratios overflow. math::bradford still divides without the check. - math::BRADFORD is public. - Mat3::mul, apply, determinant and inverse, Xy::to_xyz, BRADFORD and bradford_xyz call craft_cms::math. - oklab::lms_matrices gives OkLab::for_space's matrices in f64. * Color transform: keep the EETF's black lift rising for a high target black The BT.2408 Annex 5 lift minLum * (1 - E2)^4 has a slope of 1 - 4 minLum at E2 = 0, so a target black above a quarter of the normalized range made the output fall near black, and it raised the peak well above the target peak. The lift is now minLum * (1 - E2 / r)^k with r = max(T, min(1, 2 - 4 minLum)) and k = min(4, r / minLum), where T is the top of the output (the smaller of maxLum and 1). It equals the Annex's lift up to minLum 0.25, keeps the output rising, changes continuously with the target black, and from minLum 0.5 reaches 0 at the top of the output. A target black above the source peak reads as the source peak. * Color transform: state the composition bound for the fallback grid