[gtk/wip/otte/color-profiles: 1/3] gdk: Add GdkColorProfile
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/color-profiles: 1/3] gdk: Add GdkColorProfile
- Date: Mon, 20 Sep 2021 07:51:54 +0000 (UTC)
commit dc90c2d887dc9b708b881bc02d443ba0a8018d35
Author: Benjamin Otte <otte redhat com>
Date: Mon Sep 20 09:17:28 2021 +0200
gdk: Add GdkColorProfile
The code doesn't do anything yet, this is just the boilerplate.
gdk/gdk.h | 1 +
gdk/gdkcolorprofile.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++
gdk/gdkcolorprofile.h | 59 ++++++++++++++
gdk/gdktypes.h | 1 +
gdk/meson.build | 2 +
5 files changed, 282 insertions(+)
---
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 8b6489cbf0..5cefc54955 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/gdkcolorprofile.h>
#include <gdk/gdkconfig.h>
#include <gdk/gdkcontentdeserializer.h>
#include <gdk/gdkcontentformats.h>
diff --git a/gdk/gdkcolorprofile.c b/gdk/gdkcolorprofile.c
new file mode 100644
index 0000000000..084031bb7e
--- /dev/null
+++ b/gdk/gdkcolorprofile.c
@@ -0,0 +1,219 @@
+/* gdkcolor_profile.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/>.
+ */
+
+/**
+ * GdkColorProfile:
+ *
+ * `GdkColorProfile` is used to describe color spaces.
+ *
+ * It is used to associate color profiles defined by the [International
+ * Color Consortium (ICC)](https://color.org/) with texture and color data.
+ *
+ * Each `GdkColorProfile` encapsulates an
+ * [ICC profile](https://en.wikipedia.org/wiki/ICC_profile). That profile
+ * can be queried via the using [property@Gdk.ColorProfile:icc-profile]
+ * property.
+ *
+ * `GdkColorProfile` objects are immutable and therefore threadsafe.
+ *
+ * Since: 4.6
+ */
+
+#include "config.h"
+
+#include "gdkcolorprofile.h"
+
+#include "gdkintl.h"
+
+struct _GdkColorProfile
+{
+ GObject parent_instance;
+
+ GBytes *icc_profile;
+};
+
+struct _GdkColorProfileClass
+{
+ GObjectClass parent_class;
+};
+
+enum {
+ PROP_0,
+ PROP_ICC_PROFILE,
+
+ N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS];
+
+G_DEFINE_TYPE (GdkColorProfile, gdk_color_profile, G_TYPE_OBJECT)
+
+static void
+gdk_color_profile_set_property (GObject *gobject,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GdkColorProfile *self = GDK_COLOR_PROFILE (gobject);
+
+ switch (prop_id)
+ {
+ case PROP_ICC_PROFILE:
+ self->icc_profile = g_value_dup_boxed (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_color_profile_get_property (GObject *gobject,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdkColorProfile *self = GDK_COLOR_PROFILE (gobject);
+
+ switch (prop_id)
+ {
+ case PROP_ICC_PROFILE:
+ g_value_set_boxed (value, self->icc_profile);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_color_profile_dispose (GObject *object)
+{
+ GdkColorProfile *self = GDK_COLOR_PROFILE (object);
+
+ g_clear_pointer (&self->icc_profile, g_bytes_unref);
+
+ G_OBJECT_CLASS (gdk_color_profile_parent_class)->dispose (object);
+}
+
+static void
+gdk_color_profile_class_init (GdkColorProfileClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->set_property = gdk_color_profile_set_property;
+ gobject_class->get_property = gdk_color_profile_get_property;
+ gobject_class->dispose = gdk_color_profile_dispose;
+
+ /**
+ * GdkColorProfile:icc-profile: (attributes org.gtk.Property.get=gdk_color_profile_get_icc_profile)
+ *
+ * the ICC profile for this color profile
+ */
+ properties[PROP_ICC_PROFILE] =
+ g_param_spec_boxed ("icc-profile",
+ P_("ICC profile"),
+ P_("ICC profile for this color profile"),
+ G_TYPE_BYTES,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, properties);
+}
+
+static void
+gdk_color_profile_init (GdkColorProfile *self)
+{
+}
+
+/**
+ * gdk_color_profile_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
+ */
+GdkColorProfile *
+gdk_color_profile_get_srgb (void)
+{
+ static GdkColorProfile *srgb_profile;
+
+ if (g_once_init_enter (&srgb_profile))
+ {
+ GdkColorProfile *new_profile;
+
+ new_profile = g_object_new (GDK_TYPE_COLOR_PROFILE, NULL);
+
+ g_once_init_leave (&srgb_profile, new_profile);
+ }
+
+ return srgb_profile;
+}
+
+/**
+ * gdk_color_profile_new_from_icc_bytes:
+ * @icc_profile: The ICC profiles given as a `GBytes`
+ * @error: Return location for an error
+ *
+ * Creates a new color profile for the given ICC profile data.
+ *
+ * if the profile is not valid, %NULL is returned and an error
+ * is raised.
+ *
+ * Returns: a new `GdkColorProfile` or %NULL on error
+ *
+ * Since: 4.6
+ */
+GdkColorProfile *
+gdk_color_profile_new_from_icc_bytes (GBytes *bytes)
+{
+ g_return_val_if_fail (bytes != NULL, NULL);
+
+ return g_object_new (GDK_TYPE_COLOR_PROFILE,
+ "icc-profile", bytes,
+ NULL);
+}
+
+/**
+ * gdk_color_profile_get_icc_profile: (attributes org.gtk.Method.get_property=icc-profile)
+ * @self: a `GdkColorProfile`
+ *
+ * Returns the serialized ICC profile of @self as %GBytes.
+ *
+ * Returns: (transfer none): the ICC profile
+ *
+ * Since: 4.6
+ */
+GBytes *
+gdk_color_profile_get_icc_profile (GdkColorProfile *self)
+{
+ g_return_val_if_fail (GDK_IS_COLOR_PROFILE (self), NULL);
+
+ return self->icc_profile;
+}
+
diff --git a/gdk/gdkcolorprofile.h b/gdk/gdkcolorprofile.h
new file mode 100644
index 0000000000..fbc43bc211
--- /dev/null
+++ b/gdk/gdkcolorprofile.h
@@ -0,0 +1,59 @@
+/* gdkcolor_profile.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_PROFILE_H__
+#define __GDK_COLOR_PROFILE_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>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_COLOR_PROFILE (gdk_color_profile_get_type ())
+
+#define GDK_COLOR_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_COLOR_PROFILE,
GdkColorProfile))
+#define GDK_IS_COLOR_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_COLOR_PROFILE))
+#define GDK_COLOR_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_COLOR_PROFILE,
GdkColorProfileClass))
+#define GDK_IS_COLOR_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_COLOR_PROFILE))
+#define GDK_COLOR_PROFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_COLOR_PROFILE,
GdkColorProfileClass))
+
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkColorProfile, g_object_unref)
+
+typedef struct _GdkColorProfileClass GdkColorProfileClass;
+
+GDK_AVAILABLE_IN_4_6
+GType gdk_color_profile_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_4_6
+GdkColorProfile * gdk_color_profile_get_srgb (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_4_6
+GdkColorProfile * gdk_color_profile_new_from_icc_bytes (GBytes *bytes);
+
+GDK_AVAILABLE_IN_4_6
+GBytes * gdk_color_profile_get_icc_profile (GdkColorProfile *self);
+
+
+G_END_DECLS
+
+#endif /* __GDK_COLOR_PROFILE_H__ */
diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h
index 77059797da..0abf410591 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 _GdkColorProfile GdkColorProfile;
typedef struct _GdkContentFormats GdkContentFormats;
typedef struct _GdkContentProvider GdkContentProvider;
typedef struct _GdkCursor GdkCursor;
diff --git a/gdk/meson.build b/gdk/meson.build
index 06905233f8..d6332a9849 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -4,6 +4,7 @@ gdk_public_sources = files([
'gdkcairo.c',
'gdkcairocontext.c',
'gdkclipboard.c',
+ 'gdkcolorprofile.c',
'gdkcontentdeserializer.c',
'gdkcontentformats.c',
'gdkcontentprovider.c',
@@ -63,6 +64,7 @@ gdk_public_headers = files([
'gdkcairo.h',
'gdkcairocontext.h',
'gdkclipboard.h',
+ 'gdkcolorprofile.h',
'gdkcontentdeserializer.h',
'gdkcontentformats.h',
'gdkcontentprovider.h',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]