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 range | Depth change from N to M bits | Inverse of a widening |
|---|---|---|
| Intensity (R′G′B′, gray, Y′), full range | Nearest (q·max(M) + max(N)/2) / max(N) | Exact: every code returns |
| Intensity or chroma, narrow range | q << (M−N); narrowing rounds half up, clamped to max(M) | Exact |
| Alpha, any color range | Nearest full-scale, as full-range intensity | Exact |
| Chroma, full range | Refused: 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
SampleEncodingto another.
Enums§
- Code
MapError - A code conversion cannot be performed exactly as requested.
- Code
Role - What a component’s codes mean, which selects its depth-conversion rule.
- Codes
Error - 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 stridedPixelViewMutregion starting atsource_origin = (x, y)in each source plane.