gdk4/auto/color_state.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, CicpParams};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A [`ColorState`][crate::ColorState] object provides the information to interpret
10 /// colors and pixels in a variety of ways.
11 ///
12 /// They are also known as
13 /// [*color spaces*](https://en.wikipedia.org/wiki/Color_space).
14 ///
15 /// Crucially, GTK knows how to convert colors from one color
16 /// state to another.
17 ///
18 /// [`ColorState`][crate::ColorState] objects are immutable and therefore threadsafe.
19 #[derive(Debug, PartialOrd, Ord, Hash)]
20 pub struct ColorState(Shared<ffi::GdkColorState>);
21
22 match fn {
23 ref => |ptr| ffi::gdk_color_state_ref(ptr),
24 unref => |ptr| ffi::gdk_color_state_unref(ptr),
25 type_ => || ffi::gdk_color_state_get_type(),
26 }
27}
28
29impl ColorState {
30 /// Create a [`CicpParams`][crate::CicpParams] representing the colorstate.
31 ///
32 /// It is not guaranteed that every [`ColorState`][crate::ColorState] can be
33 /// represented with Cicp parameters. If that is the case,
34 /// this function returns `NULL`.
35 ///
36 /// # Returns
37 ///
38 /// A new [`CicpParams`][crate::CicpParams]
39 #[doc(alias = "gdk_color_state_create_cicp_params")]
40 pub fn create_cicp_params(&self) -> Option<CicpParams> {
41 unsafe {
42 from_glib_full(ffi::gdk_color_state_create_cicp_params(
43 self.to_glib_none().0,
44 ))
45 }
46 }
47
48 #[doc(alias = "gdk_color_state_equal")]
49 fn equal(&self, other: &ColorState) -> bool {
50 unsafe {
51 from_glib(ffi::gdk_color_state_equal(
52 self.to_glib_none().0,
53 other.to_glib_none().0,
54 ))
55 }
56 }
57
58 /// Returns the color state object representing the oklab color space.
59 ///
60 /// This is a perceptually uniform color state.
61 ///
62 /// # Returns
63 ///
64 /// the color state object for oklab
65 #[cfg(feature = "v4_18")]
66 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
67 #[doc(alias = "gdk_color_state_get_oklab")]
68 #[doc(alias = "get_oklab")]
69 pub fn oklab() -> ColorState {
70 assert_initialized_main_thread!();
71 unsafe { from_glib_full(ffi::gdk_color_state_get_oklab()) }
72 }
73
74 /// Returns the color state object representing the oklch color space.
75 ///
76 /// This is the polar variant of oklab, in which the hue is encoded as
77 /// a polar coordinate.
78 ///
79 /// # Returns
80 ///
81 /// the color state object for oklch
82 #[cfg(feature = "v4_18")]
83 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
84 #[doc(alias = "gdk_color_state_get_oklch")]
85 #[doc(alias = "get_oklch")]
86 pub fn oklch() -> ColorState {
87 assert_initialized_main_thread!();
88 unsafe { from_glib_full(ffi::gdk_color_state_get_oklch()) }
89 }
90
91 /// Returns the color state object representing the linear rec2100 color space.
92 ///
93 /// This color state uses the primaries defined by BT.2020-2 and BT.2100-0 and a linear
94 /// transfer function.
95 ///
96 /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 9/8/0/1.
97 ///
98 /// See e.g. [the CSS HDR Module](https://drafts.csswg.org/css-color-hdr/#valdef-color-rec2100-linear)
99 /// for details about this colorstate.
100 ///
101 /// # Returns
102 ///
103 /// the color state object for linearized rec2100
104 #[doc(alias = "gdk_color_state_get_rec2100_linear")]
105 #[doc(alias = "get_rec2100_linear")]
106 pub fn rec2100_linear() -> ColorState {
107 assert_initialized_main_thread!();
108 unsafe { from_glib_full(ffi::gdk_color_state_get_rec2100_linear()) }
109 }
110
111 /// Returns the color state object representing the rec2100-pq color space.
112 ///
113 /// This color state uses the primaries defined by BT.2020-2 and BT.2100-0 and the transfer
114 /// function defined by SMPTE ST 2084 and BT.2100-2.
115 ///
116 /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 9/16/0/1.
117 ///
118 /// See e.g. [the CSS HDR Module](https://drafts.csswg.org/css-color-hdr/#valdef-color-rec2100-pq)
119 /// for details about this colorstate.
120 ///
121 /// # Returns
122 ///
123 /// the color state object for rec2100-pq
124 #[doc(alias = "gdk_color_state_get_rec2100_pq")]
125 #[doc(alias = "get_rec2100_pq")]
126 pub fn rec2100_pq() -> ColorState {
127 assert_initialized_main_thread!();
128 unsafe { from_glib_full(ffi::gdk_color_state_get_rec2100_pq()) }
129 }
130
131 /// Returns the color state object representing the sRGB color space.
132 ///
133 /// This color state uses the primaries defined by BT.709-6 and the transfer function
134 /// defined by IEC 61966-2-1.
135 ///
136 /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 1/13/0/1.
137 ///
138 /// See e.g. [the CSS Color Module](https://www.w3.org/TR/css-color-4/#predefined-sRGB)
139 /// for details about this colorstate.
140 ///
141 /// # Returns
142 ///
143 /// the color state object for sRGB
144 #[doc(alias = "gdk_color_state_get_srgb")]
145 #[doc(alias = "get_srgb")]
146 pub fn srgb() -> ColorState {
147 assert_initialized_main_thread!();
148 unsafe { from_glib_full(ffi::gdk_color_state_get_srgb()) }
149 }
150
151 /// Returns the color state object representing the linearized sRGB color space.
152 ///
153 /// This color state uses the primaries defined by BT.709-6 and a linear transfer function.
154 ///
155 /// It is equivalent to the [Cicp](class.CicpParams.html) tuple 1/8/0/1.
156 ///
157 /// See e.g. [the CSS Color Module](https://www.w3.org/TR/css-color-4/#predefined-sRGB-linear)
158 /// for details about this colorstate.
159 ///
160 /// # Returns
161 ///
162 /// the color state object for linearized sRGB
163 #[doc(alias = "gdk_color_state_get_srgb_linear")]
164 #[doc(alias = "get_srgb_linear")]
165 pub fn srgb_linear() -> ColorState {
166 assert_initialized_main_thread!();
167 unsafe { from_glib_full(ffi::gdk_color_state_get_srgb_linear()) }
168 }
169}
170
171impl PartialEq for ColorState {
172 #[inline]
173 fn eq(&self, other: &Self) -> bool {
174 self.equal(other)
175 }
176}
177
178impl Eq for ColorState {}