css: Add a utility for color space coords

This commit is contained in:
Matthias Clasen 2024-06-02 11:04:09 -04:00
parent 20392e8840
commit 4341344545
2 changed files with 58 additions and 0 deletions

View File

@ -157,6 +157,61 @@ gtk_css_color_to_string (const GtkCssColor *color)
return g_string_free (gtk_css_color_print (color, FALSE, g_string_new ("")), FALSE);
}
const char *
gtk_css_color_space_get_coord_name (GtkCssColorSpace color_space,
guint coord)
{
if (coord == 3)
return "alpha";
switch (color_space)
{
case GTK_CSS_COLOR_SPACE_SRGB:
case GTK_CSS_COLOR_SPACE_SRGB_LINEAR:
switch (coord)
{
case 0: return "r";
case 1: return "g";
case 2: return "b";
default: g_assert_not_reached ();
}
case GTK_CSS_COLOR_SPACE_HSL:
switch (coord)
{
case 0: return "h";
case 1: return "s";
case 2: return "l";
default: g_assert_not_reached ();
}
case GTK_CSS_COLOR_SPACE_HWB:
switch (coord)
{
case 0: return "h";
case 1: return "w";
case 2: return "b";
default: g_assert_not_reached ();
}
case GTK_CSS_COLOR_SPACE_OKLAB:
switch (coord)
{
case 0: return "l";
case 1: return "a";
case 2: return "b";
default: g_assert_not_reached ();
}
case GTK_CSS_COLOR_SPACE_OKLCH:
switch (coord)
{
case 0: return "l";
case 1: return "c";
case 2: return "h";
default: g_assert_not_reached ();
}
default:
g_assert_not_reached ();
}
}
/* }}} */
/* {{{ Color conversion */

View File

@ -109,4 +109,7 @@ void gtk_css_color_interpolate (const GtkCssColor *from,
GtkCssHueInterpolation interp,
GtkCssColor *output);
const char * gtk_css_color_space_get_coord_name (GtkCssColorSpace color_space,
guint coord);
G_END_DECLS