| 1 | /*****************************************************************************/ | 
|---|
| 2 | // Copyright 2006-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_render.h#2 $ */ | 
|---|
| 10 | /* $DateTime: 2012/07/31 22:04:34 $ */ | 
|---|
| 11 | /* $Change: 840853 $ */ | 
|---|
| 12 | /* $Author: tknoll $ */ | 
|---|
| 13 |  | 
|---|
| 14 | /** \file | 
|---|
| 15 | * Classes for conversion of RAW data to final image. | 
|---|
| 16 | */ | 
|---|
| 17 |  | 
|---|
| 18 | /*****************************************************************************/ | 
|---|
| 19 |  | 
|---|
| 20 | #ifndef __dng_render__ | 
|---|
| 21 | #define __dng_render__ | 
|---|
| 22 |  | 
|---|
| 23 | /*****************************************************************************/ | 
|---|
| 24 |  | 
|---|
| 25 | #include "dng_1d_function.h" | 
|---|
| 26 | #include "dng_auto_ptr.h" | 
|---|
| 27 | #include "dng_classes.h" | 
|---|
| 28 | #include "dng_spline.h" | 
|---|
| 29 | #include "dng_xy_coord.h" | 
|---|
| 30 |  | 
|---|
| 31 | /******************************************************************************/ | 
|---|
| 32 |  | 
|---|
| 33 | /// \brief Curve for pre-exposure-compensation adjustment based on noise floor, | 
|---|
| 34 | /// shadows, and highlight level. | 
|---|
| 35 |  | 
|---|
| 36 | class dng_function_exposure_ramp: public dng_1d_function | 
|---|
| 37 | { | 
|---|
| 38 |  | 
|---|
| 39 | public: | 
|---|
| 40 |  | 
|---|
| 41 | real64 fSlope;		// Slope of straight segment. | 
|---|
| 42 |  | 
|---|
| 43 | real64 fBlack;		// Intercept of straight segment. | 
|---|
| 44 |  | 
|---|
| 45 | real64 fRadius;		// Rounding radius. | 
|---|
| 46 |  | 
|---|
| 47 | real64 fQScale;		// Quadradic scale. | 
|---|
| 48 |  | 
|---|
| 49 | public: | 
|---|
| 50 |  | 
|---|
| 51 | dng_function_exposure_ramp (real64 white, | 
|---|
| 52 | real64 black, | 
|---|
| 53 | real64 minBlack); | 
|---|
| 54 |  | 
|---|
| 55 | virtual real64 Evaluate (real64 x) const; | 
|---|
| 56 |  | 
|---|
| 57 | }; | 
|---|
| 58 |  | 
|---|
| 59 | /******************************************************************************/ | 
|---|
| 60 |  | 
|---|
| 61 | /// \brief Exposure compensation curve for a given compensation amount in stops using | 
|---|
| 62 | /// quadric for roll-off. | 
|---|
| 63 |  | 
|---|
| 64 | class dng_function_exposure_tone: public dng_1d_function | 
|---|
| 65 | { | 
|---|
| 66 |  | 
|---|
| 67 | protected: | 
|---|
| 68 |  | 
|---|
| 69 | bool fIsNOP;		// Is this a NOP function? | 
|---|
| 70 |  | 
|---|
| 71 | real64 fSlope;		// Slope for lower part of curve. | 
|---|
| 72 |  | 
|---|
| 73 | real64 a;			// Quadradic parameters for upper two f-stops. | 
|---|
| 74 | real64 b; | 
|---|
| 75 | real64 c; | 
|---|
| 76 |  | 
|---|
| 77 | public: | 
|---|
| 78 |  | 
|---|
| 79 | dng_function_exposure_tone (real64 exposure); | 
|---|
| 80 |  | 
|---|
| 81 | /// Returns output value for a given input tone. | 
|---|
| 82 |  | 
|---|
| 83 | virtual real64 Evaluate (real64 x) const; | 
|---|
| 84 |  | 
|---|
| 85 | }; | 
|---|
| 86 |  | 
|---|
| 87 | /*****************************************************************************/ | 
|---|
| 88 |  | 
|---|
| 89 | /// Default ACR3 tone curve. | 
|---|
| 90 |  | 
|---|
| 91 | class dng_tone_curve_acr3_default: public dng_1d_function | 
|---|
| 92 | { | 
|---|
| 93 |  | 
|---|
| 94 | public: | 
|---|
| 95 |  | 
|---|
| 96 | /// Returns output value for a given input tone. | 
|---|
| 97 |  | 
|---|
| 98 | virtual real64 Evaluate (real64 x) const; | 
|---|
| 99 |  | 
|---|
| 100 | /// Returns nearest input value for a given output tone. | 
|---|
| 101 |  | 
|---|
| 102 | virtual real64 EvaluateInverse (real64 x) const; | 
|---|
| 103 |  | 
|---|
| 104 | static const dng_1d_function & Get (); | 
|---|
| 105 |  | 
|---|
| 106 | }; | 
|---|
| 107 |  | 
|---|
| 108 | /*****************************************************************************/ | 
|---|
| 109 |  | 
|---|
| 110 | /// \brief Encoding gamma curve for a given color space. | 
|---|
| 111 |  | 
|---|
| 112 | class dng_function_gamma_encode: public dng_1d_function | 
|---|
| 113 | { | 
|---|
| 114 |  | 
|---|
| 115 | protected: | 
|---|
| 116 |  | 
|---|
| 117 | const dng_color_space &fSpace; | 
|---|
| 118 |  | 
|---|
| 119 | public: | 
|---|
| 120 |  | 
|---|
| 121 | dng_function_gamma_encode (const dng_color_space &space); | 
|---|
| 122 |  | 
|---|
| 123 | virtual real64 Evaluate (real64 x) const; | 
|---|
| 124 |  | 
|---|
| 125 | }; | 
|---|
| 126 |  | 
|---|
| 127 | /*****************************************************************************/ | 
|---|
| 128 |  | 
|---|
| 129 | /// \brief Class used to render digital negative to displayable image. | 
|---|
| 130 |  | 
|---|
| 131 | class dng_render | 
|---|
| 132 | { | 
|---|
| 133 |  | 
|---|
| 134 | protected: | 
|---|
| 135 |  | 
|---|
| 136 | dng_host &fHost; | 
|---|
| 137 |  | 
|---|
| 138 | const dng_negative &fNegative; | 
|---|
| 139 |  | 
|---|
| 140 | dng_xy_coord fWhiteXY; | 
|---|
| 141 |  | 
|---|
| 142 | real64 fExposure; | 
|---|
| 143 |  | 
|---|
| 144 | real64 fShadows; | 
|---|
| 145 |  | 
|---|
| 146 | const dng_1d_function *fToneCurve; | 
|---|
| 147 |  | 
|---|
| 148 | const dng_color_space *fFinalSpace; | 
|---|
| 149 |  | 
|---|
| 150 | uint32 fFinalPixelType; | 
|---|
| 151 |  | 
|---|
| 152 | uint32 fMaximumSize; | 
|---|
| 153 |  | 
|---|
| 154 | private: | 
|---|
| 155 |  | 
|---|
| 156 | AutoPtr<dng_spline_solver> fProfileToneCurve; | 
|---|
| 157 |  | 
|---|
| 158 | public: | 
|---|
| 159 |  | 
|---|
| 160 | /// Construct a rendering instance that will be used to convert a given digital negative. | 
|---|
| 161 | /// \param host The host to use for memory allocation, progress updates, and abort testing. | 
|---|
| 162 | /// \param negative The digital negative to convert to a displayable image. | 
|---|
| 163 |  | 
|---|
| 164 | dng_render (dng_host &host, | 
|---|
| 165 | const dng_negative &negative); | 
|---|
| 166 |  | 
|---|
| 167 | virtual ~dng_render () | 
|---|
| 168 | { | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | /// Set the white point to be used for conversion. | 
|---|
| 172 | /// \param white White point to use. | 
|---|
| 173 |  | 
|---|
| 174 | void SetWhiteXY (const dng_xy_coord &white) | 
|---|
| 175 | { | 
|---|
| 176 | fWhiteXY = white; | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | /// Get the white point to be used for conversion. | 
|---|
| 180 | /// \retval White point to use. | 
|---|
| 181 |  | 
|---|
| 182 | const dng_xy_coord WhiteXY () const | 
|---|
| 183 | { | 
|---|
| 184 | return fWhiteXY; | 
|---|
| 185 | } | 
|---|
| 186 |  | 
|---|
| 187 | /// Set exposure compensation. | 
|---|
| 188 | /// \param exposure Compensation value in stops, positive or negative. | 
|---|
| 189 |  | 
|---|
| 190 | void SetExposure (real64 exposure) | 
|---|
| 191 | { | 
|---|
| 192 | fExposure = exposure; | 
|---|
| 193 | } | 
|---|
| 194 |  | 
|---|
| 195 | /// Get exposure compensation. | 
|---|
| 196 | /// \retval Compensation value in stops, positive or negative. | 
|---|
| 197 |  | 
|---|
| 198 | real64 Exposure () const | 
|---|
| 199 | { | 
|---|
| 200 | return fExposure; | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | /// Set shadow clip amount. | 
|---|
| 204 | /// \param shadows Shadow clip amount. | 
|---|
| 205 |  | 
|---|
| 206 | void SetShadows (real64 shadows) | 
|---|
| 207 | { | 
|---|
| 208 | fShadows = shadows; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | /// Get shadow clip amount. | 
|---|
| 212 | /// \retval Shadow clip amount. | 
|---|
| 213 |  | 
|---|
| 214 | real64 Shadows () const | 
|---|
| 215 | { | 
|---|
| 216 | return fShadows; | 
|---|
| 217 | } | 
|---|
| 218 |  | 
|---|
| 219 | /// Set custom tone curve for conversion. | 
|---|
| 220 | /// \param curve 1D function that defines tone mapping to use during conversion. | 
|---|
| 221 |  | 
|---|
| 222 | void SetToneCurve (const dng_1d_function &curve) | 
|---|
| 223 | { | 
|---|
| 224 | fToneCurve = &curve; | 
|---|
| 225 | } | 
|---|
| 226 |  | 
|---|
| 227 | /// Get custom tone curve for conversion. | 
|---|
| 228 | /// \retval 1D function that defines tone mapping to use during conversion. | 
|---|
| 229 |  | 
|---|
| 230 | const dng_1d_function & ToneCurve () const | 
|---|
| 231 | { | 
|---|
| 232 | return *fToneCurve; | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 | /// Set final color space in which resulting image data should be represented. | 
|---|
| 236 | /// (See dng_color_space.h for possible values.) | 
|---|
| 237 | /// \param space Color space to use. | 
|---|
| 238 |  | 
|---|
| 239 | void SetFinalSpace (const dng_color_space &space) | 
|---|
| 240 | { | 
|---|
| 241 | fFinalSpace = &space; | 
|---|
| 242 | } | 
|---|
| 243 |  | 
|---|
| 244 | /// Get final color space in which resulting image data should be represented. | 
|---|
| 245 | /// \retval Color space to use. | 
|---|
| 246 |  | 
|---|
| 247 | const dng_color_space & FinalSpace () const | 
|---|
| 248 | { | 
|---|
| 249 | return *fFinalSpace; | 
|---|
| 250 | } | 
|---|
| 251 |  | 
|---|
| 252 | /// Set pixel type of final image data. | 
|---|
| 253 | /// Can be ttByte (default), ttShort, or ttFloat. | 
|---|
| 254 | /// \param type Pixel type to use. | 
|---|
| 255 |  | 
|---|
| 256 | void SetFinalPixelType (uint32 type) | 
|---|
| 257 | { | 
|---|
| 258 | fFinalPixelType = type; | 
|---|
| 259 | } | 
|---|
| 260 |  | 
|---|
| 261 | /// Get pixel type of final image data. | 
|---|
| 262 | /// Can be ttByte (default), ttShort, or ttFloat. | 
|---|
| 263 | /// \retval Pixel type to use. | 
|---|
| 264 |  | 
|---|
| 265 | uint32 FinalPixelType () const | 
|---|
| 266 | { | 
|---|
| 267 | return fFinalPixelType; | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | /// Set maximum dimension, in pixels, of resulting image. | 
|---|
| 271 | /// If final image would have either dimension larger than maximum, the larger | 
|---|
| 272 | /// of the two dimensions is set to this maximum size and the smaller dimension | 
|---|
| 273 | /// is adjusted to preserve aspect ratio. | 
|---|
| 274 | /// \param size Maximum size to allow. | 
|---|
| 275 |  | 
|---|
| 276 | void SetMaximumSize (uint32 size) | 
|---|
| 277 | { | 
|---|
| 278 | fMaximumSize = size; | 
|---|
| 279 | } | 
|---|
| 280 |  | 
|---|
| 281 | /// Get maximum dimension, in pixels, of resulting image. | 
|---|
| 282 | /// If the final image would have either dimension larger than this maximum, the larger | 
|---|
| 283 | /// of the two dimensions is set to this maximum size and the smaller dimension | 
|---|
| 284 | /// is adjusted to preserve the image's aspect ratio. | 
|---|
| 285 | /// \retval Maximum allowed size. | 
|---|
| 286 |  | 
|---|
| 287 | uint32 MaximumSize () const | 
|---|
| 288 | { | 
|---|
| 289 | return fMaximumSize; | 
|---|
| 290 | } | 
|---|
| 291 |  | 
|---|
| 292 | /// Actually render a digital negative to a displayable image. | 
|---|
| 293 | /// Input digital negative is passed to the constructor of this dng_render class. | 
|---|
| 294 | /// \retval The final resulting image. | 
|---|
| 295 |  | 
|---|
| 296 | virtual dng_image * Render (); | 
|---|
| 297 |  | 
|---|
| 298 | private: | 
|---|
| 299 |  | 
|---|
| 300 | // Hidden copy constructor and assignment operator. | 
|---|
| 301 |  | 
|---|
| 302 | dng_render (const dng_render &render); | 
|---|
| 303 |  | 
|---|
| 304 | dng_render & operator= (const dng_render &render); | 
|---|
| 305 |  | 
|---|
| 306 | }; | 
|---|
| 307 |  | 
|---|
| 308 | /*****************************************************************************/ | 
|---|
| 309 |  | 
|---|
| 310 | #endif | 
|---|
| 311 |  | 
|---|
| 312 | /*****************************************************************************/ | 
|---|
| 313 |  | 
|---|