app: s/sprintf/g_snprintf/ in xcf_save_image()
[gimp.git] / libgimpcolor / gimprgb.h
blobb789785eff60fccc1e17bb952d3cb2156acdfe1d
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."
21 #endif
23 #ifndef __GIMP_RGB_H__
24 #define __GIMP_RGB_H__
26 G_BEGIN_DECLS
28 /* For information look into the C source or the html documentation */
32 * GIMP_TYPE_RGB
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,
41 GimpRGB *rgb);
42 void gimp_value_set_rgb (GValue *value,
43 const GimpRGB *rgb);
47 * GIMP_TYPE_PARAM_RGB
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,
57 const gchar *nick,
58 const gchar *blurb,
59 gboolean has_alpha,
60 const GimpRGB *default_value,
61 GParamFlags flags);
63 gboolean gimp_param_spec_rgb_has_alpha (GParamSpec *pspec);
66 /* RGB and RGBA color types and operations taken from LibGCK */
68 typedef enum
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,
77 gdouble red,
78 gdouble green,
79 gdouble blue);
80 void gimp_rgb_set_alpha (GimpRGB *rgb,
81 gdouble alpha);
83 void gimp_rgb_set_pixel (GimpRGB *rgb,
84 const Babl *format,
85 gconstpointer pixel);
86 void gimp_rgb_get_pixel (const GimpRGB *rgb,
87 const Babl *format,
88 gpointer pixel);
90 void gimp_rgb_set_uchar (GimpRGB *rgb,
91 guchar red,
92 guchar green,
93 guchar blue);
94 void gimp_rgb_get_uchar (const GimpRGB *rgb,
95 guchar *red,
96 guchar *green,
97 guchar *blue);
99 gboolean gimp_rgb_parse_name (GimpRGB *rgb,
100 const gchar *name,
101 gint len);
102 gboolean gimp_rgb_parse_hex (GimpRGB *rgb,
103 const gchar *hex,
104 gint len);
105 gboolean gimp_rgb_parse_css (GimpRGB *rgb,
106 const gchar *css,
107 gint len);
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,
114 gdouble factor);
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,
123 gdouble gamma);
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,
134 GimpRGB **colors);
137 void gimp_rgba_set (GimpRGB *rgba,
138 gdouble red,
139 gdouble green,
140 gdouble blue,
141 gdouble alpha);
143 void gimp_rgba_set_pixel (GimpRGB *rgba,
144 const Babl *format,
145 gconstpointer pixel);
146 void gimp_rgba_get_pixel (const GimpRGB *rgba,
147 const Babl *format,
148 gpointer pixel);
150 void gimp_rgba_set_uchar (GimpRGB *rgba,
151 guchar red,
152 guchar green,
153 guchar blue,
154 guchar alpha);
155 void gimp_rgba_get_uchar (const GimpRGB *rgba,
156 guchar *red,
157 guchar *green,
158 guchar *blue,
159 guchar *alpha);
161 gboolean gimp_rgba_parse_css (GimpRGB *rgba,
162 const gchar *css,
163 gint len);
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,
170 gdouble factor);
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)
196 G_END_DECLS
198 #endif /* __GIMP_RGB_H__ */