summaryrefslogtreecommitdiff
path: root/gdk/gdkcolorspace.c
blob: bc799268b6c0cb50fe472ef1ee2be5aec79cf90e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* gdkcolorspace.c
 *
 * Copyright 2021 (c) Benjamin Otte
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * GdkColorSpace:
 *
 * `GdkColorSpace` is used to describe color spaces.
 *
 * Tell developers what a color space is instead of just linking to
 * https://en.wikipedia.org/wiki/Color_space
 *
 * `GdkColorSpace` objects are immutable and therefore threadsafe.
 *
 * Since: 4.6
 */

#include "config.h"

#include "gdkcolorspaceprivate.h"

#include "gdkintl.h"

enum {
  PROP_0,

  N_PROPS
};

//static GParamSpec *properties[N_PROPS];

G_DEFINE_TYPE (GdkColorSpace, gdk_color_space, G_TYPE_OBJECT)

static gboolean
gdk_color_space_default_supports_format (GdkColorSpace   *self,
                                         GdkMemoryFormat  format)
{
  return FALSE;
}

static GBytes *
gdk_color_space_default_save_to_icc_profile (GdkColorSpace  *self,
                                             GError        **error)
{
  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                       _("This color space does not support ICC profiles"));
  return NULL;
}

static void
gdk_color_space_set_property (GObject      *gobject,
                              guint         prop_id,
                              const GValue *value,
                              GParamSpec   *pspec)
{
  //GdkColorSpace *self = GDK_COLOR_SPACE (gobject);

  switch (prop_id)
    {
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
      break;
    }
}

static void
gdk_color_space_get_property (GObject    *gobject,
                              guint       prop_id,
                              GValue     *value,
                              GParamSpec *pspec)
{
  //GdkColorSpace *self = GDK_COLOR_SPACE (gobject);

  switch (prop_id)
    {
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
      break;
    }
}

static void
gdk_color_space_dispose (GObject *object)
{
  //GdkColorSpace *self = GDK_COLOR_SPACE (object);

  G_OBJECT_CLASS (gdk_color_space_parent_class)->dispose (object);
}

static void
gdk_color_space_class_init (GdkColorSpaceClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  klass->supports_format = gdk_color_space_default_supports_format;
  klass->save_to_icc_profile = gdk_color_space_default_save_to_icc_profile;

  gobject_class->set_property = gdk_color_space_set_property;
  gobject_class->get_property = gdk_color_space_get_property;
  gobject_class->dispose = gdk_color_space_dispose;
}

static void
gdk_color_space_init (GdkColorSpace *self)
{
}

/**
 * gdk_color_space_get_srgb:
 *
 * Returns the color profile representing the sRGB color space.
 *
 * If you don't know anything about color profiles but need one for
 * use with some function, this one is most likely the right one.
 *
 * Returns: (transfer none): the color profile for the sRGB
 *   color space.
 *
 * Since: 4.6
 */
GdkColorSpace *
gdk_color_space_get_srgb (void)
{
  static GdkColorSpace *srgb_profile;

  if (g_once_init_enter (&srgb_profile))
    {
      GdkColorSpace *new_profile;

      new_profile = NULL; //gdk_color_space_new_from_lcms_profile (cmsCreate_sRGBProfile (), NULL);
      g_assert (new_profile);

      g_once_init_leave (&srgb_profile, new_profile);
    }

  return srgb_profile;
}

/**
 * gdk_color_space_supports_format:
 * @self: a `GdkColorSpace`
 * @format: the format to check
 *
 * Checks if this color space can be used with textures in the given format.
 *
 * Returns: %TRUE if this colorspace supports the format
 *
 * Since: 4.6
 **/
gboolean
gdk_color_space_supports_format (GdkColorSpace   *self,
                                 GdkMemoryFormat  format)
{
  g_return_val_if_fail (GDK_IS_COLOR_SPACE (self), FALSE);
  g_return_val_if_fail (format < GDK_MEMORY_N_FORMATS, FALSE);

  return GDK_COLOR_SPACE_GET_CLASS (self)->supports_format (self, format);
}

/**
 * gdk_color_space_save_to_icc_profile:
 * @self: a `GdkColorSpace`
 * @error: Return location for an error
 *
 * Saves the color space to an
 * [ICC profile](https://en.wikipedia.org/wiki/ICC_profile).
 *
 * Some color spaces cannot be represented as ICC profiles. In
 * that case, an error will be set and %NULL will be returned.
 *
 * Returns: A new `GBytes` containing the ICC profile
 *
 * Since: 4.6
 **/
GBytes *
gdk_color_space_save_to_icc_profile (GdkColorSpace  *self,
                                     GError        **error)
{
  g_return_val_if_fail (GDK_IS_COLOR_SPACE (self), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  return GDK_COLOR_SPACE_GET_CLASS (self)->save_to_icc_profile (self, error);
}

/**
 * gdk_color_space_equal:
 * @profile1: (type GdkColorSpace): a `GdkColorSpace`
 * @profile2: (type GdkColorSpace): another `GdkColorSpace`
 *
 * Compares two `GdkColorSpace`s for equality.
 *
 * Note that this function is not guaranteed to be perfect and two equal
 * profiles may compare not equal. However, different profiles will
 * never compare equal.
 *
 * Returns: %TRUE if the two color profiles compare equal
 *
 * Since: 4.6
 */
gboolean
gdk_color_space_equal (gconstpointer profile1,
                       gconstpointer profile2)
{
  return profile1 == profile2;
}