JFLib

img_core/icc_xform.rs#

Source: lib/img_core/icc_xform.rs

icc_xform -- ICC colour transforms                  [src/img/icc_xform.s, inc/icc.inc]

  IccXform::build(src, dst, intent, flags) -> IccXform | ERR_*
       src / dst = profile bytes (None = the built-in sRGB); intent ICC_* , flags
       ICF_BPC / ICF_NOIDENT / ICF_LUT.  ERR_TRUNC / ERR_HDR (broken profile, bad tag),
       ERR_UNSUPPORTED (CMYK / Lab / other device spaces, links, abstract, named colour,
       unknown tag types, gray LUT profiles, singular colorants, intent > 3), ERR_LIMIT
       (curv > 2^20 entries)  [icc_xform_build]
  xf.row(src, dst)        straight BGRA pixels (8 bit), alpha unchanged; any thread, no
                          allocation  [icc_xform_row]
  xf.row_in_place(px)     the same with src == dst
  xf.kind() -> ICX_*      [icc_xform_kind]
  icc_builtin(id) -> profile bytes (static) | None   ICC_BI_*  [icc_builtin]
  icc_describe(icc, buf) -> bytes   UTF-8 'desc' text, NUL-terminated  [icc_describe]
  set_parallel(f)         the loop that builds LUT grids (plat::parallel_for in the apps;
                          without one the grid planes are built one after the other)

Profiles: RGB and gray, v2 and v4, classes mntr / scnr / prtr / spac.  Matrix/TRC
(rXYZ gXYZ bXYZ + rTRC gTRC bTRC, gray kTRC; curv identity / gamma / table, para 0..4)
and LUT tags (A2B0..2 / B2A0..2 as lut8 / lut16 / mAB / mBA; PCS XYZ or Lab).  Tag choice
like LittleCMS: the intent's LUT tag (absolute: *1), else *0, else the matrix/TRC.
Media white for the absolute intent: wtpt (D50 for v2 display profiles, like lcms).

Paths (ICX_*): identical profiles -> copy; matrix/TRC on both sides -> ICX_MATRIX: per
channel f32 linearisation tables (256), one 3x3 f32 matrix (dst^-1 * adapt * src), linear
values clamped to 0..1, index round(sqrt(v) * 4096) into u8 inverse tables (4097 entries,
built by inverting 8193 forward samples of the destination TRC) -- a simd::Kernel, 4 (SSE2)
or 8 (AVX2) pixels per step, every lane computes what the assembly's SSE lane computes;
a result that maps every channel value to itself becomes ICX_IDENTITY.  Otherwise
ICX_LUT: the whole float64 pipeline (src -> PCS XYZ -> intent / BPC -> dst) sampled on a
33^3 grid whose node positions are (k/32)^2 per axis (dense near black), f32 per channel,
tetrahedral interpolation in f32 (grid planes on the worker pool, see set_parallel).  For
matrix/TRC (gray) destinations the grid holds the destination's LINEAR values, unclamped,
and every pixel ends like the matrix path (clamp, sqrt index, inverse TRC table); for B2A
destinations device values.  The tetrahedron is chosen without branches (a table over the
three comparisons of the assembly's decision tree, the weights as max / median / min of
the fractions): the same vertices and weights, no mispredictions on random pixels.

The handle of the assembly becomes a value (dropping it frees it); the parsing and the
float64 maths are in icc_eval, the built-in profiles and the description in icc_bi.
Deviation: out of memory aborts (Vec) instead of ERR_NOMEM.

icc.inc

ICC_PERCEPTUAL: u32 = 0  // rendering intents (ICC numbering)
ICC_RELATIVE: u32 = 1  // relative colorimetric
ICC_SATURATION: u32 = 2
ICC_ABSOLUTE: u32 = 3  // absolute colorimetric
ICF_BPC: u32 = 1  // black point compensation (not with ICC_ABSOLUTE)
ICF_NOIDENT: u32 = 2  // never take the identity shortcut (tests)
ICF_LUT: u32 = 4  // always use the 3D LUT path (tests)
ICX_IDENTITY: u32 = 0  // rows are copied
ICX_MATRIX: u32 = 1  // linearisation tables + 3x3 matrix + inverse tables
ICX_LUT: u32 = 2  // 33^3 3D LUT, tetrahedral interpolation
ICC_BI_SRGB: u32 = 0  // sRGB IEC61966-2.1 compatible
ICC_BI_A98: u32 = 1  // A98 RGB compatible (CSS Color 4 a98-rgb: D65, gamma 563/256)
ICC_BI_P3: u32 = 2  // Display P3
ICC_BI_ROMM: u32 = 3  // ROMM RGB (ISO 22028-2, D50, gamma 1.8)
ICC_BI_GRAY22: u32 = 4  // gray, gamma 2.2, D50
ICC_BI_COUNT: u32 = 5
ICC_MON_PRIMARY: i32 = -1  // plat::monitor_icc: the primary monitor
  • struct IccXform a colour transform between two profiles

  • fn set_parallel(f: ParallelFor) the loop the LUT grids are built with = img_core::set_parallel (kept for its callers)

impl IccXform

  • fn build(src: Option<&[u8]>, dst: Option<&[u8]>, intent: u32, flags: u32) -> Result<IccXform, i32> a transform from profile src to profile dst (None = the built-in sRGB) [icc_xform_build]
  • fn kind(&self) -> u32 ICX_IDENTITY / ICX_MATRIX / ICX_LUT [icc_xform_kind]
  • fn row(&self, src: &[u8], dst: &mut [u8]) dst.len() / 4 straight BGRA pixels from src (at least as long) to dst, alpha unchanged [icc_xform_row]
  • fn row_in_place(&self, px: &mut [u8]) row with src == dst: px.len() / 4 pixels converted in place

Source: docs/API.md in the JFLib repository.