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