[gtk/matthiasc/color-profile-rebased: 10/57] gdk: Add GdkColorSpace




commit 7444464e3f82d40b93f88710fede1d360cc78a1c
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 20 09:17:28 2021 +0200

    gdk: Add GdkColorSpace
    
    The code doesn't do anything yet, this is just the boilerplate.

 gdk/gdk.h                  |   1 +
 gdk/gdkcolorspace.c        | 212 +++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkcolorspace.h        |  71 +++++++++++++++
 gdk/gdkcolorspaceprivate.h |  28 ++++++
 gdk/gdktypes.h             |   1 +
 gdk/meson.build            |   2 +
 6 files changed, 315 insertions(+)
---
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 <gdk/gdkcairo.h>
 #include <gdk/gdkcairocontext.h>
 #include <gdk/gdkclipboard.h>
+#include <gdk/gdkcolorspace.h>
 #include <gdk/gdkconfig.h>
 #include <gdk/gdkcontentdeserializer.h>
 #include <gdk/gdkcontentformats.h>
diff --git a/gdk/gdkcolorspace.c b/gdk/gdkcolorspace.c
new file mode 100644
index 0000000000..719419b098
--- /dev/null
+++ b/gdk/gdkcolorspace.c
@@ -0,0 +1,212 @@
+/* gdkcolor_space.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.8
+ */
+
+#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 int
+gdk_color_space_default_get_n_components (GdkColorSpace *self)
+{
+  return 0;
+}
+
+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;
+  klass->get_n_components = gdk_color_space_default_get_n_components;
+
+  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_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.8
+ **/
+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.8
+ **/
+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);
+}
+
+gboolean
+gdk_color_space_is_linear (GdkColorSpace *self)
+{
+  g_return_val_if_fail (GDK_IS_COLOR_SPACE (self), FALSE);
+
+  return FALSE:
+}
+
+int
+gdk_color_space_get_n_components (GdkColorSpace *self)
+{
+  g_return_val_if_fail (GDK_IS_COLOR_SPACE (self), 0);
+
+  return GDK_COLOR_SPACE_GET_CLASS (self)->get_n_components (self);
+}
+
+/**
+ * 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.8
+ */
+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..0a9b00f1ee
--- /dev/null
+++ b/gdk/gdkcolorspace.h
@@ -0,0 +1,71 @@
+/* gdkcolor_space.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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GDK_COLOR_SPACE_H__
+#define __GDK_COLOR_SPACE_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdkversionmacros.h>
+#include <gdk/gdktypes.h>
+#include <gdk/gdkenums.h>
+
+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_8
+GType                   gdk_color_space_get_type                (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_4_8
+GdkColorSpace *         gdk_color_space_new_from_icc_profile    (GBytes               *icc_profile,
+                                                                 GError              **error);
+
+GDK_AVAILABLE_IN_4_8
+gboolean                gdk_color_space_supports_format         (GdkColorSpace        *self,
+                                                                 GdkMemoryFormat       format);
+GDK_AVAILABLE_IN_4_8
+GBytes *                gdk_color_space_save_to_icc_profile     (GdkColorSpace        *self,
+                                                                 GError              **error);
+
+GDK_AVAILABLE_IN_4_8
+gboolean                gdk_color_space_is_linear               (GdkColorSpace        *self);
+
+GDK_AVAILABLE_IN_4_8
+int                     gdk_color_space_get_n_components        (GdkColorSpace        *self);
+
+GDK_AVAILABLE_IN_4_8
+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..87d581be3f
--- /dev/null
+++ b/gdk/gdkcolorspaceprivate.h
@@ -0,0 +1,28 @@
+#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);
+
+  int                   (* get_n_components)                    (GdkColorSpace        *self);
+};
+
+
+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',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]