File indexing completed on 2025-01-19 03:55:15

0001 /*****************************************************************************/
0002 // Copyright 2006-2019 Adobe Systems Incorporated
0003 // All Rights Reserved.
0004 //
0005 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
0006 // accordance with the terms of the Adobe license agreement accompanying it.
0007 /*****************************************************************************/
0008 
0009 /** \file
0010  * Classes for conversion of RAW data to final image.
0011  */
0012 
0013 /*****************************************************************************/
0014 
0015 #ifndef __dng_render__
0016 #define __dng_render__
0017 
0018 /*****************************************************************************/
0019 
0020 #include "dng_1d_function.h"
0021 #include "dng_auto_ptr.h"
0022 #include "dng_classes.h"
0023 #include "dng_spline.h"
0024 #include "dng_uncopyable.h"
0025 #include "dng_xy_coord.h"
0026 
0027 /******************************************************************************/
0028 
0029 /// \brief Curve for removing zero offset from stage3 image.
0030 
0031 class dng_function_zero_offset: public dng_1d_function
0032     {
0033 
0034     public:
0035 
0036         real64 fZeroOffset;
0037 
0038         real64 fScale;
0039 
0040     public:
0041 
0042         dng_function_zero_offset (real64 zeroOffset);
0043 
0044         virtual real64 Evaluate (real64 x) const;
0045 
0046     };
0047 
0048 /******************************************************************************/
0049 
0050 /// \brief Curve for pre-exposure-compensation adjustment based on noise floor,
0051 /// shadows, and highlight level.
0052 
0053 class dng_function_exposure_ramp: public dng_1d_function
0054     {
0055 
0056     public:
0057 
0058         real64 fSlope;      // Slope of straight segment.
0059 
0060         real64 fBlack;      // Intercept of straight segment.
0061 
0062         real64 fRadius;     // Rounding radius.
0063 
0064         real64 fQScale;     // Quadradic scale.
0065 
0066     public:
0067 
0068         dng_function_exposure_ramp (real64 white,
0069                                     real64 black,
0070                                     real64 minBlack);
0071 
0072         virtual real64 Evaluate (real64 x) const;
0073 
0074     };
0075 
0076 /******************************************************************************/
0077 
0078 /// \brief Exposure compensation curve for a given compensation amount in stops using
0079 /// quadric for roll-off.
0080 
0081 class dng_function_exposure_tone: public dng_1d_function
0082     {
0083 
0084     protected:
0085 
0086         bool fIsNOP;        // Is this a NOP function?
0087 
0088         real64 fSlope;      // Slope for lower part of curve.
0089 
0090         real64 a;           // Quadradic parameters for upper two f-stops.
0091         real64 b;
0092         real64 c;
0093 
0094     public:
0095 
0096         dng_function_exposure_tone (real64 exposure);
0097 
0098         /// Returns output value for a given input tone.
0099 
0100         virtual real64 Evaluate (real64 x) const;
0101 
0102     };
0103 
0104 /*****************************************************************************/
0105 
0106 /// Default ACR3 tone curve.
0107 
0108 class dng_tone_curve_acr3_default: public dng_1d_function
0109     {
0110 
0111     public:
0112 
0113         /// Returns output value for a given input tone.
0114 
0115         virtual real64 Evaluate (real64 x) const;
0116 
0117         /// Returns nearest input value for a given output tone.
0118 
0119         virtual real64 EvaluateInverse (real64 x) const;
0120 
0121         static const dng_1d_function & Get ();
0122 
0123     };
0124 
0125 /*****************************************************************************/
0126 
0127 /// \brief Encoding gamma curve for a given color space.
0128 
0129 class dng_function_gamma_encode: public dng_1d_function
0130     {
0131 
0132     protected:
0133 
0134         const dng_color_space &fSpace;
0135 
0136     public:
0137 
0138         dng_function_gamma_encode (const dng_color_space &space);
0139 
0140         virtual real64 Evaluate (real64 x) const;
0141 
0142     };
0143 
0144 /*****************************************************************************/
0145 
0146 /// \brief Class used to render digital negative to displayable image.
0147 
0148 class dng_render: private dng_uncopyable
0149     {
0150 
0151     protected:
0152 
0153         dng_host &fHost;
0154 
0155         const dng_negative &fNegative;
0156 
0157         dng_xy_coord fWhiteXY;
0158 
0159         real64 fExposure;
0160 
0161         real64 fShadows;
0162 
0163         const dng_1d_function *fToneCurve;
0164 
0165         const dng_color_space *fFinalSpace;
0166 
0167         uint32 fFinalPixelType;
0168 
0169         uint32 fMaximumSize;
0170 
0171     private:
0172 
0173         AutoPtr<dng_spline_solver> fProfileToneCurve;
0174 
0175     public:
0176 
0177         /// Construct a rendering instance that will be used to convert a given digital negative.
0178         /// \param host The host to use for memory allocation, progress updates, and abort testing.
0179         /// \param negative The digital negative to convert to a displayable image.
0180 
0181         dng_render (dng_host &host,
0182                     const dng_negative &negative);
0183 
0184         virtual ~dng_render ()
0185             {
0186             }
0187 
0188         /// Set the white point to be used for conversion.
0189         /// \param white White point to use.
0190 
0191         void SetWhiteXY (const dng_xy_coord &white)
0192             {
0193             fWhiteXY = white;
0194             }
0195 
0196         /// Get the white point to be used for conversion.
0197         /// \retval White point to use.
0198 
0199         const dng_xy_coord WhiteXY () const
0200             {
0201             return fWhiteXY;
0202             }
0203 
0204         /// Set exposure compensation.
0205         /// \param exposure Compensation value in stops, positive or negative.
0206 
0207         void SetExposure (real64 exposure)
0208             {
0209             fExposure = exposure;
0210             }
0211 
0212         /// Get exposure compensation.
0213         /// \retval Compensation value in stops, positive or negative.
0214 
0215         real64 Exposure () const
0216             {
0217             return fExposure;
0218             }
0219 
0220         /// Set shadow clip amount.
0221         /// \param shadows Shadow clip amount.
0222 
0223         void SetShadows (real64 shadows)
0224             {
0225             fShadows = shadows;
0226             }
0227 
0228         /// Get shadow clip amount.
0229         /// \retval Shadow clip amount.
0230 
0231         real64 Shadows () const
0232             {
0233             return fShadows;
0234             }
0235 
0236         /// Set custom tone curve for conversion.
0237         /// \param curve 1D function that defines tone mapping to use during conversion.
0238 
0239         void SetToneCurve (const dng_1d_function &curve)
0240             {
0241             fToneCurve = &curve;
0242             }
0243 
0244         /// Get custom tone curve for conversion.
0245         /// \retval 1D function that defines tone mapping to use during conversion.
0246 
0247         const dng_1d_function & ToneCurve () const
0248             {
0249             return *fToneCurve;
0250             }
0251 
0252         /// Set final color space in which resulting image data should be represented.
0253         /// (See dng_color_space.h for possible values.)
0254         /// \param space Color space to use.
0255 
0256         void SetFinalSpace (const dng_color_space &space)
0257             {
0258             fFinalSpace = &space;
0259             }
0260 
0261         /// Get final color space in which resulting image data should be represented.
0262         /// \retval Color space to use.
0263 
0264         const dng_color_space & FinalSpace () const
0265             {
0266             return *fFinalSpace;
0267             }
0268 
0269         /// Set pixel type of final image data.
0270         /// Can be ttByte (default), ttShort, or ttFloat.
0271         /// \param type Pixel type to use.
0272 
0273         void SetFinalPixelType (uint32 type)
0274             {
0275             fFinalPixelType = type;
0276             }
0277 
0278         /// Get pixel type of final image data.
0279         /// Can be ttByte (default), ttShort, or ttFloat.
0280         /// \retval Pixel type to use.
0281 
0282         uint32 FinalPixelType () const
0283             {
0284             return fFinalPixelType;
0285             }
0286 
0287         /// Set maximum dimension, in pixels, of resulting image.
0288         /// If final image would have either dimension larger than maximum, the larger
0289         /// of the two dimensions is set to this maximum size and the smaller dimension
0290         /// is adjusted to preserve aspect ratio.
0291         /// \param size Maximum size to allow.
0292 
0293         void SetMaximumSize (uint32 size)
0294             {
0295             fMaximumSize = size;
0296             }
0297 
0298         /// Get maximum dimension, in pixels, of resulting image.
0299         /// If the final image would have either dimension larger than this maximum, the larger
0300         /// of the two dimensions is set to this maximum size and the smaller dimension
0301         /// is adjusted to preserve the image's aspect ratio.
0302         /// \retval Maximum allowed size.
0303 
0304         uint32 MaximumSize () const
0305             {
0306             return fMaximumSize;
0307             }
0308 
0309         /// Actually render a digital negative to a displayable image.
0310         /// Input digital negative is passed to the constructor of this dng_render class.
0311         /// \retval The final resulting image.
0312 
0313         virtual dng_image * Render ();
0314 
0315     };
0316 
0317 /*****************************************************************************/
0318 
0319 #endif
0320 
0321 /*****************************************************************************/