• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*****************************************************************************/
2 // Copyright 2007 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_hue_sat_map.h#2 $ */
10 /* $DateTime: 2012/07/31 22:04:34 $ */
11 /* $Change: 840853 $ */
12 /* $Author: tknoll $ */
13 
14 /** \file
15  * Table-based color correction data structure.
16  */
17 
18 /*****************************************************************************/
19 
20 #ifndef __dng_hue_sat_map__
21 #define __dng_hue_sat_map__
22 
23 /*****************************************************************************/
24 
25 #include "dng_classes.h"
26 #include "dng_exceptions.h"
27 #include "dng_ref_counted_block.h"
28 #include "dng_safe_arithmetic.h"
29 #include "dng_types.h"
30 
31 /*****************************************************************************/
32 
33 /// \brief A 3D table that maps HSV (hue, saturation, and value) floating-point
34 /// input coordinates in the range [0,1] to delta signals. The table must have at
35 /// least 1 sample in the hue dimension, at least 2 samples in the saturation
36 /// dimension, and at least 1 sample in the value dimension. Tables are stored in
37 /// value-hue-saturation order.
38 
39 class dng_hue_sat_map
40 	{
41 
42 	public:
43 
44 		/// HSV delta signal. \param fHueShift is a delta value specified in degrees.
45 		/// This parameter, added to the original hue, determines the output hue. A
46 		/// value of 0 means no change. \param fSatScale and \param fValScale are
47 		/// scale factors that are applied to saturation and value components,
48 		/// respectively. These scale factors, multiplied by the original saturation
49 		/// and value, determine the output saturation and value. A scale factor of
50 		/// 1.0 means no change.
51 
52 		struct HSBModify
53 			{
54 			real32 fHueShift;
55 			real32 fSatScale;
56 			real32 fValScale;
57 			};
58 
59 	private:
60 
61 		uint32 fHueDivisions;
62 		uint32 fSatDivisions;
63 		uint32 fValDivisions;
64 
65 		uint32 fHueStep;
66 		uint32 fValStep;
67 
68 		dng_ref_counted_block fDeltas;
69 
SafeGetDeltas()70 		HSBModify *SafeGetDeltas ()
71 			{
72 			return (HSBModify *) fDeltas.Buffer_real32 ();
73 			}
74 
75 	public:
76 
77 		/// Construct an empty (and invalid) hue sat map.
78 
79 		dng_hue_sat_map ();
80 
81 		/// Copy an existing hue sat map.
82 
83 		dng_hue_sat_map (const dng_hue_sat_map &src);
84 
85 		/// Copy an existing hue sat map.
86 
87 		dng_hue_sat_map & operator= (const dng_hue_sat_map &rhs);
88 
89 		/// Destructor.
90 
91 		virtual ~dng_hue_sat_map ();
92 
93 		/// Is this hue sat map invalid?
94 
IsNull()95 		bool IsNull () const
96 			{
97 			return !IsValid ();
98 			}
99 
100 		/// Is this hue sat map valid?
101 
IsValid()102 		bool IsValid () const
103 			{
104 
105 			return fHueDivisions > 0 &&
106 				   fSatDivisions > 1 &&
107 				   fValDivisions > 0 &&
108 				   fDeltas.Buffer ();
109 
110 			}
111 
112 		/// Clear the hue sat map, making it invalid.
113 
SetInvalid()114 		void SetInvalid ()
115 			{
116 
117 			fHueDivisions = 0;
118 			fSatDivisions = 0;
119 			fValDivisions = 0;
120 
121 			fHueStep = 0;
122 			fValStep = 0;
123 
124 			fDeltas.Clear ();
125 
126 			}
127 
128 		/// Get the table dimensions (number of samples in each dimension).
129 
GetDivisions(uint32 & hueDivisions,uint32 & satDivisions,uint32 & valDivisions)130 		void GetDivisions (uint32 &hueDivisions,
131 						   uint32 &satDivisions,
132 						   uint32 &valDivisions) const
133 			{
134 			hueDivisions = fHueDivisions;
135 			satDivisions = fSatDivisions;
136 			valDivisions = fValDivisions;
137 			}
138 
139 		/// Set the table dimensions (number of samples in each dimension). This
140 		/// erases any existing table data.
141 
142 		void SetDivisions (uint32 hueDivisions,
143 						   uint32 satDivisions,
144 						   uint32 valDivisions = 1);
145 
146 		/// Get a specific table entry, specified by table indices.
147 
148 		void GetDelta (uint32 hueDiv,
149 					   uint32 satDiv,
150 					   uint32 valDiv,
151 					   HSBModify &modify) const;
152 
153 		/// Make sure the table is writeable.
154 
EnsureWriteable()155 		void EnsureWriteable ()
156 			{
157 			fDeltas.EnsureWriteable ();
158 			}
159 
160 		/// Set a specific table entry, specified by table indices.
161 
SetDelta(uint32 hueDiv,uint32 satDiv,uint32 valDiv,const HSBModify & modify)162 		void SetDelta (uint32 hueDiv,
163 					   uint32 satDiv,
164 					   uint32 valDiv,
165 					   const HSBModify &modify)
166 			{
167 
168 			EnsureWriteable ();
169 
170 			SetDeltaKnownWriteable (hueDiv,
171 									satDiv,
172 									valDiv,
173 									modify);
174 
175 			}
176 
177 		/// Same as SetDelta, without checking that the table is writeable.
178 
179 		void SetDeltaKnownWriteable (uint32 hueDiv,
180 									 uint32 satDiv,
181 									 uint32 valDiv,
182 									 const HSBModify &modify);
183 
184 		/// Get the total number of samples (across all dimensions).
185 
DeltasCount()186 		uint32 DeltasCount () const
187 			{
188 			uint32 deltaCount;
189 			if (!SafeUint32Mult(fValDivisions, fHueDivisions, &deltaCount) ||
190 	    			   !SafeUint32Mult(deltaCount, fSatDivisions, &deltaCount))
191 				{
192 				ThrowMemoryFull("Arithmetic overflow computing delta count");
193 				}
194 
195 			return deltaCount;
196 			}
197 
198 		/// Direct read/write access to table entries. The entries are stored in
199 		/// value-hue-saturation order (outer to inner).
200 
GetDeltas()201 		HSBModify *GetDeltas ()
202 			{
203 
204 			EnsureWriteable ();
205 
206 			return (HSBModify *) fDeltas.Buffer_real32 ();
207 
208 			}
209 
210 		/// Direct read-only access to table entries. The entries are stored in
211 		/// value-hue-saturation order (outer to inner).
212 
GetConstDeltas()213 		const HSBModify *GetConstDeltas () const
214 			{
215 			return (const HSBModify *) fDeltas.Buffer_real32 ();
216 			}
217 
218 		/// Equality test.
219 
220 		bool operator== (const dng_hue_sat_map &rhs) const;
221 
222 		/// Compute a linearly-interpolated hue sat map (i.e., delta and scale factors)
223 		/// from the specified tables, with the specified weight. map1 and map2 must
224 		/// have the same dimensions.
225 
226 		static dng_hue_sat_map * Interpolate (const dng_hue_sat_map &map1,
227 											  const dng_hue_sat_map &map2,
228 											  real64 weight1);
229 
230 	};
231 
232 /*****************************************************************************/
233 
234 #endif
235 
236 /*****************************************************************************/
237