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    /// - 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            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}