forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeMetadata.cpp
368 lines (320 loc) · 8.87 KB
/
NodeMetadata.cpp
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/* ***** 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 ***** */
// ***** 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 "NodeMetadata.h"
#include "Engine/RectI.h"
#include <cassert>
#include <vector>
NATRON_NAMESPACE_ENTER
struct PerInputData
{
//Either 1 or 2 components in the case of MotionVectors/Disparity
double pixelAspectRatio;
int nComps;
std::string componentsType;
ImageBitDepthEnum bitdepth;
PerInputData()
: pixelAspectRatio(1.)
, nComps(0)
, componentsType()
, bitdepth(eImageBitDepthFloat)
{
}
};
struct NodeMetadataPrivate
{
//The premult in output of the node
ImagePremultiplicationEnum outputPremult;
//The image fielding in output
ImageFieldingOrderEnum outputFielding;
//The fps in output
double frameRate;
PerInputData outputData;
//For each input specific datas
std::vector<PerInputData> inputsData;
//True if the images can only be sampled continuously (eg: the clip is in fact an animating roto spline and can be rendered anywhen).
//False if the images can only be sampled at discreet times (eg: the clip is a sequence of frames),
bool canRenderAtNonframes;
//True if the effect changes throughout the time
bool isFrameVarying;
// The output format in pixel coords
RectI outputFormat;
NodeMetadataPrivate()
: outputPremult(eImagePremultiplicationPremultiplied)
, outputFielding(eImageFieldingOrderNone)
, frameRate(24.)
, outputData()
, inputsData()
, canRenderAtNonframes(true)
, isFrameVarying(false)
, outputFormat()
{
}
NodeMetadataPrivate(const NodeMetadataPrivate& other)
{
*this = other;
}
void operator=(const NodeMetadataPrivate& other)
{
outputPremult = other.outputPremult;
outputFielding = other.outputFielding;
frameRate = other.frameRate;
outputData = other.outputData;
inputsData = other.inputsData;
canRenderAtNonframes = other.canRenderAtNonframes;
isFrameVarying = other.isFrameVarying;
outputFormat = other.outputFormat;
}
};
NodeMetadata::NodeMetadata()
: _imp( new NodeMetadataPrivate() )
{
}
NodeMetadata::NodeMetadata(const NodeMetadata& other)
: _imp( new NodeMetadataPrivate(*other._imp) )
{
}
NodeMetadata::~NodeMetadata()
{
}
void
NodeMetadata::clearAndResize(int inputCount)
{
_imp->inputsData.resize(inputCount);
}
void
NodeMetadata::operator=(const NodeMetadata& other)
{
*_imp = *other._imp;
}
bool
NodeMetadata::operator==(const NodeMetadata& other) const
{
if (_imp->outputPremult != other._imp->outputPremult) {
return false;
}
if (_imp->outputFielding != other._imp->outputFielding) {
return false;
}
if (_imp->frameRate != other._imp->frameRate) {
return false;
}
if (_imp->canRenderAtNonframes != other._imp->canRenderAtNonframes) {
return false;
}
if (_imp->isFrameVarying != other._imp->isFrameVarying) {
return false;
}
if (_imp->outputData.bitdepth != other._imp->outputData.bitdepth) {
return false;
}
if (_imp->outputData.pixelAspectRatio != other._imp->outputData.pixelAspectRatio) {
return false;
}
if (_imp->outputData.nComps != other._imp->outputData.nComps) {
return false;
}
if (_imp->outputData.componentsType != other._imp->outputData.componentsType) {
return false;
}
if ( _imp->inputsData.size() != other._imp->inputsData.size() ) {
return false;
}
if (_imp->outputFormat != other._imp->outputFormat) {
return false;
}
for (std::size_t i = 0; i < _imp->inputsData.size(); ++i) {
if (_imp->inputsData[i].pixelAspectRatio != other._imp->inputsData[i].pixelAspectRatio) {
return false;
}
if (_imp->inputsData[i].bitdepth != other._imp->inputsData[i].bitdepth) {
return false;
}
if (_imp->inputsData[i].componentsType != other._imp->inputsData[i].componentsType) {
return false;
}
if (_imp->inputsData[i].nComps != other._imp->inputsData[i].nComps) {
return false;
}
}
return true;
}
void
NodeMetadata::setOutputPremult(ImagePremultiplicationEnum premult)
{
_imp->outputPremult = premult;
}
ImagePremultiplicationEnum
NodeMetadata::getOutputPremult() const
{
return _imp->outputPremult;
}
void
NodeMetadata::setOutputFrameRate(double fps)
{
_imp->frameRate = fps;
}
double
NodeMetadata::getOutputFrameRate() const
{
return _imp->frameRate;
}
void
NodeMetadata::setOutputFielding(ImageFieldingOrderEnum fielding)
{
_imp->outputFielding = fielding;
}
ImageFieldingOrderEnum
NodeMetadata::getOutputFielding() const
{
return _imp->outputFielding;
}
void
NodeMetadata::setIsContinuous(bool continuous)
{
_imp->canRenderAtNonframes = continuous;
}
bool
NodeMetadata::getIsContinuous() const
{
return _imp->canRenderAtNonframes;
}
void
NodeMetadata::setIsFrameVarying(bool varying)
{
_imp->isFrameVarying = varying;
}
bool
NodeMetadata::getIsFrameVarying() const
{
return _imp->isFrameVarying;
}
void
NodeMetadata::setPixelAspectRatio(int inputNb,
double par)
{
if (inputNb == -1) {
_imp->outputData.pixelAspectRatio = par;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
_imp->inputsData[inputNb].pixelAspectRatio = par;
}
}
}
double
NodeMetadata::getPixelAspectRatio(int inputNb) const
{
if (inputNb == -1) {
return _imp->outputData.pixelAspectRatio;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
return _imp->inputsData[inputNb].pixelAspectRatio;
} else {
return 1.;
}
}
}
void
NodeMetadata::setBitDepth(int inputNb,
ImageBitDepthEnum depth)
{
if (inputNb == -1) {
_imp->outputData.bitdepth = depth;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
_imp->inputsData[inputNb].bitdepth = depth;
}
}
}
ImageBitDepthEnum
NodeMetadata::getBitDepth(int inputNb) const
{
if (inputNb == -1) {
return _imp->outputData.bitdepth;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
return _imp->inputsData[inputNb].bitdepth;
} else {
return eImageBitDepthFloat;
}
}
}
void
NodeMetadata::setNComps(int inputNb, int nComps)
{
if (inputNb == -1) {
_imp->outputData.nComps = nComps;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
_imp->inputsData[inputNb].nComps = nComps;
}
}
}
int
NodeMetadata::getNComps(int inputNb) const
{
if (inputNb == -1) {
return _imp->outputData.nComps;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
return _imp->inputsData[inputNb].nComps;
} else {
return 4;
}
}
}
void
NodeMetadata::setComponentsType(int inputNb,const std::string& componentsType)
{
if (inputNb == -1) {
_imp->outputData.componentsType = componentsType;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
_imp->inputsData[inputNb].componentsType = componentsType;
}
}
}
std::string
NodeMetadata::getComponentsType(int inputNb) const
{
if (inputNb == -1) {
return _imp->outputData.componentsType;
} else {
if ( inputNb < (int)_imp->inputsData.size() ) {
return _imp->inputsData[inputNb].componentsType;
} else {
return kNatronColorPlaneID;
}
}
}
void
NodeMetadata::setOutputFormat(const RectI& format)
{
_imp->outputFormat = format;
}
const RectI&
NodeMetadata::getOutputFormat() const
{
return _imp->outputFormat;
}
NATRON_NAMESPACE_EXIT