1 /* LIBGIMP - The GIMP Library
2 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
4 * This library is free software: you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <https://www.gnu.org/licenses/>.
19 #if !defined (__GIMP_COLOR_H_INSIDE__) && !defined (GIMP_COLOR_COMPILATION)
20 #error "Only <libgimpcolor/gimpcolor.h> can be included directly."
23 #ifndef __GIMP_RGB_H__
24 #define __GIMP_RGB_H__
28 /* For information look into the C source or the html documentation */
35 #define GIMP_TYPE_RGB (gimp_rgb_get_type ())
36 #define GIMP_VALUE_HOLDS_RGB(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_RGB))
38 GType
gimp_rgb_get_type (void) G_GNUC_CONST
;
40 void gimp_value_get_rgb (const GValue
*value
,
42 void gimp_value_set_rgb (GValue
*value
,
50 #define GIMP_TYPE_PARAM_RGB (gimp_param_rgb_get_type ())
51 #define GIMP_IS_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_RGB))
54 GType
gimp_param_rgb_get_type (void) G_GNUC_CONST
;
56 GParamSpec
* gimp_param_spec_rgb (const gchar
*name
,
60 const GimpRGB
*default_value
,
63 gboolean
gimp_param_spec_rgb_has_alpha (GParamSpec
*pspec
);
66 /* RGB and RGBA color types and operations taken from LibGCK */
70 GIMP_RGB_COMPOSITE_NONE
= 0,
71 GIMP_RGB_COMPOSITE_NORMAL
,
72 GIMP_RGB_COMPOSITE_BEHIND
73 } GimpRGBCompositeMode
;
76 void gimp_rgb_set (GimpRGB
*rgb
,
80 void gimp_rgb_set_alpha (GimpRGB
*rgb
,
83 void gimp_rgb_set_pixel (GimpRGB
*rgb
,
86 void gimp_rgb_get_pixel (const GimpRGB
*rgb
,
90 void gimp_rgb_set_uchar (GimpRGB
*rgb
,
94 void gimp_rgb_get_uchar (const GimpRGB
*rgb
,
99 gboolean
gimp_rgb_parse_name (GimpRGB
*rgb
,
102 gboolean
gimp_rgb_parse_hex (GimpRGB
*rgb
,
105 gboolean
gimp_rgb_parse_css (GimpRGB
*rgb
,
109 void gimp_rgb_add (GimpRGB
*rgb1
,
110 const GimpRGB
*rgb2
);
111 void gimp_rgb_subtract (GimpRGB
*rgb1
,
112 const GimpRGB
*rgb2
);
113 void gimp_rgb_multiply (GimpRGB
*rgb1
,
115 gdouble
gimp_rgb_distance (const GimpRGB
*rgb1
,
116 const GimpRGB
*rgb2
);
118 gdouble
gimp_rgb_max (const GimpRGB
*rgb
);
119 gdouble
gimp_rgb_min (const GimpRGB
*rgb
);
120 void gimp_rgb_clamp (GimpRGB
*rgb
);
122 void gimp_rgb_gamma (GimpRGB
*rgb
,
125 gdouble
gimp_rgb_luminance (const GimpRGB
*rgb
);
126 guchar
gimp_rgb_luminance_uchar (const GimpRGB
*rgb
);
128 void gimp_rgb_composite (GimpRGB
*color1
,
129 const GimpRGB
*color2
,
130 GimpRGBCompositeMode mode
);
132 /* access to the list of color names */
133 gint
gimp_rgb_list_names (const gchar
***names
,
137 void gimp_rgba_set (GimpRGB
*rgba
,
143 void gimp_rgba_set_pixel (GimpRGB
*rgba
,
145 gconstpointer pixel
);
146 void gimp_rgba_get_pixel (const GimpRGB
*rgba
,
150 void gimp_rgba_set_uchar (GimpRGB
*rgba
,
155 void gimp_rgba_get_uchar (const GimpRGB
*rgba
,
161 gboolean
gimp_rgba_parse_css (GimpRGB
*rgba
,
165 void gimp_rgba_add (GimpRGB
*rgba1
,
166 const GimpRGB
*rgba2
);
167 void gimp_rgba_subtract (GimpRGB
*rgba1
,
168 const GimpRGB
*rgba2
);
169 void gimp_rgba_multiply (GimpRGB
*rgba
,
172 gdouble
gimp_rgba_distance (const GimpRGB
*rgba1
,
173 const GimpRGB
*rgba2
);
177 /* Map D50-adapted sRGB to luminance */
180 * The weights to compute true CIE luminance from linear red, green
181 * and blue as defined by the sRGB color space specs in an ICC profile
182 * color managed application. The weights below have been chromatically
183 * adapted from D65 (as specified by the sRGB color space specs)
184 * to D50 (as specified by D50 illuminant values in the ICC V4 specs).
187 #define GIMP_RGB_LUMINANCE_RED (0.22248840)
188 #define GIMP_RGB_LUMINANCE_GREEN (0.71690369)
189 #define GIMP_RGB_LUMINANCE_BLUE (0.06060791)
191 #define GIMP_RGB_LUMINANCE(r,g,b) ((r) * GIMP_RGB_LUMINANCE_RED + \
192 (g) * GIMP_RGB_LUMINANCE_GREEN + \
193 (b) * GIMP_RGB_LUMINANCE_BLUE)
198 #endif /* __GIMP_RGB_H__ */