1 /* LIBGIMP - The GIMP Library 2 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball 3 * 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. 8 * 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. 13 * 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/>. 17 */ 18 19 #if !defined (__GIMP_COLOR_H_INSIDE__) && !defined (GIMP_COLOR_COMPILATION) 20 #error "Only <libgimpcolor/gimpcolor.h> can be included directly." 21 #endif 22 23 #ifndef __GIMP_RGB_H__ 24 #define __GIMP_RGB_H__ 25 26 G_BEGIN_DECLS 27 28 /* For information look into the C source or the html documentation */ 29 30 31 /* 32 * GIMP_TYPE_RGB 33 */ 34 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)) 37 38 GType gimp_rgb_get_type (void) G_GNUC_CONST; 39 40 void gimp_value_get_rgb (const GValue *value, 41 GimpRGB *rgb); 42 void gimp_value_set_rgb (GValue *value, 43 const GimpRGB *rgb); 44 45 46 /* 47 * GIMP_TYPE_PARAM_RGB 48 */ 49 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)) 52 53 54 GType gimp_param_rgb_get_type (void) G_GNUC_CONST; 55 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); 62 63 void gimp_param_spec_rgb_get_default (GParamSpec *pspec, 64 GimpRGB *default_value); 65 gboolean gimp_param_spec_rgb_has_alpha (GParamSpec *pspec); 66 67 68 /* RGB and RGBA color types and operations taken from LibGCK */ 69 70 /** 71 * GimpRGBCompositeMode: 72 * @GIMP_RGB_COMPOSITE_NONE: don't do compositing 73 * @GIMP_RGB_COMPOSITE_NORMAL: composite on top 74 * @GIMP_RGB_COMPOSITE_BEHIND: composite behind 75 **/ 76 typedef enum 77 { 78 GIMP_RGB_COMPOSITE_NONE = 0, 79 GIMP_RGB_COMPOSITE_NORMAL, 80 GIMP_RGB_COMPOSITE_BEHIND 81 } GimpRGBCompositeMode; 82 83 84 void gimp_rgb_set (GimpRGB *rgb, 85 gdouble red, 86 gdouble green, 87 gdouble blue); 88 void gimp_rgb_set_alpha (GimpRGB *rgb, 89 gdouble alpha); 90 91 void gimp_rgb_set_pixel (GimpRGB *rgb, 92 const Babl *format, 93 gconstpointer pixel); 94 void gimp_rgb_get_pixel (const GimpRGB *rgb, 95 const Babl *format, 96 gpointer pixel); 97 98 void gimp_rgb_set_uchar (GimpRGB *rgb, 99 guchar red, 100 guchar green, 101 guchar blue); 102 void gimp_rgb_get_uchar (const GimpRGB *rgb, 103 guchar *red, 104 guchar *green, 105 guchar *blue); 106 107 gboolean gimp_rgb_parse_name (GimpRGB *rgb, 108 const gchar *name, 109 gint len); 110 gboolean gimp_rgb_parse_hex (GimpRGB *rgb, 111 const gchar *hex, 112 gint len); 113 gboolean gimp_rgb_parse_css (GimpRGB *rgb, 114 const gchar *css, 115 gint len); 116 117 void gimp_rgb_add (GimpRGB *rgb1, 118 const GimpRGB *rgb2); 119 void gimp_rgb_subtract (GimpRGB *rgb1, 120 const GimpRGB *rgb2); 121 void gimp_rgb_multiply (GimpRGB *rgb1, 122 gdouble factor); 123 gdouble gimp_rgb_distance (const GimpRGB *rgb1, 124 const GimpRGB *rgb2); 125 126 gdouble gimp_rgb_max (const GimpRGB *rgb); 127 gdouble gimp_rgb_min (const GimpRGB *rgb); 128 void gimp_rgb_clamp (GimpRGB *rgb); 129 130 void gimp_rgb_gamma (GimpRGB *rgb, 131 gdouble gamma); 132 133 gdouble gimp_rgb_luminance (const GimpRGB *rgb); 134 guchar gimp_rgb_luminance_uchar (const GimpRGB *rgb); 135 136 GIMP_DEPRECATED_FOR(gimp_rgb_luminance) 137 gdouble gimp_rgb_intensity (const GimpRGB *rgb); 138 GIMP_DEPRECATED_FOR(gimp_rgb_luminance_uchar) 139 guchar gimp_rgb_intensity_uchar (const GimpRGB *rgb); 140 141 void gimp_rgb_composite (GimpRGB *color1, 142 const GimpRGB *color2, 143 GimpRGBCompositeMode mode); 144 145 /* access to the list of color names */ 146 gint gimp_rgb_list_names (const gchar ***names, 147 GimpRGB **colors); 148 149 150 void gimp_rgba_set (GimpRGB *rgba, 151 gdouble red, 152 gdouble green, 153 gdouble blue, 154 gdouble alpha); 155 156 void gimp_rgba_set_pixel (GimpRGB *rgba, 157 const Babl *format, 158 gconstpointer pixel); 159 void gimp_rgba_get_pixel (const GimpRGB *rgba, 160 const Babl *format, 161 gpointer pixel); 162 163 void gimp_rgba_set_uchar (GimpRGB *rgba, 164 guchar red, 165 guchar green, 166 guchar blue, 167 guchar alpha); 168 void gimp_rgba_get_uchar (const GimpRGB *rgba, 169 guchar *red, 170 guchar *green, 171 guchar *blue, 172 guchar *alpha); 173 174 gboolean gimp_rgba_parse_css (GimpRGB *rgba, 175 const gchar *css, 176 gint len); 177 178 void gimp_rgba_add (GimpRGB *rgba1, 179 const GimpRGB *rgba2); 180 void gimp_rgba_subtract (GimpRGB *rgba1, 181 const GimpRGB *rgba2); 182 void gimp_rgba_multiply (GimpRGB *rgba, 183 gdouble factor); 184 185 gdouble gimp_rgba_distance (const GimpRGB *rgba1, 186 const GimpRGB *rgba2); 187 188 189 190 /* Map D50-adapted sRGB to luminance */ 191 192 /* 193 * The weights to compute true CIE luminance from linear red, green 194 * and blue as defined by the sRGB color space specs in an ICC profile 195 * color managed application. The weights below have been chromatically 196 * adapted from D65 (as specified by the sRGB color space specs) 197 * to D50 (as specified by D50 illuminant values in the ICC V4 specs). 198 */ 199 200 #define GIMP_RGB_LUMINANCE_RED (0.22248840) 201 #define GIMP_RGB_LUMINANCE_GREEN (0.71690369) 202 #define GIMP_RGB_LUMINANCE_BLUE (0.06060791) 203 204 #define GIMP_RGB_LUMINANCE(r,g,b) ((r) * GIMP_RGB_LUMINANCE_RED + \ 205 (g) * GIMP_RGB_LUMINANCE_GREEN + \ 206 (b) * GIMP_RGB_LUMINANCE_BLUE) 207 208 209 #ifndef GIMP_DISABLE_DEPRECATED 210 211 /* 212 * The coefficients below properly computed luminance for monitors 213 * having phosphors that were contemporary at the introduction of NTSC 214 * television in 1953. They are still appropriate for computing video 215 * luma. However, these coefficients do not accurately compute 216 * luminance for contemporary monitors. The use of these definitions 217 * is deprecated. 218 */ 219 220 #define GIMP_RGB_INTENSITY_RED (0.30) 221 #define GIMP_RGB_INTENSITY_GREEN (0.59) 222 #define GIMP_RGB_INTENSITY_BLUE (0.11) 223 224 #define GIMP_RGB_INTENSITY(r,g,b) ((r) * GIMP_RGB_INTENSITY_RED + \ 225 (g) * GIMP_RGB_INTENSITY_GREEN + \ 226 (b) * GIMP_RGB_INTENSITY_BLUE) 227 228 #endif 229 230 231 G_END_DECLS 232 233 #endif /* __GIMP_RGB_H__ */ 234