From b7630f26dfcb42a3929cb40cbd9ad6c461e2a692 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 20 Sep 2021 09:17:28 +0200 Subject: gdk: Add GdkColorSpace The code doesn't do anything yet, this is just the boilerplate. --- gdk/gdk.h | 1 + gdk/gdkcolorspace.c | 220 +++++++++++++++++++++++++++++++++++++++++++++ gdk/gdkcolorspace.h | 68 ++++++++++++++ gdk/gdkcolorspaceprivate.h | 26 ++++++ gdk/gdktypes.h | 1 + gdk/meson.build | 2 + 6 files changed, 318 insertions(+) create mode 100644 gdk/gdkcolorspace.c create mode 100644 gdk/gdkcolorspace.h create mode 100644 gdk/gdkcolorspaceprivate.h diff --git a/gdk/gdk.h b/gdk/gdk.h index 37bac5adc2..34209bde5e 100644 --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/gdk/gdkcolorspace.c b/gdk/gdkcolorspace.c new file mode 100644 index 0000000000..bc799268b6 --- /dev/null +++ b/gdk/gdkcolorspace.c @@ -0,0 +1,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 . + */ + +/** + * 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; +} + diff --git a/gdk/gdkcolorspace.h b/gdk/gdkcolorspace.h new file mode 100644 index 0000000000..acf91b41e5 --- /dev/null +++ b/gdk/gdkcolorspace.h @@ -0,0 +1,68 @@ +/* gdkcolorspace.h + * + * 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 . + */ + +#ifndef __GDK_COLOR_SPACE_H__ +#define __GDK_COLOR_SPACE_H__ + +#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include +#include + +G_BEGIN_DECLS + +#define GDK_TYPE_COLOR_SPACE (gdk_color_space_get_type ()) + +#define GDK_COLOR_SPACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_COLOR_SPACE, GdkColorSpace)) +#define GDK_IS_COLOR_SPACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_COLOR_SPACE)) +#define GDK_COLOR_SPACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_COLOR_SPACE, GdkColorSpaceClass)) +#define GDK_IS_COLOR_SPACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_COLOR_SPACE)) +#define GDK_COLOR_SPACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_COLOR_SPACE, GdkColorSpaceClass)) + + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkColorSpace, g_object_unref) + +typedef struct _GdkColorSpaceClass GdkColorSpaceClass; + +GDK_AVAILABLE_IN_4_6 +GType gdk_color_space_get_type (void) G_GNUC_CONST; + +GDK_AVAILABLE_IN_4_6 +GdkColorSpace * gdk_color_space_get_srgb (void) G_GNUC_CONST; + +GDK_AVAILABLE_IN_4_6 +GdkColorSpace * gdk_color_space_new_from_icc_profile (GBytes *icc_profile, + GError **error); + +GDK_AVAILABLE_IN_4_6 +gboolean gdk_color_space_supports_format (GdkColorSpace *self, + GdkMemoryFormat format); +GDK_AVAILABLE_IN_4_6 +GBytes * gdk_color_space_save_to_icc_profile (GdkColorSpace *self, + GError **error); + +GDK_AVAILABLE_IN_4_6 +gboolean gdk_color_space_equal (gconstpointer profile1, + gconstpointer profile2); + +G_END_DECLS + +#endif /* __GDK_COLOR_SPACE_H__ */ diff --git a/gdk/gdkcolorspaceprivate.h b/gdk/gdkcolorspaceprivate.h new file mode 100644 index 0000000000..06646c4394 --- /dev/null +++ b/gdk/gdkcolorspaceprivate.h @@ -0,0 +1,26 @@ +#ifndef __GDK_COLOR_SPACE_PRIVATE_H__ +#define __GDK_COLOR_SPACE_PRIVATE_H__ + +#include "gdkcolorspace.h" + +G_BEGIN_DECLS + +struct _GdkColorSpace +{ + GObject parent_instance; +}; + +struct _GdkColorSpaceClass +{ + GObjectClass parent_class; + + gboolean (* supports_format) (GdkColorSpace *self, + GdkMemoryFormat format); + GBytes * (* save_to_icc_profile) (GdkColorSpace *self, + GError **error); +}; + + +G_END_DECLS + +#endif /* __GDK_COLOR_SPACE_PRIVATE_H__ */ diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h index 3cf195df09..65be1075e3 100644 --- a/gdk/gdktypes.h +++ b/gdk/gdktypes.h @@ -73,6 +73,7 @@ typedef cairo_rectangle_int_t GdkRectangle; /* Forward declarations of commonly used types */ typedef struct _GdkRGBA GdkRGBA; +typedef struct _GdkColorSpace GdkColorSpace; typedef struct _GdkContentFormats GdkContentFormats; typedef struct _GdkContentProvider GdkContentProvider; typedef struct _GdkCursor GdkCursor; diff --git a/gdk/meson.build b/gdk/meson.build index f119fadf9d..f40d1d3b5b 100644 --- a/gdk/meson.build +++ b/gdk/meson.build @@ -4,6 +4,7 @@ gdk_public_sources = files([ 'gdkcairo.c', 'gdkcairocontext.c', 'gdkclipboard.c', + 'gdkcolorspace.c', 'gdkcontentdeserializer.c', 'gdkcontentformats.c', 'gdkcontentprovider.c', @@ -64,6 +65,7 @@ gdk_public_headers = files([ 'gdkcairo.h', 'gdkcairocontext.h', 'gdkclipboard.h', + 'gdkcolorspace.h', 'gdkcontentdeserializer.h', 'gdkcontentformats.h', 'gdkcontentprovider.h', -- cgit v1.2.1