summaryrefslogtreecommitdiff
path: root/source/dng_render.h
blob: 1a7ea02dbd58b2eb1162ddbab1a34ce5e02dc791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*****************************************************************************/
// Copyright 2006-2007 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
// accordance with the terms of the Adobe license agreement accompanying it.
/*****************************************************************************/

/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_render.h#2 $ */ 
/* $DateTime: 2012/07/31 22:04:34 $ */
/* $Change: 840853 $ */
/* $Author: tknoll $ */

/** \file
 * Classes for conversion of RAW data to final image.
 */

/*****************************************************************************/

#ifndef __dng_render__
#define __dng_render__

/*****************************************************************************/

#include "dng_1d_function.h"
#include "dng_auto_ptr.h"
#include "dng_classes.h"
#include "dng_spline.h"
#include "dng_xy_coord.h"

/******************************************************************************/

/// \brief Curve for pre-exposure-compensation adjustment based on noise floor,
/// shadows, and highlight level.

class dng_function_exposure_ramp: public dng_1d_function
	{
	
	public:
	
		real64 fSlope;		// Slope of straight segment.
		
		real64 fBlack;		// Intercept of straight segment.
		
		real64 fRadius;		// Rounding radius.
		
		real64 fQScale;		// Quadradic scale.
		
	public:
		
		dng_function_exposure_ramp (real64 white,
				   					real64 black,
				   					real64 minBlack);
			
		virtual real64 Evaluate (real64 x) const;

	};
			
/******************************************************************************/

/// \brief Exposure compensation curve for a given compensation amount in stops using
/// quadric for roll-off.

class dng_function_exposure_tone: public dng_1d_function
	{
	
	protected:
	
		bool fIsNOP;		// Is this a NOP function?
		
		real64 fSlope;		// Slope for lower part of curve.
		
		real64 a;			// Quadradic parameters for upper two f-stops.
		real64 b;
		real64 c;
	
	public:
	
		dng_function_exposure_tone (real64 exposure);
				
		/// Returns output value for a given input tone.

		virtual real64 Evaluate (real64 x) const;
	
	};
	
/*****************************************************************************/

/// Default ACR3 tone curve.

class dng_tone_curve_acr3_default: public dng_1d_function
	{
	
	public:
		
		/// Returns output value for a given input tone.

		virtual real64 Evaluate (real64 x) const;
		
		/// Returns nearest input value for a given output tone.

		virtual real64 EvaluateInverse (real64 x) const;
		
		static const dng_1d_function & Get ();

	};
			
/*****************************************************************************/

/// \brief Encoding gamma curve for a given color space.

class dng_function_gamma_encode: public dng_1d_function
	{
	
	protected:
	
		const dng_color_space &fSpace;
	
	public:
	
		dng_function_gamma_encode (const dng_color_space &space);
		
		virtual real64 Evaluate (real64 x) const;
		
	};

/*****************************************************************************/

/// \brief Class used to render digital negative to displayable image.

class dng_render
	{
	
	protected:
	
		dng_host &fHost;
	
		const dng_negative &fNegative;
	
		dng_xy_coord fWhiteXY;
		
		real64 fExposure;
		
		real64 fShadows;
		
		const dng_1d_function *fToneCurve;
		
		const dng_color_space *fFinalSpace;
		
		uint32 fFinalPixelType;
		
		uint32 fMaximumSize;
		
	private:
	
		AutoPtr<dng_spline_solver> fProfileToneCurve;
		
	public:
	
		/// Construct a rendering instance that will be used to convert a given digital negative.
		/// \param host The host to use for memory allocation, progress updates, and abort testing.
		/// \param negative The digital negative to convert to a displayable image.

		dng_render (dng_host &host,
					const dng_negative &negative);
		
		virtual ~dng_render ()
			{
			}
		
		/// Set the white point to be used for conversion.
		/// \param white White point to use.

		void SetWhiteXY (const dng_xy_coord &white)
			{
			fWhiteXY = white;
			}
			
		/// Get the white point to be used for conversion.
		/// \retval White point to use.

		const dng_xy_coord WhiteXY () const
			{
			return fWhiteXY;
			}
			
		/// Set exposure compensation.
		/// \param exposure Compensation value in stops, positive or negative.

		void SetExposure (real64 exposure)
			{
			fExposure = exposure;
			}
			
		/// Get exposure compensation.
		/// \retval Compensation value in stops, positive or negative.

		real64 Exposure () const
			{
			return fExposure;
			}
			
		/// Set shadow clip amount.
		/// \param shadows Shadow clip amount.

		void SetShadows (real64 shadows)
			{
			fShadows = shadows;
			}
			
		/// Get shadow clip amount.
		/// \retval Shadow clip amount.

		real64 Shadows () const
			{
			return fShadows;
			}
			
		/// Set custom tone curve for conversion.
		/// \param curve 1D function that defines tone mapping to use during conversion.
	
		void SetToneCurve (const dng_1d_function &curve)
			{
			fToneCurve = &curve;
			}
			
		/// Get custom tone curve for conversion.
		/// \retval 1D function that defines tone mapping to use during conversion.

		const dng_1d_function & ToneCurve () const
			{
			return *fToneCurve;
			}

		/// Set final color space in which resulting image data should be represented.
		/// (See dng_color_space.h for possible values.)
		/// \param space Color space to use.

		void SetFinalSpace (const dng_color_space &space)
			{
			fFinalSpace = &space;
			}
			
		/// Get final color space in which resulting image data should be represented.
		/// \retval Color space to use.

		const dng_color_space & FinalSpace () const
			{
			return *fFinalSpace;
			}
			
		/// Set pixel type of final image data.
		/// Can be ttByte (default), ttShort, or ttFloat.
		/// \param type Pixel type to use.

		void SetFinalPixelType (uint32 type)
			{
			fFinalPixelType = type;
			}
			
		/// Get pixel type of final image data.
		/// Can be ttByte (default), ttShort, or ttFloat.
		/// \retval Pixel type to use.

		uint32 FinalPixelType () const
			{
			return fFinalPixelType;
			}

		/// Set maximum dimension, in pixels, of resulting image.
		/// If final image would have either dimension larger than maximum, the larger
		/// of the two dimensions is set to this maximum size and the smaller dimension
		/// is adjusted to preserve aspect ratio.
		/// \param size Maximum size to allow.

		void SetMaximumSize (uint32 size)
			{
			fMaximumSize = size;
			}
			
		/// Get maximum dimension, in pixels, of resulting image.
		/// If the final image would have either dimension larger than this maximum, the larger
		/// of the two dimensions is set to this maximum size and the smaller dimension
		/// is adjusted to preserve the image's aspect ratio.
		/// \retval Maximum allowed size.

		uint32 MaximumSize () const
			{
			return fMaximumSize;
			}

		/// Actually render a digital negative to a displayable image.
		/// Input digital negative is passed to the constructor of this dng_render class.
		/// \retval The final resulting image.

		virtual dng_image * Render ();
									
	private:
	
		// Hidden copy constructor and assignment operator.
		
		dng_render (const dng_render &render);
		
		dng_render & operator= (const dng_render &render);
	
	};

/*****************************************************************************/

#endif
	
/*****************************************************************************/