pub struct TransferLut(pub [u8; 256]);Expand description
Re-export every public type from the color crate, including all
arithmetic helpers from color::convert.
Downstream modules within this crate can import everything they need with
a single use crate::types::*.
A per-channel lookup table: output[i] = lut[input[i]].
Always exactly 256 entries — one for every possible byte value. The type is
a newtype so that callers cannot accidentally pass a raw [u8; 256] in the
wrong argument position.
The inner field is pub intentionally: PDF transfer functions are arbitrary
256-entry tables, and the code that samples them needs direct write access.
Prefer [From<[u8; 256]>] for construction from an owned array.
Tuple Fields§
§0: [u8; 256]Implementations§
Source§impl TransferLut
impl TransferLut
Sourcepub const IDENTITY: TransferLut
pub const IDENTITY: TransferLut
The identity mapping: every value i maps to i.
This is the correct default when no PDF transfer function is active.
All 256 entries are initialised at compile time via a const loop using
a u8 counter so that the index-to-byte cast is lossless by type.
Sourcepub const INVERTED: TransferLut
pub const INVERTED: TransferLut
The per-byte inverting mapping: every value i maps to 255 - i.
Unlike invert_complement (which composes an
existing LUT with the complement), this is the standalone “negate” LUT —
suitable for test fixtures that need a non-identity transfer where the
output is easy to assert against. Same u8 loop-counter rationale as
IDENTITY: index-to-byte cast is lossless by type.
Sourcepub const fn apply(&self, v: u8) -> u8
pub const fn apply(&self, v: u8) -> u8
Apply the LUT to a single byte.
§Safety / infallibility
v is a u8, so v as usize is always in 0..=255. The inner array
is always 256 entries (enforced by the compile-time assertion
_ASSERT_LUT_LEN), so the index is always in bounds. This method
cannot panic.
Sourcepub fn invert_complement(&self) -> TransferLut
pub fn invert_complement(&self) -> TransferLut
Produce a new LUT where output[i] = 255 - self[255 - i].
Used by GraphicsState::set_transfer to derive the CMYK LUTs from the
RGB/gray LUTs, matching SplashState::setTransfer in SplashState.cc.
§Index safety
The closure index i comes from 0..256 (the length of the output
array), so 255 - i is always in 0..=255 — always a valid index into
the 256-entry self.0 array.
Sourcepub const fn as_array(&self) -> &[u8; 256]
pub const fn as_array(&self) -> &[u8; 256]
Return a reference to the raw 256-entry array.
Useful for memcpy-style copies into an external state block.
Sourcepub fn compose(&self, other: &TransferLut) -> TransferLut
pub fn compose(&self, other: &TransferLut) -> TransferLut
Compose two LUTs: apply self first, then other.
The returned LUT is equivalent to other.apply(self.apply(v)) for every
input byte v. This is the natural piping / chaining operation for
transfer functions.
§Examples
use color::TransferLut;
// Build an inversion LUT: i → 255 - i.
let mut inv_table = [0u8; 256];
for i in 0usize..=255 {
inv_table[i] = (255 - i) as u8;
}
let inv = TransferLut::from(inv_table);
// Composing inversion with itself gives the identity.
let composed = inv.compose(&inv);
assert_eq!(composed, TransferLut::IDENTITY);
// Composing with identity leaves any LUT unchanged.
let id = TransferLut::IDENTITY;
assert_eq!(inv.compose(&id), inv);
assert_eq!(id.compose(&inv), inv);Sourcepub fn compose_many(luts: &[&TransferLut]) -> TransferLut
pub fn compose_many(luts: &[&TransferLut]) -> TransferLut
Compose a slice of LUTs left-to-right, starting from the identity.
compose_many(&[a, b, c]) is equivalent to
IDENTITY.compose(a).compose(b).compose(c). An empty slice returns
IDENTITY.
Trait Implementations§
Source§impl AsRef<[u8]> for TransferLut
impl AsRef<[u8]> for TransferLut
Source§impl Clone for TransferLut
impl Clone for TransferLut
Source§fn clone(&self) -> TransferLut
fn clone(&self) -> TransferLut
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TransferLut
impl Debug for TransferLut
Source§impl Default for TransferLut
impl Default for TransferLut
Source§fn default() -> TransferLut
fn default() -> TransferLut
Source§impl PartialEq for TransferLut
impl PartialEq for TransferLut
Source§fn eq(&self, other: &TransferLut) -> bool
fn eq(&self, other: &TransferLut) -> bool
self and other values to be equal, and is used by ==.