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 iffbasedividesdepth(because2^base - 1divides2^depth - 1). For example, 8-bit full-range content inU16is exact at 8 and 16 bits, not at 10 or 12 bits; 3-bit content inU16does not embed inU8(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
impl ExactDepth
Sourcepub const fn new(
storage: SampleType,
range: SignalRange,
color_bits: u8,
alpha_bits: u8,
) -> Result<ExactDepth, ExactDepthError>
pub const fn new( storage: SampleType, range: SignalRange, color_bits: u8, alpha_bits: u8, ) -> Result<ExactDepth, ExactDepthError>
Sourcepub const fn new_opaque(
storage: SampleType,
range: SignalRange,
color_bits: u8,
) -> Result<ExactDepth, ExactDepthError>
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).
Sourcepub const fn storage(self) -> SampleType
pub const fn storage(self) -> SampleType
Storage the statement applies to (SampleType::U8 or SampleType::U16).
Sourcepub const fn range(self) -> SignalRange
pub const fn range(self) -> SignalRange
Signal range whose canonical rule defines the color grid.
Sourcepub const fn color_bits(self) -> u8
pub const fn color_bits(self) -> u8
Smallest proven exact color depth (1..=storage_bits, or 8..=storage_bits for narrow).
Sourcepub const fn alpha_bits(self) -> u8
pub const fn alpha_bits(self) -> u8
Smallest proven exact alpha depth (1..=storage_bits, always full scale).
Sourcepub const fn color_exact_at(self, bits: u8) -> bool
pub const fn color_exact_at(self, bits: u8) -> bool
Whether quantizing color to bits and widening back reproduces every sample.
Sourcepub const fn alpha_exact_at(self, bits: u8) -> bool
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.
Sourcepub const fn color_codes_recoverable_at(self, bits: u8) -> bool
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).
Sourcepub const fn validate_format(
self,
format: &PixelFormat,
) -> Result<(), ExactDepthError>
pub const fn validate_format( self, format: &PixelFormat, ) -> Result<(), ExactDepthError>
Validate that this evidence is compatible with format without requiring a pixel buffer.
Sourcepub fn measure(view: &PixelView<'_>) -> Result<ExactDepth, ExactDepthError>
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.
Sourcepub fn holds_for(self, view: &PixelView<'_>) -> Result<bool, ExactDepthError>
pub fn holds_for(self, view: &PixelView<'_>) -> Result<bool, ExactDepthError>
Whether every active sample of view lies on this statement’s color & alpha grids.
Sourcepub const fn intersect_same_buffer(
a: ExactDepth,
b: ExactDepth,
) -> Option<ExactDepth>
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.
Sourcepub const fn union_disjoint_regions(
a: ExactDepth,
b: ExactDepth,
) -> Option<ExactDepth>
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)whenlcm(a, b) <= storage_bits, otherwisestorage_bits(because full-ranged1-bit andd2-bit grids embed indiff bothd1andd2divided, ord == storage_bits).
Returns None if storage type or signal range disagree.
Trait Implementations§
Source§impl Clone for ExactDepth
impl Clone for ExactDepth
Source§fn clone(&self) -> ExactDepth
fn clone(&self) -> ExactDepth
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more