-
Notifications
You must be signed in to change notification settings - Fork 14
/
ofxsTransform3x3.h
215 lines (176 loc) · 9.16 KB
/
ofxsTransform3x3.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
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of openfx-supportext <https://github.com/NatronGitHub/openfx-supportext>,
* (C) 2018-2021 The Natron Developers
* (C) 2013-2018 INRIA
*
* openfx-supportext 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.
*
* openfx-supportext 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 openfx-supportext. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
/*
* OFX Transform3x3 plugin: a base plugin for 2D homographic transform,
* represented by a 3x3 matrix.
*/
#ifndef openfx_supportext_ofxsTransform3x3_h
#define openfx_supportext_ofxsTransform3x3_h
#include <memory>
#include "ofxsImageEffect.h"
#include "ofxsTransform3x3Processor.h"
#include "ofxsShutter.h"
#include "ofxsMacros.h"
#define kParamTransform3x3Invert "invert"
#define kParamTransform3x3InvertLabel "Invert"
#define kParamTransform3x3InvertHint "Invert the transform."
#define kParamTransform3x3MotionBlur "motionBlur"
#define kParamTransform3x3MotionBlurLabel "Motion Blur"
#define kParamTransform3x3MotionBlurHint "Quality of motion blur rendering. 0 disables motion blur, 1 is a good value. Increasing this slows down rendering."
// extra parameters for DirBlur:
#define kParamTransform3x3DirBlurAmount "amount"
#define kParamTransform3x3DirBlurAmountLabel "Amount"
#define kParamTransform3x3DirBlurAmountHint "Amount of blur transform to apply. A value of 1 means to apply the full transform range. A value of 0 means to apply no blur at all. Default is 1."
#define kParamTransform3x3DirBlurCentered "centered"
#define kParamTransform3x3DirBlurCenteredLabel "Centered"
#define kParamTransform3x3DirBlurCenteredHint "When checked, apply directional blur symmetrically around the neutral position."
#define kParamTransform3x3DirBlurFading "fading"
#define kParamTransform3x3DirBlurFadingLabel "Fading"
#define kParamTransform3x3DirBlurFadingHint "Controls the fading function. A value of 1 corresponds to linear fading. A value of 0 disables fading. Default is 0."
// extra parameters for non-DirBlur
#define kParamTransform3x3DirectionalBlur "directionalBlur"
#define kParamTransform3x3DirectionalBlurLabel "Directional Blur Mode"
#define kParamTransform3x3DirectionalBlurHint "Motion blur is computed from the original image to the transformed image, each parameter being interpolated linearly. The motionBlur parameter must be set to a nonzero value, and the blackOutside parameter may have an important effect on the result."
namespace OFX {
////////////////////////////////////////////////////////////////////////////////
/** @brief The plugin that does our work */
class Transform3x3Plugin
: public OFX::ImageEffect
{
protected:
// do not need to delete these, the ImageEffect is managing them for us
OFX::Clip *_dstClip;
OFX::Clip *_srcClip;
OFX::Clip *_maskClip;
public:
enum Transform3x3ParamsTypeEnum
{
eTransform3x3ParamsTypeNone = 0,
eTransform3x3ParamsTypeDirBlur,
eTransform3x3ParamsTypeMotionBlur
};
/** @brief ctor */
Transform3x3Plugin(OfxImageEffectHandle handle,
bool masked,
Transform3x3ParamsTypeEnum paramsType);
/** @brief destructor */
virtual ~Transform3x3Plugin();
// a default implementation of isIdentity is provided, which may be overridden by the derived class
virtual bool isIdentity(double /*time*/)
{
return false;
};
/** @brief recover a transform matrix from an effect */
virtual bool getInverseTransformCanonical(double time, int view, double amount, bool invert, OFX::Matrix3x3* invtransform) const = 0;
// The following functions override those is OFX::ImageEffect
// override the rod call (not final, since overriden by Reformat)
virtual bool getRegionOfDefinition(const OFX::RegionOfDefinitionArguments &args, OfxRectD &rod) OVERRIDE;
// override the roi call
virtual void getRegionsOfInterest(const OFX::RegionsOfInterestArguments &args, OFX::RegionOfInterestSetter &rois) OVERRIDE FINAL;
/* Override the render */
virtual void render(const OFX::RenderArguments &args) OVERRIDE;
// override isIdentity
virtual bool isIdentity(const OFX::IsIdentityArguments &args, OFX::Clip * &identityClip, double &identityTime
#ifdef OFX_EXTENSIONS_NUKE
, int& view
, std::string& plane
#endif
) OVERRIDE FINAL;
#ifdef OFX_EXTENSIONS_NUKE
/** @brief recover a transform matrix from an effect */
virtual bool getTransform(const OFX::TransformArguments & args, OFX::Clip * &transformClip, double transformMatrix[9]) OVERRIDE;
#endif
// override changedParam. note that the derived class MUST explicitly call this method after handling its own parameter changes
virtual void changedParam(const OFX::InstanceChangedArgs &args, const std::string ¶mName) OVERRIDE;
// this method must be called by the derived class when the transform was changed
void changedTransform(const OFX::InstanceChangedArgs &args);
protected:
size_t getInverseTransforms(double time,
int view,
OfxPointD renderscale,
bool fielded,
double srcpixelAspectRatio,
double dstpixelAspectRatio,
bool invert,
double shutter,
ShutterOffsetEnum shutteroffset,
double shuttercustomoffset,
OFX::Matrix3x3* invtransform,
size_t invtransformsizealloc) const;
size_t getInverseTransformsBlur(double time,
int view,
OfxPointD renderscale,
bool fielded,
double srcpixelAspectRatio,
double dstpixelAspectRatio,
bool invert,
double amountFrom,
double amountTo,
OFX::Matrix3x3* invtransform,
double* amount,
size_t invtransformsizealloc) const;
private:
/* internal render function */
template <class PIX, int nComponents, int maxValue, bool masked>
void renderInternalForBitDepth(const OFX::RenderArguments &args);
template <int nComponents, bool masked>
void renderInternal(const OFX::RenderArguments &args, OFX::BitDepthEnum dstBitDepth);
/* set up and run a processor */
void setupAndProcess(Transform3x3ProcessorBase &, const OFX::RenderArguments &args);
bool isIdentity(double time, OFX::Clip * &identityClip, double &identityTime);
void transformRegion(const OfxRectD &rectFrom,
double time,
int view,
bool invert,
double motionblur,
bool directionalBlur,
double amountFrom,
double amountTo,
double shutter,
ShutterOffsetEnum shutteroffset,
double shuttercustomoffset,
bool isIdentity,
OfxRectD *rectTo);
protected:
// Transform3x3-GENERIC
Transform3x3ParamsTypeEnum _paramsType;
OFX::BooleanParam* _invert;
// GENERIC
OFX::ChoiceParam* _filter;
OFX::BooleanParam* _clamp;
OFX::BooleanParam* _blackOutside;
OFX::DoubleParam* _motionblur;
OFX::DoubleParam* _dirBlurAmount; // DirBlur only
OFX::BooleanParam* _dirBlurCentered; // DirBlur only
OFX::DoubleParam* _dirBlurFading; // DirBlur only
OFX::BooleanParam* _directionalBlur; // non-DirBlur
OFX::DoubleParam* _shutter; // non-DirBlur
OFX::ChoiceParam* _shutteroffset; // non-DirBlur
OFX::DoubleParam* _shuttercustomoffset; // non-DirBlur
bool _masked;
OFX::DoubleParam* _mix;
OFX::BooleanParam* _maskApply;
OFX::BooleanParam* _maskInvert;
};
void Transform3x3Describe(OFX::ImageEffectDescriptor &desc, bool masked);
OFX::PageParamDescriptor * Transform3x3DescribeInContextBegin(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context, bool masked);
void Transform3x3DescribeInContextEnd(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum context, OFX::PageParamDescriptor* page, bool masked, OFX::Transform3x3Plugin::Transform3x3ParamsTypeEnum paramsType);
} // namespace OFX
#endif /* defined(openfx_supportext_ofxsTransform3x3_h) */