1use crate::{ffi, CicpRange, ColorState};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GdkCicpParams")]
90 pub struct CicpParams(Object<ffi::GdkCicpParams, ffi::GdkCicpParamsClass>);
91
92 match fn {
93 type_ => || ffi::gdk_cicp_params_get_type(),
94 }
95}
96
97impl CicpParams {
98 #[doc(alias = "gdk_cicp_params_new")]
107 pub fn new() -> CicpParams {
108 assert_initialized_main_thread!();
109 unsafe { from_glib_full(ffi::gdk_cicp_params_new()) }
110 }
111
112 #[doc(alias = "gdk_cicp_params_build_color_state")]
122 pub fn build_color_state(&self) -> Result<ColorState, glib::Error> {
123 unsafe {
124 let mut error = std::ptr::null_mut();
125 let ret = ffi::gdk_cicp_params_build_color_state(self.to_glib_none().0, &mut error);
126 if error.is_null() {
127 Ok(from_glib_full(ret))
128 } else {
129 Err(from_glib_full(error))
130 }
131 }
132 }
133
134 #[doc(alias = "gdk_cicp_params_get_color_primaries")]
141 #[doc(alias = "get_color_primaries")]
142 #[doc(alias = "color-primaries")]
143 pub fn color_primaries(&self) -> u32 {
144 unsafe { ffi::gdk_cicp_params_get_color_primaries(self.to_glib_none().0) }
145 }
146
147 #[doc(alias = "gdk_cicp_params_get_matrix_coefficients")]
153 #[doc(alias = "get_matrix_coefficients")]
154 #[doc(alias = "matrix-coefficients")]
155 pub fn matrix_coefficients(&self) -> u32 {
156 unsafe { ffi::gdk_cicp_params_get_matrix_coefficients(self.to_glib_none().0) }
157 }
158
159 #[doc(alias = "gdk_cicp_params_get_range")]
165 #[doc(alias = "get_range")]
166 pub fn range(&self) -> CicpRange {
167 unsafe { from_glib(ffi::gdk_cicp_params_get_range(self.to_glib_none().0)) }
168 }
169
170 #[doc(alias = "gdk_cicp_params_get_transfer_function")]
176 #[doc(alias = "get_transfer_function")]
177 #[doc(alias = "transfer-function")]
178 pub fn transfer_function(&self) -> u32 {
179 unsafe { ffi::gdk_cicp_params_get_transfer_function(self.to_glib_none().0) }
180 }
181
182 #[doc(alias = "gdk_cicp_params_set_color_primaries")]
186 #[doc(alias = "color-primaries")]
187 pub fn set_color_primaries(&self, color_primaries: u32) {
188 unsafe {
189 ffi::gdk_cicp_params_set_color_primaries(self.to_glib_none().0, color_primaries);
190 }
191 }
192
193 #[doc(alias = "gdk_cicp_params_set_matrix_coefficients")]
198 #[doc(alias = "matrix-coefficients")]
199 pub fn set_matrix_coefficients(&self, matrix_coefficients: u32) {
200 unsafe {
201 ffi::gdk_cicp_params_set_matrix_coefficients(
202 self.to_glib_none().0,
203 matrix_coefficients,
204 );
205 }
206 }
207
208 #[doc(alias = "gdk_cicp_params_set_range")]
212 #[doc(alias = "range")]
213 pub fn set_range(&self, range: CicpRange) {
214 unsafe {
215 ffi::gdk_cicp_params_set_range(self.to_glib_none().0, range.into_glib());
216 }
217 }
218
219 #[doc(alias = "gdk_cicp_params_set_transfer_function")]
223 #[doc(alias = "transfer-function")]
224 pub fn set_transfer_function(&self, transfer_function: u32) {
225 unsafe {
226 ffi::gdk_cicp_params_set_transfer_function(self.to_glib_none().0, transfer_function);
227 }
228 }
229
230 #[cfg(feature = "v4_16")]
231 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
232 #[doc(alias = "color-primaries")]
233 pub fn connect_color_primaries_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
234 unsafe extern "C" fn notify_color_primaries_trampoline<F: Fn(&CicpParams) + 'static>(
235 this: *mut ffi::GdkCicpParams,
236 _param_spec: glib::ffi::gpointer,
237 f: glib::ffi::gpointer,
238 ) {
239 let f: &F = &*(f as *const F);
240 f(&from_glib_borrow(this))
241 }
242 unsafe {
243 let f: Box_<F> = Box_::new(f);
244 connect_raw(
245 self.as_ptr() as *mut _,
246 c"notify::color-primaries".as_ptr() as *const _,
247 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
248 notify_color_primaries_trampoline::<F> as *const (),
249 )),
250 Box_::into_raw(f),
251 )
252 }
253 }
254
255 #[cfg(feature = "v4_16")]
256 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
257 #[doc(alias = "matrix-coefficients")]
258 pub fn connect_matrix_coefficients_notify<F: Fn(&Self) + 'static>(
259 &self,
260 f: F,
261 ) -> SignalHandlerId {
262 unsafe extern "C" fn notify_matrix_coefficients_trampoline<F: Fn(&CicpParams) + 'static>(
263 this: *mut ffi::GdkCicpParams,
264 _param_spec: glib::ffi::gpointer,
265 f: glib::ffi::gpointer,
266 ) {
267 let f: &F = &*(f as *const F);
268 f(&from_glib_borrow(this))
269 }
270 unsafe {
271 let f: Box_<F> = Box_::new(f);
272 connect_raw(
273 self.as_ptr() as *mut _,
274 c"notify::matrix-coefficients".as_ptr() as *const _,
275 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
276 notify_matrix_coefficients_trampoline::<F> as *const (),
277 )),
278 Box_::into_raw(f),
279 )
280 }
281 }
282
283 #[cfg(feature = "v4_16")]
284 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
285 #[doc(alias = "range")]
286 pub fn connect_range_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
287 unsafe extern "C" fn notify_range_trampoline<F: Fn(&CicpParams) + 'static>(
288 this: *mut ffi::GdkCicpParams,
289 _param_spec: glib::ffi::gpointer,
290 f: glib::ffi::gpointer,
291 ) {
292 let f: &F = &*(f as *const F);
293 f(&from_glib_borrow(this))
294 }
295 unsafe {
296 let f: Box_<F> = Box_::new(f);
297 connect_raw(
298 self.as_ptr() as *mut _,
299 c"notify::range".as_ptr() as *const _,
300 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
301 notify_range_trampoline::<F> as *const (),
302 )),
303 Box_::into_raw(f),
304 )
305 }
306 }
307
308 #[cfg(feature = "v4_16")]
309 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
310 #[doc(alias = "transfer-function")]
311 pub fn connect_transfer_function_notify<F: Fn(&Self) + 'static>(
312 &self,
313 f: F,
314 ) -> SignalHandlerId {
315 unsafe extern "C" fn notify_transfer_function_trampoline<F: Fn(&CicpParams) + 'static>(
316 this: *mut ffi::GdkCicpParams,
317 _param_spec: glib::ffi::gpointer,
318 f: glib::ffi::gpointer,
319 ) {
320 let f: &F = &*(f as *const F);
321 f(&from_glib_borrow(this))
322 }
323 unsafe {
324 let f: Box_<F> = Box_::new(f);
325 connect_raw(
326 self.as_ptr() as *mut _,
327 c"notify::transfer-function".as_ptr() as *const _,
328 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329 notify_transfer_function_trampoline::<F> as *const (),
330 )),
331 Box_::into_raw(f),
332 )
333 }
334 }
335}
336
337#[cfg(feature = "v4_16")]
338#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
339impl Default for CicpParams {
340 fn default() -> Self {
341 Self::new()
342 }
343}