Skip to main content

ExactDepth

Struct ExactDepth 

Source
pub struct ExactDepth { /* private fields */ }
Expand description

Proven exact code depth of the current samples of a canonical U8/U16 image.

color_bits = N states that every current color sample v survives re-quantization to N-bit codes: narrowing it to N bits and widening back to storage depth reproduces v exactly, using the canonical rule for range:

  • Full range: nearest full-scale rescaling ((q * max(M) + max(N)/2) / max(N)). Full-range grids nest iff base divides depth (because 2^base - 1 divides 2^depth - 1). For example, 8-bit full-range content in U16 is exact at 8 and 16 bits, not at 10 or 12 bits; 3-bit content in U16 does not embed in U8 (8 % 3 != 0).
  • Narrow range: power-of-two anchor scaling (q << (M - N)). Narrow grids require at least 8 bits and nest monotonically (depth >= base).
  • Alpha: always full scale, tracked independently in alpha_bits.

Implementations§

Source§

impl ExactDepth

Source

pub const fn new( storage: SampleType, range: SignalRange, color_bits: u8, alpha_bits: u8, ) -> Result<ExactDepth, ExactDepthError>

State that current color and alpha samples are exact at the given depths.

Checked for consistency with storage and range; does not inspect pixel bytes. Use measure or holds_for to verify untrusted buffers.

Source

pub const fn new_opaque( storage: SampleType, range: SignalRange, color_bits: u8, ) -> Result<ExactDepth, ExactDepthError>

Convenience for formats without an alpha channel: states that color channels are exact at color_bits (setting alpha_bits to full storage depth, matching measure).

Source

pub const fn storage(self) -> SampleType

Storage the statement applies to (SampleType::U8 or SampleType::U16).

Source

pub const fn range(self) -> SignalRange

Signal range whose canonical rule defines the color grid.

Source

pub const fn color_bits(self) -> u8

Smallest proven exact color depth (1..=storage_bits, or 8..=storage_bits for narrow).

Source

pub const fn alpha_bits(self) -> u8

Smallest proven exact alpha depth (1..=storage_bits, always full scale).

Source

pub const fn color_exact_at(self, bits: u8) -> bool

Whether quantizing color to bits and widening back reproduces every sample.

Source

pub const fn alpha_exact_at(self, bits: u8) -> bool

Whether quantizing alpha to bits and widening back reproduces every sample.

Alpha is always full scale. alpha_bits == 1 allows both transparent and opaque samples; it does not by itself prove an opaque image.

Source

pub const fn color_codes_recoverable_at(self, bits: u8) -> bool

Whether the color_bits-deep color codes remain recoverable at bits (weaker than exactness).

Source

pub const fn validate_format( self, format: &PixelFormat, ) -> Result<(), ExactDepthError>

Validate that this evidence is compatible with format without requiring a pixel buffer.

Source

pub fn measure(view: &PixelView<'_>) -> Result<ExactDepth, ExactDepthError>

Measure the smallest depths whose grids hold every active sample in view.

Color and alpha are measured separately; without real alpha, alpha_bits is the storage depth. Reads only active samples (never row padding or an RGBX/BGRX padding slot) and exits early once only storage depth remains.

Source

pub fn holds_for(self, view: &PixelView<'_>) -> Result<bool, ExactDepthError>

Whether every active sample of view lies on this statement’s color & alpha grids.

Source

pub const fn intersect_same_buffer( a: ExactDepth, b: ExactDepth, ) -> Option<ExactDepth>

Intersect two ExactDepth claims that both describe the same sample set, returning the tighter proven depth (min) for matching storage & range.

Taking min (rather than gcd) is intentionally sound under integer rounding: rounded non-divisor full-range grids can intersect outside gcd (for example, U16 value 64 lies on both the 10-bit and 12-bit grids, but not on the 2-bit grid).

This is for merging independent evidence about the same buffer (e.g., caller policy claims plus buffer claims). To merge evidence from disjoint strips or regions of an image into a common containing grid, use ExactDepth::union_disjoint_regions.

Source

pub const fn union_disjoint_regions( a: ExactDepth, b: ExactDepth, ) -> Option<ExactDepth>

Merge two ExactDepth measurements from disjoint strips or regions of the same image into the smallest common containing grid holding every sample from both regions.

  • Narrow range: monotonic max(a, b) (power-of-two anchor grids nest monotonically).
  • Full range: lcm(a, b) when lcm(a, b) <= storage_bits, otherwise storage_bits (because full-range d1-bit and d2-bit grids embed in d iff both d1 and d2 divide d, or d == storage_bits).

Returns None if storage type or signal range disagree.

Trait Implementations§

Source§

impl Clone for ExactDepth

Source§

fn clone(&self) -> ExactDepth

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 Copy for ExactDepth

Source§

impl Debug for ExactDepth

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for ExactDepth

Source§

impl Hash for ExactDepth

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ExactDepth

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ExactDepth

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.