Skip to main content

Module codes

Module codes 

Source
Expand description

Exact depth, placement, and range conversion of native integer codes.

A code is the unsigned integer that a SampleEncoding extracts from a storage word. Canonical U16 and U8 image samples are codes of the full word width: a canonical U16 white is 65535, never a ten-bit 1023. Native codecs keep their codes in CodePlane views; this module converts between those codes and canonical samples, or between two native encodings.

Role and rangeDepth change from N to M bitsInverse of a widening
Intensity (R′G′B′, gray, Y′), full rangeNearest (q·max(M) + max(N)/2) / max(N)Exact: every code returns
Intensity or chroma, narrow rangeq << (M−N); narrowing rounds half up, clamped to max(M)Exact
Alpha, any color rangeNearest full-scale, as full-range intensityExact
Chroma, full rangeRefused: neutral and span have no exact relation between depths—

max(N) = 2^N − 1; odd denominators make nearest rounding tie-free. Narrow range needs at least 8 bits so its anchors (16·2^(N−8) black, 128·2^(N−8) neutral) are integers.

Structs§

CodeMap
A checked conversion of one component from one SampleEncoding to another.

Enums§

CodeMapError
A code conversion cannot be performed exactly as requested.
CodeRole
What a component’s codes mean, which selects its depth-conversion rule.
CodesError
Native components cannot be widened into the requested canonical image.

Functions§

unpack_code_planes_into
Unpack and widen borrowed native component CodePlanes into a canonical strided PixelViewMut region starting at source_origin = (x, y) in each source plane.