gdk: Add GdkColorSpace
The code doesn't do anything yet, this is just the boilerplate.
This commit is contained in:
@@ -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>
|
||||
|
||||
220
gdk/gdkcolorspace.c
Normal file
220
gdk/gdkcolorspace.c
Normal file
@@ -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 <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;
|
||||
}
|
||||
|
||||
68
gdk/gdkcolorspace.h
Normal file
68
gdk/gdkcolorspace.h
Normal file
@@ -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 <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/gdkenums.h>
|
||||
#include <gdk/gdktypes.h>
|
||||
#include <gdk/gdkversionmacros.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_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__ */
|
||||
26
gdk/gdkcolorspaceprivate.h
Normal file
26
gdk/gdkcolorspaceprivate.h
Normal file
@@ -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__ */
|
||||
@@ -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;
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user