Skip to main content

PyramidPlanner

Struct PyramidPlanner 

Source
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

Source

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.

Source

pub fn with_centre(self, centre: bool) -> Self

Enable or disable centring the image within the tile grid.

Source

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
Source

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:

  1. Source raster — the caller-owned RGBA8 image passed by reference to generate_pyramid_observed. Size: image_width × image_height × 4.

  2. Canvas raster — when centring is enabled, the engine embeds the source into a padded canvas before downscaling. For Google layout this canvas is square (2^z × tile_size per side) and can be significantly larger than the source. For DeepZoom/Xyz layouts 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
}
Source

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

Source§

fn clone(&self) -> PyramidPlanner

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PyramidPlanner

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V