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