Skip to main content

gdk4/auto/
cicp_params.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{CicpRange, ColorState, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// Contains the parameters that define a colorstate with cicp parameters.
15    ///
16    /// Cicp parameters are specified in the ITU-T H.273
17    /// [specification](https://www.itu.int/rec/T-REC-H.273/en).
18    ///
19    /// See the documentation of individual properties for supported values.
20    ///
21    /// The 'unspecified' value (2) is not treated in any special way, and
22    /// must be replaced by a different value before creating a color state.
23    ///
24    /// [`CicpParams`][crate::CicpParams] can be used as a builder object to construct a color
25    /// state from Cicp data with [`build_color_state()`][Self::build_color_state()].
26    /// The function will return an error if the given parameters are not
27    /// supported.
28    ///
29    /// You can obtain a [`CicpParams`][crate::CicpParams] object from a color state with
30    /// [`ColorState::create_cicp_params()`][crate::ColorState::create_cicp_params()]. This can be used to
31    /// create a variant of a color state, by changing just one of the cicp
32    /// parameters, or just to obtain information about the color state.
33    ///
34    /// ## Properties
35    ///
36    ///
37    /// #### `color-primaries`
38    ///  The color primaries to use.
39    ///
40    /// Supported values:
41    ///
42    /// - 1: BT.709 / sRGB
43    /// - 2: unspecified
44    /// - 5: PAL
45    /// - 6,7: BT.601 / NTSC
46    /// - 9: BT.2020
47    /// - 12: Display P3
48    ///
49    /// Readable | Writeable
50    ///
51    ///
52    /// #### `matrix-coefficients`
53    ///  The matrix coefficients (for YUV to RGB conversion).
54    ///
55    /// Supported values:
56    ///
57    /// - 0: RGB
58    /// - 1: BT.709
59    /// - 2: unspecified
60    /// - 5,6: BT.601
61    /// - 9: BT.2020
62    ///
63    /// Readable | Writeable
64    ///
65    ///
66    /// #### `range`
67    ///  Whether the data is using the full range of values.
68    ///
69    /// The range of the data.
70    ///
71    /// Readable | Writeable
72    ///
73    ///
74    /// #### `transfer-function`
75    ///  The transfer function to use.
76    ///
77    /// Supported values:
78    ///
79    /// - 1,6,14,15: BT.709, BT.601, BT.2020
80    /// - 2: unspecified
81    /// - 4: gamma 2.2
82    /// - 5: gamma 2.8
83    /// - 8: linear
84    /// - 13: sRGB
85    /// - 16: BT.2100 PQ
86    /// - 18: BT.2100 HLG
87    ///
88    /// Readable | Writeable
89    #[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    /// Creates a new [`CicpParams`][crate::CicpParams] object.
99    ///
100    /// The initial values of the properties are the values for "undefined"
101    /// and need to be set before a color state object can be built.
102    ///
103    /// # Returns
104    ///
105    /// a new [`CicpParams`][crate::CicpParams]
106    #[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    /// Creates a new [`ColorState`][crate::ColorState] object for the cicp parameters in @self.
113    ///
114    /// Note that this may fail if the cicp parameters in @self are not
115    /// supported by GTK. In that case, `NULL` is returned, and @error is set
116    /// with an error message that can be presented to the user.
117    ///
118    /// # Returns
119    ///
120    /// A newly allocated [`ColorState`][crate::ColorState]
121    #[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    /// Returns the value of the color-primaries property
135    /// of @self.
136    ///
137    /// # Returns
138    ///
139    /// the color-primaries value
140    #[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    /// Gets the matrix-coefficients property of @self.
148    ///
149    /// # Returns
150    ///
151    /// the matrix-coefficients value
152    #[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    /// Gets the range property of @self.
160    ///
161    /// # Returns
162    ///
163    /// the range value
164    #[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    /// Gets the transfer-function property of @self.
171    ///
172    /// # Returns
173    ///
174    /// the transfer-function value
175    #[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    /// Sets the color-primaries property of @self.
183    /// ## `color_primaries`
184    /// the new color primaries value
185    #[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    /// @self a [`CicpParams`][crate::CicpParams]
194    /// Sets the matrix-coefficients property of @self.
195    /// ## `matrix_coefficients`
196    /// the new matrix-coefficients value
197    #[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    /// Sets the range property of @self
209    /// ## `range`
210    /// the range value
211    #[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    /// Sets the transfer-function property of @self.
220    /// ## `transfer_function`
221    /// the new transfer-function value
222    #[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            unsafe {
240                let f: &F = &*(f as *const F);
241                f(&from_glib_borrow(this))
242            }
243        }
244        unsafe {
245            let f: Box_<F> = Box_::new(f);
246            connect_raw(
247                self.as_ptr() as *mut _,
248                c"notify::color-primaries".as_ptr() as *const _,
249                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
250                    notify_color_primaries_trampoline::<F> as *const (),
251                )),
252                Box_::into_raw(f),
253            )
254        }
255    }
256
257    #[cfg(feature = "v4_16")]
258    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
259    #[doc(alias = "matrix-coefficients")]
260    pub fn connect_matrix_coefficients_notify<F: Fn(&Self) + 'static>(
261        &self,
262        f: F,
263    ) -> SignalHandlerId {
264        unsafe extern "C" fn notify_matrix_coefficients_trampoline<F: Fn(&CicpParams) + 'static>(
265            this: *mut ffi::GdkCicpParams,
266            _param_spec: glib::ffi::gpointer,
267            f: glib::ffi::gpointer,
268        ) {
269            unsafe {
270                let f: &F = &*(f as *const F);
271                f(&from_glib_borrow(this))
272            }
273        }
274        unsafe {
275            let f: Box_<F> = Box_::new(f);
276            connect_raw(
277                self.as_ptr() as *mut _,
278                c"notify::matrix-coefficients".as_ptr() as *const _,
279                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280                    notify_matrix_coefficients_trampoline::<F> as *const (),
281                )),
282                Box_::into_raw(f),
283            )
284        }
285    }
286
287    #[cfg(feature = "v4_16")]
288    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
289    #[doc(alias = "range")]
290    pub fn connect_range_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
291        unsafe extern "C" fn notify_range_trampoline<F: Fn(&CicpParams) + 'static>(
292            this: *mut ffi::GdkCicpParams,
293            _param_spec: glib::ffi::gpointer,
294            f: glib::ffi::gpointer,
295        ) {
296            unsafe {
297                let f: &F = &*(f as *const F);
298                f(&from_glib_borrow(this))
299            }
300        }
301        unsafe {
302            let f: Box_<F> = Box_::new(f);
303            connect_raw(
304                self.as_ptr() as *mut _,
305                c"notify::range".as_ptr() as *const _,
306                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
307                    notify_range_trampoline::<F> as *const (),
308                )),
309                Box_::into_raw(f),
310            )
311        }
312    }
313
314    #[cfg(feature = "v4_16")]
315    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
316    #[doc(alias = "transfer-function")]
317    pub fn connect_transfer_function_notify<F: Fn(&Self) + 'static>(
318        &self,
319        f: F,
320    ) -> SignalHandlerId {
321        unsafe extern "C" fn notify_transfer_function_trampoline<F: Fn(&CicpParams) + 'static>(
322            this: *mut ffi::GdkCicpParams,
323            _param_spec: glib::ffi::gpointer,
324            f: glib::ffi::gpointer,
325        ) {
326            unsafe {
327                let f: &F = &*(f as *const F);
328                f(&from_glib_borrow(this))
329            }
330        }
331        unsafe {
332            let f: Box_<F> = Box_::new(f);
333            connect_raw(
334                self.as_ptr() as *mut _,
335                c"notify::transfer-function".as_ptr() as *const _,
336                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
337                    notify_transfer_function_trampoline::<F> as *const (),
338                )),
339                Box_::into_raw(f),
340            )
341        }
342    }
343}
344
345#[cfg(feature = "v4_16")]
346#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
347impl Default for CicpParams {
348    fn default() -> Self {
349        Self::new()
350    }
351}