gsk4/auto/
component_transfer.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;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// Specifies a transfer function for a color component to be applied
10    /// while rendering.
11    ///
12    /// The available functions include linear, piecewise-linear,
13    /// gamma and step functions.
14    ///
15    /// Note that the transfer function is applied to un-premultiplied
16    /// values, and all results are clamped to the [0, 1] range.
17    #[derive(Debug, PartialOrd, Ord, Hash)]
18    pub struct ComponentTransfer(Boxed<ffi::GskComponentTransfer>);
19
20    match fn {
21        copy => |ptr| ffi::gsk_component_transfer_copy(ptr),
22        free => |ptr| ffi::gsk_component_transfer_free(ptr),
23        type_ => || ffi::gsk_component_transfer_get_type(),
24    }
25}
26
27impl ComponentTransfer {
28    /// Creates a new component transfer that applies
29    /// a step function.
30    ///
31    /// The new value is computed as
32    ///
33    ///     C' = values[k]
34    ///
35    /// where k is the smallest value such that
36    ///
37    ///     k / n <= C < (k + 1) / n
38    ///
39    /// <figure>
40    ///   <picture>
41    ///     <source srcset="discrete-dark.png" media="(prefers-color-scheme: dark)">
42    ///       <img alt="Component transfer: discrete" src="discrete-light.png">
43    ///   </picture>
44    /// </figure>
45    /// ## `values`
46    /// Values
47    ///
48    /// # Returns
49    ///
50    /// a new [`ComponentTransfer`][crate::ComponentTransfer]
51    #[doc(alias = "gsk_component_transfer_new_discrete")]
52    pub fn new_discrete(values: &[f32]) -> ComponentTransfer {
53        assert_initialized_main_thread!();
54        let n = values.len() as _;
55        unsafe {
56            from_glib_full(ffi::gsk_component_transfer_new_discrete(
57                n,
58                values.to_glib_none().0,
59            ))
60        }
61    }
62
63    /// Creates a new component transfer that applies
64    /// a gamma transform.
65    ///
66    /// The new value is computed as
67    ///
68    ///     C' = amp * pow (C, exp) + ofs
69    ///
70    /// <figure>
71    ///   <picture>
72    ///     <source srcset="gamma-dark.png" media="(prefers-color-scheme: dark)">
73    ///       <img alt="Component transfer: gamma" src="gamma-light.png">
74    ///   </picture>
75    /// </figure>
76    /// ## `amp`
77    /// Amplitude
78    /// ## `exp`
79    /// Exponent
80    /// ## `ofs`
81    /// Offset
82    ///
83    /// # Returns
84    ///
85    /// a new [`ComponentTransfer`][crate::ComponentTransfer]
86    #[doc(alias = "gsk_component_transfer_new_gamma")]
87    pub fn new_gamma(amp: f32, exp: f32, ofs: f32) -> ComponentTransfer {
88        assert_initialized_main_thread!();
89        unsafe { from_glib_full(ffi::gsk_component_transfer_new_gamma(amp, exp, ofs)) }
90    }
91
92    /// Creates a new component transfer that doesn't
93    /// change the component value.
94    ///
95    /// <figure>
96    ///   <picture>
97    ///     <source srcset="identity-dark.png" media="(prefers-color-scheme: dark)">
98    ///       <img alt="Component transfer: identity" src="identity-light.png">
99    ///   </picture>
100    /// </figure>
101    ///
102    /// # Returns
103    ///
104    /// a new [`ComponentTransfer`][crate::ComponentTransfer]
105    #[doc(alias = "gsk_component_transfer_new_identity")]
106    pub fn new_identity() -> ComponentTransfer {
107        assert_initialized_main_thread!();
108        unsafe { from_glib_full(ffi::gsk_component_transfer_new_identity()) }
109    }
110
111    /// Creates a new component transfer that limits
112    /// the values of the component to `n` levels.
113    ///
114    /// The new value is computed as
115    ///
116    ///     C' = (floor (C * n) + 0.5) / n
117    ///
118    /// <figure>
119    ///   <picture>
120    ///     <source srcset="levels-dark.png" media="(prefers-color-scheme: dark)">
121    ///       <img alt="Component transfer: levels" src="levels-light.png">
122    ///   </picture>
123    /// </figure>
124    /// ## `n`
125    /// Number of levels
126    ///
127    /// # Returns
128    ///
129    /// a new [`ComponentTransfer`][crate::ComponentTransfer]
130    #[doc(alias = "gsk_component_transfer_new_levels")]
131    pub fn new_levels(n: f32) -> ComponentTransfer {
132        assert_initialized_main_thread!();
133        unsafe { from_glib_full(ffi::gsk_component_transfer_new_levels(n)) }
134    }
135
136    /// Creates a new component transfer that applies
137    /// a linear transform.
138    ///
139    /// The new value is computed as
140    ///
141    ///     C' = C * m + b
142    ///
143    /// <figure>
144    ///   <picture>
145    ///     <source srcset="linear-dark.png" media="(prefers-color-scheme: dark)">
146    ///       <img alt="Component transfer: linear" src="linear-light.png">
147    ///   </picture>
148    /// </figure>
149    /// ## `m`
150    /// Slope
151    /// ## `b`
152    /// Offset
153    ///
154    /// # Returns
155    ///
156    /// a new [`ComponentTransfer`][crate::ComponentTransfer]
157    #[doc(alias = "gsk_component_transfer_new_linear")]
158    pub fn new_linear(m: f32, b: f32) -> ComponentTransfer {
159        assert_initialized_main_thread!();
160        unsafe { from_glib_full(ffi::gsk_component_transfer_new_linear(m, b)) }
161    }
162
163    /// Creates a new component transfer that applies
164    /// a piecewise linear function.
165    ///
166    /// The new value is computed as
167    ///
168    ///     C' = values[k] + (C - k / (n - 1)) * n * (values[k + 1] - values[k])
169    ///
170    /// where k is the smallest value such that
171    ///
172    ///     k / (n - 1) <= C < (k + 1) / (n - 1)
173    ///
174    /// <figure>
175    ///   <picture>
176    ///     <source srcset="table-dark.png" media="(prefers-color-scheme: dark)">
177    ///       <img alt="Component transfer: table" src="table-light.png">
178    ///   </picture>
179    /// </figure>
180    /// ## `values`
181    /// Values
182    ///
183    /// # Returns
184    ///
185    /// a new [`ComponentTransfer`][crate::ComponentTransfer]
186    #[doc(alias = "gsk_component_transfer_new_table")]
187    pub fn new_table(values: &[f32]) -> ComponentTransfer {
188        assert_initialized_main_thread!();
189        let n = values.len() as _;
190        unsafe {
191            from_glib_full(ffi::gsk_component_transfer_new_table(
192                n,
193                values.to_glib_none().0,
194            ))
195        }
196    }
197
198    #[doc(alias = "gsk_component_transfer_equal")]
199    fn equal(&self, other: &ComponentTransfer) -> bool {
200        assert_initialized_main_thread!();
201        unsafe {
202            from_glib(ffi::gsk_component_transfer_equal(
203                ToGlibPtr::<*const ffi::GskComponentTransfer>::to_glib_none(self).0
204                    as glib::ffi::gconstpointer,
205                ToGlibPtr::<*const ffi::GskComponentTransfer>::to_glib_none(other).0
206                    as glib::ffi::gconstpointer,
207            ))
208        }
209    }
210}
211
212impl PartialEq for ComponentTransfer {
213    #[inline]
214    fn eq(&self, other: &Self) -> bool {
215        self.equal(other)
216    }
217}
218
219impl Eq for ComponentTransfer {}