pub struct Budget { /* private fields */ }Expand description
How much of a picture may be kept in memory at once.
Implementations§
Source§impl Budget
impl Budget
Sourcepub fn for_viewport(viewport: ViewportPixels) -> Budget
pub fn for_viewport(viewport: ViewportPixels) -> Budget
The budget for showing a picture in a given viewport.
Sourcepub fn for_edge(max_edge: u32) -> Budget
pub fn for_edge(max_edge: u32) -> Budget
A budget with an explicit edge, for a thumbnail or a filmstrip frame, where the size wanted is known exactly.
Sourcepub fn fit(&self, source: SourcePixels) -> DecodePixels
pub fn fit(&self, source: SourcePixels) -> DecodePixels
What source should be decoded to under this budget.
Aspect ratio is preserved, and a picture already inside the budget is decoded at its own size — never scaled up, which would allocate a buffer of invented pixels.
Sourcepub fn allows_source(&self, source: SourcePixels) -> bool
pub fn allows_source(&self, source: SourcePixels) -> bool
Whether a source this size may be decoded at all.
Sourcepub fn limits(&self) -> Limits
pub fn limits(&self) -> Limits
The limits handed to image’s decoder, which refuse an absurd
file before it allocates rather than after.
Built on Limits::default() rather than no_limits(), which
keeps that default’s 512MiB ceiling on decoder allocation.
Worth being precise about what that ceiling does, because it is
easy to credit it with more: measured on a 36-megapixel JPEG, the
peak is the same with it and without it (509MB either way
before the fix in decode). It is not what bounds the transient
cost, and the near-match between 509MB and 512MiB is coincidence —
the sort of suspiciously round number CLAUDE.md warns is usually
somebody else’s limit, which here it was not.
What it does buy is a refusal for a file whose header claims a size no allocator can serve, alongside the two edge caps. That is worth keeping; it is simply not a defence against a large ordinary photograph.
Sourcepub fn max_retained_bytes(&self) -> u64
pub fn max_retained_bytes(&self) -> u64
The most an image decoded under this budget can retain, in bytes. What a cache multiplies, and what a test asserts on.