gdk4/auto/
cicp_params.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi, CicpRange, ColorState};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// The [`CicpParams`][crate::CicpParams] struct contains the parameters that define
    /// a colorstate according to the ITU-T H.273
    /// [specification](https://www.itu.int/rec/T-REC-H.273/en).
    ///
    /// See the documentation of individual properties for supported values.
    ///
    /// The 'unspecified' value (2) is not treated in any special way, and
    /// must be replaced by a different value before creating a color state.
    ///
    /// [`CicpParams`][crate::CicpParams] can be used as a builder object to construct a color
    /// state from Cicp data with [`build_color_state()`][Self::build_color_state()].
    /// The function will return an error if the given parameters are not
    /// supported.
    ///
    /// You can obtain a [`CicpParams`][crate::CicpParams] object from a color state with
    /// [`ColorState::create_cicp_params()`][crate::ColorState::create_cicp_params()]. This can be used to
    /// create a variant of a color state, by changing just one of the cicp
    /// parameters, or just to obtain information about the color state.
    ///
    /// ## Properties
    ///
    ///
    /// #### `color-primaries`
    ///  The color primaries to use.
    ///
    /// Supported values:
    ///
    /// - 1: BT.709 / sRGB
    /// - 2: unspecified
    /// - 5: PAL
    /// - 6,7: BT.601 / NTSC
    /// - 9: BT.2020
    /// - 12: Display P3
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `matrix-coefficients`
    ///  The matrix coefficients (for YUV to RGB conversion).
    ///
    /// Supported values:
    ///
    /// - 0: RGB
    /// - 2: unspecified
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `range`
    ///  Whether the data is using the full range of values.
    ///
    /// The range of the data.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `transfer-function`
    ///  The transfer function to use.
    ///
    /// Supported values:
    ///
    /// - 1,6,14,15: BT.709, BT.601, BT.2020
    /// - 2: unspecified
    /// - 4: gamma 2.2
    /// - 5: gamma 2.8
    /// - 8: linear
    /// - 13: sRGB
    /// - 16: BT.2100 PQ
    /// - 18: BT.2100 HLG
    ///
    /// Readable | Writeable
    #[doc(alias = "GdkCicpParams")]
    pub struct CicpParams(Object<ffi::GdkCicpParams, ffi::GdkCicpParamsClass>);

    match fn {
        type_ => || ffi::gdk_cicp_params_get_type(),
    }
}

impl CicpParams {
    /// Creates a new [`CicpParams`][crate::CicpParams] object.
    ///
    /// The initial values of the properties are the values for "undefined"
    /// and need to be set before a color state object can be built.
    ///
    /// # Returns
    ///
    /// a new [`CicpParams`][crate::CicpParams]
    #[doc(alias = "gdk_cicp_params_new")]
    pub fn new() -> CicpParams {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gdk_cicp_params_new()) }
    }

    /// Creates a new [`ColorState`][crate::ColorState] object for the cicp parameters in @self.
    ///
    /// Note that this may fail if the cicp parameters in @self are not
    /// supported by GTK. In that case, `NULL` is returned, and @error is set
    /// with an error message that can be presented to the user.
    ///
    /// # Returns
    ///
    /// A newly allocated [`ColorState`][crate::ColorState]
    #[doc(alias = "gdk_cicp_params_build_color_state")]
    pub fn build_color_state(&self) -> Result<ColorState, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::gdk_cicp_params_build_color_state(self.to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Returns the value of the color-primaries property
    /// of @self.
    ///
    /// # Returns
    ///
    /// the color-primaries value
    #[doc(alias = "gdk_cicp_params_get_color_primaries")]
    #[doc(alias = "get_color_primaries")]
    #[doc(alias = "color-primaries")]
    pub fn color_primaries(&self) -> u32 {
        unsafe { ffi::gdk_cicp_params_get_color_primaries(self.to_glib_none().0) }
    }

    /// Gets the matrix-coefficients property of @self.
    ///
    /// # Returns
    ///
    /// the matrix-coefficients value
    #[doc(alias = "gdk_cicp_params_get_matrix_coefficients")]
    #[doc(alias = "get_matrix_coefficients")]
    #[doc(alias = "matrix-coefficients")]
    pub fn matrix_coefficients(&self) -> u32 {
        unsafe { ffi::gdk_cicp_params_get_matrix_coefficients(self.to_glib_none().0) }
    }

    /// Gets the range property of @self.
    ///
    /// # Returns
    ///
    /// the range value
    #[doc(alias = "gdk_cicp_params_get_range")]
    #[doc(alias = "get_range")]
    pub fn range(&self) -> CicpRange {
        unsafe { from_glib(ffi::gdk_cicp_params_get_range(self.to_glib_none().0)) }
    }

    /// Gets the transfer-function property of @self.
    ///
    /// # Returns
    ///
    /// the transfer-function value
    #[doc(alias = "gdk_cicp_params_get_transfer_function")]
    #[doc(alias = "get_transfer_function")]
    #[doc(alias = "transfer-function")]
    pub fn transfer_function(&self) -> u32 {
        unsafe { ffi::gdk_cicp_params_get_transfer_function(self.to_glib_none().0) }
    }

    /// Sets the color-primaries property of @self.
    /// ## `color_primaries`
    /// the new color primaries value
    #[doc(alias = "gdk_cicp_params_set_color_primaries")]
    #[doc(alias = "color-primaries")]
    pub fn set_color_primaries(&self, color_primaries: u32) {
        unsafe {
            ffi::gdk_cicp_params_set_color_primaries(self.to_glib_none().0, color_primaries);
        }
    }

    /// @self a [`CicpParams`][crate::CicpParams]
    /// Sets the matrix-coefficients property of @self.
    /// ## `matrix_coefficients`
    /// the new matrix-coefficients value
    #[doc(alias = "gdk_cicp_params_set_matrix_coefficients")]
    #[doc(alias = "matrix-coefficients")]
    pub fn set_matrix_coefficients(&self, matrix_coefficients: u32) {
        unsafe {
            ffi::gdk_cicp_params_set_matrix_coefficients(
                self.to_glib_none().0,
                matrix_coefficients,
            );
        }
    }

    /// Sets the range property of @self
    /// ## `range`
    /// the range value
    #[doc(alias = "gdk_cicp_params_set_range")]
    #[doc(alias = "range")]
    pub fn set_range(&self, range: CicpRange) {
        unsafe {
            ffi::gdk_cicp_params_set_range(self.to_glib_none().0, range.into_glib());
        }
    }

    /// Sets the transfer-function property of @self.
    /// ## `transfer_function`
    /// the new transfer-function value
    #[doc(alias = "gdk_cicp_params_set_transfer_function")]
    #[doc(alias = "transfer-function")]
    pub fn set_transfer_function(&self, transfer_function: u32) {
        unsafe {
            ffi::gdk_cicp_params_set_transfer_function(self.to_glib_none().0, transfer_function);
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "color-primaries")]
    pub fn connect_color_primaries_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_color_primaries_trampoline<F: Fn(&CicpParams) + 'static>(
            this: *mut ffi::GdkCicpParams,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::color-primaries\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_color_primaries_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "matrix-coefficients")]
    pub fn connect_matrix_coefficients_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_matrix_coefficients_trampoline<F: Fn(&CicpParams) + 'static>(
            this: *mut ffi::GdkCicpParams,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::matrix-coefficients\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_matrix_coefficients_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "range")]
    pub fn connect_range_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_range_trampoline<F: Fn(&CicpParams) + 'static>(
            this: *mut ffi::GdkCicpParams,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::range\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_range_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "transfer-function")]
    pub fn connect_transfer_function_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_transfer_function_trampoline<F: Fn(&CicpParams) + 'static>(
            this: *mut ffi::GdkCicpParams,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::transfer-function\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_transfer_function_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

#[cfg(feature = "v4_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
impl Default for CicpParams {
    fn default() -> Self {
        Self::new()
    }
}