1 | use super::Vector; |
2 | use ffi::*; |
3 | |
4 | pub struct Filter { |
5 | ptr: *mut SwsFilter, |
6 | } |
7 | |
8 | impl Filter { |
9 | pub unsafe fn as_ptr(&self) -> *const SwsFilter { |
10 | self.ptr as *const _ |
11 | } |
12 | |
13 | pub unsafe fn as_mut_ptr(&mut self) -> *mut SwsFilter { |
14 | self.ptr |
15 | } |
16 | } |
17 | |
18 | impl Filter { |
19 | pub fn get( |
20 | luma_g_blur: f32, |
21 | chroma_g_blur: f32, |
22 | luma_sharpen: f32, |
23 | chroma_sharpen: f32, |
24 | chroma_h_shift: f32, |
25 | chroma_v_shift: f32, |
26 | ) -> Self { |
27 | unsafe { |
28 | Filter { |
29 | ptr: sws_getDefaultFilter( |
30 | luma_g_blur, |
31 | chroma_g_blur, |
32 | luma_sharpen, |
33 | chroma_sharpen, |
34 | chroma_h_shift, |
35 | chroma_v_shift, |
36 | 0, |
37 | ), |
38 | } |
39 | } |
40 | } |
41 | |
42 | pub fn new() -> Self { |
43 | Self::get(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) |
44 | } |
45 | |
46 | pub fn luma_horizontal(&self) -> Vector { |
47 | unsafe { Vector::wrap((*self.as_ptr()).lumH) } |
48 | } |
49 | |
50 | pub fn luma_horizontal_mut(&mut self) -> Vector { |
51 | unsafe { Vector::wrap((*self.as_mut_ptr()).lumH) } |
52 | } |
53 | |
54 | pub fn luma_vertical(&self) -> Vector { |
55 | unsafe { Vector::wrap((*self.as_ptr()).lumV) } |
56 | } |
57 | |
58 | pub fn luma_vertical_mut(&mut self) -> Vector { |
59 | unsafe { Vector::wrap((*self.as_mut_ptr()).lumV) } |
60 | } |
61 | |
62 | pub fn chroma_horizontal(&self) -> Vector { |
63 | unsafe { Vector::wrap((*self.as_ptr()).lumV) } |
64 | } |
65 | |
66 | pub fn chroma_horizontal_mut(&mut self) -> Vector { |
67 | unsafe { Vector::wrap((*self.as_mut_ptr()).lumV) } |
68 | } |
69 | |
70 | pub fn chroma_vertical(&self) -> Vector { |
71 | unsafe { Vector::wrap((*self.as_ptr()).lumV) } |
72 | } |
73 | |
74 | pub fn chroma_vertical_mut(&mut self) -> Vector { |
75 | unsafe { Vector::wrap((*self.as_mut_ptr()).lumV) } |
76 | } |
77 | } |
78 | |
79 | impl Default for Filter { |
80 | fn default() -> Self { |
81 | Self::new() |
82 | } |
83 | } |
84 | |
85 | impl Drop for Filter { |
86 | fn drop(&mut self) { |
87 | unsafe { |
88 | sws_freeFilter(self.as_mut_ptr()); |
89 | } |
90 | } |
91 | } |
92 | |