pub struct PyramidPlanner { /* private fields */ }Expand description
Configuration builder for pyramid tile generation.
Holds the source image dimensions, tile size, overlap, and target layout.
Call PyramidPlanner::plan to compute a complete PyramidPlan that
describes every level and tile coordinate in the pyramid.
Constructing a PyramidPlanner validates all parameters up-front, so
downstream code can assume the configuration is sane.
§Example usage
Implementations§
Source§impl PyramidPlanner
impl PyramidPlanner
Sourcepub fn new(
image_width: u32,
image_height: u32,
tile_size: u32,
overlap: u32,
layout: Layout,
) -> Result<Self, PlannerError>
pub fn new( image_width: u32, image_height: u32, tile_size: u32, overlap: u32, layout: Layout, ) -> Result<Self, PlannerError>
Create a new PyramidPlanner after validating all parameters.
Returns PlannerError if any dimension is zero, tile size is zero,
or overlap is not strictly less than tile size.
Sourcepub fn with_centre(self, centre: bool) -> Self
pub fn with_centre(self, centre: bool) -> Self
Enable or disable centring the image within the tile grid.
Sourcepub fn plan(&self) -> PyramidPlan
pub fn plan(&self) -> PyramidPlan
Compute the full pyramid plan.
Builds every LevelPlan from level 0 (1x1) up to the full-resolution
level, computing tile grid dimensions at each step. The returned
PyramidPlan is a pure data structure with no side-effects; it can
be queried, serialised, or handed to a tile-writing executor.
§Example usage
Sourcepub fn estimate_peak_memory(&self) -> u64
pub fn estimate_peak_memory(&self) -> u64
Estimates the peak heap memory (in bytes) that
generate_pyramid_observed will
consume for this planner configuration.
The estimate covers the two largest allocations that coexist at peak:
-
Source raster — the caller-owned RGBA8 image passed by reference to
generate_pyramid_observed. Size:image_width × image_height × 4. -
Canvas raster — when centring is enabled, the engine embeds the source into a padded canvas before downscaling. For
Googlelayout this canvas is square (2^z × tile_sizeper side) and can be significantly larger than the source. ForDeepZoom/Xyzlayouts the canvas is rectangular, padded to the tile grid boundary.
These two allocations coexist because the engine receives the source
by shared reference (&Raster) while it allocates the canvas
internally. The first downscale step frees the canvas and replaces it
with a quarter-sized copy, so the peak occurs at canvas creation.
The estimate does not include PNG encoding buffers, filesystem I/O buffers, or process baseline memory — only raster pixel buffers. For container memory budgeting, add 200–500 MB of headroom on top of this value.
This method is cheap (no heap allocation, no I/O) and can be called before rendering to verify that the pipeline will fit in available memory, enabling callers to reduce DPI or reject oversized inputs before committing to an expensive render.
§Examples
use libviprs::{PyramidPlanner, Layout};
let planner = PyramidPlanner::new(16820, 11888, 256, 0, Layout::Google)
.unwrap()
.with_centre(true);
let peak = planner.estimate_peak_memory();
// 16820×11888 → 66×47 tiles → z=7 → canvas 32768² → ~4.8 GB peak
assert!(peak > 4_000_000_000);
// Use this to gate rendering:
let memory_budget: u64 = 1_500_000_000; // 1.5 GB
if peak > memory_budget {
// reduce DPI and retry with smaller dimensions
}Sourcepub fn canvas_dimensions(&self) -> (u32, u32)
pub fn canvas_dimensions(&self) -> (u32, u32)
Computes the canvas dimensions that plan would produce,
without building the full PyramidPlan.
For Google layout the canvas is square: tile_size × 2^(n_levels−1)
per side. For DeepZoom/Xyz layouts the canvas is rectangular,
padded to the tile grid boundary at the top level.
When centring is disabled, returns the original image dimensions (no padding).
This is a pure computation with no allocations.
Trait Implementations§
Source§impl Clone for PyramidPlanner
impl Clone for PyramidPlanner
Source§fn clone(&self) -> PyramidPlanner
fn clone(&self) -> PyramidPlanner
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PyramidPlanner
impl RefUnwindSafe for PyramidPlanner
impl Send for PyramidPlanner
impl Sync for PyramidPlanner
impl Unpin for PyramidPlanner
impl UnsafeUnpin for PyramidPlanner
impl UnwindSafe for PyramidPlanner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more