zoomvtools 2.0.0

Video motion vector analysis utilities in pure Rust
Documentation
//! Pre-selected block functions for optimized motion vector estimation.
//!
//! This module provides function pointer types and selection utilities that allow
//! block-size-specific implementations to be selected once at filter initialization,
//! avoiding runtime block size dispatching on every function call.

use std::num::NonZeroUsize;

use super::Pixel;
use crate::{
    luma::{LumaSumFn, select_luma_sum},
    sad::{SadFn, select_sad},
    satd::{SatdFn, select_satd},
};

/// Pre-selected block functions for a specific block size configuration.
///
/// This struct holds function pointers to block-size-specific implementations,
/// allowing direct calls without runtime block size dispatching.
pub struct BlockFunctions {
    /// Luma sum function for the configured luma block size.
    pub luma_sum: LumaSumFn,
    /// SAD function for the configured luma block size.
    pub luma_sad: SadFn,
    /// SAD function for the configured chroma block size.
    pub chroma_sad: SadFn,
    /// SATD function for the configured luma block size.
    pub satd: SatdFn,
}

/// Creates a `BlockFunctions` struct with pre-selected functions for the given block sizes.
///
/// # Arguments
/// * `blk_size_x` - Width of luma blocks
/// * `blk_size_y` - Height of luma blocks
/// * `chroma_blk_x` - Width of chroma blocks (typically `blk_size_x / x_ratio_uv`)
/// * `chroma_blk_y` - Height of chroma blocks (typically `blk_size_y / y_ratio_uv`)
///
/// # Panics
/// Panics if any of the block sizes are not supported by the respective functions.
#[must_use]
#[inline]
pub fn select_block_functions<T: Pixel>(
    blk_size_x: NonZeroUsize,
    blk_size_y: NonZeroUsize,
    chroma_blk_x: NonZeroUsize,
    chroma_blk_y: NonZeroUsize,
) -> BlockFunctions {
    BlockFunctions {
        luma_sum: select_luma_sum::<T>(blk_size_x, blk_size_y),
        luma_sad: select_sad::<T>(blk_size_x, blk_size_y),
        chroma_sad: select_sad::<T>(chroma_blk_x, chroma_blk_y),
        satd: select_satd::<T>(blk_size_x, blk_size_y),
    }
}