libgimpcolor: Remove GimpHSL and GimpRGB

This completes the GimpRGB API removal
project for the color space invasion.
Note that the GIMP_RGB_LUMINANCE macro is
temporarily moved to gimpcolor. It does not
require GimpRGB but was included in gimprgb.h.
This commit is contained in:
Alx Sa 2024-09-21 23:16:25 +00:00 committed by Jehan
parent 3cfadbf078
commit 0b7c2d39f4
8 changed files with 11 additions and 418 deletions

View File

@ -65,10 +65,6 @@ EXPORTS
gimp_color_transform_new_proofing
gimp_color_transform_process_buffer
gimp_color_transform_process_pixels
gimp_hsl_get_type
gimp_hsl_set
gimp_hsl_set_alpha
gimp_hsl_to_rgb
gimp_param_color_get_type
gimp_param_spec_color
gimp_param_spec_color_from_string
@ -76,19 +72,3 @@ EXPORTS
gimp_pixbuf_create_buffer
gimp_pixbuf_get_format
gimp_pixbuf_get_icc_profile
gimp_rgb_add
gimp_rgb_clamp
gimp_rgb_composite
gimp_rgb_get_type
gimp_rgb_get_uchar
gimp_rgb_max
gimp_rgb_min
gimp_rgb_multiply
gimp_rgb_set
gimp_rgb_set_alpha
gimp_rgb_set_uchar
gimp_rgb_to_hsl
gimp_rgba_distance
gimp_rgba_get_uchar
gimp_rgba_set
gimp_rgba_set_uchar

View File

@ -30,11 +30,8 @@
#include <libgimpcolor/gimpcairo.h>
#include <libgimpcolor/gimpcolormanaged.h>
#include <libgimpcolor/gimpcolorprofile.h>
#include <libgimpcolor/gimpcolorspace.h>
#include <libgimpcolor/gimpcolortransform.h>
#include <libgimpcolor/gimphsl.h>
#include <libgimpcolor/gimppixbuf.h>
#include <libgimpcolor/gimprgb.h>
#undef __GIMP_COLOR_H_INSIDE__
@ -96,6 +93,17 @@ GParamSpec * gimp_param_spec_color_from_string (const gchar *name,
gboolean gimp_param_spec_color_has_alpha (GParamSpec *pspec);
/* Legacy definition to calculate luminance from sRGB */
#define GIMP_RGB_LUMINANCE_RED (0.22248840)
#define GIMP_RGB_LUMINANCE_GREEN (0.71690369)
#define GIMP_RGB_LUMINANCE_BLUE (0.06060791)
#define GIMP_RGB_LUMINANCE(r,g,b) ((r) * GIMP_RGB_LUMINANCE_RED + \
(g) * GIMP_RGB_LUMINANCE_GREEN + \
(b) * GIMP_RGB_LUMINANCE_BLUE)
/*
* GIMP_TYPE_BABL_FORMAT
*/

View File

@ -1,177 +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
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <babl/babl.h>
#include <glib-object.h>
#include "libgimpmath/gimpmath.h"
#include "gimpcolortypes.h"
#include "gimpcolorspace.h"
#include "gimprgb.h"
/**
* SECTION: gimpcolorspace
* @title: GimpColorSpace
* @short_description: Utility functions which convert colors between
* different color models.
*
* When programming pixel data manipulation functions you will often
* use algorithms operating on a color model different from the one
* GIMP uses. This file provides utility functions to convert colors
* between different color spaces.
**/
#define GIMP_HSL_UNDEFINED -1.0
/* GimpRGB functions */
/**
* gimp_rgb_to_hsl:
* @rgb: A color value in the RGB colorspace
* @hsl: (out caller-allocates): The value converted to HSL
*
* Convert an RGB color value to a HSL (Hue, Saturation, Lightness)
* color value.
**/
void
gimp_rgb_to_hsl (const GimpRGB *rgb,
GimpHSL *hsl)
{
gdouble max, min, delta;
g_return_if_fail (rgb != NULL);
g_return_if_fail (hsl != NULL);
max = gimp_rgb_max (rgb);
min = gimp_rgb_min (rgb);
hsl->l = (max + min) / 2.0;
if (max == min)
{
hsl->s = 0.0;
hsl->h = GIMP_HSL_UNDEFINED;
}
else
{
if (hsl->l <= 0.5)
hsl->s = (max - min) / (max + min);
else
hsl->s = (max - min) / (2.0 - max - min);
delta = max - min;
if (delta == 0.0)
delta = 1.0;
if (rgb->r == max)
{
hsl->h = (rgb->g - rgb->b) / delta;
}
else if (rgb->g == max)
{
hsl->h = 2.0 + (rgb->b - rgb->r) / delta;
}
else
{
hsl->h = 4.0 + (rgb->r - rgb->g) / delta;
}
hsl->h /= 6.0;
if (hsl->h < 0.0)
hsl->h += 1.0;
}
hsl->a = rgb->a;
}
static inline gdouble
gimp_hsl_value (gdouble n1,
gdouble n2,
gdouble hue)
{
gdouble val;
if (hue > 6.0)
hue -= 6.0;
else if (hue < 0.0)
hue += 6.0;
if (hue < 1.0)
val = n1 + (n2 - n1) * hue;
else if (hue < 3.0)
val = n2;
else if (hue < 4.0)
val = n1 + (n2 - n1) * (4.0 - hue);
else
val = n1;
return val;
}
/**
* gimp_hsl_to_rgb:
* @hsl: A color value in the HSL colorspace
* @rgb: (out caller-allocates): The value converted to a value
* in the RGB colorspace
*
* Convert a HSL color value to an RGB color value.
**/
void
gimp_hsl_to_rgb (const GimpHSL *hsl,
GimpRGB *rgb)
{
g_return_if_fail (hsl != NULL);
g_return_if_fail (rgb != NULL);
if (hsl->s == 0)
{
/* achromatic case */
rgb->r = hsl->l;
rgb->g = hsl->l;
rgb->b = hsl->l;
}
else
{
gdouble m1, m2;
if (hsl->l <= 0.5)
m2 = hsl->l * (1.0 + hsl->s);
else
m2 = hsl->l + hsl->s - hsl->l * hsl->s;
m1 = 2.0 * hsl->l - m2;
rgb->r = gimp_hsl_value (m1, m2, hsl->h * 6.0 + 2.0);
rgb->g = gimp_hsl_value (m1, m2, hsl->h * 6.0);
rgb->b = gimp_hsl_value (m1, m2, hsl->h * 6.0 - 2.0);
}
rgb->a = hsl->a;
}

View File

@ -1,44 +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
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_COLOR_H_INSIDE__) && !defined (GIMP_COLOR_COMPILATION)
#error "Only <libgimpcolor/gimpcolor.h> can be included directly."
#endif
#ifndef __GIMP_COLOR_SPACE_H__
#define __GIMP_COLOR_SPACE_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/* Color conversion routines */
/* GimpRGB function */
void gimp_rgb_to_hsl (const GimpRGB *rgb,
GimpHSL *hsl);
void gimp_hsl_to_rgb (const GimpHSL *hsl,
GimpRGB *rgb);
G_END_DECLS
#endif /* __GIMP_COLOR_SPACE_H__ */

View File

@ -35,43 +35,6 @@ typedef struct _GimpColorTransform GimpColorTransform;
typedef struct _GimpParamSpecColor GimpParamSpecColor;
/* usually we don't keep the structure definitions in the types file
* but GimpRGB appears in too many header files...
*/
typedef struct _GimpRGB GimpRGB;
typedef struct _GimpHSL GimpHSL;
/**
* GimpRGB:
* @r: the red component
* @g: the green component
* @b: the blue component
* @a: the alpha component
*
* Used to keep RGB and RGBA colors. All components are in a range of
* [0.0..1.0].
**/
struct _GimpRGB
{
gdouble r, g, b, a;
};
/**
* GimpHSL:
* @h: the hue component
* @s: the saturation component
* @l: the lightness component
* @a: the alpha component
*
* Used to keep HSL and HSLA colors. All components are in a range of
* [0.0..1.0].
**/
struct _GimpHSL
{
gdouble h, s, l, a;
};
G_END_DECLS

View File

@ -1,82 +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
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib-object.h>
#include "gimpcolortypes.h"
#include "gimphsl.h"
/*
* GIMP_TYPE_HSL
*/
static GimpHSL * gimp_hsl_copy (const GimpHSL *hsl);
G_DEFINE_BOXED_TYPE (GimpHSL, gimp_hsl, gimp_hsl_copy, g_free)
static GimpHSL *
gimp_hsl_copy (const GimpHSL *hsl)
{
return g_memdup2 (hsl, sizeof (GimpHSL));
}
/* HSL functions */
/**
* gimp_hsl_set:
* @hsl:
* @h:
* @s:
* @l:
*
* Since: 2.8
**/
void
gimp_hsl_set (GimpHSL *hsl,
gdouble h,
gdouble s,
gdouble l)
{
g_return_if_fail (hsl != NULL);
hsl->h = h;
hsl->s = s;
hsl->l = l;
}
/**
* gimp_hsl_set_alpha:
* @hsl:
* @a:
*
* Since: 2.10
**/
void
gimp_hsl_set_alpha (GimpHSL *hsl,
gdouble a)
{
g_return_if_fail (hsl != NULL);
hsl->a = a;
}

View File

@ -1,49 +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
* <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_COLOR_H_INSIDE__) && !defined (GIMP_COLOR_COMPILATION)
#error "Only <libgimpcolor/gimpcolor.h> can be included directly."
#endif
#ifndef __GIMP_HSL_H__
#define __GIMP_HSL_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/*
* GIMP_TYPE_HSL
*/
#define GIMP_TYPE_HSL (gimp_hsl_get_type ())
GType gimp_hsl_get_type (void) G_GNUC_CONST;
void gimp_hsl_set (GimpHSL *hsl,
gdouble h,
gdouble s,
gdouble l);
void gimp_hsl_set_alpha (GimpHSL *hsl,
gdouble a);
G_END_DECLS
#endif /* __GIMP_HSL_H__ */

View File

@ -6,11 +6,8 @@ libgimpcolor_sources = files(
'gimpcolor-parse.c',
'gimpcolormanaged.c',
'gimpcolorprofile.c',
'gimpcolorspace.c',
'gimpcolortransform.c',
'gimphsl.c',
'gimppixbuf.c',
'gimprgb.c',
)
libgimpcolor_headers_introspectable = files(
@ -20,11 +17,8 @@ libgimpcolor_headers_introspectable = files(
'gimpcairo.h',
'gimpcolormanaged.h',
'gimpcolorprofile.h',
'gimpcolorspace.h',
'gimpcolortransform.h',
'gimphsl.h',
'gimppixbuf.h',
'gimprgb.h',
'gimpcolor.h',
)