diff --git a/libgimpcolor/gimpcolor.def b/libgimpcolor/gimpcolor.def index bdfbbeaece..3a3d02ec1a 100644 --- a/libgimpcolor/gimpcolor.def +++ b/libgimpcolor/gimpcolor.def @@ -69,11 +69,6 @@ EXPORTS gimp_hsl_set gimp_hsl_set_alpha gimp_hsl_to_rgb - gimp_hsv_clamp - gimp_hsv_get_type - gimp_hsv_set - gimp_hsv_to_rgb - gimp_hsva_set gimp_param_color_get_type gimp_param_spec_color gimp_param_spec_color_from_string @@ -96,7 +91,6 @@ EXPORTS gimp_rgb_set_alpha gimp_rgb_set_uchar gimp_rgb_to_hsl - gimp_rgb_to_hsv gimp_rgba_add gimp_rgba_distance gimp_rgba_get_uchar diff --git a/libgimpcolor/gimpcolor.h b/libgimpcolor/gimpcolor.h index a0ae259d70..7f4c174a98 100644 --- a/libgimpcolor/gimpcolor.h +++ b/libgimpcolor/gimpcolor.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include diff --git a/libgimpcolor/gimpcolorspace.c b/libgimpcolor/gimpcolorspace.c index 4ef1152269..6e0c07d9d5 100644 --- a/libgimpcolor/gimpcolorspace.c +++ b/libgimpcolor/gimpcolorspace.c @@ -27,7 +27,6 @@ #include "gimpcolorspace.h" #include "gimprgb.h" -#include "gimphsv.h" @@ -50,138 +49,6 @@ /* GimpRGB functions */ -/** - * gimp_rgb_to_hsv: - * @rgb: A color value in the RGB colorspace - * @hsv: (out caller-allocates): The value converted to the HSV colorspace - * - * Does a conversion from RGB to HSV (Hue, Saturation, - * Value) colorspace. - **/ -void -gimp_rgb_to_hsv (const GimpRGB *rgb, - GimpHSV *hsv) -{ - gdouble max, min, delta; - - g_return_if_fail (rgb != NULL); - g_return_if_fail (hsv != NULL); - - max = gimp_rgb_max (rgb); - min = gimp_rgb_min (rgb); - - hsv->v = max; - delta = max - min; - - if (delta > 0.0001) - { - hsv->s = delta / max; - - if (rgb->r == max) - { - hsv->h = (rgb->g - rgb->b) / delta; - if (hsv->h < 0.0) - hsv->h += 6.0; - } - else if (rgb->g == max) - { - hsv->h = 2.0 + (rgb->b - rgb->r) / delta; - } - else - { - hsv->h = 4.0 + (rgb->r - rgb->g) / delta; - } - - hsv->h /= 6.0; - } - else - { - hsv->s = 0.0; - hsv->h = 0.0; - } - - hsv->a = rgb->a; -} - -/** - * gimp_hsv_to_rgb: - * @hsv: A color value in the HSV colorspace - * @rgb: (out caller-allocates): The returned RGB value. - * - * Converts a color value from HSV to RGB colorspace - **/ -void -gimp_hsv_to_rgb (const GimpHSV *hsv, - GimpRGB *rgb) -{ - gint i; - gdouble f, w, q, t; - - gdouble hue; - - g_return_if_fail (rgb != NULL); - g_return_if_fail (hsv != NULL); - - if (hsv->s == 0.0) - { - rgb->r = hsv->v; - rgb->g = hsv->v; - rgb->b = hsv->v; - } - else - { - hue = hsv->h; - - if (hue == 1.0) - hue = 0.0; - - hue *= 6.0; - - i = (gint) hue; - f = hue - i; - w = hsv->v * (1.0 - hsv->s); - q = hsv->v * (1.0 - (hsv->s * f)); - t = hsv->v * (1.0 - (hsv->s * (1.0 - f))); - - switch (i) - { - case 0: - rgb->r = hsv->v; - rgb->g = t; - rgb->b = w; - break; - case 1: - rgb->r = q; - rgb->g = hsv->v; - rgb->b = w; - break; - case 2: - rgb->r = w; - rgb->g = hsv->v; - rgb->b = t; - break; - case 3: - rgb->r = w; - rgb->g = q; - rgb->b = hsv->v; - break; - case 4: - rgb->r = t; - rgb->g = w; - rgb->b = hsv->v; - break; - case 5: - rgb->r = hsv->v; - rgb->g = w; - rgb->b = q; - break; - } - } - - rgb->a = hsv->a; -} - - /** * gimp_rgb_to_hsl: * @rgb: A color value in the RGB colorspace diff --git a/libgimpcolor/gimpcolorspace.h b/libgimpcolor/gimpcolorspace.h index 744bf1f544..a3081d66cd 100644 --- a/libgimpcolor/gimpcolorspace.h +++ b/libgimpcolor/gimpcolorspace.h @@ -33,13 +33,9 @@ G_BEGIN_DECLS /* GimpRGB function */ -void gimp_rgb_to_hsv (const GimpRGB *rgb, - GimpHSV *hsv); void gimp_rgb_to_hsl (const GimpRGB *rgb, GimpHSL *hsl); -void gimp_hsv_to_rgb (const GimpHSV *hsv, - GimpRGB *rgb); void gimp_hsl_to_rgb (const GimpHSL *hsl, GimpRGB *rgb); diff --git a/libgimpcolor/gimpcolortypes.h b/libgimpcolor/gimpcolortypes.h index d44b204bfc..be638b315c 100644 --- a/libgimpcolor/gimpcolortypes.h +++ b/libgimpcolor/gimpcolortypes.h @@ -40,7 +40,6 @@ typedef struct _GimpParamSpecColor GimpParamSpecColor; */ typedef struct _GimpRGB GimpRGB; -typedef struct _GimpHSV GimpHSV; typedef struct _GimpHSL GimpHSL; /** @@ -58,21 +57,6 @@ struct _GimpRGB gdouble r, g, b, a; }; -/** - * GimpHSV: - * @h: the hue component - * @s: the saturation component - * @v: the value component - * @a: the alpha component - * - * Used to keep HSV and HSVA colors. All components are in a range of - * [0.0..1.0]. - **/ -struct _GimpHSV -{ - gdouble h, s, v, a; -}; - /** * GimpHSL: * @h: the hue component diff --git a/libgimpcolor/gimphsv.c b/libgimpcolor/gimphsv.c deleted file mode 100644 index 741ae24dfe..0000000000 --- a/libgimpcolor/gimphsv.c +++ /dev/null @@ -1,96 +0,0 @@ -/* LIBGIMP - The GIMP Library - * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball - * - * 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 3 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 - * Library 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 - * . - */ - -#include "config.h" - -#include - -#include "gimpcolortypes.h" - -#include "gimphsv.h" - - -/** - * SECTION: gimphsv - * @title: GimpHSV - * @short_description: Definitions and Functions relating to HSV colors. - * - * Definitions and Functions relating to HSV colors. - **/ - - -/* - * GIMP_TYPE_HSV - */ - -static GimpHSV * gimp_hsv_copy (const GimpHSV *hsv); - - -G_DEFINE_BOXED_TYPE (GimpHSV, gimp_hsv, gimp_hsv_copy, g_free) - -static GimpHSV * -gimp_hsv_copy (const GimpHSV *hsv) -{ - return g_memdup2 (hsv, sizeof (GimpHSV)); -} - - -/* HSV functions */ - -void -gimp_hsv_set (GimpHSV *hsv, - gdouble h, - gdouble s, - gdouble v) -{ - g_return_if_fail (hsv != NULL); - - hsv->h = h; - hsv->s = s; - hsv->v = v; -} - -void -gimp_hsv_clamp (GimpHSV *hsv) -{ - g_return_if_fail (hsv != NULL); - - hsv->h -= (gint) hsv->h; - - if (hsv->h < 0) - hsv->h += 1.0; - - hsv->s = CLAMP (hsv->s, 0.0, 1.0); - hsv->v = CLAMP (hsv->v, 0.0, 1.0); - hsv->a = CLAMP (hsv->a, 0.0, 1.0); -} - -void -gimp_hsva_set (GimpHSV *hsva, - gdouble h, - gdouble s, - gdouble v, - gdouble a) -{ - g_return_if_fail (hsva != NULL); - - hsva->h = h; - hsva->s = s; - hsva->v = v; - hsva->a = a; -} diff --git a/libgimpcolor/gimphsv.h b/libgimpcolor/gimphsv.h deleted file mode 100644 index 7063d7b017..0000000000 --- a/libgimpcolor/gimphsv.h +++ /dev/null @@ -1,54 +0,0 @@ -/* LIBGIMP - The GIMP Library - * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball - * - * 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 3 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 - * Library 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 - * . - */ - -#if !defined (__GIMP_COLOR_H_INSIDE__) && !defined (GIMP_COLOR_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef __GIMP_HSV_H__ -#define __GIMP_HSV_H__ - -G_BEGIN_DECLS - -/* For information look into the C source or the html documentation */ - - -/* - * GIMP_TYPE_HSV - */ - -#define GIMP_TYPE_HSV (gimp_hsv_get_type ()) - -GType gimp_hsv_get_type (void) G_GNUC_CONST; - -void gimp_hsv_set (GimpHSV *hsv, - gdouble hue, - gdouble saturation, - gdouble value); -void gimp_hsv_clamp (GimpHSV *hsv); - -void gimp_hsva_set (GimpHSV *hsva, - gdouble hue, - gdouble saturation, - gdouble value, - gdouble alpha); - - -G_END_DECLS - -#endif /* __GIMP_HSV_H__ */ diff --git a/libgimpcolor/meson.build b/libgimpcolor/meson.build index 197870d484..805b0b899a 100644 --- a/libgimpcolor/meson.build +++ b/libgimpcolor/meson.build @@ -9,7 +9,6 @@ libgimpcolor_sources = files( 'gimpcolorspace.c', 'gimpcolortransform.c', 'gimphsl.c', - 'gimphsv.c', 'gimppixbuf.c', 'gimprgb.c', ) @@ -24,7 +23,6 @@ libgimpcolor_headers_introspectable = files( 'gimpcolorspace.h', 'gimpcolortransform.h', 'gimphsl.h', - 'gimphsv.h', 'gimppixbuf.h', 'gimprgb.h', diff --git a/plug-ins/common/cml-explorer.c b/plug-ins/common/cml-explorer.c index e5c984dd0e..b4afe7863d 100644 --- a/plug-ins/common/cml-explorer.c +++ b/plug-ins/common/cml-explorer.c @@ -661,6 +661,8 @@ CML_main_function (gboolean preview_p) GeglBuffer *dest_buffer; const Babl *src_format; const Babl *dest_format; + const Babl *to_hsv; + const Babl *to_rgb; guchar *dest_buf = NULL; guchar *src_buf = NULL; gint x, y; @@ -684,6 +686,9 @@ CML_main_function (gboolean preview_p) &width_by_pixel, &height_by_pixel)) return TRUE; + to_hsv = babl_fish (babl_format ("R'G'B' float"), babl_format ("HSV float")); + to_rgb = babl_fish (babl_format ("HSV float"), babl_format ("R'G'B' float")); + src_has_alpha = dest_has_alpha = gimp_drawable_has_alpha (drawable); src_is_gray = dest_is_gray = gimp_drawable_is_gray (drawable); @@ -881,7 +886,7 @@ CML_main_function (gboolean preview_p) if (VALS.initial_value == 3) { - int index; + int index; for (index = 0; index < MIN (cell_num, width_by_pixel / VALS.scale); @@ -941,19 +946,14 @@ CML_main_function (gboolean preview_p) if (! dest_is_gray) { - GimpHSV hsv; - GimpRGB rgb; + gfloat hsv[3] = { h / 255.0, s / 255.0, v / 255.0 }; + gfloat rgb[3]; - gimp_hsv_set (&hsv, - (gdouble) h / 255.0, - (gdouble) s / 255.0, - (gdouble) v / 255.0); + babl_process (to_rgb, hsv, rgb, 1); - gimp_hsv_to_rgb (&hsv, &rgb); - - r = ROUND (rgb.r * 255.0); - g = ROUND (rgb.g * 255.0); - b = ROUND (rgb.b * 255.0); + r = ROUND (rgb[0] * 255.0); + g = ROUND (rgb[1] * 255.0); + b = ROUND (rgb[2] * 255.0); } /* render destination */ @@ -980,29 +980,28 @@ CML_main_function (gboolean preview_p) } else { - GimpRGB rgb; - GimpHSV hsv; + gfloat rgb[3]; + gfloat hsv[3]; - rgb.r = (gdouble) rgbi[0] / 255.0; - rgb.g = (gdouble) rgbi[1] / 255.0; - rgb.b = (gdouble) rgbi[2] / 255.0; + for (i = 0; i < 3; i++) + rgb[i] = (gfloat) rgbi[i] / 255.0; - gimp_rgb_to_hsv (&rgb, &hsv); + babl_process (to_hsv, rgb, hsv, 1); if (VALS.hue.function != CML_KEEP_VALUES) - hsv.h = (gdouble) h / 255.0; + hsv[0] = (gfloat) h / 255.0; if (VALS.sat.function != CML_KEEP_VALUES) - hsv.s = (gdouble) s / 255.0; + hsv[1] = (gfloat) s / 255.0; if (VALS.val.function != CML_KEEP_VALUES) - hsv.v = (gdouble) v / 255.0; + hsv[2] = (gfloat) v / 255.0; - gimp_hsv_to_rgb (&hsv, &rgb); + babl_process (to_rgb, hsv, rgb, 1); - r = ROUND (rgb.r * 255.0); - g = ROUND (rgb.g * 255.0); - b = ROUND (rgb.b * 255.0); + r = ROUND (rgb[0] * 255.0); + g = ROUND (rgb[1] * 255.0); + b = ROUND (rgb[2] * 255.0); } } @@ -1933,12 +1932,15 @@ function_graph_draw (GtkWidget *widget, cairo_t *cr, gpointer *data) { - gint x, y; - gint rgbi[3]; - GimpHSV hsv; - GimpRGB rgb; - gint channel_id = GPOINTER_TO_INT (data[0]); - CML_PARAM *param = data[1]; + gint x, y; + gint rgbi[3]; + gfloat hsv[3]; + gfloat rgb[3]; + gint channel_id = GPOINTER_TO_INT (data[0]); + CML_PARAM *param = data[1]; + const Babl *fish; + + fish = babl_fish (babl_format ("HSV float"), babl_format ("R'G'B' float")); cairo_set_line_width (cr, 1.0); @@ -1951,18 +1953,18 @@ function_graph_draw (GtkWidget *widget, if ((0 <= channel_id) && (channel_id <= 2)) rgbi[channel_id] = CANNONIZE ((*param), ((gdouble) x / (gdouble) 255)); - hsv.h = (gdouble) rgbi[0] / 255.0; - hsv.s = (gdouble) rgbi[1] / 255.0; - hsv.v = (gdouble) rgbi[2] / 255.0; + hsv[0] = (gdouble) rgbi[0] / 255.0; + hsv[1] = (gdouble) rgbi[1] / 255.0; + hsv[2] = (gdouble) rgbi[2] / 255.0; - gimp_hsv_to_rgb (&hsv, &rgb); + babl_process (fish, hsv, rgb, 1); for (y = 0; y < GRAPHSIZE; y++) { GIMP_CAIRO_RGB24_SET_PIXEL((img+(y*img_stride+x*4)), - ROUND (rgb.r * 255.0), - ROUND (rgb.g * 255.0), - ROUND (rgb.b * 255.0)); + ROUND (rgb[0] * 255.0), + ROUND (rgb[1] * 255.0), + ROUND (rgb[2] * 255.0)); } } diff --git a/plug-ins/gradient-flare/gradient-flare.c b/plug-ins/gradient-flare/gradient-flare.c index 0fb2c81a73..201667eb07 100644 --- a/plug-ins/gradient-flare/gradient-flare.c +++ b/plug-ins/gradient-flare/gradient-flare.c @@ -1960,8 +1960,10 @@ calc_sample_one_gradient (void) GFlare *gflare = calc.gflare; GradientName *grad_name; guchar *gradient; - gdouble hue_deg; - gint i, j, hue; + gdouble hue_deg; + gint i, j, hue; + const Babl *to_hsv = babl_fish ("R'G'B'A u8", "HSVA float"); + const Babl *to_rgb = babl_fish ("HSVA float", "R'G'B'A u8"); for (i = 0; i < G_N_ELEMENTS (table); i++) { @@ -1986,27 +1988,22 @@ calc_sample_one_gradient (void) if (hue > 0) { + gfloat *hsva; + + hsva = g_new0 (gfloat, sizeof (gfloat) * (GRADIENT_RESOLUTION * 4)); + babl_process (to_hsv, gradient, hsva, GRADIENT_RESOLUTION); + for (j = 0; j < GRADIENT_RESOLUTION; j++) { - GimpRGB rgb; - GimpHSV hsv; + hsva[j * 4] = (hsva[j * 4] + ((gdouble) hue / 255.0)); - rgb.r = (gdouble) gradient[j*4] / 255.0; - rgb.g = (gdouble) gradient[j*4+1] / 255.0; - rgb.b = (gdouble) gradient[j*4+2] / 255.0; - - gimp_rgb_to_hsv (&rgb, &hsv); - - hsv.h = (hsv.h + ((gdouble) hue / 255.0)); - if (hsv.h > 1.0) - hsv.h -= 1.0; - - gimp_hsv_to_rgb (&hsv, &rgb); - - gradient[j*4] = ROUND (rgb.r * 255.0); - gradient[j*4+1] = ROUND (rgb.g * 255.0); - gradient[j*4+2] = ROUND (rgb.b * 255.0); + if (hsva[j * 4] > 1.0) + hsva[j * 4] -= 1.0; } + + babl_process (to_rgb, hsva, gradient, GRADIENT_RESOLUTION); + + g_free (hsva); } }