Skip to main content

ResamplingPlan

Trait ResamplingPlan 

Source
pub trait ResamplingPlan<T: Copy, const N: usize> {
    // Required methods
    fn resample(
        &self,
        store: &ImageStore<'_, T, N>,
        into: &mut ImageStoreMut<'_, T, N>,
    ) -> Result<(), PicScaleError>;
    fn resample_with_scratch(
        &self,
        store: &ImageStore<'_, T, N>,
        into: &mut ImageStoreMut<'_, T, N>,
        scratch: &mut [T],
    ) -> Result<(), PicScaleError>;
    fn alloc_scratch(&self) -> Vec<T>;
    fn scratch_size(&self) -> usize;
    fn target_size(&self) -> ImageSize;
    fn source_size(&self) -> ImageSize;
}
Expand description

A precomputed resampling plan for scaling images of pixel type T with N channels.

A plan is created once via methods like [plan_rgba_resampling] or [plan_rgb_resampling] on a scaler, and can then be executed repeatedly against different image buffers of the same dimensions without recomputing filter weights.

Required Methods§

Source

fn resample( &self, store: &ImageStore<'_, T, N>, into: &mut ImageStoreMut<'_, T, N>, ) -> Result<(), PicScaleError>

Resamples store into into, allocating any necessary scratch memory internally.

This is the simplest way to execute a plan. If you are resampling many images in a tight loop and want to avoid repeated allocations, prefer [resample_with_scratch] with a buffer obtained from [alloc_scratch].

Source

fn resample_with_scratch( &self, store: &ImageStore<'_, T, N>, into: &mut ImageStoreMut<'_, T, N>, scratch: &mut [T], ) -> Result<(), PicScaleError>

Resamples store into into using the caller-supplied scratch buffer.

Avoids internal allocation on every call, which is useful when resampling many images of the same size. The scratch buffer must be at least [scratch_size] elements long; obtain a correctly sized buffer with [alloc_scratch].

§Example
let plan = scaler.plan_rgb_resampling(source_size, target_size)?;
let mut scratch = plan.alloc_scratch();

for frame in frames {
    plan.resample_with_scratch(&frame, &mut output, &mut scratch)?;
}
Source

fn alloc_scratch(&self) -> Vec<T>

Allocates a scratch buffer of the correct size for use with [resample_with_scratch].

The returned Vec is zero initialized and exactly [scratch_size] elements long. Reuse it across calls to avoid repeated allocation.

Source

fn scratch_size(&self) -> usize

Returns the number of T elements required in the scratch buffer.

Pass a slice of at least this length to [resample_with_scratch].

Source

fn target_size(&self) -> ImageSize

Returns the target (output) image dimensions this plan was built for.

Source

fn source_size(&self) -> ImageSize

Returns the source (input) image dimensions this plan was built for.

Implementors§