From 0f9b08c37eaf5c986c405ccd93125df85202be14 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 20 Apr 2024 16:07:53 +0200 Subject: [PATCH] libgimpcolor: more GimpRGB-based functions are now unused. --- libgimpcolor/gimpcolor.def | 2 - libgimpcolor/gimprgb-parse.c | 269 ----------------------------------- libgimpcolor/gimprgb.h | 8 -- 3 files changed, 279 deletions(-) diff --git a/libgimpcolor/gimpcolor.def b/libgimpcolor/gimpcolor.def index 161f8e884d..ae62a145b0 100644 --- a/libgimpcolor/gimpcolor.def +++ b/libgimpcolor/gimpcolor.def @@ -102,7 +102,6 @@ EXPORTS gimp_rgb_max gimp_rgb_min gimp_rgb_multiply - gimp_rgb_parse_css gimp_rgb_parse_name gimp_rgb_set gimp_rgb_set_alpha @@ -114,6 +113,5 @@ EXPORTS gimp_rgba_distance gimp_rgba_get_uchar gimp_rgba_multiply - gimp_rgba_parse_css gimp_rgba_set gimp_rgba_set_uchar diff --git a/libgimpcolor/gimprgb-parse.c b/libgimpcolor/gimprgb-parse.c index 33d5741d64..66db629a89 100644 --- a/libgimpcolor/gimprgb-parse.c +++ b/libgimpcolor/gimprgb-parse.c @@ -42,12 +42,6 @@ static gchar * gimp_rgb_parse_strip (const gchar *str, static gboolean gimp_rgb_parse_name_internal (GimpRGB *rgb, const gchar *name); -static gboolean gimp_rgb_parse_hex_internal (GimpRGB *rgb, - const gchar *hex); -static gboolean gimp_rgb_parse_css_internal (GimpRGB *rgb, - const gchar *css); -static gboolean gimp_rgba_parse_css_internal (GimpRGB *rgb, - const gchar *css); typedef struct @@ -247,96 +241,6 @@ gimp_rgb_parse_name (GimpRGB *rgb, return result; } -/** - * gimp_rgb_parse_css: - * @rgb: a #GimpRGB struct used to return the parsed color - * @css: (array length=len): a string describing a color in CSS notation - * @len: the length of @css, in bytes. or -1 if @css is nul-terminated - * - * Attempts to parse a string describing an RGB color in CSS - * notation. This can be either a numerical representation - * (rgb(255,0,0) or rgb(100%,0%,0%)) - * or a hexadecimal notation as parsed by gimp_rgb_parse_hex() - * (##ff0000) or a color name as parsed by - * gimp_rgb_parse_name() (red). - * - * This function does not touch the alpha component of @rgb. - * - * Returns: %TRUE if @css was parsed successfully and @rgb has been - * set, %FALSE otherwise - * - * Since: 2.2 - **/ -gboolean -gimp_rgb_parse_css (GimpRGB *rgb, - const gchar *css, - gint len) -{ - gchar *tmp; - gboolean result; - - g_return_val_if_fail (rgb != NULL, FALSE); - g_return_val_if_fail (css != NULL, FALSE); - - tmp = gimp_rgb_parse_strip (css, len); - - result = gimp_rgb_parse_css_internal (rgb, tmp); - - g_free (tmp); - - return result; -} - -/** - * gimp_rgba_parse_css: - * @rgba: a #GimpRGB struct used to return the parsed color - * @css: (array length=len): a string describing a color in CSS notation - * @len: the length of @css, in bytes. or -1 if @css is nul-terminated - * - * Similar to gimp_rgb_parse_css() but handles RGB colors with alpha - * channel in the numerical CSS notation (rgba(255,0,0,255) - * or rgba(100%,0%,0%,1000%)). - * - * It doesn't handle the hexadecimal notation or color names because - * they leave the alpha channel unspecified. - * - * Returns: %TRUE if @css was parsed successfully and @rgb has been - * set, %FALSE otherwise - * - * Since: 2.2 - **/ -gboolean -gimp_rgba_parse_css (GimpRGB *rgba, - const gchar *css, - gint len) -{ - gchar *tmp; - gboolean result; - - g_return_val_if_fail (rgba != NULL, FALSE); - g_return_val_if_fail (css != NULL, FALSE); - - if (len < 0) - len = strlen (css); - - tmp = gimp_rgb_parse_strip (css, len); - - if (strcmp (tmp, "transparent") == 0) - { - gimp_rgba_set (rgba, 0.0, 0.0, 0.0, 0.0); - result = TRUE; - } - else - { - result = gimp_rgba_parse_css_internal (rgba, tmp); - } - - g_free (tmp); - - return result; -} - - /** * gimp_rgb_list_names: * @names: (out) (array length=n_colors) (transfer container): return location for an array of color names @@ -438,176 +342,3 @@ gimp_rgb_parse_name_internal (GimpRGB *rgb, return FALSE; } - - -static gboolean -gimp_rgb_parse_hex_component (const gchar *hex, - gint len, - gdouble *value) -{ - gint i; - guint c = 0; - - for (i = 0; i < len; i++, hex++) - { - if (!*hex || !g_ascii_isxdigit (*hex)) - return FALSE; - - c = (c << 4) | g_ascii_xdigit_value (*hex); - } - - switch (len) - { - case 1: *value = (gdouble) c / 15.0; break; - case 2: *value = (gdouble) c / 255.0; break; - case 3: *value = (gdouble) c / 4095.0; break; - case 4: *value = (gdouble) c / 65535.0; break; - default: - g_return_val_if_reached (FALSE); - } - - return TRUE; -} - -static gboolean -gimp_rgb_parse_hex_internal (GimpRGB *rgb, - const gchar *hex) -{ - gint i; - gsize len; - gdouble val[3]; - - if (hex[0] == '#') - hex++; - - len = strlen (hex); - if (len % 3 || len < 3 || len > 12) - return FALSE; - - len /= 3; - - for (i = 0; i < 3; i++, hex += len) - { - if (! gimp_rgb_parse_hex_component (hex, len, val + i)) - return FALSE; - } - - gimp_rgb_set (rgb, val[0], val[1], val[2]); - - return TRUE; -} - - -static gboolean -gimp_rgb_parse_css_numeric (GimpRGB *rgb, - const gchar *css) -{ - gdouble values[4]; - gboolean alpha; - gboolean hsl; - gint i; - - if (css[0] == 'r' && css[1] == 'g' && css[2] == 'b') - hsl = FALSE; - else if (css[0] == 'h' && css[1] == 's' && css[2] == 'l') - hsl = TRUE; - else - return FALSE; - - if (css[3] == 'a' && css[4] == '(') - alpha = TRUE; -else if (css[3] == '(') - alpha = FALSE; - else - return FALSE; - - css += (alpha ? 5 : 4); - - for (i = 0; i < (alpha ? 4 : 3); i++) - { - const gchar *end = css; - - while (*end && *end != ',' && *end != '%' && *end != ')') - end++; - - if (i == 3 || *end == '%') - { - values[i] = g_ascii_strtod (css, (gchar **) &end); - - if (errno == ERANGE) - return FALSE; - - if (*end == '%') - { - end++; - values[i] /= 100.0; - } - } - else - { - glong value = strtol (css, (gchar **) &end, 10); - - if (errno == ERANGE) - return FALSE; - - if (hsl) - values[i] = value / (i == 0 ? 360.0 : 100.0); - else - values[i] = value / 255.0; - } - - while (*end == ',' || g_ascii_isspace (*end)) - end++; - - css = end; - } - - if (*css != ')') - return FALSE; - - if (alpha) - gimp_rgba_set (rgb, values[0], values[1], values[2], values[3]); - else - gimp_rgb_set (rgb, values[0], values[1], values[2]); - - gimp_rgb_clamp (rgb); - - if (hsl) - { - GimpHSL tmp = (*((GimpHSL *) rgb)); - - gimp_hsl_to_rgb (&tmp, rgb); - } - - return TRUE; -} - -static gboolean -gimp_rgb_parse_css_internal (GimpRGB *rgb, - const gchar *css) -{ - if (css[0] == '#') - { - return gimp_rgb_parse_hex_internal (rgb, css); - } - else if (strncmp (css, "rgb(", 4) == 0 || - strncmp (css, "hsl(", 4) == 0) - { - return gimp_rgb_parse_css_numeric (rgb, css); - } - else - { - return gimp_rgb_parse_name_internal (rgb, css); - } -} - -static gboolean -gimp_rgba_parse_css_internal (GimpRGB *rgba, - const gchar *css) -{ - if (strncmp (css, "rgba(", 5) != 0 && - strncmp (css, "hsla(", 5) != 0) - return FALSE; - - return gimp_rgb_parse_css_numeric (rgba, css); -} diff --git a/libgimpcolor/gimprgb.h b/libgimpcolor/gimprgb.h index 31f383a6bc..fc0c703697 100644 --- a/libgimpcolor/gimprgb.h +++ b/libgimpcolor/gimprgb.h @@ -72,10 +72,6 @@ void gimp_rgb_get_uchar (const GimpRGB *rgb, gboolean gimp_rgb_parse_name (GimpRGB *rgb, const gchar *name, gint len); -gboolean gimp_rgb_parse_css (GimpRGB *rgb, - const gchar *css, - gint len); - void gimp_rgb_add (GimpRGB *rgb1, const GimpRGB *rgb2); void gimp_rgb_multiply (GimpRGB *rgb1, @@ -115,10 +111,6 @@ void gimp_rgba_get_uchar (const GimpRGB *rgba, guchar *blue, guchar *alpha); -gboolean gimp_rgba_parse_css (GimpRGB *rgba, - const gchar *css, - gint len); - void gimp_rgba_add (GimpRGB *rgba1, const GimpRGB *rgba2); void gimp_rgba_multiply (GimpRGB *rgba,