colorstate: Add a color conversion function
Add a function for converting a single color from one color state to another. This is a generalization of the already existing function to convert a GdkRGBA to another color state.
This commit is contained in:
@@ -74,6 +74,9 @@ extern GdkDefaultColorState gdk_default_color_states[GDK_COLOR_STATE_N_IDS];
|
||||
const char * gdk_color_state_get_name (GdkColorState *color_state);
|
||||
GdkColorState * gdk_color_state_get_no_srgb_tf (GdkColorState *self);
|
||||
|
||||
GdkColorState * gdk_color_state_new_for_cicp (const GdkCicp *cicp,
|
||||
GError **error);
|
||||
|
||||
static inline GdkColorState *
|
||||
gdk_color_state_get_rendering_color_state (GdkColorState *self)
|
||||
{
|
||||
@@ -158,30 +161,53 @@ gdk_color_state_get_convert_from (GdkColorState *self,
|
||||
return self->klass->get_convert_from (self, source);
|
||||
}
|
||||
|
||||
static inline void
|
||||
gdk_color_state_from_rgba (GdkColorState *self,
|
||||
const GdkRGBA *rgba,
|
||||
float out_color[4])
|
||||
{
|
||||
GdkFloatColorConvert convert;
|
||||
|
||||
out_color[0] = rgba->red;
|
||||
out_color[1] = rgba->green;
|
||||
out_color[2] = rgba->blue;
|
||||
out_color[3] = rgba->alpha;
|
||||
|
||||
if (gdk_color_state_equal (GDK_COLOR_STATE_SRGB, self))
|
||||
return;
|
||||
|
||||
convert = gdk_color_state_get_convert_to (GDK_COLOR_STATE_SRGB, self);
|
||||
convert (GDK_COLOR_STATE_SRGB, (float(*)[4]) out_color, 1);
|
||||
}
|
||||
|
||||
static inline const GdkCicp *
|
||||
gdk_color_state_get_cicp (GdkColorState *self)
|
||||
{
|
||||
return self->klass->get_cicp (self);
|
||||
}
|
||||
|
||||
GdkColorState * gdk_color_state_new_for_cicp (const GdkCicp *cicp,
|
||||
GError **error);
|
||||
static inline void
|
||||
gdk_color_state_convert_color (GdkColorState *src_cs,
|
||||
const float src[4],
|
||||
GdkColorState *dest_cs,
|
||||
float dest[4])
|
||||
{
|
||||
GdkFloatColorConvert convert = NULL;
|
||||
GdkFloatColorConvert convert2 = NULL;
|
||||
|
||||
memcpy (dest, src, sizeof (float) * 4);
|
||||
|
||||
if (gdk_color_state_equal (src_cs, dest_cs))
|
||||
return;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static inline void
|
||||
gdk_color_state_from_rgba (GdkColorState *self,
|
||||
const GdkRGBA *rgba,
|
||||
float out_color[4])
|
||||
{
|
||||
gdk_color_state_convert_color (GDK_COLOR_STATE_SRGB,
|
||||
(const float *) rgba,
|
||||
self,
|
||||
out_color);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user