Skip to main content

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