Skip to main content

DecodeLimits

Struct DecodeLimits 

Source
#[non_exhaustive]
pub struct DecodeLimits { pub memory_budget: u64, pub max_pixels: Option<u64>, pub downstream_bytes_per_pixel: u64, }
Expand description

The memory a caller allows one image decode, plus an optional operator pixel cap (decision 227 sources (a) and (c)).

The budget is supplied by the shell, normally half the machine’s physical memory; the engine never queries the machine itself, so a result is reproducible from its inputs.

§Examples

use pdfcer_image_codec::peak::DecodeLimits;

let limits = DecodeLimits::for_physical_memory(16 << 30)
    .with_max_pixels(Some(100_000_000))
    .with_downstream_bytes_per_pixel(4);
assert_eq!(limits.memory_budget, 8 << 30);
assert_eq!(limits.max_pixels, Some(100_000_000));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§memory_budget: u64

Heap bytes one decode may hold at its peak, including the samples it returns and downstream_bytes_per_pixel for every pixel.

§max_pixels: Option<u64>

Operator strict mode: the most pixels an image may declare. None (the default) means memory alone decides.

§downstream_bytes_per_pixel: u64

Bytes per pixel the caller allocates after the decode (an RGBA pixmap is 4, each spot plane 1), added to the codec’s own peak.

Implementations§

Source§

impl DecodeLimits

Source

pub const FALLBACK_MEMORY_BUDGET: u64

The budget used when no shell supplies one: 4 GiB on 64-bit targets, 1 GiB on 32-bit targets including wasm32.

Source

pub const fn new(memory_budget: u64) -> Self

A budget of memory_budget bytes, no pixel cap, nothing downstream.

Source

pub const fn for_physical_memory(physical_bytes: u64) -> Self

The default budget for a machine with physical_bytes of RAM: half of it, so a decode never competes for the whole machine.

Source

pub const fn with_max_pixels(self, max_pixels: Option<u64>) -> Self

Sets or clears the operator pixel cap.

Source

pub const fn with_downstream_bytes_per_pixel(self, bytes: u64) -> Self

Sets the bytes per pixel the caller allocates after the decode.

Trait Implementations§

Source§

impl Clone for DecodeLimits

Source§

fn clone(&self) -> Self

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 DecodeLimits

Source§

impl Debug for DecodeLimits

Source§

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

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

impl Default for DecodeLimits

Source§

impl Eq for DecodeLimits

Source§

impl Hash for DecodeLimits

Source§

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

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 DecodeLimits

Source§

fn eq(&self, other: &Self) -> 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 DecodeLimits

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, Ctx> BundleDefault<Ctx> for T
where T: Default,

Source§

fn default_with_context(_: Ctx) -> T

Creates a default value with the given context.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more