Skip to main content

moq_vaapi/buffer/
jpeg_baseline.rs

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 JPEGBaseline `VABuffer` types.
6
7use crate::bindings;
8
9/// Wrapper over the `components` bindgen field in `VAPictureParameterBufferJPEGBaseline`.
10pub struct PictureParameterBufferJPEGBaselineComponent(bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1);
11
12impl PictureParameterBufferJPEGBaselineComponent {
13	/// Creates the bindgen field.
14	#[allow(clippy::too_many_arguments)]
15	pub fn new(component_id: u8, h_sampling_factor: u8, v_sampling_factor: u8, quantiser_table_selector: u8) -> Self {
16		Self(bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1 {
17			component_id,
18			h_sampling_factor,
19			v_sampling_factor,
20			quantiser_table_selector,
21		})
22	}
23
24	/// Returns the inner FFI type. Useful for testing purposes.
25	pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferJPEGBaseline__bindgen_ty_1 {
26		&self.0
27	}
28}
29
30/// Wrapper over the `VAPictureParameterBufferJPEGBaseline` FFI type.
31pub struct PictureParameterBufferJPEGBaseline(Box<bindings::VAPictureParameterBufferJPEGBaseline>);
32
33impl PictureParameterBufferJPEGBaseline {
34	/// Creates the wrapper.
35	pub fn new(
36		picture_width: u16,
37		picture_height: u16,
38		components: [PictureParameterBufferJPEGBaselineComponent; 255usize],
39		num_components: u8,
40		color_space: u8,
41		rotation: u32,
42		crop_rectangle: bindings::VARectangle,
43	) -> Self {
44		Self(Box::new(bindings::VAPictureParameterBufferJPEGBaseline {
45			picture_width,
46			picture_height,
47			components: components.map(|component| component.0),
48			num_components,
49			color_space,
50			rotation,
51			#[cfg(libva_1_20_or_higher)]
52			crop_rectangle,
53			va_reserved: Default::default(),
54		}))
55	}
56
57	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferJPEGBaseline {
58		self.0.as_mut()
59	}
60
61	/// Returns the inner FFI type. Useful for testing purposes.
62	pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferJPEGBaseline {
63		self.0.as_ref()
64	}
65}
66
67/// Wrapper over the `components` bindgen field in `VASliceParameterBufferJPEGBaseline`.
68pub struct VASliceParameterBufferJPEGBaselineComponent(bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1);
69
70impl VASliceParameterBufferJPEGBaselineComponent {
71	/// Creates the bindgen field.
72	#[allow(clippy::too_many_arguments)]
73	pub fn new(component_selector: u8, dc_table_selector: u8, ac_table_selector: u8) -> Self {
74		Self(bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1 {
75			component_selector,
76			dc_table_selector,
77			ac_table_selector,
78		})
79	}
80
81	/// Returns the inner FFI type. Useful for testing purposes.
82	pub fn inner(&mut self) -> &bindings::_VASliceParameterBufferJPEGBaseline__bindgen_ty_1 {
83		&self.0
84	}
85}
86
87/// Wrapper over the `VASliceParameterBufferJPEGBaseline` FFI type.
88pub struct SliceParameterBufferJPEGBaseline(Box<bindings::VASliceParameterBufferJPEGBaseline>);
89
90impl SliceParameterBufferJPEGBaseline {
91	/// Creates the wrapper.
92	pub fn new(
93		slice_data_size: u32,
94		slice_data_offset: u32,
95		slice_data_flag: u32,
96		slice_horizontal_position: u32,
97		slice_vertical_position: u32,
98		components: [VASliceParameterBufferJPEGBaselineComponent; 4usize],
99		num_components: u8,
100		restart_interval: u16,
101		num_mcus: u32,
102	) -> Self {
103		Self(Box::new(bindings::VASliceParameterBufferJPEGBaseline {
104			slice_data_size,
105			slice_data_offset,
106			slice_data_flag,
107			slice_horizontal_position,
108			slice_vertical_position,
109			components: components.map(|component| component.0),
110			num_components,
111			restart_interval,
112			num_mcus,
113			va_reserved: Default::default(),
114		}))
115	}
116
117	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferJPEGBaseline {
118		self.0.as_mut()
119	}
120
121	/// Returns the inner FFI type. Useful for testing purposes.
122	pub fn inner(&mut self) -> &bindings::VASliceParameterBufferJPEGBaseline {
123		self.0.as_ref()
124	}
125}
126
127/// Wrapper over the `VAIQMatrixBufferJPEGBaseline` FFI type.
128pub struct IQMatrixBufferJPEGBaseline(Box<bindings::VAIQMatrixBufferJPEGBaseline>);
129
130impl IQMatrixBufferJPEGBaseline {
131	/// Creates the wrapper.
132	#[allow(clippy::too_many_arguments)]
133	pub fn new(load_quantiser_table: [u8; 4usize], quantiser_table: [[u8; 64usize]; 4usize]) -> Self {
134		Self(Box::new(bindings::VAIQMatrixBufferJPEGBaseline {
135			load_quantiser_table,
136			quantiser_table,
137			va_reserved: Default::default(),
138		}))
139	}
140
141	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferJPEGBaseline {
142		self.0.as_mut()
143	}
144
145	/// Returns the inner FFI type. Useful for testing purposes.
146	pub fn inner(&self) -> &bindings::VAIQMatrixBufferJPEGBaseline {
147		self.0.as_ref()
148	}
149}
150
151/// Wrapper over the `huffman_table` bindgen field in `VAHuffmanTableBufferJPEGBaseline`.
152pub struct HuffmanTableBufferJPEGBaselineHuffmanTable(bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1);
153
154impl HuffmanTableBufferJPEGBaselineHuffmanTable {
155	/// Creates the bindgen field.
156	#[allow(clippy::too_many_arguments)]
157	pub fn new(
158		num_dc_codes: [u8; 16usize],
159		dc_values: [u8; 12usize],
160		num_ac_codes: [u8; 16usize],
161		ac_values: [u8; 162usize],
162		pad: [u8; 2usize],
163	) -> Self {
164		Self(bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1 {
165			num_dc_codes,
166			dc_values,
167			num_ac_codes,
168			ac_values,
169			pad,
170		})
171	}
172
173	/// Returns the inner FFI type. Useful for testing purposes.
174	pub fn inner(&mut self) -> &bindings::_VAHuffmanTableBufferJPEGBaseline__bindgen_ty_1 {
175		&self.0
176	}
177}
178
179/// Wrapper over the `VAHuffmanTableBufferJPEGBaseline` FFI type.
180pub struct HuffmanTableBufferJPEGBaseline(Box<bindings::VAHuffmanTableBufferJPEGBaseline>);
181
182impl HuffmanTableBufferJPEGBaseline {
183	/// Creates the wrapper.
184	pub fn new(
185		load_huffman_table: [u8; 2usize],
186		huffman_table: [HuffmanTableBufferJPEGBaselineHuffmanTable; 2usize],
187	) -> Self {
188		Self(Box::new(bindings::VAHuffmanTableBufferJPEGBaseline {
189			load_huffman_table,
190			huffman_table: huffman_table.map(|component| component.0),
191			va_reserved: Default::default(),
192		}))
193	}
194
195	pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAHuffmanTableBufferJPEGBaseline {
196		self.0.as_mut()
197	}
198
199	/// Returns the inner FFI type. Useful for testing purposes.
200	pub fn inner(&mut self) -> &bindings::VAHuffmanTableBufferJPEGBaseline {
201		self.0.as_ref()
202	}
203}