Skip to main content

inter_area

Function inter_area 

Source
pub fn inter_area(src: &RgbImage, dw: u32, dh: u32) -> RgbImage
Expand description

cv2.resize(..., interpolation=INTER_AREA) for shrinking — area-weighted averaging, separable (horizontal then vertical), f64 accumulation.

The per-pixel addition order is the naive form’s — horizontal taps in increasing source column, then vertical taps in increasing source row — so the f64 sums, and the rounded bytes, are bit-identical to it (asserted by area_tests). Within that contract the work is arranged for the cache: a horizontally-shrunk source row is computed on demand as the vertical pass reaches it and kept only while an output row still needs it (a source row feeds at most two output rows, so a ring of a few f64 rows replaces the 30 MB sh × dw intermediate a full first pass wrote and re-read), the horizontal taps run over the contiguous byte span they cover (no per-tap indexing), and the vertical pass is a flat f64 axpy the compiler vectorizes. ~3× faster than the two-pass form on a page render (43 → 18 ms, 1224×1584 → 791×1024, release, one thread).