zoomvtools 1.1.1

Video motion vector analysis utilities in pure Rust
Documentation
#![allow(clippy::unwrap_used, reason = "allow in test files")]

use std::num::{NonZeroU8, NonZeroUsize};

use crate::{
    filters::analyse::SuperClipInfo,
    frame::{FramePlanes, FramePlanesMut, FrameView, PlaneRef},
    params::{MVPlaneSet, Subpel},
    video::{ColorFamily, Resolution, SampleType, VideoFormat, VideoInfo},
};

use super::Finest;

fn gray8_info(width: usize, height: usize) -> VideoInfo {
    VideoInfo {
        format: VideoFormat {
            color_family: ColorFamily::Gray,
            sample_type: SampleType::Integer,
            bits_per_sample: NonZeroU8::new(8).unwrap(),
            bytes_per_sample: NonZeroU8::new(1).unwrap(),
            sub_sampling_w: 0,
            sub_sampling_h: 0,
        },
        resolution: Resolution { width, height },
        num_frames: 1,
    }
}

#[test]
fn finest_render_frame_copies_full_pel_gray_plane_without_vapoursynth_types() {
    let finest = Finest::new(
        gray8_info(2, 2),
        SuperClipInfo {
            height: NonZeroUsize::new(2).unwrap(),
            hpad: 0,
            vpad: 0,
            pel: Subpel::Full,
            mode_yuv: MVPlaneSet::YPLANE,
            levels: 1,
        },
    )
    .unwrap();
    let source = [10u8, 20, 30, 40];
    let source_view = FrameView::new(
        FramePlanes::new([Some(PlaneRef::new(&source)), None, None]),
        (NonZeroUsize::new(2).unwrap(), None, None),
    );
    let mut output = [0u8; 4];
    let mut output_planes = FramePlanesMut::new([Some(&mut output), None, None]);

    finest
        .render_frame(
            &source_view,
            &mut output_planes,
            (NonZeroUsize::new(2).unwrap(), None, None),
        )
        .unwrap();

    assert_eq!(output, source);
}

#[test]
fn finest_render_frame_merges_half_pel_windows_without_vapoursynth_types() {
    let finest = Finest::new(
        gray8_info(1, 4),
        SuperClipInfo {
            height: NonZeroUsize::new(1).unwrap(),
            hpad: 0,
            vpad: 0,
            pel: Subpel::Half,
            mode_yuv: MVPlaneSet::YPLANE,
            levels: 1,
        },
    )
    .unwrap();
    let source = [10u8, 20, 30, 40];
    let source_view = FrameView::new(
        FramePlanes::new([Some(PlaneRef::new(&source)), None, None]),
        (NonZeroUsize::new(1).unwrap(), None, None),
    );
    let mut output = [0u8; 4];
    let mut output_planes = FramePlanesMut::new([Some(&mut output), None, None]);

    finest
        .render_frame(
            &source_view,
            &mut output_planes,
            (NonZeroUsize::new(2).unwrap(), None, None),
        )
        .unwrap();

    assert_eq!(output, [10, 20, 30, 40]);
}