1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! Traits for hardware acceleration.
use crate::error::AccelResult;
use oximedia_core::PixelFormat;
/// Scaling filter quality/algorithm.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ScaleFilter {
/// Nearest neighbor (fastest, lowest quality).
Nearest,
/// Bilinear interpolation (good speed/quality balance).
Bilinear,
/// Bicubic interpolation (slower, higher quality).
Bicubic,
/// Lanczos resampling (slowest, highest quality).
Lanczos,
}
/// Hardware acceleration trait for video processing operations.
///
/// This trait provides a unified interface for GPU and CPU implementations
/// of common video processing operations.
pub trait HardwareAccel: Send + Sync {
/// Scales an image from source dimensions to destination dimensions.
///
/// # Arguments
///
/// * `input` - Input image data
/// * `src_width` - Source image width
/// * `src_height` - Source image height
/// * `dst_width` - Destination image width
/// * `dst_height` - Destination image height
/// * `format` - Pixel format of the image
/// * `filter` - Scaling filter to use
///
/// # Errors
///
/// Returns an error if:
/// - Input buffer size doesn't match dimensions
/// - GPU operation fails
/// - Format is unsupported
fn scale_image(
&self,
input: &[u8],
src_width: u32,
src_height: u32,
dst_width: u32,
dst_height: u32,
format: PixelFormat,
filter: ScaleFilter,
) -> AccelResult<Vec<u8>>;
/// Converts image from one pixel format to another.
///
/// # Arguments
///
/// * `input` - Input image data
/// * `width` - Image width
/// * `height` - Image height
/// * `src_format` - Source pixel format
/// * `dst_format` - Destination pixel format
///
/// # Errors
///
/// Returns an error if:
/// - Input buffer size doesn't match dimensions
/// - GPU operation fails
/// - Format conversion is unsupported
fn convert_color(
&self,
input: &[u8],
width: u32,
height: u32,
src_format: PixelFormat,
dst_format: PixelFormat,
) -> AccelResult<Vec<u8>>;
/// Performs block-based motion estimation between two frames.
///
/// Returns a vector of motion vectors (dx, dy) for each block.
/// Blocks are scanned left-to-right, top-to-bottom.
///
/// # Arguments
///
/// * `reference` - Reference frame data
/// * `current` - Current frame data
/// * `width` - Frame width
/// * `height` - Frame height
/// * `block_size` - Size of motion estimation blocks (typically 8 or 16)
///
/// # Errors
///
/// Returns an error if:
/// - Input buffer sizes don't match dimensions
/// - GPU operation fails
/// - Block size is invalid
fn motion_estimation(
&self,
reference: &[u8],
current: &[u8],
width: u32,
height: u32,
block_size: u32,
) -> AccelResult<Vec<(i16, i16)>>;
}