Skip to main content

box_image_pyramid/
lib.rs

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