1 /* -*- C++ -*-
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2017 Alberto Griggio
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 <https://www.gnu.org/licenses/>.
18  */
19 #pragma once
20 
21 #include <glibmm/ustring.h>
22 #include <vector>
23 
24 namespace rtengine
25 {
26     class FramesMetaData;
27 }
28 
29 class DynamicProfileRule
30 {
31 public:
32     template <class T>
33     struct Range {
34         T min;
35         T max;
minRange36         explicit Range (T l = T(), T u = T()): min (l), max (u) {}
37 
operatorRange38         bool operator() (T val) const
39         {
40             return val >= min && val <= max;
41         }
42     };
43 
44     struct Optional {
45         Glib::ustring value;
46         bool enabled;
47         explicit Optional (const Glib::ustring v = "", bool e = false):
valueOptional48             value (v), enabled (e) {}
49 
50         bool operator() (const Glib::ustring &val) const;
51     };
52 
53     DynamicProfileRule();
54     bool matches (const rtengine::FramesMetaData *im) const;
55     bool operator< (const DynamicProfileRule &other) const;
56 
57     int serial_number;
58     Range<int> iso;
59     Range<double> fnumber;
60     Range<double> focallen;
61     Range<double> shutterspeed;
62     Range<double> expcomp;
63     Optional camera;
64     Optional lens;
65     Optional imagetype;
66     Glib::ustring profilepath;
67 };
68 
69 class DynamicProfileRules
70 {
71 protected:
72     /** cache for dynamic profile rules */
73     std::vector<DynamicProfileRule> dynamicRules;
74     bool rulesLoaded;
75 
76 public:
77     bool loadRules();
78     bool storeRules();
79     const std::vector<DynamicProfileRule> &getRules();
80     void setRules (const std::vector<DynamicProfileRule> &r);
81 };
82