• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*****************************************************************************/
2 // Copyright 2006 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8 
9 /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_color_space.h#2 $ */
10 /* $DateTime: 2012/07/11 10:36:56 $ */
11 /* $Change: 838485 $ */
12 /* $Author: tknoll $ */
13 
14 /** \file
15  *  Standard gamma functions and color spaces used within the DNG SDK.
16  */
17 
18 #ifndef __dng_color_space__
19 #define __dng_color_space__
20 
21 /*****************************************************************************/
22 
23 #include "dng_1d_function.h"
24 #include "dng_classes.h"
25 #include "dng_matrix.h"
26 #include "dng_types.h"
27 
28 /*****************************************************************************/
29 
30 /// \brief A dng_1d_function for gamma encoding in sRGB color space
31 
32 class dng_function_GammaEncode_sRGB: public dng_1d_function
33 	{
34 
35 	public:
36 
37 		virtual real64 Evaluate (real64 x) const;
38 
39 		virtual real64 EvaluateInverse (real64 y) const;
40 
41 		static const dng_1d_function & Get ();
42 
43 	};
44 
45 /*****************************************************************************/
46 
47 /// \brief A dng_1d_function for gamma encoding with 1.8 gamma.
48 
49 class dng_function_GammaEncode_1_8: public dng_1d_function
50 	{
51 
52 	public:
53 
54 		virtual real64 Evaluate (real64 x) const;
55 
56 		virtual real64 EvaluateInverse (real64 y) const;
57 
58 		static const dng_1d_function & Get ();
59 
60 	};
61 
62 /*****************************************************************************/
63 
64 /// \brief A dng_1d_function for gamma encoding with 2.2 gamma.
65 
66 class dng_function_GammaEncode_2_2: public dng_1d_function
67 	{
68 
69 	public:
70 
71 		virtual real64 Evaluate (real64 x) const;
72 
73 		virtual real64 EvaluateInverse (real64 y) const;
74 
75 		static const dng_1d_function & Get ();
76 
77 	};
78 
79 /*****************************************************************************/
80 
81 /// \brief An abstract color space
82 
83 class dng_color_space
84 	{
85 
86 	protected:
87 
88 		dng_matrix fMatrixToPCS;
89 
90 		dng_matrix fMatrixFromPCS;
91 
92 	public:
93 
94 		virtual ~dng_color_space ();
95 
96 		/// Return a matrix which transforms source data in this color space into the
97 		/// Profile Connection Space.
98 
MatrixToPCS()99 		const dng_matrix & MatrixToPCS () const
100 			{
101 			return fMatrixToPCS;
102 			}
103 
104 		/// Return a matrix which transforms Profile Connection Space data into this
105 		/// color space.
106 
MatrixFromPCS()107 		const dng_matrix & MatrixFromPCS () const
108 			{
109 			return fMatrixFromPCS;
110 			}
111 
112 		/// Predicate which is true if this color space is monochrome (has only a
113 		/// single column).
114 
IsMonochrome()115 		bool IsMonochrome () const
116 			{
117 			return fMatrixToPCS.Cols () == 1;
118 			}
119 
120 		/// Getter for the gamma function for this color space.
121 
122 		virtual const dng_1d_function & GammaFunction () const;
123 
124 		/// Returns true if this color space is linear. (I.e. has gamma 1.0.)
125 
IsLinear()126 		bool IsLinear () const
127 			{
128 			return GammaFunction ().IsIdentity ();
129 			}
130 
131 		/// Map an input value through this color space's encoding gamma.
132 
GammaEncode(real64 x)133 		real64 GammaEncode (real64 x) const
134 			{
135 			return GammaFunction ().Evaluate (x);
136 			}
137 
138 		/// Map an input value through this color space's decoding gamma (inverse of
139 		/// the encoding gamma).
140 
GammaDecode(real64 y)141 		real64 GammaDecode (real64 y) const
142 			{
143 			return GammaFunction ().EvaluateInverse (y);
144 			}
145 
146 		/// Getter for ICC profile, if this color space has one.
147 		/// \param size Out parameter which receives size on return.
148 		/// \param data Receives bytes of profile.
149 		/// \retval Returns true if this color space has an ICC profile, false otherwise.
150 
151 		virtual bool ICCProfile (uint32 &size,
152 								 const uint8 *&data) const;
153 
154 	protected:
155 
156 		dng_color_space ();
157 
158 		void SetMonochrome ();
159 
160 		void SetMatrixToPCS (const dng_matrix_3by3 &M);
161 
162 	};
163 
164 /*****************************************************************************/
165 
166 /// Singleton class for sRGB color space.
167 
168 class dng_space_sRGB: public dng_color_space
169 	{
170 
171 	protected:
172 
173 		dng_space_sRGB ();
174 
175 	public:
176 
177 		/// Returns dng_function_GammaEncode_sRGB
178 
179 		virtual const dng_1d_function & GammaFunction () const;
180 
181 		/// Returns sRGB IEC61966-2.1 ICC profile
182 
183 		virtual bool ICCProfile (uint32 &size,
184 								 const uint8 *&data) const;
185 
186 		/// Static method for getting single global instance of this color space.
187 
188 		static const dng_color_space & Get ();
189 
190 	};
191 
192 /*****************************************************************************/
193 
194 /// \brief Singleton class for AdobeRGB color space.
195 
196 class dng_space_AdobeRGB: public dng_color_space
197 	{
198 
199 	protected:
200 
201 		dng_space_AdobeRGB ();
202 
203 	public:
204 
205 		/// Returns dng_function_GammaEncode_1_8
206 
207 		virtual const dng_1d_function & GammaFunction () const;
208 
209 		/// Returns AdobeRGB (1998) ICC profile
210 
211 		virtual bool ICCProfile (uint32 &size,
212 								 const uint8 *&data) const;
213 
214 		/// Static method for getting single global instance of this color space.
215 
216 		static const dng_color_space & Get ();
217 
218 	};
219 
220 /*****************************************************************************/
221 
222 /// \brief Singleton class for ColorMatch color space.
223 
224 class dng_space_ColorMatch: public dng_color_space
225 	{
226 
227 	protected:
228 
229 		dng_space_ColorMatch ();
230 
231 	public:
232 
233 		/// Returns dng_function_GammaEncode_1_8
234 
235 		virtual const dng_1d_function & GammaFunction () const;
236 
237 		/// Returns ColorMatch RGB ICC profile
238 
239 		virtual bool ICCProfile (uint32 &size,
240 								 const uint8 *&data) const;
241 
242 		/// Static method for getting single global instance of this color space.
243 
244 		static const dng_color_space & Get ();
245 
246 	};
247 
248 /*****************************************************************************/
249 
250 /// \brief Singleton class for ProPhoto RGB color space.
251 
252 class dng_space_ProPhoto: public dng_color_space
253 	{
254 
255 	protected:
256 
257 		dng_space_ProPhoto ();
258 
259 	public:
260 
261 		/// Returns dng_function_GammaEncode_1_8
262 
263 		virtual const dng_1d_function & GammaFunction () const;
264 
265 		/// Returns ProPhoto RGB ICC profile
266 
267 		virtual bool ICCProfile (uint32 &size,
268 								 const uint8 *&data) const;
269 
270 		/// Static method for getting single global instance of this color space.
271 
272 		static const dng_color_space & Get ();
273 
274 	};
275 
276 /*****************************************************************************/
277 
278 /// \brief Singleton class for gamma 1.8 grayscale color space.
279 
280 class dng_space_GrayGamma18: public dng_color_space
281 	{
282 
283 	protected:
284 
285 		dng_space_GrayGamma18 ();
286 
287 	public:
288 
289 		/// Returns dng_function_GammaEncode_1_8
290 
291 		virtual const dng_1d_function & GammaFunction () const;
292 
293 		/// Returns simple grayscale gamma 1.8 ICC profile
294 
295 		virtual bool ICCProfile (uint32 &size,
296 								 const uint8 *&data) const;
297 
298 		/// Static method for getting single global instance of this color space.
299 
300 		static const dng_color_space & Get ();
301 
302 	};
303 
304 /*****************************************************************************/
305 
306 /// \brief Singleton class for gamma 2.2 grayscale color space.
307 
308 class dng_space_GrayGamma22: public dng_color_space
309 	{
310 
311 	protected:
312 
313 		dng_space_GrayGamma22 ();
314 
315 	public:
316 
317 		/// Returns dng_function_GammaEncode_2_2
318 
319 		virtual const dng_1d_function & GammaFunction () const;
320 
321 		/// Returns simple grayscale gamma 2.2 ICC profile
322 
323 		virtual bool ICCProfile (uint32 &size,
324 								 const uint8 *&data) const;
325 
326 		/// Static method for getting single global instance of this color space.
327 
328 		static const dng_color_space & Get ();
329 
330 	};
331 
332 /*****************************************************************************/
333 
334 class dng_space_fakeRGB: public dng_color_space
335 	{
336 
337 	protected:
338 
339 		dng_space_fakeRGB ();
340 
341 	public:
342 
343 		static const dng_color_space & Get ();
344 
345 	};
346 
347 /*****************************************************************************/
348 
349 #endif
350 
351 /*****************************************************************************/
352