1 /*
2  * This file is part of openfx-arena <https://github.com/olear/openfx-arena>,
3  * Copyright (C) 2016 INRIA
4  *
5  * openfx-arena is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation.
8  *
9  * openfx-arena is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with openfx-arena.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
16 */
17 
18 #include "MagickPlugin.h"
19 
20 using namespace OFX;
21 OFXS_NAMESPACE_ANONYMOUS_ENTER
22 
23 #define kPluginName "SwirlOFX"
24 #define kPluginGrouping "Extra/Distort"
25 #define kPluginIdentifier "net.fxarena.openfx.Swirl"
26 #define kPluginDescription "Swirl effect using ImageMagick."
27 #define kPluginVersionMajor 2
28 #define kPluginVersionMinor 9
29 
30 #define kSupportsTiles 0
31 #define kSupportsMultiResolution 1
32 #define kSupportsRenderScale 1
33 #define kRenderThreadSafety eRenderFullySafe
34 #define kHostFrameThreading false
35 #define kHostMasking true
36 #define kHostMixing true
37 
38 #define kParamSwirl "amount"
39 #define kParamSwirlLabel "Amount"
40 #define kParamSwirlHint "Swirl amount."
41 #define kParamSwirlDefault 60
42 
43 class SwirlPlugin
44     : public MagickPluginHelper<kSupportsRenderScale>
45 {
46 public:
SwirlPlugin(OfxImageEffectHandle handle)47     SwirlPlugin(OfxImageEffectHandle handle)
48         : MagickPluginHelper<kSupportsRenderScale>(handle)
49         , _swirl(NULL)
50     {
51         _swirl = fetchDoubleParam(kParamSwirl);
52         assert(_swirl);
53     }
54 
render(const OFX::RenderArguments & args,Magick::Image & image)55     virtual void render(const OFX::RenderArguments &args, Magick::Image &image) OVERRIDE FINAL
56     {
57         double amount;
58         _swirl->getValueAtTime(args.time, amount);
59         image.swirl(amount);
60     }
61 private:
62     DoubleParam *_swirl;
63 };
64 
65 mDeclarePluginFactory(SwirlPluginFactory, {}, {});
66 
describe(ImageEffectDescriptor & desc)67 void SwirlPluginFactory::describe(ImageEffectDescriptor &desc)
68 {
69     desc.setLabel(kPluginName);
70     desc.setPluginGrouping(kPluginGrouping);
71     desc.setPluginDescription(kPluginDescription);
72     desc.addSupportedContext(eContextGeneral);
73     desc.addSupportedContext(eContextFilter);
74     desc.addSupportedBitDepth(eBitDepthFloat);
75     desc.setSupportsTiles(kSupportsTiles);
76     desc.setSupportsMultiResolution(kSupportsMultiResolution);
77     desc.setRenderThreadSafety(kRenderThreadSafety);
78     desc.setHostFrameThreading(kHostFrameThreading);
79     desc.setHostMaskingEnabled(kHostMasking);
80     desc.setHostMixingEnabled(kHostMixing);
81 }
82 
describeInContext(ImageEffectDescriptor & desc,ContextEnum context)83 void SwirlPluginFactory::describeInContext(ImageEffectDescriptor &desc, ContextEnum context)
84 {
85     OFX::PageParamDescriptor *page = SwirlPlugin::describeInContextBegin(desc, context);
86     {
87         DoubleParamDescriptor *param = desc.defineDoubleParam(kParamSwirl);
88         param->setLabel(kParamSwirlLabel);
89         param->setHint(kParamSwirlHint);
90         param->setRange(-360, 360);
91         param->setDisplayRange(-360, 360);
92         param->setDefault(kParamSwirlDefault);
93         if (page) {
94             page->addChild(*param);
95         }
96     }
97     SwirlPlugin::describeInContextEnd(desc, context, page);
98 }
99 
100 OFX::ImageEffect*
createInstance(OfxImageEffectHandle handle,ContextEnum)101 SwirlPluginFactory::createInstance(OfxImageEffectHandle handle, ContextEnum /*context*/)
102 {
103     return new SwirlPlugin(handle);
104 }
105 
106 static SwirlPluginFactory p(kPluginIdentifier, kPluginVersionMajor, kPluginVersionMinor);
107 mRegisterPluginFactoryInstance(p)
108 
109 OFXS_NAMESPACE_ANONYMOUS_EXIT
110