File indexing completed on 2024-04-28 15:50:41

0001 /*
0002     SPDX-FileCopyrightText: 2006-2015 Gilles Caulier <caulier dot gilles at gmail dot com>
0003     SPDX-FileCopyrightText: 2006-2013 Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0004     SPDX-FileCopyrightText: 2007-2008 Guillaume Castagnino <casta at xwing dot info>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef RAW_DECODING_SETTINGS_H
0010 #define RAW_DECODING_SETTINGS_H
0011 
0012 // Qt includes
0013 
0014 #include <QRect>
0015 #include <QString>
0016 #include <QDebug>
0017 
0018 // Local includes
0019 
0020 #include "libkdcraw_export.h"
0021 
0022 namespace KDcrawIface
0023 {
0024 
0025 /** Settings for raw decoding
0026  */
0027 class LIBKDCRAW_EXPORT RawDecodingSettings
0028 {
0029 
0030 public:
0031 
0032     /** RAW decoding Interpolation methods
0033      *
0034      *  Bilinear: use high-speed but low-quality bilinear
0035      *            interpolation (default - for slow computer). In this method,
0036      *            the red value of a non-red pixel is computed as the average of
0037      *            the adjacent red pixels, and similar for blue and green.
0038      *  VNG:      use Variable Number of Gradients interpolation.
0039      *            This method computes gradients near the pixel of interest and uses
0040      *            the lower gradients (representing smoother and more similar parts
0041      *            of the image) to make an estimate.
0042      *  PPG:      use Patterned Pixel Grouping interpolation.
0043      *            Pixel Grouping uses assumptions about natural scenery in making estimates.
0044      *            It has fewer color artifacts on natural images than the Variable Number of
0045      *            Gradients method.
0046      *  AHD:      use Adaptive Homogeneity-Directed interpolation.
0047      *            This method selects the direction of interpolation so as to
0048      *            maximize a homogeneity metric, thus typically minimizing color artifacts.
0049      *  DCB:      DCB interpolation (see http://www.linuxphoto.org/html/dcb.html for details)
0050      * 
0051      * NOTE: from GPL2/GPL3 demosaic packs - will not work with libraw>=0.19
0052      * 
0053      *  PL_AHD:   modified AHD interpolation (see https://sites.google.com/site/demosaicalgorithms/modified-dcraw
0054      *            for details).
0055      *  AFD:      demosaicing through 5 pass median filter from PerfectRaw project.
0056      *  VCD:      VCD interpolation.
0057      *  VCD_AHD:  mixed demosaicing between VCD and AHD.
0058      *  LMMSE:    LMMSE interpolation from PerfectRaw.
0059      *  AMAZE:    AMaZE interpolation and color aberration removal from RawTherapee project.
0060      *
0061      * NOTE: for libraw>=0.19 only
0062      * 
0063      *  DHT:      DHT interpolation.
0064      *  AAHD:     Enhanced Adaptive AHD interpolation.
0065      */
0066     enum DecodingQuality
0067     {
0068         BILINEAR = 0,
0069         VNG      = 1,
0070         PPG      = 2,
0071         AHD      = 3,
0072         DCB      = 4,
0073         PL_AHD   = 5,
0074         AFD      = 6,
0075         VCD      = 7,
0076         VCD_AHD  = 8,
0077         LMMSE    = 9,
0078         AMAZE    = 10,
0079         DHT      = 11,
0080         AAHD     = 12
0081     };
0082 
0083     /** White balances alternatives
0084      *  NONE:     no white balance used : reverts to standard daylight D65 WB.
0085      *  CAMERA:   Use the camera embedded WB if available. Reverts to NONE if not.
0086      *  AUTO:     Averages an auto WB on the entire image.
0087      *  CUSTOM:   Let use set its own temperature and green factor (later converted to RGBG factors).
0088      *  AERA:     Let use an area from image to average white balance (see whiteBalanceArea for details).
0089      */
0090     enum WhiteBalance
0091     {
0092         NONE    = 0,
0093         CAMERA  = 1,
0094         AUTO    = 2,
0095         CUSTOM  = 3,
0096         AERA    = 4
0097     };
0098 
0099     /** Noise Reduction method to apply before demosaicing
0100      *  NONR:       No noise reduction.
0101      *  WAVELETSNR: wavelets correction to erase noise while preserving real detail. It's applied after interpolation.
0102      *  FBDDNR:     Fake Before Demosaicing Denoising noise reduction. It's applied before interpolation.
0103      *  LINENR:     CFA Line Denoise. It's applied after interpolation.
0104      *  IMPULSENR:  Impulse Denoise. It's applied after interpolation.
0105      */
0106     enum NoiseReduction
0107     {
0108         NONR = 0,
0109         WAVELETSNR,
0110         FBDDNR,
0111         LINENR,
0112         IMPULSENR
0113     };
0114 
0115     /** Input color profile used to decoded image
0116      *  NOINPUTCS:     No input color profile.
0117      *  EMBEDDED:      Use the camera profile embedded in RAW file if exist.
0118      *  CUSTOMINPUTCS: Use a custom input color space profile.
0119      */
0120     enum InputColorSpace
0121     {
0122         NOINPUTCS = 0,
0123         EMBEDDED,
0124         CUSTOMINPUTCS
0125     };
0126 
0127     /** Output RGB color space used to decoded image
0128      *  RAWCOLOR:       No output color profile (Linear RAW).
0129      *  SRGB:           Use standard sRGB color space.
0130      *  ADOBERGB:       Use standard Adobe RGB color space.
0131      *  WIDEGAMMUT:     Use standard RGB Wide Gamut color space.
0132      *  PROPHOTO:       Use standard RGB Pro Photo color space.
0133      *  CUSTOMOUTPUTCS: Use a custom workspace color profile.
0134      */
0135     enum OutputColorSpace
0136     {
0137         RAWCOLOR = 0,
0138         SRGB,
0139         ADOBERGB,
0140         WIDEGAMMUT,
0141         PROPHOTO,
0142         CUSTOMOUTPUTCS
0143     };
0144 
0145     /** Standard constructor with default settings
0146      */
0147     RawDecodingSettings();
0148 
0149     RawDecodingSettings(const RawDecodingSettings& prm);
0150     /** Equivalent to the copy constructor
0151      */
0152     RawDecodingSettings& operator=(const RawDecodingSettings& prm);
0153 
0154     /** Compare for equality
0155      */
0156     bool operator==(const RawDecodingSettings& o) const;
0157 
0158     /** Standard destructor
0159      */
0160     virtual ~RawDecodingSettings();
0161 
0162     /** Method to use a settings to optimize time loading, for example to compute image histogram
0163      */
0164     void optimizeTimeLoading();
0165 
0166 public:
0167 
0168     /** If true, images with overblown channels are processed much more accurate,
0169      *  without 'pink clouds' (and blue highlights under tungsten lamps).
0170      */
0171     bool fixColorsHighlights;
0172 
0173     /** If false, use a fixed white level, ignoring the image histogram.
0174      */
0175     bool autoBrightness;
0176 
0177     /** Turn on RAW file decoding in 16 bits per color per pixel instead 8 bits.
0178      */
0179     bool sixteenBitsImage;
0180 
0181     /** Half-size color image decoding (twice as fast as "enableRAWQuality").
0182      *  Turn on this option to reduce time loading to render histogram for example,
0183      *  no to render an image to screen.
0184      */
0185     bool halfSizeColorImage;
0186 
0187     /** White balance type to use. See WhiteBalance values for detail
0188      */
0189     WhiteBalance whiteBalance;
0190 
0191     /** The temperature and the green multiplier of the custom white balance
0192      */
0193     int    customWhiteBalance;
0194     double customWhiteBalanceGreen;
0195 
0196     /** Turn on RAW file decoding using RGB interpolation as four colors.
0197      */
0198     bool RGBInterpolate4Colors;
0199 
0200     /** For cameras with non-square pixels, do not stretch the image to its
0201      *  correct aspect ratio. In any case, this option guarantees that each
0202      *  output pixel corresponds to one RAW pixel.
0203      */
0204     bool DontStretchPixels;
0205 
0206     /** Unclip Highlight color level:
0207      *  0   = Clip all highlights to solid white.
0208      *  1   = Leave highlights unclipped in various shades of pink.
0209      *  2   = Blend clipped and unclipped values together for a gradual
0210      *        fade to white.
0211      *  3-9 = Reconstruct highlights. Low numbers favor whites; high numbers
0212      *        favor colors.
0213      */
0214     int unclipColors;
0215 
0216     /** RAW quality decoding factor value. See DecodingQuality values
0217      *  for details.
0218      */
0219     DecodingQuality RAWQuality;
0220 
0221     /** After interpolation, clean up color artifacts by repeatedly applying
0222      *  a 3x3 median filter to the R-G and B-G channels.
0223      */
0224     int medianFilterPasses;
0225 
0226     /** Noise reduction method to apply before demosaicing.
0227      */
0228     NoiseReduction NRType;
0229 
0230     /** Noise reduction threshold value. Null value disable NR. Range is between 100 and 1000.
0231      *  For IMPULSENR : set the amount of Luminance impulse denoise.
0232      */
0233     int NRThreshold;
0234 
0235     /** Turn on chromatic aberrations correction
0236      *  @deprecated does not work with libraw>=0.19
0237      */
0238     bool enableCACorrection;
0239 
0240     /** Magnification factor for Red and Blue layers
0241      *  - caMultiplier[0] = amount of correction on red-green axis.
0242      *  - caMultiplier[1] = amount of correction on blue-yellow axis.
0243      *  - Both values set to 0.0 = automatic CA correction.
0244      *  @deprecated does not work with libraw>=0.19
0245      */
0246     double caMultiplier[2];
0247 
0248     /** Brightness of output image.
0249      */
0250     double brightness;
0251 
0252     /** Turn on the black point setting to decode RAW image.
0253      */
0254     bool enableBlackPoint;
0255 
0256     /** Black Point value of output image.
0257      */
0258     int blackPoint;
0259 
0260     /** Turn on the white point setting to decode RAW image.
0261      */
0262     bool enableWhitePoint;
0263 
0264     /** White Point value of output image.
0265      */
0266     int whitePoint;
0267 
0268     /** The input color profile used to decoded RAW data. See OutputColorProfile
0269      *  values for details.
0270      */
0271     InputColorSpace inputColorSpace;
0272 
0273     /** Path to custom input ICC profile to define the camera's raw colorspace.
0274      */
0275     QString inputProfile;
0276 
0277     /** The output color profile used to decoded RAW data. See OutputColorProfile
0278      *  values for details.
0279      */
0280     OutputColorSpace outputColorSpace;
0281 
0282     /** Path to custom output ICC profile to define the color workspace.
0283      */
0284     QString outputProfile;
0285 
0286     /** Path to text file including dead pixel list.
0287      */
0288     QString deadPixelMap;
0289 
0290     /** Rectangle used to calculate the white balance by averaging the region of image.
0291      */
0292     QRect whiteBalanceArea;
0293 
0294     //-- Extended demosaicing settings ----------------------------------------------------------
0295 
0296     /// For DCB interpolation.
0297 
0298     /** Number of DCB median filtering correction passes.
0299      * -1   : disable (default)
0300      * 1-10 : DCB correction passes
0301      */
0302     int dcbIterations;
0303 
0304     /** Turn on the DCB interpolation with enhance interpolated colors.
0305      */
0306     bool dcbEnhanceFl;
0307 
0308     /// For VCD_AHD interpolation.
0309 
0310     /** Turn on the EECI refine for VCD Demosaicing.
0311      *  @deprecated does not work with libraw>=0.19
0312      */
0313     bool eeciRefine;
0314 
0315     /** Use edge-sensitive median filtering for artifact suppression after VCD demosaicing.
0316      * 0   : disable (default)
0317      * 1-10 : median filter passes.
0318      * @deprecated does not work with libraw>=0.19
0319      */
0320     int esMedPasses;
0321 
0322     /** For IMPULSENR Noise reduction. Set the amount of Chrominance impulse denoise.
0323      *  Null value disable NR. Range is between 100 and 1000.
0324      *  @deprecated does not work with libraw>=0.19
0325      */
0326     int NRChroThreshold;
0327 
0328     /** Turn on the Exposure Correction before interpolation.
0329      */
0330     bool expoCorrection;
0331 
0332     /** Shift of Exposure Correction before interpolation in linear scale.
0333      *  Usable range is from 0.25 (darken image 1 stop : -2EV) to 8.0 (lighten ~1.5 photographic stops : +3EV).
0334      */
0335     double expoCorrectionShift;
0336 
0337     /** Amount of highlight preservation for exposure correction before interpolation in E.V.
0338      *  Usable range is from 0.0 (linear exposure shift, highlights may blow) to 1.0 (maximum highlights preservation)
0339      *  This settings can only take effect if expoCorrectionShift > 1.0. 
0340      */
0341     double expoCorrectionHighlight;
0342 };
0343 
0344 //! qDebug() stream operator. Writes settings @a s to the debug output in a nicely formatted way.
0345 LIBKDCRAW_EXPORT QDebug operator<<(QDebug dbg, const RawDecodingSettings& s);
0346 
0347 }  // namespace KDcrawIface
0348 
0349 #endif /* RAW_DECODING_SETTINGS_H */