#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.memory_budget: u64Heap 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: u64Bytes 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
impl DecodeLimits
Sourcepub const FALLBACK_MEMORY_BUDGET: u64
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.
Sourcepub const fn new(memory_budget: u64) -> Self
pub const fn new(memory_budget: u64) -> Self
A budget of memory_budget bytes, no pixel cap, nothing downstream.
Sourcepub const fn for_physical_memory(physical_bytes: u64) -> Self
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.
Sourcepub const fn with_max_pixels(self, max_pixels: Option<u64>) -> Self
pub const fn with_max_pixels(self, max_pixels: Option<u64>) -> Self
Sets or clears the operator pixel cap.
Sourcepub const fn with_downstream_bytes_per_pixel(self, bytes: u64) -> Self
pub const fn with_downstream_bytes_per_pixel(self, bytes: u64) -> Self
Sets the bytes per pixel the caller allocates after the decode.