1use 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 #[doc(alias = "GdkCicpParams")]
15 pub struct CicpParams(Object<ffi::GdkCicpParams, ffi::GdkCicpParamsClass>);
16
17 match fn {
18 type_ => || ffi::gdk_cicp_params_get_type(),
19 }
20}
21
22impl CicpParams {
23 #[doc(alias = "gdk_cicp_params_new")]
24 pub fn new() -> CicpParams {
25 assert_initialized_main_thread!();
26 unsafe { from_glib_full(ffi::gdk_cicp_params_new()) }
27 }
28
29 #[doc(alias = "gdk_cicp_params_build_color_state")]
30 pub fn build_color_state(&self) -> Result<ColorState, glib::Error> {
31 unsafe {
32 let mut error = std::ptr::null_mut();
33 let ret = ffi::gdk_cicp_params_build_color_state(self.to_glib_none().0, &mut error);
34 if error.is_null() {
35 Ok(from_glib_full(ret))
36 } else {
37 Err(from_glib_full(error))
38 }
39 }
40 }
41
42 #[doc(alias = "gdk_cicp_params_get_color_primaries")]
43 #[doc(alias = "get_color_primaries")]
44 #[doc(alias = "color-primaries")]
45 pub fn color_primaries(&self) -> u32 {
46 unsafe { ffi::gdk_cicp_params_get_color_primaries(self.to_glib_none().0) }
47 }
48
49 #[doc(alias = "gdk_cicp_params_get_matrix_coefficients")]
50 #[doc(alias = "get_matrix_coefficients")]
51 #[doc(alias = "matrix-coefficients")]
52 pub fn matrix_coefficients(&self) -> u32 {
53 unsafe { ffi::gdk_cicp_params_get_matrix_coefficients(self.to_glib_none().0) }
54 }
55
56 #[doc(alias = "gdk_cicp_params_get_range")]
57 #[doc(alias = "get_range")]
58 pub fn range(&self) -> CicpRange {
59 unsafe { from_glib(ffi::gdk_cicp_params_get_range(self.to_glib_none().0)) }
60 }
61
62 #[doc(alias = "gdk_cicp_params_get_transfer_function")]
63 #[doc(alias = "get_transfer_function")]
64 #[doc(alias = "transfer-function")]
65 pub fn transfer_function(&self) -> u32 {
66 unsafe { ffi::gdk_cicp_params_get_transfer_function(self.to_glib_none().0) }
67 }
68
69 #[doc(alias = "gdk_cicp_params_set_color_primaries")]
70 #[doc(alias = "color-primaries")]
71 pub fn set_color_primaries(&self, color_primaries: u32) {
72 unsafe {
73 ffi::gdk_cicp_params_set_color_primaries(self.to_glib_none().0, color_primaries);
74 }
75 }
76
77 #[doc(alias = "gdk_cicp_params_set_matrix_coefficients")]
78 #[doc(alias = "matrix-coefficients")]
79 pub fn set_matrix_coefficients(&self, matrix_coefficients: u32) {
80 unsafe {
81 ffi::gdk_cicp_params_set_matrix_coefficients(
82 self.to_glib_none().0,
83 matrix_coefficients,
84 );
85 }
86 }
87
88 #[doc(alias = "gdk_cicp_params_set_range")]
89 #[doc(alias = "range")]
90 pub fn set_range(&self, range: CicpRange) {
91 unsafe {
92 ffi::gdk_cicp_params_set_range(self.to_glib_none().0, range.into_glib());
93 }
94 }
95
96 #[doc(alias = "gdk_cicp_params_set_transfer_function")]
97 #[doc(alias = "transfer-function")]
98 pub fn set_transfer_function(&self, transfer_function: u32) {
99 unsafe {
100 ffi::gdk_cicp_params_set_transfer_function(self.to_glib_none().0, transfer_function);
101 }
102 }
103
104 #[cfg(feature = "v4_16")]
105 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
106 #[doc(alias = "color-primaries")]
107 pub fn connect_color_primaries_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
108 unsafe extern "C" fn notify_color_primaries_trampoline<F: Fn(&CicpParams) + 'static>(
109 this: *mut ffi::GdkCicpParams,
110 _param_spec: glib::ffi::gpointer,
111 f: glib::ffi::gpointer,
112 ) {
113 let f: &F = &*(f as *const F);
114 f(&from_glib_borrow(this))
115 }
116 unsafe {
117 let f: Box_<F> = Box_::new(f);
118 connect_raw(
119 self.as_ptr() as *mut _,
120 c"notify::color-primaries".as_ptr() as *const _,
121 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
122 notify_color_primaries_trampoline::<F> as *const (),
123 )),
124 Box_::into_raw(f),
125 )
126 }
127 }
128
129 #[cfg(feature = "v4_16")]
130 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
131 #[doc(alias = "matrix-coefficients")]
132 pub fn connect_matrix_coefficients_notify<F: Fn(&Self) + 'static>(
133 &self,
134 f: F,
135 ) -> SignalHandlerId {
136 unsafe extern "C" fn notify_matrix_coefficients_trampoline<F: Fn(&CicpParams) + 'static>(
137 this: *mut ffi::GdkCicpParams,
138 _param_spec: glib::ffi::gpointer,
139 f: glib::ffi::gpointer,
140 ) {
141 let f: &F = &*(f as *const F);
142 f(&from_glib_borrow(this))
143 }
144 unsafe {
145 let f: Box_<F> = Box_::new(f);
146 connect_raw(
147 self.as_ptr() as *mut _,
148 c"notify::matrix-coefficients".as_ptr() as *const _,
149 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
150 notify_matrix_coefficients_trampoline::<F> as *const (),
151 )),
152 Box_::into_raw(f),
153 )
154 }
155 }
156
157 #[cfg(feature = "v4_16")]
158 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
159 #[doc(alias = "range")]
160 pub fn connect_range_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
161 unsafe extern "C" fn notify_range_trampoline<F: Fn(&CicpParams) + 'static>(
162 this: *mut ffi::GdkCicpParams,
163 _param_spec: glib::ffi::gpointer,
164 f: glib::ffi::gpointer,
165 ) {
166 let f: &F = &*(f as *const F);
167 f(&from_glib_borrow(this))
168 }
169 unsafe {
170 let f: Box_<F> = Box_::new(f);
171 connect_raw(
172 self.as_ptr() as *mut _,
173 c"notify::range".as_ptr() as *const _,
174 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
175 notify_range_trampoline::<F> as *const (),
176 )),
177 Box_::into_raw(f),
178 )
179 }
180 }
181
182 #[cfg(feature = "v4_16")]
183 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
184 #[doc(alias = "transfer-function")]
185 pub fn connect_transfer_function_notify<F: Fn(&Self) + 'static>(
186 &self,
187 f: F,
188 ) -> SignalHandlerId {
189 unsafe extern "C" fn notify_transfer_function_trampoline<F: Fn(&CicpParams) + 'static>(
190 this: *mut ffi::GdkCicpParams,
191 _param_spec: glib::ffi::gpointer,
192 f: glib::ffi::gpointer,
193 ) {
194 let f: &F = &*(f as *const F);
195 f(&from_glib_borrow(this))
196 }
197 unsafe {
198 let f: Box_<F> = Box_::new(f);
199 connect_raw(
200 self.as_ptr() as *mut _,
201 c"notify::transfer-function".as_ptr() as *const _,
202 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
203 notify_transfer_function_trampoline::<F> as *const (),
204 )),
205 Box_::into_raw(f),
206 )
207 }
208 }
209}
210
211#[cfg(feature = "v4_16")]
212#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
213impl Default for CicpParams {
214 fn default() -> Self {
215 Self::new()
216 }
217}