use std::mem::size_of;
use bitflags::bitflags;
pub const MV_SIZE: usize = size_of::<MotionVector>();
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MotionVector {
pub x: i32,
pub y: i32,
pub sad: i64,
}
impl MotionVector {
#[must_use]
#[inline]
pub const fn square_difference_norm(v1: MotionVector, v2: MotionVector) -> u64 {
((v1.x - v2.x).pow(2) + (v1.y - v2.y).pow(2)) as u64
}
}
impl MotionVector {
#[must_use]
pub(crate) const fn bytes(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
self as *const Self as *const u8,
std::mem::size_of::<Self>(),
)
}
}
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CheckMVFlags: u32 {
const PENALTY_NEW = 1 << 1;
const UPDATE_DIR = 1 << 2;
const UPDATE_BEST_MV = 1 << 3;
}
}
impl MotionVector {
#[must_use]
#[inline]
pub const fn zero() -> Self {
MotionVector {
x: 0,
y: 0,
sad: -1,
}
}
}
impl Default for MotionVector {
#[inline]
fn default() -> Self {
Self::zero()
}
}