2024-06-08 18:37:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "gdkcolorstate.h"
|
2024-06-28 15:28:02 +00:00
|
|
|
|
2024-07-22 13:13:51 +00:00
|
|
|
#include "gdkcicpparamsprivate.h"
|
2024-06-28 15:28:02 +00:00
|
|
|
#include "gdkdebugprivate.h"
|
2024-06-08 18:37:51 +00:00
|
|
|
#include "gdkmemoryformatprivate.h"
|
2024-07-02 04:59:57 +00:00
|
|
|
#include "gdkrgba.h"
|
2024-06-08 18:37:51 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GDK_COLOR_STATE_ID_SRGB,
|
|
|
|
GDK_COLOR_STATE_ID_SRGB_LINEAR,
|
2024-07-12 23:43:38 +00:00
|
|
|
GDK_COLOR_STATE_ID_REC2100_PQ,
|
|
|
|
GDK_COLOR_STATE_ID_REC2100_LINEAR,
|
2024-06-08 18:37:51 +00:00
|
|
|
|
|
|
|
GDK_COLOR_STATE_N_IDS
|
|
|
|
} GdkColorStateId;
|
|
|
|
|
|
|
|
typedef struct _GdkColorStateClass GdkColorStateClass;
|
|
|
|
|
|
|
|
struct _GdkColorState
|
|
|
|
{
|
|
|
|
const GdkColorStateClass *klass;
|
|
|
|
gatomicrefcount ref_count;
|
|
|
|
|
|
|
|
GdkMemoryDepth depth;
|
2024-06-28 15:28:02 +00:00
|
|
|
GdkColorState *rendering_color_state;
|
2024-08-14 05:59:08 +00:00
|
|
|
GdkColorState *rendering_color_state_linear;
|
2024-06-08 18:37:51 +00:00
|
|
|
};
|
|
|
|
|
2024-07-15 12:08:57 +00:00
|
|
|
/* Note: self may be the source or the target colorstate */
|
2024-06-19 12:24:35 +00:00
|
|
|
typedef void (* GdkFloatColorConvert)(GdkColorState *self,
|
|
|
|
float (*values)[4],
|
|
|
|
gsize n_values);
|
|
|
|
|
2024-06-08 18:37:51 +00:00
|
|
|
struct _GdkColorStateClass
|
|
|
|
{
|
|
|
|
void (* free) (GdkColorState *self);
|
|
|
|
gboolean (* equal) (GdkColorState *self,
|
|
|
|
GdkColorState *other);
|
|
|
|
const char * (* get_name) (GdkColorState *self);
|
2024-06-27 22:22:21 +00:00
|
|
|
GdkColorState * (* get_no_srgb_tf) (GdkColorState *self);
|
2024-06-19 12:24:35 +00:00
|
|
|
GdkFloatColorConvert (* get_convert_to) (GdkColorState *self,
|
|
|
|
GdkColorState *target);
|
2024-07-15 03:00:56 +00:00
|
|
|
GdkFloatColorConvert (* get_convert_from) (GdkColorState *self,
|
|
|
|
GdkColorState *source);
|
2024-07-15 12:08:57 +00:00
|
|
|
const GdkCicp * (* get_cicp) (GdkColorState *self);
|
2024-08-06 20:15:53 +00:00
|
|
|
void (* clamp) (GdkColorState *self,
|
|
|
|
const float src[4],
|
|
|
|
float dest[4]);
|
2024-06-08 18:37:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _GdkDefaultColorState GdkDefaultColorState;
|
|
|
|
|
|
|
|
struct _GdkDefaultColorState
|
|
|
|
{
|
|
|
|
GdkColorState parent;
|
|
|
|
|
|
|
|
const char *name;
|
2024-06-27 22:22:21 +00:00
|
|
|
GdkColorState *no_srgb;
|
2024-06-19 12:24:35 +00:00
|
|
|
GdkFloatColorConvert convert_to[GDK_COLOR_STATE_N_IDS];
|
2024-08-06 20:15:53 +00:00
|
|
|
void (* clamp) (GdkColorState *self,
|
|
|
|
const float src[4],
|
|
|
|
float dest[4]);
|
2024-07-15 12:08:57 +00:00
|
|
|
|
|
|
|
GdkCicp cicp;
|
2024-06-08 18:37:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern GdkDefaultColorState gdk_default_color_states[GDK_COLOR_STATE_N_IDS];
|
|
|
|
|
2024-07-12 23:43:38 +00:00
|
|
|
#define GDK_COLOR_STATE_SRGB ((GdkColorState *) &gdk_default_color_states[GDK_COLOR_STATE_ID_SRGB])
|
|
|
|
#define GDK_COLOR_STATE_SRGB_LINEAR ((GdkColorState *) &gdk_default_color_states[GDK_COLOR_STATE_ID_SRGB_LINEAR])
|
|
|
|
#define GDK_COLOR_STATE_REC2100_PQ ((GdkColorState *) &gdk_default_color_states[GDK_COLOR_STATE_ID_REC2100_PQ])
|
|
|
|
#define GDK_COLOR_STATE_REC2100_LINEAR ((GdkColorState *) &gdk_default_color_states[GDK_COLOR_STATE_ID_REC2100_LINEAR])
|
2024-06-08 18:37:51 +00:00
|
|
|
|
|
|
|
#define GDK_IS_DEFAULT_COLOR_STATE(c) ((GdkDefaultColorState *) (c) >= &gdk_default_color_states[0] && \
|
|
|
|
(GdkDefaultColorState *) (c) < &gdk_default_color_states[GDK_COLOR_STATE_N_IDS])
|
|
|
|
#define GDK_DEFAULT_COLOR_STATE_ID(c) ((GdkColorStateId) (((GdkDefaultColorState *) c) - gdk_default_color_states))
|
|
|
|
|
|
|
|
const char * gdk_color_state_get_name (GdkColorState *color_state);
|
2024-06-27 22:22:21 +00:00
|
|
|
GdkColorState * gdk_color_state_get_no_srgb_tf (GdkColorState *self);
|
2024-06-08 18:37:51 +00:00
|
|
|
|
2024-07-31 22:32:58 +00:00
|
|
|
GdkColorState * gdk_color_state_new_for_cicp (const GdkCicp *cicp,
|
|
|
|
GError **error);
|
|
|
|
|
2024-08-06 20:15:53 +00:00
|
|
|
void gdk_color_state_clamp (GdkColorState *self,
|
|
|
|
const float src[4],
|
|
|
|
float dest[4]);
|
|
|
|
|
2024-06-28 15:28:02 +00:00
|
|
|
static inline GdkColorState *
|
|
|
|
gdk_color_state_get_rendering_color_state (GdkColorState *self)
|
|
|
|
{
|
2024-07-13 12:55:22 +00:00
|
|
|
if (GDK_DEBUG_CHECK (HDR))
|
|
|
|
self = GDK_COLOR_STATE_REC2100_PQ;
|
|
|
|
|
2024-06-28 15:28:02 +00:00
|
|
|
if (!GDK_DEBUG_CHECK (LINEAR))
|
2024-08-14 05:59:08 +00:00
|
|
|
return self->rendering_color_state;
|
2024-06-28 15:28:02 +00:00
|
|
|
|
2024-08-14 05:59:08 +00:00
|
|
|
return self->rendering_color_state_linear;
|
2024-06-28 15:28:02 +00:00
|
|
|
}
|
|
|
|
|
2024-06-08 18:37:51 +00:00
|
|
|
static inline GdkMemoryDepth
|
|
|
|
gdk_color_state_get_depth (GdkColorState *self)
|
|
|
|
{
|
2024-06-28 15:53:20 +00:00
|
|
|
if (!GDK_DEBUG_CHECK (LINEAR) && self->depth == GDK_MEMORY_U8_SRGB)
|
|
|
|
return GDK_MEMORY_U8;
|
|
|
|
|
2024-06-08 18:37:51 +00:00
|
|
|
return self->depth;
|
|
|
|
}
|
|
|
|
|
2024-06-22 21:53:01 +00:00
|
|
|
static inline GdkColorState *
|
|
|
|
gdk_color_state_get_by_id (GdkColorStateId id)
|
|
|
|
{
|
|
|
|
return (GdkColorState *) &gdk_default_color_states[id];
|
|
|
|
}
|
|
|
|
|
2024-06-08 18:37:51 +00:00
|
|
|
#define gdk_color_state_ref(self) _gdk_color_state_ref (self)
|
|
|
|
static inline GdkColorState *
|
|
|
|
_gdk_color_state_ref (GdkColorState *self)
|
|
|
|
{
|
|
|
|
if (GDK_IS_DEFAULT_COLOR_STATE (self))
|
|
|
|
return self;
|
|
|
|
|
|
|
|
g_atomic_ref_count_inc (&self->ref_count);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define gdk_color_state_unref(self) _gdk_color_state_unref (self)
|
|
|
|
static inline void
|
|
|
|
_gdk_color_state_unref (GdkColorState *self)
|
|
|
|
{
|
|
|
|
if (GDK_IS_DEFAULT_COLOR_STATE (self))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_atomic_ref_count_dec (&self->ref_count))
|
|
|
|
self->klass->free (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define gdk_color_state_equal(a,b) _gdk_color_state_equal ((a), (b))
|
|
|
|
static inline gboolean
|
|
|
|
_gdk_color_state_equal (GdkColorState *self,
|
|
|
|
GdkColorState *other)
|
|
|
|
{
|
|
|
|
if (self == other)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (self->klass != other->klass)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return self->klass->equal (self, other);
|
|
|
|
}
|
|
|
|
|
2024-07-15 12:08:57 +00:00
|
|
|
/* Note: the functions returned from this expect the source
|
|
|
|
* color state to be passed as self
|
|
|
|
*/
|
2024-06-19 12:24:35 +00:00
|
|
|
static inline GdkFloatColorConvert
|
|
|
|
gdk_color_state_get_convert_to (GdkColorState *self,
|
|
|
|
GdkColorState *target)
|
|
|
|
{
|
|
|
|
return self->klass->get_convert_to (self, target);
|
|
|
|
}
|
|
|
|
|
2024-07-15 12:08:57 +00:00
|
|
|
/* Note: the functions returned from this expect the target
|
|
|
|
* color state to be passed as self
|
|
|
|
*/
|
2024-07-15 03:00:56 +00:00
|
|
|
static inline GdkFloatColorConvert
|
|
|
|
gdk_color_state_get_convert_from (GdkColorState *self,
|
|
|
|
GdkColorState *source)
|
|
|
|
{
|
|
|
|
return self->klass->get_convert_from (self, source);
|
|
|
|
}
|
|
|
|
|
2024-07-31 22:32:58 +00:00
|
|
|
static inline const GdkCicp *
|
|
|
|
gdk_color_state_get_cicp (GdkColorState *self)
|
|
|
|
{
|
|
|
|
return self->klass->get_cicp (self);
|
|
|
|
}
|
|
|
|
|
2024-07-02 04:59:57 +00:00
|
|
|
static inline void
|
2024-07-31 22:32:58 +00:00
|
|
|
gdk_color_state_convert_color (GdkColorState *src_cs,
|
|
|
|
const float src[4],
|
|
|
|
GdkColorState *dest_cs,
|
|
|
|
float dest[4])
|
2024-07-02 04:59:57 +00:00
|
|
|
{
|
2024-07-31 22:32:58 +00:00
|
|
|
GdkFloatColorConvert convert = NULL;
|
|
|
|
GdkFloatColorConvert convert2 = NULL;
|
2024-07-02 04:59:57 +00:00
|
|
|
|
2024-08-11 20:28:43 +00:00
|
|
|
dest[0] = src[0];
|
|
|
|
dest[1] = src[1];
|
|
|
|
dest[2] = src[2];
|
|
|
|
dest[3] = src[3];
|
2024-07-02 04:59:57 +00:00
|
|
|
|
2024-07-31 22:32:58 +00:00
|
|
|
if (gdk_color_state_equal (src_cs, dest_cs))
|
2024-07-02 04:59:57 +00:00
|
|
|
return;
|
|
|
|
|
2024-07-31 22:32:58 +00:00
|
|
|
convert = gdk_color_state_get_convert_to (src_cs, dest_cs);
|
|
|
|
|
|
|
|
if (!convert)
|
|
|
|
convert2 = gdk_color_state_get_convert_from (dest_cs, src_cs);
|
|
|
|
|
|
|
|
if (!convert && !convert2)
|
|
|
|
{
|
|
|
|
GdkColorState *connection = GDK_COLOR_STATE_REC2100_LINEAR;
|
|
|
|
convert = gdk_color_state_get_convert_to (src_cs, connection);
|
|
|
|
convert2 = gdk_color_state_get_convert_from (dest_cs, connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (convert)
|
|
|
|
convert (src_cs, (float(*)[4]) dest, 1);
|
|
|
|
|
|
|
|
if (convert2)
|
|
|
|
convert2 (dest_cs, (float(*)[4]) dest, 1);
|
2024-07-02 04:59:57 +00:00
|
|
|
}
|
2024-07-15 12:08:57 +00:00
|
|
|
|
2024-07-31 22:32:58 +00:00
|
|
|
static inline void
|
|
|
|
gdk_color_state_from_rgba (GdkColorState *self,
|
|
|
|
const GdkRGBA *rgba,
|
|
|
|
float out_color[4])
|
2024-07-15 12:08:57 +00:00
|
|
|
{
|
2024-07-31 22:32:58 +00:00
|
|
|
gdk_color_state_convert_color (GDK_COLOR_STATE_SRGB,
|
|
|
|
(const float *) rgba,
|
|
|
|
self,
|
|
|
|
out_color);
|
2024-07-15 12:08:57 +00:00
|
|
|
}
|