forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImagePlaneDesc.h
266 lines (208 loc) · 9.12 KB
/
ImagePlaneDesc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of Natron <https://natrongithub.github.io/>,
* (C) 2018-2021 The Natron developers
* (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat
*
* Natron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Natron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
#ifndef IMAGECOMPONENTS_H
#define IMAGECOMPONENTS_H
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#include <Python.h>
// ***** END PYTHON BLOCK *****
#include "Global/Macros.h"
#include <string>
#include <vector>
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_OFF
GCC_DIAG_OFF(unused-parameter)
// /opt/local/include/boost/serialization/smart_cast.hpp:254:25: warning: unused parameter 'u' [-Wunused-parameter]
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/version.hpp>
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_ON
GCC_DIAG_ON(unused-parameter)
#endif
#define IMAGEPLANEDESC_SERIALIZATION_INTRODUCES_ID 2
#define IMAGEPLANEDESC_SERIALIZATION_VERSION IMAGEPLANEDESC_SERIALIZATION_INTRODUCES_ID
#include <nuke/fnOfxExtensions.h>
#include "Engine/EngineFwd.h"
#include "Engine/ChoiceOption.h"
#define kNatronColorPlaneID kFnOfxImagePlaneColour
#define kNatronColorPlaneLabel "Color"
#define kNatronBackwardMotionVectorsPlaneID kFnOfxImagePlaneBackwardMotionVector
#define kNatronBackwardMotionVectorsPlaneLabel "Backward"
#define kNatronForwardMotionVectorsPlaneID kFnOfxImagePlaneForwardMotionVector
#define kNatronForwardMotionVectorsPlaneLabel "Forward"
#define kNatronDisparityLeftPlaneID kFnOfxImagePlaneStereoDisparityLeft
#define kNatronDisparityLeftPlaneLabel "DisparityLeft"
#define kNatronDisparityRightPlaneID kFnOfxImagePlaneStereoDisparityRight
#define kNatronDisparityRightPlaneLabel "DisparityRight"
#define kNatronDisparityComponentsLabel "Disparity"
#define kNatronMotionComponentsLabel "Motion"
NATRON_NAMESPACE_ENTER
class ImagePlaneDesc
{
public:
ImagePlaneDesc();
ImagePlaneDesc(const std::string& planeID,
const std::string& planeLabel,
const std::string& channelsLabel,
const std::vector<std::string>& channels);
ImagePlaneDesc(const std::string& planeID,
const std::string& planeLabel,
const std::string& channelsLabel,
const char** chanels,
int count);
ImagePlaneDesc(const ImagePlaneDesc& other);
ImagePlaneDesc& operator=(const ImagePlaneDesc& other);
~ImagePlaneDesc();
// Is it Alpha, RGB or RGBA
bool isColorPlane() const;
static bool isColorPlane(const std::string& layerID);
/**
* @brief Returns the number of channels in this plane.
**/
int getNumComponents() const;
/**
* @brief Returns the plane unique identifier. This should be used to compare ImagePlaneDesc together.
* This is not supposed to be used for display purpose, use getPlaneLabel() instead.
**/
const std::string& getPlaneID() const;
/**
* @brief Returns the plane label.
* This is what is used to display to the user.
**/
const std::string& getPlaneLabel() const;
/**
* @brief Returns the channels composing this plane.
**/
const std::vector<std::string>& getChannels() const;
/**
* @brief Returns a label used to better represent the type of components used by this plane.
* e.g: "Motion" can be used to better label "XY" component types.
**/
const std::string& getChannelsLabel() const;
bool operator==(const ImagePlaneDesc& other) const;
bool operator!=(const ImagePlaneDesc& other) const
{
return !(*this == other);
}
// For std::map
bool operator<(const ImagePlaneDesc& other) const;
operator bool() const
{
return getNumComponents() > 0;
}
bool operator!() const
{
return getNumComponents() == 0;
}
ChoiceOption getPlaneOption() const;
ChoiceOption getChannelOption(int channelIndex) const;
/**
* @brief Maps the given nComps to the color plane
**/
static const ImagePlaneDesc& mapNCompsToColorPlane(int nComps);
/**
* @brief Maps the given OpenFX plane to a ImagePlaneDesc.
* @param ofxPlane Can be
* kFnOfxImagePlaneBackwardMotionVector
* kFnOfxImagePlaneForwardMotionVector
* kFnOfxImagePlaneStereoDisparityLeft
* kFnOfxImagePlaneStereoDisparityRight
* Or any plane encoded in the format specified by the Natron multi-plane extension.
* This function CANNOT be used to map the color plane, instead use mapNCompsToColorPlane.
*
* This function returns an empty plane desc upon failure.
**/
static ImagePlaneDesc mapOFXPlaneStringToPlane(const std::string& ofxPlane);
/**
* @brief Maps OpenFX components string to a plane, optionnally also to a paired plane in the case of disparity/motion vectors.
* @param ofxComponents Must be a string between
* kOfxImageComponentRGBA, kOfxImageComponentRGB, kOfxImageComponentAlpha, kNatronOfxImageComponentXY, kOfxImageComponentNone
* or kFnOfxImageComponentStereoDisparity or kFnOfxImageComponentMotionVectors
* Or any plane encoded in the format specified by the Natron multi-plane extension.
**/
static void mapOFXComponentsTypeStringToPlanes(const std::string& ofxComponents, ImagePlaneDesc* plane, ImagePlaneDesc* pairedPlane);
/**
* @brief Does the inverse of mapOFXPlaneStringToPlane, except that it can also be used for
* the color plane.
**/
static std::string mapPlaneToOFXPlaneString(const ImagePlaneDesc& plane);
/**
* @brief Returns an OpenFX encoded string representing the components type of the plane.
* @returns One of the following strings:
* kOfxImageComponentRGBA, kOfxImageComponentRGB, kOfxImageComponentAlpha, kNatronOfxImageComponentXY, kOfxImageComponentNone
* or kFnOfxImageComponentStereoDisparity or kFnOfxImageComponentMotionVectors
* Or any plane encoded in the format specified by the Natron multi-plane extension.
**/
static std::string mapPlaneToOFXComponentsTypeString(const ImagePlaneDesc& plane);
/**
* @brief Find a layer equivalent to this layer in the other layers container.
* ITERATOR must be either a std::vector<ImagePlaneDesc>::iterator or std::list<ImagePlaneDesc>::iterator
**/
template <typename ITERATOR>
static ITERATOR findEquivalentLayer(const ImagePlaneDesc& layer, ITERATOR begin, ITERATOR end)
{
bool isColor = layer.isColorPlane();
ITERATOR foundExistingColorMatch = end;
ITERATOR foundExistingComponents = end;
for (ITERATOR it = begin; it != end; ++it) {
if (it->isColorPlane() && isColor) {
foundExistingColorMatch = it;
} else {
if (*it == layer) {
foundExistingComponents = it;
break;
}
}
} // for each output components
if (foundExistingComponents != end) {
return foundExistingComponents;
} else if (foundExistingColorMatch != end) {
return foundExistingColorMatch;
} else {
return end;
}
} // findEquivalentLayer
/*
* These are default presets image components
*/
static const ImagePlaneDesc& getNoneComponents();
static const ImagePlaneDesc& getRGBAComponents();
static const ImagePlaneDesc& getRGBComponents();
static const ImagePlaneDesc& getAlphaComponents();
static const ImagePlaneDesc& getBackwardMotionComponents();
static const ImagePlaneDesc& getForwardMotionComponents();
static const ImagePlaneDesc& getDisparityLeftComponents();
static const ImagePlaneDesc& getDisparityRightComponents();
static const ImagePlaneDesc& getXYComponents();
template<class Archive>
void save(Archive & ar, const unsigned int version) const;
template<class Archive>
void load(Archive & ar, const unsigned int version);
private:
std::string _planeID, _planeLabel;
std::vector<std::string> _channels;
std::string _channelsLabel;
friend class boost::serialization::access;
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
NATRON_NAMESPACE_EXIT
BOOST_CLASS_VERSION(NATRON_NAMESPACE::ImagePlaneDesc, IMAGEPLANEDESC_SERIALIZATION_VERSION)
#endif // IMAGECOMPONENTS_H