mirror of https://github.com/GNOME/gimp.git
libgimpcolor: remove deprecated integer RGB <-> HSL conversion functions
This commit is contained in:
parent
07f5527998
commit
f8ce6b7440
|
@ -62,7 +62,6 @@ EXPORTS
|
||||||
gimp_hsl_set
|
gimp_hsl_set
|
||||||
gimp_hsl_set_alpha
|
gimp_hsl_set_alpha
|
||||||
gimp_hsl_to_rgb
|
gimp_hsl_to_rgb
|
||||||
gimp_hsl_to_rgb_int
|
|
||||||
gimp_hsv_clamp
|
gimp_hsv_clamp
|
||||||
gimp_hsv_get_type
|
gimp_hsv_get_type
|
||||||
gimp_hsv_set
|
gimp_hsv_set
|
||||||
|
@ -98,9 +97,7 @@ EXPORTS
|
||||||
gimp_rgb_subtract
|
gimp_rgb_subtract
|
||||||
gimp_rgb_to_cmyk
|
gimp_rgb_to_cmyk
|
||||||
gimp_rgb_to_hsl
|
gimp_rgb_to_hsl
|
||||||
gimp_rgb_to_hsl_int
|
|
||||||
gimp_rgb_to_hsv
|
gimp_rgb_to_hsv
|
||||||
gimp_rgb_to_l_int
|
|
||||||
gimp_rgba_add
|
gimp_rgba_add
|
||||||
gimp_rgba_distance
|
gimp_rgba_distance
|
||||||
gimp_rgba_get_pixel
|
gimp_rgba_get_pixel
|
||||||
|
|
|
@ -46,10 +46,6 @@
|
||||||
|
|
||||||
#define GIMP_HSL_UNDEFINED -1.0
|
#define GIMP_HSL_UNDEFINED -1.0
|
||||||
|
|
||||||
/*********************************
|
|
||||||
* color conversion routines *
|
|
||||||
*********************************/
|
|
||||||
|
|
||||||
|
|
||||||
/* GimpRGB functions */
|
/* GimpRGB functions */
|
||||||
|
|
||||||
|
@ -401,184 +397,3 @@ gimp_cmyk_to_rgb (const GimpCMYK *cmyk,
|
||||||
rgb->b = 1.0 - y;
|
rgb->b = 1.0 - y;
|
||||||
rgb->a = cmyk->a;
|
rgb->a = cmyk->a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* gint functions */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gimp_rgb_to_hsl_int:
|
|
||||||
* @red: Red channel, returns Hue channel
|
|
||||||
* @green: Green channel, returns Lightness channel
|
|
||||||
* @blue: Blue channel, returns Saturation channel
|
|
||||||
*
|
|
||||||
* The arguments are pointers to int representing channel values in the
|
|
||||||
* RGB colorspace, and the values pointed to are all in the range [0, 255].
|
|
||||||
*
|
|
||||||
* The function changes the arguments to point to the corresponding HLS
|
|
||||||
* value with the values pointed to in the following ranges: H [0, 360],
|
|
||||||
* L [0, 255], S [0, 255].
|
|
||||||
**/
|
|
||||||
void
|
|
||||||
gimp_rgb_to_hsl_int (gint *red,
|
|
||||||
gint *green,
|
|
||||||
gint *blue)
|
|
||||||
{
|
|
||||||
gint r, g, b;
|
|
||||||
gdouble h, s, l;
|
|
||||||
gint min, max;
|
|
||||||
gint delta;
|
|
||||||
|
|
||||||
r = *red;
|
|
||||||
g = *green;
|
|
||||||
b = *blue;
|
|
||||||
|
|
||||||
if (r > g)
|
|
||||||
{
|
|
||||||
max = MAX (r, b);
|
|
||||||
min = MIN (g, b);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
max = MAX (g, b);
|
|
||||||
min = MIN (r, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
l = (max + min) / 2.0;
|
|
||||||
|
|
||||||
if (max == min)
|
|
||||||
{
|
|
||||||
s = 0.0;
|
|
||||||
h = 0.0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delta = (max - min);
|
|
||||||
|
|
||||||
if (l < 128)
|
|
||||||
s = 255 * (gdouble) delta / (gdouble) (max + min);
|
|
||||||
else
|
|
||||||
s = 255 * (gdouble) delta / (gdouble) (511 - max - min);
|
|
||||||
|
|
||||||
if (r == max)
|
|
||||||
h = (g - b) / (gdouble) delta;
|
|
||||||
else if (g == max)
|
|
||||||
h = 2 + (b - r) / (gdouble) delta;
|
|
||||||
else
|
|
||||||
h = 4 + (r - g) / (gdouble) delta;
|
|
||||||
|
|
||||||
h = h * 42.5;
|
|
||||||
|
|
||||||
if (h < 0)
|
|
||||||
h += 255;
|
|
||||||
else if (h > 255)
|
|
||||||
h -= 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
*red = ROUND (h);
|
|
||||||
*green = ROUND (s);
|
|
||||||
*blue = ROUND (l);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gimp_rgb_to_l_int:
|
|
||||||
* @red: Red channel
|
|
||||||
* @green: Green channel
|
|
||||||
* @blue: Blue channel
|
|
||||||
*
|
|
||||||
* Calculates the lightness value of an RGB triplet with the formula
|
|
||||||
* L = (max(R, G, B) + min (R, G, B)) / 2
|
|
||||||
*
|
|
||||||
* Return value: Luminance value corresponding to the input RGB value
|
|
||||||
**/
|
|
||||||
gint
|
|
||||||
gimp_rgb_to_l_int (gint red,
|
|
||||||
gint green,
|
|
||||||
gint blue)
|
|
||||||
{
|
|
||||||
gint min, max;
|
|
||||||
|
|
||||||
if (red > green)
|
|
||||||
{
|
|
||||||
max = MAX (red, blue);
|
|
||||||
min = MIN (green, blue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
max = MAX (green, blue);
|
|
||||||
min = MIN (red, blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ROUND ((max + min) / 2.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline gint
|
|
||||||
gimp_hsl_value_int (gdouble n1,
|
|
||||||
gdouble n2,
|
|
||||||
gdouble hue)
|
|
||||||
{
|
|
||||||
gdouble value;
|
|
||||||
|
|
||||||
if (hue > 255)
|
|
||||||
hue -= 255;
|
|
||||||
else if (hue < 0)
|
|
||||||
hue += 255;
|
|
||||||
|
|
||||||
if (hue < 42.5)
|
|
||||||
value = n1 + (n2 - n1) * (hue / 42.5);
|
|
||||||
else if (hue < 127.5)
|
|
||||||
value = n2;
|
|
||||||
else if (hue < 170)
|
|
||||||
value = n1 + (n2 - n1) * ((170 - hue) / 42.5);
|
|
||||||
else
|
|
||||||
value = n1;
|
|
||||||
|
|
||||||
return ROUND (value * 255.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gimp_hsl_to_rgb_int:
|
|
||||||
* @hue: Hue channel, returns Red channel
|
|
||||||
* @saturation: Saturation channel, returns Green channel
|
|
||||||
* @lightness: Lightness channel, returns Blue channel
|
|
||||||
*
|
|
||||||
* The arguments are pointers to int, with the values pointed to in the
|
|
||||||
* following ranges: H [0, 360], L [0, 255], S [0, 255].
|
|
||||||
*
|
|
||||||
* The function changes the arguments to point to the RGB value
|
|
||||||
* corresponding, with the returned values all in the range [0, 255].
|
|
||||||
**/
|
|
||||||
void
|
|
||||||
gimp_hsl_to_rgb_int (gint *hue,
|
|
||||||
gint *saturation,
|
|
||||||
gint *lightness)
|
|
||||||
{
|
|
||||||
gdouble h, s, l;
|
|
||||||
|
|
||||||
h = *hue;
|
|
||||||
s = *saturation;
|
|
||||||
l = *lightness;
|
|
||||||
|
|
||||||
if (s == 0)
|
|
||||||
{
|
|
||||||
/* achromatic case */
|
|
||||||
*hue = l;
|
|
||||||
*lightness = l;
|
|
||||||
*saturation = l;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gdouble m1, m2;
|
|
||||||
|
|
||||||
if (l < 128)
|
|
||||||
m2 = (l * (255 + s)) / 65025.0;
|
|
||||||
else
|
|
||||||
m2 = (l + s - (l * s) / 255.0) / 255.0;
|
|
||||||
|
|
||||||
m1 = (l / 127.5) - m2;
|
|
||||||
|
|
||||||
/* chromatic case */
|
|
||||||
*hue = gimp_hsl_value_int (m1, m2, h + 85);
|
|
||||||
*saturation = gimp_hsl_value_int (m1, m2, h);
|
|
||||||
*lightness = gimp_hsl_value_int (m1, m2, h - 85);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -48,25 +48,6 @@ void gimp_hsl_to_rgb (const GimpHSL *hsl,
|
||||||
void gimp_cmyk_to_rgb (const GimpCMYK *cmyk,
|
void gimp_cmyk_to_rgb (const GimpCMYK *cmyk,
|
||||||
GimpRGB *rgb);
|
GimpRGB *rgb);
|
||||||
|
|
||||||
|
|
||||||
/* gint functions */
|
|
||||||
|
|
||||||
GIMP_DEPRECATED_FOR (gimp_rgb_to_hsl)
|
|
||||||
void gimp_rgb_to_hsl_int (gint *red /* returns hue */,
|
|
||||||
gint *green /* returns saturation */,
|
|
||||||
gint *blue /* returns lightness */);
|
|
||||||
|
|
||||||
GIMP_DEPRECATED_FOR (gimp_rgb_to_hsl)
|
|
||||||
gint gimp_rgb_to_l_int (gint red,
|
|
||||||
gint green,
|
|
||||||
gint blue);
|
|
||||||
|
|
||||||
GIMP_DEPRECATED_FOR (gimp_hsl_to_rgb)
|
|
||||||
void gimp_hsl_to_rgb_int (gint *hue /* returns red */,
|
|
||||||
gint *saturation /* returns green */,
|
|
||||||
gint *lightness /* returns blue */);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GIMP_COLOR_SPACE_H__ */
|
#endif /* __GIMP_COLOR_SPACE_H__ */
|
||||||
|
|
Loading…
Reference in New Issue