Skip to main content

TransferLut

Struct TransferLut 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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);
Source

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

Source§

fn as_ref(&self) -> &[u8]

View the LUT as a byte slice (length 256).

Source§

impl Clone for TransferLut

Source§

fn clone(&self) -> TransferLut

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TransferLut

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Compact representation showing the first two and last entry only, avoiding a 256-element dump that would overwhelm debug output.

Source§

impl Default for TransferLut

Source§

fn default() -> TransferLut

Returns the “default value” for a type. Read more
Source§

impl From<[u8; 256]> for TransferLut

Source§

fn from(arr: [u8; 256]) -> TransferLut

Construct a TransferLut from a raw 256-entry array.

Source§

impl PartialEq for TransferLut

Source§

fn eq(&self, other: &TransferLut) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TransferLut

Source§

impl StructuralPartialEq for TransferLut

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.