1 /* -*- C++ -*-
2  *
3  *  This file is part of RawTherapee.
4  *
5  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
6  *
7  *  RawTherapee is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  RawTherapee is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with RawTherapee.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 #ifndef _IMAGESOURCE_
21 #define _IMAGESOURCE_
22 
23 #include <glibmm.h>
24 #include <vector>
25 #include "rtengine.h"
26 #include "colortemp.h"
27 #include "procparams.h"
28 #include "coord2d.h"
29 #include "dcp.h"
30 #include "LUT.h"
31 #include "imagedata.h"
32 #include "image8.h"
33 #include "image16.h"
34 #include "imagefloat.h"
35 
36 namespace rtengine {
37 
38 using namespace procparams;
39 
40 class ImageMatrices {
41 
42 public:
43     double rgb_cam[3][3] = {};
44     double cam_rgb[3][3] = {};
45     double xyz_cam[3][3] = {};
46     double cam_xyz[3][3] = {};
47 };
48 
49 
50 class ImageSource: public InitialImage {
51 
52 private:
53     int references;
54 
55 protected:
56     double redAWBMul, greenAWBMul, blueAWBMul; // local copy of the multipliers, to avoid recomputing the values
57     cmsHPROFILE embProfile;
58     Glib::ustring fileName;
59     FramesData* idata;
60     ImageMatrices imatrices;
61     // double dirpyrdenoiseExpComp;
62 
63 public:
ImageSource()64     ImageSource(): references (1), redAWBMul(-1.), greenAWBMul(-1.), blueAWBMul(-1.),
65                    embProfile(nullptr), idata(nullptr) {} //, dirpyrdenoiseExpComp(INFINITY) {}
66 
~ImageSource()67     ~ImageSource() override {}
68     virtual int load(const Glib::ustring &fname) = 0;
69     virtual void preprocess(const RAWParams &raw, const LensProfParams &lensProf, const CoarseTransformParams& coarse, bool prepareDenoise=true, const ColorTemp &wb=ColorTemp()) {};
demosaic(const RAWParams & raw,bool autoContrast,double & contrastThreshold)70     virtual void demosaic(const RAWParams &raw, bool autoContrast, double &contrastThreshold) {};
flushRawData()71     virtual void flushRawData() {};
flushRGB()72     virtual void flushRGB() {};
HLRecovery_Global(const ExposureParams & hrp)73     virtual void HLRecovery_Global(const ExposureParams &hrp) {};
74     //virtual void HLRecovery_inpaint(float** red, float** green, float** blue) {};
75 
76     virtual bool isRGBSourceModified() const = 0; // tracks whether cached rgb output of demosaic has been modified
77 
setBorder(unsigned int border)78     virtual void setBorder(unsigned int border) {}
79     virtual void setCurrentFrame(unsigned int frameNum) = 0;
80     virtual int getFrameCount() = 0;
81     virtual int getFlatFieldAutoClipValue() = 0;
82 
83 
84     // use right after demosaicing image, add coarse transformation and put the result in the provided Imagefloat*
85     virtual void getImage(const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const ExposureParams &hlp, const RAWParams &raw) = 0;
86     virtual eSensorType getSensorType() const = 0;
87     virtual bool isMono() const = 0;
88     // true is ready to provide the AutoWB, i.e. when the image has been demosaiced for RawImageSource
89     virtual bool isWBProviderReady() = 0;
90 
91     virtual void convertColorSpace(Imagefloat* image, const ColorManagementParams &cmp, const ColorTemp &wb) = 0; // DIRTY HACK: this method is derived in rawimagesource and strimagesource, but (...,RAWParams raw) will be used ONLY for raw images
92     virtual void getAutoWBMultipliers(double &rm, double &gm, double &bm) = 0;
93     virtual ColorTemp getWB() const = 0;
94     virtual ColorTemp getSpotWB(std::vector<Coord2D> &red, std::vector<Coord2D> &green, std::vector<Coord2D> &blue, int tran, double equal) = 0;
95 
getDefGain()96     virtual double getDefGain() const { return 1.0; }
97 
98     virtual void getFullSize(int& w, int& h, int tr = TR_NONE) {}
99     virtual void getSize(const PreviewProps &pp, int& w, int& h) = 0;
getRotateDegree()100     virtual int getRotateDegree() const { return 0; }
101 
102     virtual ImageMatrices* getImageMatrices() = 0;
103     virtual bool isRAW() const = 0;
getDCP(const ColorManagementParams & cmp,DCPProfile::ApplyState & as)104     virtual DCPProfile* getDCP(const ColorManagementParams &cmp, DCPProfile::ApplyState &as)
105     {
106         return nullptr;
107     };
108 
setProgressListener(ProgressListener * pl)109     virtual void setProgressListener(ProgressListener* pl) {}
110 
increaseRef()111     void increaseRef() override
112     {
113         references++;
114     }
decreaseRef()115     void decreaseRef() override
116     {
117         references--;
118 
119         if (!references) {
120             delete this;
121         }
122     }
123 
124     virtual void getAutoExpHistogram(LUTu & histogram, int& histcompr) = 0;
getRAWHistogram(LUTu & histRedRaw,LUTu & histGreenRaw,LUTu & histBlueRaw)125     virtual void getRAWHistogram(LUTu & histRedRaw, LUTu & histGreenRaw, LUTu & histBlueRaw)
126     {
127         histRedRaw.clear();
128         histGreenRaw.clear();
129         histBlueRaw.clear(); // only some sources will supply this
130     }
131 
132     // for RAW files, compute a tone curve using histogram matching on the embedded thumbnail
getAutoMatchedToneCurve(const ColorManagementParams & cp,std::vector<double> & outCurve,std::vector<double> & outCurve2)133     virtual void getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve, std::vector<double> &outCurve2)
134     {
135         outCurve = { 0 };
136         outCurve2 = { 0 };
137     }
138 
139     // double getDirPyrDenoiseExpComp()
140     // {
141     //     return dirpyrdenoiseExpComp;
142     // }
143     // functions inherited from the InitialImage interface
getFileName()144     Glib::ustring getFileName() override
145     {
146         return fileName;
147     }
getEmbeddedProfile()148     cmsHPROFILE getEmbeddedProfile() override
149     {
150         return embProfile;
151     }
getMetaData()152     const FramesMetaData* getMetaData() override
153     {
154         return idata;
155     }
getImageSource()156     ImageSource* getImageSource() override
157     {
158         return this;
159     }
160     virtual void getRawValues(int x, int y, int rotate, int &R, int &G, int &B) = 0;
161 
162     virtual bool getDeconvAutoRadius(float *out=nullptr) { return false; }
163 
filmNegativeProcess(const procparams::FilmNegativeParams & params,std::array<float,3> & filmBaseValues)164     virtual void  filmNegativeProcess(const procparams::FilmNegativeParams &params, std::array<float, 3>& filmBaseValues) {}
getFilmNegativeExponents(Coord2D spotA,Coord2D spotB,int tran,const FilmNegativeParams & currentParams,std::array<float,3> & newExps)165     virtual bool getFilmNegativeExponents(Coord2D spotA, Coord2D spotB, int tran, const FilmNegativeParams& currentParams, std::array<float, 3>& newExps) { return false; }
getImageSpotValues(Coord2D spot,int spotSize,int tran,const procparams::FilmNegativeParams & params,std::array<float,3> & rawValues)166     virtual bool getImageSpotValues (Coord2D spot, int spotSize, int tran, const procparams::FilmNegativeParams &params, std::array<float, 3>& rawValues) { return false; };
167 };
168 } // namespace rtengine
169 #endif
170