1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2  *
3  * Copyright (C) 2010-2014 Richard Hughes <richard@hughsie.com>
4  *
5  * Licensed under the GNU Lesser General Public License Version 2.1
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21 
22 #if !defined (__COLORD_H_INSIDE__) && !defined (CD_COMPILATION)
23 #error "Only <colord.h> can be included directly."
24 #endif
25 
26 #ifndef __CD_COLOR_H__
27 #define __CD_COLOR_H__
28 
29 #include <glib-object.h>
30 
31 G_BEGIN_DECLS
32 
33 typedef struct {
34 	guint8	 R;
35 	guint8	 G;
36 	guint8	 B;
37 } CdColorRGB8;
38 
39 typedef struct {
40 	gdouble	 L;
41 	gdouble	 a;
42 	gdouble	 b;
43 } CdColorLab;
44 
45 typedef struct {
46 	gdouble	 Y;
47 	gdouble	 x;
48 	gdouble	 y;
49 } CdColorYxy;
50 
51 typedef struct {
52 	gdouble	 X;
53 	gdouble	 Y;
54 	gdouble	 Z;
55 } CdColorXYZ;
56 
57 typedef struct {
58 	gdouble	 R;
59 	gdouble	 G;
60 	gdouble	 B;
61 } CdColorRGB;
62 
63 typedef struct {
64 	gdouble	 U;
65 	gdouble	 V;
66 	gdouble	 W;
67 } CdColorUVW;
68 
69 /**
70  * CdColorBlackbodyFlags:
71  * @CD_COLOR_BLACKBODY_FLAG_NONE:		No flags set.
72  * @CD_COLOR_BLACKBODY_FLAG_USE_PLANCKIAN:	Use Planckian below 5000K
73  *
74  * Flags used when returning an RGB color from a temperature.
75  *
76  * Since: 1.3.5
77  **/
78 typedef enum {
79 	CD_COLOR_BLACKBODY_FLAG_NONE,		/* Since: 1.3.5 */
80 	CD_COLOR_BLACKBODY_FLAG_USE_PLANCKIAN,	/* Since: 1.3.5 */
81 	/*< private >*/
82 	CD_COLOR_BLACKBODY_FLAG_LAST
83 } CdColorBlackbodyFlags;
84 
85 typedef struct _CdColorSwatch	CdColorSwatch;
86 
87 #define	CD_TYPE_COLOR_RGB	(cd_color_rgb_get_type ())
88 #define	CD_TYPE_COLOR_XYZ	(cd_color_xyz_get_type ())
89 #define	CD_TYPE_COLOR_LAB	(cd_color_lab_get_type ())
90 #define	CD_TYPE_COLOR_YXY	(cd_color_yxy_get_type ())
91 #define	CD_TYPE_COLOR_UVW	(cd_color_uvw_get_type ())
92 #define	CD_TYPE_COLOR_SWATCH	(cd_color_swatch_get_type ())
93 
94 /* types */
95 GType		 cd_color_xyz_get_type			(void);
96 GType		 cd_color_lab_get_type			(void);
97 GType		 cd_color_rgb_get_type			(void);
98 GType		 cd_color_yxy_get_type			(void);
99 GType		 cd_color_uvw_get_type			(void);
100 GType		 cd_color_swatch_get_type		(void);
101 
102 const gchar	*cd_color_swatch_get_name		(const CdColorSwatch	*swatch);
103 const CdColorLab*cd_color_swatch_get_value		(const CdColorSwatch	*swatch);
104 
105 CdColorXYZ	*cd_color_xyz_new			(void);
106 CdColorLab	*cd_color_lab_new			(void);
107 CdColorRGB	*cd_color_rgb_new			(void);
108 CdColorYxy	*cd_color_yxy_new			(void);
109 CdColorUVW	*cd_color_uvw_new			(void);
110 CdColorSwatch	*cd_color_swatch_new			(void);
111 
112 void		 cd_color_xyz_free			(CdColorXYZ		*src);
113 void		 cd_color_rgb_free			(CdColorRGB		*src);
114 void		 cd_color_lab_free			(CdColorLab		*src);
115 void		 cd_color_yxy_free			(CdColorYxy		*src);
116 void		 cd_color_uvw_free			(CdColorUVW		*src);
117 void		 cd_color_swatch_free			(CdColorSwatch		*src);
118 
119 G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorXYZ, cd_color_xyz_free)
120 G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorRGB, cd_color_rgb_free)
121 G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorLab, cd_color_lab_free)
122 G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorYxy, cd_color_yxy_free)
123 G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorUVW, cd_color_uvw_free)
124 G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorSwatch, cd_color_swatch_free)
125 
126 CdColorXYZ	*cd_color_xyz_dup			(const CdColorXYZ	*src);
127 CdColorLab	*cd_color_lab_dup			(const CdColorLab	*src);
128 CdColorRGB	*cd_color_rgb_dup			(const CdColorRGB	*src);
129 CdColorYxy	*cd_color_yxy_dup			(const CdColorYxy	*src);
130 CdColorUVW	*cd_color_uvw_dup			(const CdColorUVW	*src);
131 CdColorSwatch	*cd_color_swatch_dup			(const CdColorSwatch	*src);
132 
133 void		 cd_color_xyz_set			(CdColorXYZ		*dest,
134 							 gdouble		 X,
135 							 gdouble		 Y,
136 							 gdouble		 Z);
137 void		 cd_color_rgb_set			(CdColorRGB		*dest,
138 							 gdouble		 R,
139 							 gdouble		 G,
140 							 gdouble		 B);
141 void		 cd_color_lab_set			(CdColorLab		*dest,
142 							 gdouble		 L,
143 							 gdouble		 a,
144 							 gdouble		 b);
145 void		 cd_color_yxy_set			(CdColorYxy		*dest,
146 							 gdouble		 Y,
147 							 gdouble		 x,
148 							 gdouble		 y);
149 void		 cd_color_uvw_set			(CdColorUVW		*dest,
150 							 gdouble		 U,
151 							 gdouble		 V,
152 							 gdouble		 W);
153 void		 cd_color_swatch_set_name		(CdColorSwatch		*dest,
154 							 const gchar		*name);
155 void		 cd_color_swatch_set_value		(CdColorSwatch		*dest,
156 							 const CdColorLab	*value);
157 
158 void		 cd_color_xyz_copy			(const CdColorXYZ	*src,
159 							 CdColorXYZ		*dest);
160 void		 cd_color_yxy_copy			(const CdColorYxy	*src,
161 							 CdColorYxy		*dest);
162 void		 cd_color_uvw_copy			(const CdColorUVW	*src,
163 							 CdColorUVW		*dest);
164 void		 cd_color_lab_copy			(const CdColorLab	*src,
165 							 CdColorLab		*dest);
166 gdouble		 cd_color_lab_delta_e76			(const CdColorLab	*p1,
167 							 const CdColorLab	*p2);
168 void		 cd_color_xyz_clear			(CdColorXYZ		*dest);
169 void		 cd_color_rgb_copy			(const CdColorRGB	*src,
170 							 CdColorRGB		*dest);
171 void		 cd_color_rgb8_to_rgb			(const CdColorRGB8	*src,
172 							 CdColorRGB		*dest);
173 void		 cd_color_rgb_to_rgb8			(const CdColorRGB	*src,
174 							 CdColorRGB8		*dest);
175 void		 cd_color_yxy_to_xyz			(const CdColorYxy	*src,
176 							 CdColorXYZ		*dest);
177 void		 cd_color_xyz_to_yxy			(const CdColorXYZ	*src,
178 							 CdColorYxy		*dest);
179 void		 cd_color_xyz_to_uvw			(const CdColorXYZ	*src,
180 							 const CdColorXYZ	*whitepoint,
181 							 CdColorUVW		*dest);
182 void		 cd_color_yxy_to_uvw			(const CdColorYxy	*src,
183 							 CdColorUVW		*dest);
184 void		 cd_color_uvw_set_planckian_locus	(CdColorUVW		*dest,
185 							 gdouble		 temp);
186 gdouble		 cd_color_uvw_get_chroma_difference	(const CdColorUVW	*p1,
187 							 const CdColorUVW	*p2);
188 gboolean	 cd_color_get_blackbody_rgb		(guint			 temp,
189 							 CdColorRGB		*result);
190 gboolean	 cd_color_get_blackbody_rgb_full	(gdouble		 temp,
191 							 CdColorRGB		*result,
192 							 CdColorBlackbodyFlags	 flags);
193 void		 cd_color_rgb_interpolate		(const CdColorRGB	*p1,
194 							 const CdColorRGB	*p2,
195 							 gdouble		 index,
196 							 CdColorRGB		*result);
197 void		 cd_color_rgb_from_wavelength		(CdColorRGB		*dest,
198 							 gdouble		 wavelength);
199 gdouble		 cd_color_xyz_to_cct			(const CdColorXYZ	*src);
200 void		 cd_color_xyz_normalize			(const CdColorXYZ	*src,
201 							 gdouble		 max,
202 							 CdColorXYZ		*dest);
203 
204 GPtrArray	*cd_color_rgb_array_new			(void);
205 gboolean	 cd_color_rgb_array_is_monotonic	(const GPtrArray	*array);
206 GPtrArray	*cd_color_rgb_array_interpolate		(const GPtrArray	*array,
207 							 guint			 new_length)
208 							 G_GNUC_WARN_UNUSED_RESULT;
209 
210 G_END_DECLS
211 
212 #endif /* __CD_COLOR_H__ */
213 
214