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 /// ## `values`
39 /// Values
40 ///
41 /// # Returns
42 ///
43 /// a new [`ComponentTransfer`][crate::ComponentTransfer]
44 #[doc(alias = "gsk_component_transfer_new_discrete")]
45 pub fn new_discrete(values: &[f32]) -> ComponentTransfer {
46 assert_initialized_main_thread!();
47 let n = values.len() as _;
48 unsafe {
49 from_glib_full(ffi::gsk_component_transfer_new_discrete(
50 n,
51 values.to_glib_none().0,
52 ))
53 }
54 }
55
56 /// Creates a new component transfer that applies
57 /// a gamma transform.
58 ///
59 /// The new value is computed as
60 ///
61 /// C' = amp * pow (C, exp) + ofs
62 /// ## `amp`
63 /// Amplitude
64 /// ## `exp`
65 /// Exponent
66 /// ## `ofs`
67 /// Offset
68 ///
69 /// # Returns
70 ///
71 /// a new [`ComponentTransfer`][crate::ComponentTransfer]
72 #[doc(alias = "gsk_component_transfer_new_gamma")]
73 pub fn new_gamma(amp: f32, exp: f32, ofs: f32) -> ComponentTransfer {
74 assert_initialized_main_thread!();
75 unsafe { from_glib_full(ffi::gsk_component_transfer_new_gamma(amp, exp, ofs)) }
76 }
77
78 /// Creates a new component transfer that doesn't
79 /// change the component value.
80 ///
81 /// # Returns
82 ///
83 /// a new [`ComponentTransfer`][crate::ComponentTransfer]
84 #[doc(alias = "gsk_component_transfer_new_identity")]
85 pub fn new_identity() -> ComponentTransfer {
86 assert_initialized_main_thread!();
87 unsafe { from_glib_full(ffi::gsk_component_transfer_new_identity()) }
88 }
89
90 /// Creates a new component transfer that limits
91 /// the values of the component to `n` levels.
92 ///
93 /// The new value is computed as
94 ///
95 /// C' = floor (C * n) / n
96 /// ## `n`
97 /// Number of levels
98 ///
99 /// # Returns
100 ///
101 /// a new [`ComponentTransfer`][crate::ComponentTransfer]
102 #[doc(alias = "gsk_component_transfer_new_levels")]
103 pub fn new_levels(n: f32) -> ComponentTransfer {
104 assert_initialized_main_thread!();
105 unsafe { from_glib_full(ffi::gsk_component_transfer_new_levels(n)) }
106 }
107
108 /// Creates a new component transfer that applies
109 /// a linear transform.
110 ///
111 /// The new value is computed as
112 ///
113 /// C' = C * m + b
114 /// ## `m`
115 /// Slope
116 /// ## `b`
117 /// Offset
118 ///
119 /// # Returns
120 ///
121 /// a new [`ComponentTransfer`][crate::ComponentTransfer]
122 #[doc(alias = "gsk_component_transfer_new_linear")]
123 pub fn new_linear(m: f32, b: f32) -> ComponentTransfer {
124 assert_initialized_main_thread!();
125 unsafe { from_glib_full(ffi::gsk_component_transfer_new_linear(m, b)) }
126 }
127
128 /// Creates a new component transfer that applies
129 /// a piecewise linear function.
130 ///
131 /// The new value is computed as
132 ///
133 /// C' = values[k] + (C - k / n) * n * (values[k + 1] - values[k])
134 ///
135 /// where k is the smallest value such that
136 ///
137 /// k / n <= C < (k + 1) / n
138 /// ## `values`
139 /// Values
140 ///
141 /// # Returns
142 ///
143 /// a new [`ComponentTransfer`][crate::ComponentTransfer]
144 #[doc(alias = "gsk_component_transfer_new_table")]
145 pub fn new_table(values: &[f32]) -> ComponentTransfer {
146 assert_initialized_main_thread!();
147 let n = values.len() as _;
148 unsafe {
149 from_glib_full(ffi::gsk_component_transfer_new_table(
150 n,
151 values.to_glib_none().0,
152 ))
153 }
154 }
155
156 #[doc(alias = "gsk_component_transfer_equal")]
157 fn equal(&self, other: &ComponentTransfer) -> bool {
158 assert_initialized_main_thread!();
159 unsafe {
160 from_glib(ffi::gsk_component_transfer_equal(
161 ToGlibPtr::<*const ffi::GskComponentTransfer>::to_glib_none(self).0
162 as glib::ffi::gconstpointer,
163 ToGlibPtr::<*const ffi::GskComponentTransfer>::to_glib_none(other).0
164 as glib::ffi::gconstpointer,
165 ))
166 }
167 }
168}
169
170impl PartialEq for ComponentTransfer {
171 #[inline]
172 fn eq(&self, other: &Self) -> bool {
173 self.equal(other)
174 }
175}
176
177impl Eq for ComponentTransfer {}