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 <https://www.gnu.org/licenses/>.
18  */
19 #include "clipboard.h"
20 
21 #include "paramsedited.h"
22 #include "../rtengine/procparams.h"
23 
24 Clipboard clipboard;
25 
Clipboard()26 Clipboard::Clipboard () :
27     _hasIPTC(false),
28     iptc(new rtengine::procparams::IPTCPairs),
29     partProfile(new rtengine::procparams::PartialProfile(false)),
30     hasDiagonalCurveDataType(DCT_Empty),
31     hasFlatCurveDataType(FCT_Empty)
32 {
33 }
34 
~Clipboard()35 Clipboard::~Clipboard ()
36 {
37     partProfile->deleteInstance();
38 }
39 
hasIPTC() const40 bool Clipboard::hasIPTC() const
41 {
42     return _hasIPTC;
43 }
44 
getIPTC() const45 const rtengine::procparams::IPTCPairs& Clipboard::getIPTC() const
46 {
47     return *iptc;
48 }
49 
setIPTC(const rtengine::procparams::IPTCPairs & iptcc)50 void Clipboard::setIPTC(const rtengine::procparams::IPTCPairs& iptcc)
51 {
52     *iptc = iptcc;
53     _hasIPTC = true;
54 }
55 
getPartialProfile() const56 const rtengine::procparams::PartialProfile& Clipboard::getPartialProfile() const
57 {
58     return *partProfile;
59 }
60 
61 /*
62  * set both the "pparams" and "pedited" field of the PartialProfile; each one can be NULL
63  */
setPartialProfile(const rtengine::procparams::PartialProfile & pprofile)64 void Clipboard::setPartialProfile(const rtengine::procparams::PartialProfile& pprofile)
65 {
66     if (pprofile.pparams) {
67         if (!partProfile->pparams) {
68             partProfile->pparams = new rtengine::procparams::ProcParams();
69         }
70 
71         *partProfile->pparams = *pprofile.pparams;
72     } else {
73         if (partProfile->pparams) {
74             delete partProfile->pparams;
75             partProfile->pparams = nullptr;
76         }
77     }
78 
79     if (pprofile.pedited) {
80         if (!partProfile->pedited) {
81             partProfile->pedited = new ParamsEdited();
82         }
83 
84         *partProfile->pedited = *pprofile.pedited;
85     } else {
86         if (partProfile->pedited) {
87             delete partProfile->pedited;
88             partProfile->pedited = nullptr;
89         }
90     }
91 }
92 
getProcParams() const93 const rtengine::procparams::ProcParams& Clipboard::getProcParams() const
94 {
95     return *partProfile->pparams;
96 }
97 
98 /*
99  * this method copy the procparams to "pparams" and delete "pedited"
100  */
setProcParams(const rtengine::procparams::ProcParams & pparams)101 void Clipboard::setProcParams(const rtengine::procparams::ProcParams& pparams)
102 {
103     // copy procparams
104     if (!partProfile->pparams) {
105         partProfile->pparams = new rtengine::procparams::ProcParams();
106     }
107 
108     *partProfile->pparams = pparams;
109 
110     // delete pedited
111     if (partProfile->pedited) {
112         delete partProfile->pedited;
113         partProfile->pedited = nullptr;
114     }
115 }
116 
getParamsEdited() const117 const ParamsEdited& Clipboard::getParamsEdited() const
118 {
119     return *partProfile->pedited;
120 }
121 
hasProcParams() const122 bool Clipboard::hasProcParams() const
123 {
124     return partProfile->pparams;
125 }
126 
hasPEdited() const127 bool Clipboard::hasPEdited() const
128 {
129     return partProfile->pedited;
130 }
131 
hasDiagonalCurveData() const132 DiagonalCurveType Clipboard::hasDiagonalCurveData() const
133 {
134     return hasDiagonalCurveDataType;
135 }
136 
getDiagonalCurveData() const137 const std::vector<double>& Clipboard::getDiagonalCurveData() const
138 {
139     return diagonalCurve;
140 }
141 
setDiagonalCurveData(const std::vector<double> & p,DiagonalCurveType type)142 void Clipboard::setDiagonalCurveData(const std::vector<double>& p, DiagonalCurveType type)
143 {
144     diagonalCurve = p;
145     hasDiagonalCurveDataType = type;
146     return;
147 }
148 
hasFlatCurveData() const149 FlatCurveType Clipboard::hasFlatCurveData() const
150 {
151     return hasFlatCurveDataType;
152 }
153 
getFlatCurveData() const154 const std::vector<double>& Clipboard:: getFlatCurveData() const
155 {
156     return flatCurve;
157 }
158 
setFlatCurveData(const std::vector<double> & p,FlatCurveType type)159 void Clipboard::setFlatCurveData(const std::vector<double>& p, FlatCurveType type)
160 {
161     flatCurve = p;
162     hasFlatCurveDataType = type;
163     return;
164 }
165