forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

enc_jpeg.rs159 lines, 5.0 KiBHistoryRawDownload
1// Copyright 2025 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Wrappers around JPEG-Encoding `VABuffer` types.
6
7use crate::bindings;
8
9/// Wrapper over the `pic_flags` bindgen field in `VAEncPictureParameterBufferJPEG`
10pub struct PicFlags(bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1);
11
12impl PicFlags {
13 pub fn new(
14 profile: u32,
15 progressive: u32,
16 huffman: u32,
17 interleaved: u32,
18 differential: u32,
19 ) -> Self {
20 let _bitfield_1 =
21 bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
22 profile,
23 progressive,
24 huffman,
25 interleaved,
26 differential,
27 );
28 Self(bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1 {
29 bits: bindings::_VAEncPictureParameterBufferJPEG__bindgen_ty_1__bindgen_ty_1 {
30 _bitfield_align_1: Default::default(),
31 _bitfield_1,
32 __bindgen_padding_0: Default::default(),
33 },
34 })
35 }
36}
37
38/// Wrapper over the `VAEncPictureParameterBufferJPEG` FFI type.
39pub struct EncPictureParameterBufferJPEG(Box<bindings::VAEncPictureParameterBufferJPEG>);
40
41impl EncPictureParameterBufferJPEG {
42 /// Creates the wrapper.
43 pub fn new(
44 reconstructed_picture: bindings::VASurfaceID,
45 picture_width: u16,
46 picture_height: u16,
47 coded_buf: bindings::VABufferID,
48 pic_flags: PicFlags,
49 sample_bit_depth: u8,
50 num_scan: u8,
51 num_components: u16,
52 component_id: [u8; 4usize],
53 quantiser_table_selector: [u8; 4usize],
54 quality: u8,
55 ) -> Self {
56 Self(Box::new(bindings::VAEncPictureParameterBufferJPEG {
57 reconstructed_picture,
58 picture_width,
59 picture_height,
60 coded_buf,
61 pic_flags: pic_flags.0,
62 sample_bit_depth,
63 num_scan,
64 num_components,
65 component_id,
66 quantiser_table_selector,
67 quality,
68 va_reserved: Default::default(),
69 }))
70 }
71
72 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncPictureParameterBufferJPEG {
73 self.0.as_mut()
74 }
75
76 /// Returns the inner FFI type. Useful for testing purposes.
77 pub fn inner(&self) -> &bindings::VAEncPictureParameterBufferJPEG {
78 self.0.as_ref()
79 }
80}
81
82/// Wrapper over the `components` bindgen field in `VAEncSliceParameterBufferJPEG`.
83pub struct EncSliceParameterBufferJPEGComponent(
84 bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1,
85);
86
87impl EncSliceParameterBufferJPEGComponent {
88 /// Creates the bindgen field.
89 pub fn new(component_selector: u8, dc_table_selector: u8, ac_table_selector: u8) -> Self {
90 Self(bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1 {
91 component_selector,
92 dc_table_selector,
93 ac_table_selector,
94 })
95 }
96
97 /// Returns the inner FFI type. Useful for testing purposes.
98 pub fn inner(&self) -> &bindings::_VAEncSliceParameterBufferJPEG__bindgen_ty_1 {
99 &self.0
100 }
101}
102
103/// Wrapper over the `VAEncSliceParameterBufferJPEG` FFI type.
104pub struct EncSliceParameterBufferJPEG(Box<bindings::VAEncSliceParameterBufferJPEG>);
105
106impl EncSliceParameterBufferJPEG {
107 /// Creates the wrapper.
108 pub fn new(
109 restart_interval: u16,
110 num_components: u16,
111 components: [EncSliceParameterBufferJPEGComponent; 4usize],
112 ) -> Self {
113 Self(Box::new(bindings::VAEncSliceParameterBufferJPEG {
114 restart_interval,
115 num_components,
116 components: components.map(|component| component.0),
117 va_reserved: Default::default(),
118 }))
119 }
120
121 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAEncSliceParameterBufferJPEG {
122 self.0.as_mut()
123 }
124
125 /// Returns the inner FFI type. Useful for testing purposes.
126 pub fn inner(&self) -> &bindings::VAEncSliceParameterBufferJPEG {
127 self.0.as_ref()
128 }
129}
130
131/// Wrapper over the `VAQMatrixBufferJPEG` FFI type.
132pub struct QMatrixBufferJPEG(Box<bindings::VAQMatrixBufferJPEG>);
133
134impl QMatrixBufferJPEG {
135 /// Creates the wrapper.
136 pub fn new(
137 load_lum_quantiser_matrix: i32,
138 load_chroma_quantiser_matrix: i32,
139 lum_quantiser_matrix: [u8; 64usize],
140 chroma_quantiser_matrix: [u8; 64usize],
141 ) -> Self {
142 Self(Box::new(bindings::VAQMatrixBufferJPEG {
143 load_lum_quantiser_matrix,
144 load_chroma_quantiser_matrix,
145 lum_quantiser_matrix,
146 chroma_quantiser_matrix,
147 va_reserved: Default::default(),
148 }))
149 }
150
151 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAQMatrixBufferJPEG {
152 self.0.as_mut()
153 }
154
155 /// Returns the inner FFI type. Useful for testing purposes.
156 pub fn inner(&self) -> &bindings::VAQMatrixBufferJPEG {
157 self.0.as_ref()
158 }
159}