zoomvtools 1.1.1

Video motion vector analysis utilities in pure Rust
Documentation
#[cfg(all(target_arch = "x86_64", feature = "avx2"))]
mod avx2;
mod rust;

#[cfg(test)]
mod tests;

use std::num::NonZeroUsize;

use crate::util::Pixel;

/// Downscales an image by 2x using bilinear interpolation.
///
/// This function reduces both the width and height of the source image by half
/// using a two-pass bilinear filtering approach. First, vertical filtering is
/// applied to reduce the height, then horizontal filtering is applied in-place
/// to reduce the width. This produces higher quality results than simple averaging
/// by using weighted interpolation that considers neighboring pixels.
///
/// # Parameters
/// - `dest`: Destination buffer to store the downscaled image
/// - `src`: Source image buffer to downscale
/// - `dest_pitch`: Number of pixels per row in the destination buffer
/// - `src_pitch`: Number of pixels per row in the source buffer
/// - `dest_width`: Width of the destination image (half of source width)
/// - `dest_height`: Height of the destination image (half of source height)
#[inline]
pub fn reduce_bilinear<T: Pixel>(
    dest: &mut [T],
    src: &[T],
    dest_pitch: NonZeroUsize,
    src_pitch: NonZeroUsize,
    dest_width: NonZeroUsize,
    dest_height: NonZeroUsize,
) {
    #[cfg(all(target_arch = "x86_64", feature = "avx2"))]
    if crate::util::has_avx2() {
        // SAFETY: We check for AVX2 first
        unsafe {
            // PERF: 70% faster than scalar on test machine for 8-bit
            // PERF: 60% faster than scalar on test machine for 10-bit
            avx2::reduce_bilinear(dest, src, dest_pitch, src_pitch, dest_width, dest_height);
        }
        return;
    }

    rust::reduce_bilinear(dest, src, dest_pitch, src_pitch, dest_width, dest_height);
}