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::{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    /// 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    /// - 2: unspecified
59    ///
60    /// Readable | Writeable
61    ///
62    ///
63    /// #### `range`
64    ///  Whether the data is using the full range of values.
65    ///
66    /// The range of the data.
67    ///
68    /// Readable | Writeable
69    ///
70    ///
71    /// #### `transfer-function`
72    ///  The transfer function to use.
73    ///
74    /// Supported values:
75    ///
76    /// - 1,6,14,15: BT.709, BT.601, BT.2020
77    /// - 2: unspecified
78    /// - 4: gamma 2.2
79    /// - 5: gamma 2.8
80    /// - 8: linear
81    /// - 13: sRGB
82    /// - 16: BT.2100 PQ
83    /// - 18: BT.2100 HLG
84    ///
85    /// Readable | Writeable
86    #[doc(alias = "GdkCicpParams")]
87    pub struct CicpParams(Object<ffi::GdkCicpParams, ffi::GdkCicpParamsClass>);
88
89    match fn {
90        type_ => || ffi::gdk_cicp_params_get_type(),
91    }
92}
93
94impl CicpParams {
95    /// Creates a new [`CicpParams`][crate::CicpParams] object.
96    ///
97    /// The initial values of the properties are the values for "undefined"
98    /// and need to be set before a color state object can be built.
99    ///
100    /// # Returns
101    ///
102    /// a new [`CicpParams`][crate::CicpParams]
103    #[doc(alias = "gdk_cicp_params_new")]
104    pub fn new() -> CicpParams {
105        assert_initialized_main_thread!();
106        unsafe { from_glib_full(ffi::gdk_cicp_params_new()) }
107    }
108
109    /// Creates a new [`ColorState`][crate::ColorState] object for the cicp parameters in @self.
110    ///
111    /// Note that this may fail if the cicp parameters in @self are not
112    /// supported by GTK. In that case, `NULL` is returned, and @error is set
113    /// with an error message that can be presented to the user.
114    ///
115    /// # Returns
116    ///
117    /// A newly allocated [`ColorState`][crate::ColorState]
118    #[doc(alias = "gdk_cicp_params_build_color_state")]
119    pub fn build_color_state(&self) -> Result<ColorState, glib::Error> {
120        unsafe {
121            let mut error = std::ptr::null_mut();
122            let ret = ffi::gdk_cicp_params_build_color_state(self.to_glib_none().0, &mut error);
123            if error.is_null() {
124                Ok(from_glib_full(ret))
125            } else {
126                Err(from_glib_full(error))
127            }
128        }
129    }
130
131    /// Returns the value of the color-primaries property
132    /// of @self.
133    ///
134    /// # Returns
135    ///
136    /// the color-primaries value
137    #[doc(alias = "gdk_cicp_params_get_color_primaries")]
138    #[doc(alias = "get_color_primaries")]
139    #[doc(alias = "color-primaries")]
140    pub fn color_primaries(&self) -> u32 {
141        unsafe { ffi::gdk_cicp_params_get_color_primaries(self.to_glib_none().0) }
142    }
143
144    /// Gets the matrix-coefficients property of @self.
145    ///
146    /// # Returns
147    ///
148    /// the matrix-coefficients value
149    #[doc(alias = "gdk_cicp_params_get_matrix_coefficients")]
150    #[doc(alias = "get_matrix_coefficients")]
151    #[doc(alias = "matrix-coefficients")]
152    pub fn matrix_coefficients(&self) -> u32 {
153        unsafe { ffi::gdk_cicp_params_get_matrix_coefficients(self.to_glib_none().0) }
154    }
155
156    /// Gets the range property of @self.
157    ///
158    /// # Returns
159    ///
160    /// the range value
161    #[doc(alias = "gdk_cicp_params_get_range")]
162    #[doc(alias = "get_range")]
163    pub fn range(&self) -> CicpRange {
164        unsafe { from_glib(ffi::gdk_cicp_params_get_range(self.to_glib_none().0)) }
165    }
166
167    /// Gets the transfer-function property of @self.
168    ///
169    /// # Returns
170    ///
171    /// the transfer-function value
172    #[doc(alias = "gdk_cicp_params_get_transfer_function")]
173    #[doc(alias = "get_transfer_function")]
174    #[doc(alias = "transfer-function")]
175    pub fn transfer_function(&self) -> u32 {
176        unsafe { ffi::gdk_cicp_params_get_transfer_function(self.to_glib_none().0) }
177    }
178
179    /// Sets the color-primaries property of @self.
180    /// ## `color_primaries`
181    /// the new color primaries value
182    #[doc(alias = "gdk_cicp_params_set_color_primaries")]
183    #[doc(alias = "color-primaries")]
184    pub fn set_color_primaries(&self, color_primaries: u32) {
185        unsafe {
186            ffi::gdk_cicp_params_set_color_primaries(self.to_glib_none().0, color_primaries);
187        }
188    }
189
190    /// @self a [`CicpParams`][crate::CicpParams]
191    /// Sets the matrix-coefficients property of @self.
192    /// ## `matrix_coefficients`
193    /// the new matrix-coefficients value
194    #[doc(alias = "gdk_cicp_params_set_matrix_coefficients")]
195    #[doc(alias = "matrix-coefficients")]
196    pub fn set_matrix_coefficients(&self, matrix_coefficients: u32) {
197        unsafe {
198            ffi::gdk_cicp_params_set_matrix_coefficients(
199                self.to_glib_none().0,
200                matrix_coefficients,
201            );
202        }
203    }
204
205    /// Sets the range property of @self
206    /// ## `range`
207    /// the range value
208    #[doc(alias = "gdk_cicp_params_set_range")]
209    #[doc(alias = "range")]
210    pub fn set_range(&self, range: CicpRange) {
211        unsafe {
212            ffi::gdk_cicp_params_set_range(self.to_glib_none().0, range.into_glib());
213        }
214    }
215
216    /// Sets the transfer-function property of @self.
217    /// ## `transfer_function`
218    /// the new transfer-function value
219    #[doc(alias = "gdk_cicp_params_set_transfer_function")]
220    #[doc(alias = "transfer-function")]
221    pub fn set_transfer_function(&self, transfer_function: u32) {
222        unsafe {
223            ffi::gdk_cicp_params_set_transfer_function(self.to_glib_none().0, transfer_function);
224        }
225    }
226
227    #[cfg(feature = "v4_16")]
228    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
229    #[doc(alias = "color-primaries")]
230    pub fn connect_color_primaries_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
231        unsafe extern "C" fn notify_color_primaries_trampoline<F: Fn(&CicpParams) + 'static>(
232            this: *mut ffi::GdkCicpParams,
233            _param_spec: glib::ffi::gpointer,
234            f: glib::ffi::gpointer,
235        ) {
236            let f: &F = &*(f as *const F);
237            f(&from_glib_borrow(this))
238        }
239        unsafe {
240            let f: Box_<F> = Box_::new(f);
241            connect_raw(
242                self.as_ptr() as *mut _,
243                c"notify::color-primaries".as_ptr() as *const _,
244                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
245                    notify_color_primaries_trampoline::<F> as *const (),
246                )),
247                Box_::into_raw(f),
248            )
249        }
250    }
251
252    #[cfg(feature = "v4_16")]
253    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
254    #[doc(alias = "matrix-coefficients")]
255    pub fn connect_matrix_coefficients_notify<F: Fn(&Self) + 'static>(
256        &self,
257        f: F,
258    ) -> SignalHandlerId {
259        unsafe extern "C" fn notify_matrix_coefficients_trampoline<F: Fn(&CicpParams) + 'static>(
260            this: *mut ffi::GdkCicpParams,
261            _param_spec: glib::ffi::gpointer,
262            f: glib::ffi::gpointer,
263        ) {
264            let f: &F = &*(f as *const F);
265            f(&from_glib_borrow(this))
266        }
267        unsafe {
268            let f: Box_<F> = Box_::new(f);
269            connect_raw(
270                self.as_ptr() as *mut _,
271                c"notify::matrix-coefficients".as_ptr() as *const _,
272                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
273                    notify_matrix_coefficients_trampoline::<F> as *const (),
274                )),
275                Box_::into_raw(f),
276            )
277        }
278    }
279
280    #[cfg(feature = "v4_16")]
281    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
282    #[doc(alias = "range")]
283    pub fn connect_range_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
284        unsafe extern "C" fn notify_range_trampoline<F: Fn(&CicpParams) + 'static>(
285            this: *mut ffi::GdkCicpParams,
286            _param_spec: glib::ffi::gpointer,
287            f: glib::ffi::gpointer,
288        ) {
289            let f: &F = &*(f as *const F);
290            f(&from_glib_borrow(this))
291        }
292        unsafe {
293            let f: Box_<F> = Box_::new(f);
294            connect_raw(
295                self.as_ptr() as *mut _,
296                c"notify::range".as_ptr() as *const _,
297                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298                    notify_range_trampoline::<F> as *const (),
299                )),
300                Box_::into_raw(f),
301            )
302        }
303    }
304
305    #[cfg(feature = "v4_16")]
306    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
307    #[doc(alias = "transfer-function")]
308    pub fn connect_transfer_function_notify<F: Fn(&Self) + 'static>(
309        &self,
310        f: F,
311    ) -> SignalHandlerId {
312        unsafe extern "C" fn notify_transfer_function_trampoline<F: Fn(&CicpParams) + 'static>(
313            this: *mut ffi::GdkCicpParams,
314            _param_spec: glib::ffi::gpointer,
315            f: glib::ffi::gpointer,
316        ) {
317            let f: &F = &*(f as *const F);
318            f(&from_glib_borrow(this))
319        }
320        unsafe {
321            let f: Box_<F> = Box_::new(f);
322            connect_raw(
323                self.as_ptr() as *mut _,
324                c"notify::transfer-function".as_ptr() as *const _,
325                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
326                    notify_transfer_function_trampoline::<F> as *const (),
327                )),
328                Box_::into_raw(f),
329            )
330        }
331    }
332}
333
334#[cfg(feature = "v4_16")]
335#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
336impl Default for CicpParams {
337    fn default() -> Self {
338        Self::new()
339    }
340}