1use crate::{CicpRange, ColorState, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 unsafe {
240 let f: &F = &*(f as *const F);
241 f(&from_glib_borrow(this))
242 }
243 }
244 unsafe {
245 let f: Box_<F> = Box_::new(f);
246 connect_raw(
247 self.as_ptr() as *mut _,
248 c"notify::color-primaries".as_ptr() as *const _,
249 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
250 notify_color_primaries_trampoline::<F> as *const (),
251 )),
252 Box_::into_raw(f),
253 )
254 }
255 }
256
257 #[cfg(feature = "v4_16")]
258 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
259 #[doc(alias = "matrix-coefficients")]
260 pub fn connect_matrix_coefficients_notify<F: Fn(&Self) + 'static>(
261 &self,
262 f: F,
263 ) -> SignalHandlerId {
264 unsafe extern "C" fn notify_matrix_coefficients_trampoline<F: Fn(&CicpParams) + 'static>(
265 this: *mut ffi::GdkCicpParams,
266 _param_spec: glib::ffi::gpointer,
267 f: glib::ffi::gpointer,
268 ) {
269 unsafe {
270 let f: &F = &*(f as *const F);
271 f(&from_glib_borrow(this))
272 }
273 }
274 unsafe {
275 let f: Box_<F> = Box_::new(f);
276 connect_raw(
277 self.as_ptr() as *mut _,
278 c"notify::matrix-coefficients".as_ptr() as *const _,
279 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280 notify_matrix_coefficients_trampoline::<F> as *const (),
281 )),
282 Box_::into_raw(f),
283 )
284 }
285 }
286
287 #[cfg(feature = "v4_16")]
288 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
289 #[doc(alias = "range")]
290 pub fn connect_range_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
291 unsafe extern "C" fn notify_range_trampoline<F: Fn(&CicpParams) + 'static>(
292 this: *mut ffi::GdkCicpParams,
293 _param_spec: glib::ffi::gpointer,
294 f: glib::ffi::gpointer,
295 ) {
296 unsafe {
297 let f: &F = &*(f as *const F);
298 f(&from_glib_borrow(this))
299 }
300 }
301 unsafe {
302 let f: Box_<F> = Box_::new(f);
303 connect_raw(
304 self.as_ptr() as *mut _,
305 c"notify::range".as_ptr() as *const _,
306 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
307 notify_range_trampoline::<F> as *const (),
308 )),
309 Box_::into_raw(f),
310 )
311 }
312 }
313
314 #[cfg(feature = "v4_16")]
315 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
316 #[doc(alias = "transfer-function")]
317 pub fn connect_transfer_function_notify<F: Fn(&Self) + 'static>(
318 &self,
319 f: F,
320 ) -> SignalHandlerId {
321 unsafe extern "C" fn notify_transfer_function_trampoline<F: Fn(&CicpParams) + 'static>(
322 this: *mut ffi::GdkCicpParams,
323 _param_spec: glib::ffi::gpointer,
324 f: glib::ffi::gpointer,
325 ) {
326 unsafe {
327 let f: &F = &*(f as *const F);
328 f(&from_glib_borrow(this))
329 }
330 }
331 unsafe {
332 let f: Box_<F> = Box_::new(f);
333 connect_raw(
334 self.as_ptr() as *mut _,
335 c"notify::transfer-function".as_ptr() as *const _,
336 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
337 notify_transfer_function_trampoline::<F> as *const (),
338 )),
339 Box_::into_raw(f),
340 )
341 }
342 }
343}
344
345#[cfg(feature = "v4_16")]
346#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
347impl Default for CicpParams {
348 fn default() -> Self {
349 Self::new()
350 }
351}