| 1 | /* GDK - The GIMP Drawing Kit |
| 2 | * |
| 3 | * Copyright (C) 2021 Benjamin Otte |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "config.h"cxx . . $ `<file>/build/config.h`/ |
| 20 | |
| 21 | #include "gdkcolorprivate.h"cxx . . $ `<file>/gdk/gdkcolorprivate.h`/ |
| 22 | #include "gdkcolorstateprivate.h"cxx . . $ `<file>/gdk/gdkcolorstateprivate.h`/ |
| 23 | #include "gdkrgbaprivate.h"cxx . . $ `<file>/gdk/gdkrgbaprivate.h`/ |
| 24 | |
| 25 | /*< private > |
| 26 | * GdkColor: |
| 27 | * @color_state: the color state to interpret the values in |
| 28 | * @values: the 3 coordinates that define the color, followed |
| 29 | * by the alpha value |
| 30 | * |
| 31 | * A `GdkColor` represents a color. |
| 32 | * |
| 33 | * The color state defines the meaning and range of the values. |
| 34 | * E.g., the srgb color state has r, g, b components representing |
| 35 | * red, green and blue with a range of [0,1], while the oklch color |
| 36 | * state has l, c, h components representing luminosity, chromaticity |
| 37 | * and hue, with l ranging from 0 to 1 and c from 0 to about 0.4, while |
| 38 | * h is interpreted as angle in degrees. |
| 39 | * |
| 40 | * value[3] is always the alpha value with a range of [0,1]. |
| 41 | * |
| 42 | * The values are also available under the names red, green, blue |
| 43 | * and alpha, or r, g, b and a. |
| 44 | */ |
| 45 | |
| 46 | /*< private > |
| 47 | * gdk_color_init: |
| 48 | * @self: the `GdkColor` struct to initialize |
| 49 | * @color_state: the color state |
| 50 | * @values: the values |
| 51 | * |
| 52 | * Initializes the `GdkColor` with the given color state |
| 53 | * and values. |
| 54 | * |
| 55 | * Note that this takes a reference on @color_state that |
| 56 | * must be freed by calling [[email protected]] |
| 57 | * when the `GdkColor` is no longer needed. |
| 58 | */ |
| 59 | void |
| 60 | (gdk_color_initcxx . . $ gdk_color_init(d32b7139ef9e8598).) (GdkColorcxx . . $ GdkColor# *self, |
| 61 | GdkColorStatecxx . . $ GdkColorState# *color_state, |
| 62 | const float values[4]) |
| 63 | { |
| 64 | _gdk_color_initcxx . . $ _gdk_color_init(d32b7139ef9e8598). (self, color_state, values); |
| 65 | } |
| 66 | |
| 67 | /*< private > |
| 68 | * gdk_color_init_copy: |
| 69 | * @self: the `GdkColor` struct to initialize |
| 70 | * @color: the `GdkColor` to copy |
| 71 | * |
| 72 | * Initializes the `GdkColor` by copying the contents |
| 73 | * of another `GdkColor`. |
| 74 | * |
| 75 | * Note that this takes a reference on the color state |
| 76 | * that must be freed by calling [[email protected]] |
| 77 | * when the `GdkColor` is no longer needed. |
| 78 | */ |
| 79 | void |
| 80 | (gdk_color_init_copycxx . . $ gdk_color_init_copy(91ab563183ff6c74).) (GdkColorcxx . . $ GdkColor# *self, |
| 81 | const GdkColorcxx . . $ GdkColor# *color) |
| 82 | { |
| 83 | _gdk_color_init_copycxx . . $ _gdk_color_init_copy(91ab563183ff6c74). (self, color); |
| 84 | } |
| 85 | |
| 86 | /*< private > |
| 87 | * gdk_color_init_from_rgba: |
| 88 | * @self: the `GdkColor` struct to initialize |
| 89 | * @rgba: the `GdkRGBA` to copy |
| 90 | * |
| 91 | * Initializes the `GdkColor` by copying the contents |
| 92 | * of a `GdkRGBA`. |
| 93 | * |
| 94 | * Note that `GdkRGBA` colors are always in the sRGB |
| 95 | * color state. |
| 96 | * |
| 97 | * Note that this takes a reference on the color state |
| 98 | * that must be freed by calling [[email protected]] |
| 99 | * when the `GdkColor` is no longer needed. |
| 100 | */ |
| 101 | void |
| 102 | (gdk_color_init_from_rgbacxx . . $ gdk_color_init_from_rgba(589eb61072587365).) (GdkColorcxx . . $ GdkColor# *self, |
| 103 | const GdkRGBAcxx . . $ GdkRGBA# *rgba) |
| 104 | { |
| 105 | _gdk_color_init_from_rgbacxx . . $ _gdk_color_init_from_rgba(589eb61072587365). (self, rgba); |
| 106 | } |
| 107 | |
| 108 | /*< private > |
| 109 | * @self: a `GdkColor` |
| 110 | * |
| 111 | * Drop the reference on the color state of @self. |
| 112 | * |
| 113 | * After this, @self is empty and can be initialized again |
| 114 | * with [[email protected]] and its variants. |
| 115 | */ |
| 116 | void |
| 117 | (gdk_color_finishcxx . . $ gdk_color_finish(f85da762293f2dc7).) (GdkColorcxx . . $ GdkColor# *self) |
| 118 | { |
| 119 | _gdk_color_finishcxx . . $ _gdk_color_finish(f85da762293f2dc7). (self); |
| 120 | } |
| 121 | |
| 122 | /*< private > |
| 123 | * gdk_color_equal: |
| 124 | * @self: a `GdkColor` |
| 125 | * @other: another `GdkColor` |
| 126 | * |
| 127 | * Compares two `GdkColor` structs for equality. |
| 128 | * |
| 129 | * Returns: `TRUE` if @self and @other are equal |
| 130 | */ |
| 131 | gbooleancxx . . $ gboolean# |
| 132 | (gdk_color_equalcxx . . $ gdk_color_equal(420b9312adb041d2).) (const GdkColorcxx . . $ GdkColor# *self, |
| 133 | const GdkColorcxx . . $ GdkColor# *other) |
| 134 | { |
| 135 | return _gdk_color_equalcxx . . $ _gdk_color_equal(420b9312adb041d2). (self, other); |
| 136 | } |
| 137 | |
| 138 | /*< private > |
| 139 | * gdk_color_is_clear: |
| 140 | * @self: a `GdkColor` |
| 141 | * |
| 142 | * Returns whether @self is fully transparent. |
| 143 | * |
| 144 | * Returns: `TRUE` if @self is transparent |
| 145 | */ |
| 146 | gbooleancxx . . $ gboolean# |
| 147 | (gdk_color_is_clearcxx . . $ gdk_color_is_clear(67c193e548a47067).) (const GdkColorcxx . . $ GdkColor# *self) |
| 148 | { |
| 149 | return _gdk_color_is_clearcxx . . $ _gdk_color_is_clear(67c193e548a47067). (self); |
| 150 | } |
| 151 | |
| 152 | /*< private > |
| 153 | * gdk_color_is_opaque: |
| 154 | * @self: a `GdkColor` |
| 155 | * |
| 156 | * Returns whether @self is fully opaque. |
| 157 | * |
| 158 | * Returns: `TRUE` if @self if opaque |
| 159 | */ |
| 160 | gbooleancxx . . $ gboolean# |
| 161 | (gdk_color_is_opaquecxx . . $ gdk_color_is_opaque(67c193e548a47067).) (const GdkColorcxx . . $ GdkColor# *self) |
| 162 | { |
| 163 | return _gdk_color_is_opaquecxx . . $ _gdk_color_is_opaque(67c193e548a47067). (self); |
| 164 | } |
| 165 | |
| 166 | /*< private > |
| 167 | * gdk_color_is_srgb: |
| 168 | * @self: a `GdkColor` |
| 169 | * |
| 170 | * Returns whether @self is inside the sRGB color volume. |
| 171 | * |
| 172 | * Returns: `TRUE` if @self if inside the sRGB color volume |
| 173 | */ |
| 174 | gbooleancxx . . $ gboolean# |
| 175 | gdk_color_is_srgbcxx . . $ gdk_color_is_srgb(67c193e548a47067). (const GdkColorcxx . . $ GdkColor# *self) |
| 176 | { |
| 177 | return self->color_statecxx . . $ _GdkColor#color_state. == GDK_COLOR_STATE_SRGBcxx . . $ `gdk/gdkcolorstateprivate.h:87:9`! || |
| 178 | self->color_statecxx . . $ _GdkColor#color_state. == GDK_COLOR_STATE_SRGB_LINEARcxx . . $ `gdk/gdkcolorstateprivate.h:88:9`!; |
| 179 | } |
| 180 | |
| 181 | /*< private > |
| 182 | * gdk_color_convert: |
| 183 | * @self: the `GdkColor` to store the result in |
| 184 | * @color_state: the target color state |
| 185 | * @other: the `GdkColor` to convert |
| 186 | * |
| 187 | * Converts a given `GdkColor` to another color state. |
| 188 | * |
| 189 | * After the conversion, @self will represent the same |
| 190 | * color as @other in @color_state, to the degree possible. |
| 191 | * |
| 192 | * Different color states have different gamuts of colors |
| 193 | * they can represent, and converting a color to a color |
| 194 | * state with a smaller gamut may yield an 'out of gamut' |
| 195 | * result. |
| 196 | */ |
| 197 | void |
| 198 | (gdk_color_convertcxx . . $ gdk_color_convert(ab9eaed2105a7344).) (GdkColorcxx . . $ GdkColor# *self, |
| 199 | GdkColorStatecxx . . $ GdkColorState# *color_state, |
| 200 | const GdkColorcxx . . $ GdkColor# *other) |
| 201 | { |
| 202 | gdk_color_convertcxx . . $ `gdk/gdkcolorimpl.h:93:9`! (self, color_state, other); |
| 203 | } |
| 204 | |
| 205 | /*< private > |
| 206 | * gdk_color_to_float: |
| 207 | * @self: a `GdkColor` |
| 208 | * @target: the color state to convert to |
| 209 | * @values: the location to store the result in |
| 210 | * |
| 211 | * Converts a given `GdkColor to another color state |
| 212 | * and stores the result in a `float[4]`. |
| 213 | */ |
| 214 | void |
| 215 | (gdk_color_to_floatcxx . . $ gdk_color_to_float(e3874f90a9fb702e).) (const GdkColorcxx . . $ GdkColor# *self, |
| 216 | GdkColorStatecxx . . $ GdkColorState# *target, |
| 217 | float values[4]) |
| 218 | { |
| 219 | gdk_color_to_floatcxx . . $ `gdk/gdkcolorimpl.h:113:9`! (self, target, values); |
| 220 | } |
| 221 | |
| 222 | /*< private > |
| 223 | * gdk_color_from_rgba: |
| 224 | * @self: the `GdkColor` to store the result in |
| 225 | * @color_state: the target color state |
| 226 | * @rgba: the `GdkRGBA` to convert |
| 227 | * |
| 228 | * Converts a given `GdkRGBA` to the target @color_state. |
| 229 | */ |
| 230 | void |
| 231 | gdk_color_from_rgbacxx . . $ gdk_color_from_rgba(58f908a1c91dd023). (GdkColorcxx . . $ GdkColor# *self, |
| 232 | GdkColorStatecxx . . $ GdkColorState# *color_state, |
| 233 | const GdkRGBAcxx . . $ GdkRGBA# *rgba) |
| 234 | { |
| 235 | GdkColorcxx . . $ GdkColor# tmp = { |
| 236 | .color_state = GDK_COLOR_STATE_SRGBcxx . . $ `gdk/gdkcolorstateprivate.h:87:9`!, |
| 237 | .r = rgba->redcxx . . $ _GdkRGBA#red., |
| 238 | .g = rgba->greencxx . . $ _GdkRGBA#green., |
| 239 | .b = rgba->bluecxx . . $ _GdkRGBA#blue., |
| 240 | .a = rgba->alphacxx . . $ _GdkRGBA#alpha. |
| 241 | }; |
| 242 | |
| 243 | gdk_color_convertcxx . . $ `gdk/gdkcolorimpl.h:93:9`! (self, color_state, &tmp); |
| 244 | gdk_color_finishcxx . . $ `gdk/gdkcolorimpl.h:52:9`! (&tmp); |
| 245 | } |
| 246 | |
| 247 | /*< private > |
| 248 | * gdk_color_print: |
| 249 | * @self: the `GdkColor` to print |
| 250 | * @string: the string to print to |
| 251 | * |
| 252 | * Appends a representation of @self to @string. |
| 253 | * |
| 254 | * The representation is inspired by CSS3 colors, |
| 255 | * but not 100% identical, and looks like this: |
| 256 | * |
| 257 | * color(NAME R G B / A) |
| 258 | * |
| 259 | * where `NAME` identifies color state, and |
| 260 | * `R`, `G`, `B` and `A` are the components of the color. |
| 261 | * |
| 262 | * The alpha may be omitted if it is 1. |
| 263 | */ |
| 264 | void |
| 265 | gdk_color_printcxx . . $ gdk_color_print(fb9f1d77eaba4d4c). (const GdkColorcxx . . $ GdkColor# *self, |
| 266 | GStringcxx . . $ GString# *string) |
| 267 | { |
| 268 | if (gdk_color_state_equalcxx . . $ `gdk/gdkcolorstateprivate.h:163:9`! (self->color_state, GDK_COLOR_STATE_SRGBcxx . . $ `gdk/gdkcolorstateprivate.h:87:9`!)) |
| 269 | { |
| 270 | gdk_rgba_printcxx . . $ gdk_rgba_print(deb62284e39db7ed). ((const GdkRGBAcxx . . $ GdkRGBA# *) self->valuescxx . . $ _GdkColor#$anonymous_type_0#values., string); |
| 271 | } |
| 272 | else |
| 273 | { |
| 274 | g_string_append_printfcxx . . $ g_string_append_printf(eeccf837eb821d11). (string, "color(%s %g %g %g", |
| 275 | gdk_color_state_get_namecxx . . $ gdk_color_state_get_name(5247ad7030db0d80). (self->color_statecxx . . $ _GdkColor#color_state.), |
| 276 | self->rcxx . . $ _GdkColor#$anonymous_type_0#$anonymous_type_1#r., self->gcxx . . $ _GdkColor#$anonymous_type_0#$anonymous_type_1#g., self->bcxx . . $ _GdkColor#$anonymous_type_0#$anonymous_type_1#b.); |
| 277 | if (self->acxx . . $ _GdkColor#$anonymous_type_0#$anonymous_type_1#a. < 1) |
| 278 | g_string_append_printfcxx . . $ g_string_append_printf(eeccf837eb821d11). (string, " / %g", self->acxx . . $ _GdkColor#$anonymous_type_0#$anonymous_type_1#a.); |
| 279 | g_string_append_ccxx . . $ `<external>/2906017559248664336/gstring.h:215:9`! (string, ')'); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /*< private > |
| 284 | * gdk_color_to_string: |
| 285 | * @self: the `GdkColor` to print |
| 286 | * |
| 287 | * Create a string representation of @self. |
| 288 | * |
| 289 | * See [[email protected]] for details about |
| 290 | * the format. |
| 291 | |
| 292 | * Returns: (transfer full): a newly-allocated string |
| 293 | */ |
| 294 | char * |
| 295 | gdk_color_to_stringcxx . . $ gdk_color_to_string(a4bcad1e1ca37bb7). (const GdkColorcxx . . $ GdkColor# *self) |
| 296 | { |
| 297 | GStringcxx . . $ GString# *string = g_string_newcxx . . $ g_string_new(e8737c02110bb79b). (""); |
| 298 | gdk_color_printcxx . . $ gdk_color_print(fb9f1d77eaba4d4c). (self, string); |
| 299 | return g_string_freecxx . . $ `<external>/2906017559248664336/gstring.h:73:9`! (string, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!); |
| 300 | } |
| 301 | |
| 302 |