1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  RawTherapee is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with RawTherapee.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef _RTENGINE_
20 #define _RTENGINE_
21 
22 #include <string>
23 #include <glibmm.h>
24 #include "../rtexif/rtexif.h"
25 #include "opthelper.h"
26 #include "progresslistener.h"
27 #include "procparams.h"
28 #include "imageformat.h"
29 /**
30  * @file
31  * This file contains the main functionality of the RawTherapee engine.
32  *
33  */
34 
35 namespace rtengine
36 {
37 
38 /**
39   * This class provides functions to obtain exif and IPTC metadata information
40   * from any of the sub-frame of an image file
41   */
42 class FramesMetaData
43 {
44 
45 public:
46     /** @return Returns the number of root Metadata */
47     virtual unsigned int getRootCount () const = 0;
48     /** @return Returns the number of frame contained in the file based on Metadata */
49     virtual unsigned int getFrameCount () const = 0;
50 
51     /** Checks the availability of exif metadata tags.
52       * @return Returns true if image contains exif metadata tags */
53     virtual bool hasExif (unsigned int frame = 0) const = 0;
54     /** Returns the directory of exif metadata tags.
55       * @param root root number in the metadata tree
56       * @return The directory of exif metadata tags */
57     virtual rtexif::TagDirectory* getRootExifData (unsigned int root = 0) const = 0;
58     /** Returns the directory of exif metadata tags.
59       * @param frame frame number in the metadata tree
60       * @return The directory of exif metadata tags */
61     virtual rtexif::TagDirectory* getFrameExifData (unsigned int frame = 0) const = 0;
62     /** Returns the directory of exif metadata tags containing at least the 'Make' tag for the requested frame.
63       * If no usable metadata exist in the frame, send back the best TagDirectory describing the frame content.
64       * @param imgSource rawimage that we want the metadata from
65       * @param rawParams RawParams to select the frame number
66       * @return The directory of exif metadata tags containing at least the 'Make' tag */
67     //virtual rtexif::TagDirectory* getBestExifData (ImageSource *imgSource, procparams::RAWParams *rawParams) const = 0;
68     /** Checks the availability of IPTC tags.
69       * @return Returns true if image contains IPTC tags */
70     virtual bool hasIPTC (unsigned int frame = 0) const = 0;
71     /** Returns the directory of IPTC tags.
72       * @return The directory of IPTC tags */
73     virtual procparams::IPTCPairs getIPTCData (unsigned int frame = 0) const = 0;
74     /** @return a struct containing the date and time of the image */
75     virtual tm getDateTime (unsigned int frame = 0) const = 0;
76     /** @return a timestamp containing the date and time of the image */
77     virtual time_t getDateTimeAsTS(unsigned int frame = 0) const = 0;
78     /** @return the ISO of the image */
79     virtual int getISOSpeed (unsigned int frame = 0) const = 0;
80     /** @return the F number of the image */
81     virtual double getFNumber  (unsigned int frame = 0) const = 0;
82     /** @return the focal length used at the exposure */
83     virtual double getFocalLen (unsigned int frame = 0) const = 0;
84     /** @return the focal length in 35mm used at the exposure */
85     virtual double getFocalLen35mm (unsigned int frame = 0) const = 0;
86     /** @return the focus distance in meters, 0=unknown, 10000=infinity */
87     virtual float getFocusDist (unsigned int frame = 0) const = 0;
88     /** @return the shutter speed */
89     virtual double getShutterSpeed (unsigned int frame = 0) const = 0;
90     /** @return the exposure compensation */
91     virtual double getExpComp (unsigned int frame = 0) const = 0;
92     /** @return the maker of the camera */
93     virtual std::string getMake     (unsigned int frame = 0) const = 0;
94     /** @return the model of the camera */
95     virtual std::string getModel    (unsigned int frame = 0) const = 0;
96 
97     std::string getCamera   (unsigned int frame = 0) const
98     {
99         return getMake(frame) + " " + getModel(frame);
100     }
101 
102     /** @return the lens on the camera  */
103     virtual std::string getLens     (unsigned int frame = 0) const = 0;
104     /** @return the orientation of the image */
105     virtual std::string getOrientation (unsigned int frame = 0) const = 0;
106     /** @return the rating of the image */
107     virtual int getRating (unsigned int frame = 0) const = 0;
108 
109     /** @return true if the file is a PixelShift shot (Pentax and Sony bodies) */
110     virtual bool getPixelShift () const = 0;
111     /** @return false: not an HDR file ; true: single or multi-frame HDR file (e.g. Pentax HDR raw file or 32 bit float DNG file or Log compressed) */
112     virtual bool getHDR (unsigned int frame = 0) const = 0;
113 
114     /** @return false: not an HDR file ; true: single or multi-frame HDR file (e.g. Pentax HDR raw file or 32 bit float DNG file or Log compressed) */
115     virtual std::string getImageType (unsigned int frame) const = 0;
116     /** @return the sample format based on MetaData */
117     virtual IIOSampleFormat getSampleFormat (unsigned int frame = 0) const = 0;
118 
119     /** Functions to convert between floating point and string representation of shutter and aperture */
120     static std::string apertureToString (double aperture);
121     /** Functions to convert between floating point and string representation of shutter and aperture */
122     static std::string shutterToString (double shutter);
123     /** Functions to convert between floating point and string representation of shutter and aperture */
124     static double apertureFromString (std::string shutter);
125     /** Functions to convert between floating point and string representation of shutter and aperture */
126     static double shutterFromString (std::string shutter);
127     /** Functions to convert between floating point and string representation of exposure compensation */
128     static std::string expcompToString (double expcomp, bool maskZeroexpcomp);
129 
130     virtual ~FramesMetaData () = default;
131 
132     /** Reads metadata from file.
133       * @param fname is the name of the file
134       * @param rml is a struct containing information about metadata location of the first frame.
135       * Use it only for raw files. In caseof jpgs and tiffs pass a NULL pointer.
136       * @param firstFrameOnly must be true to get the MetaData of the first frame only, e.g. for a PixelShift file.
137       * @return The metadata */
138     static FramesMetaData* fromFile (const Glib::ustring& fname, std::unique_ptr<RawMetaDataLocation> rml, bool firstFrameOnly = false);
139 };
140 
141 
142 }
143 
144 #endif
145 
146