Skip to main content

box_image_pyramid/
lib.rs

1#![cfg_attr(all(feature = "simd", feature = "par_pyramid"), feature(portable_simd))]
2//! Minimal image pyramid using 2x box-filter downsampling.
3//!
4//! This crate provides a simple, efficient image pyramid for u8 grayscale
5//! images. Each level is produced by a 2x2 box-filter downsample (averaging
6//! four pixels into one). It is designed for real-time pipelines where you
7//! need coarse-to-fine processing without pulling in a full image processing
8//! library.
9//!
10//! # Key features
11//!
12//! - **Reusable buffers**: construct a [`PyramidBuffers`] once and reuse it
13//!   across frames to avoid repeated allocations.
14//! - **Optional parallelism**: enable the `rayon` and `par_pyramid` features
15//!   for parallel row processing.
16//! - **Optional SIMD**: enable the `simd` and `par_pyramid` features for
17//!   portable SIMD acceleration (requires nightly Rust).
18//!
19//! # Example
20//!
21//! ```
22//! use box_image_pyramid::{ImageView, PyramidParams, PyramidBuffers, build_pyramid};
23//!
24//! let pixels = vec![128u8; 256 * 256];
25//! let base = ImageView::new(256, 256, &pixels).unwrap();
26//!
27//! let mut params = PyramidParams::default();
28//! params.num_levels = 3;
29//! params.min_size = 32;
30//! let mut buffers = PyramidBuffers::new();
31//! let pyramid = build_pyramid(base, &params, &mut buffers);
32//!
33//! assert_eq!(pyramid.levels.len(), 3);
34//! assert_eq!(pyramid.levels[0].img.width, 256);
35//! assert_eq!(pyramid.levels[1].img.width, 128);
36//! assert_eq!(pyramid.levels[2].img.width, 64);
37//! ```
38
39mod imageview;
40mod pyramid;
41
42pub use imageview::{ImageBuffer, ImageView};
43pub use pyramid::{build_pyramid, Pyramid, PyramidBuffers, PyramidLevel, PyramidParams};