1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; -*- */ 2 /* ***** BEGIN LICENSE BLOCK ***** 3 * This file is part of openfx-supportext <https://github.com/devernay/openfx-supportext>, 4 * Copyright (C) 2013-2018 INRIA 5 * 6 * openfx-supportext 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 2 of the License, or 9 * (at your option) any later version. 10 * 11 * openfx-supportext 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 openfx-supportext. If not, see <http://www.gnu.org/licenses/gpl-2.0.html> 18 * ***** END LICENSE BLOCK ***** */ 19 20 /* 21 * OFX Generator plug-in helper 22 */ 23 24 #ifndef openfx_supportext_ofxsGenerator_h 25 #define openfx_supportext_ofxsGenerator_h 26 27 #include "ofxsImageEffect.h" 28 #include "ofxsMacros.h" 29 #include "ofxsRectangleInteract.h" 30 #ifdef OFX_EXTENSIONS_NATRON 31 #include "ofxNatron.h" 32 #endif 33 34 #define kParamGeneratorExtent "extent" 35 #define kParamGeneratorExtentLabel "Extent" 36 #define kParamGeneratorExtentHint "Extent (size and offset) of the output." 37 #define kParamGeneratorExtentOptionFormat "Format", "Use a pre-defined image format.", "format" 38 #define kParamGeneratorExtentOptionSize "Size", "Use a specific extent (size and offset).", "size" 39 #define kParamGeneratorExtentOptionProject "Project", "Use the project extent (size and offset).", "project" 40 #define kParamGeneratorExtentOptionDefault "Default", "Use the default extent (e.g. the source clip extent, if connected).", "default" 41 42 #define kParamGeneratorOutputComponents "outputComponents" 43 #define kParamGeneratorOutputComponentsLabel "Output Components" 44 #define kParamGeneratorOutputComponentsHint "Components in the output" 45 #define kParamGeneratorOutputComponentsOptionRGBA "RGBA" 46 #define kParamGeneratorOutputComponentsOptionRGB "RGB" 47 #define kParamGeneratorOutputComponentsOptionXY "XY" 48 #define kParamGeneratorOutputComponentsOptionAlpha "Alpha" 49 50 #define kParamGeneratorOutputBitDepth "outputBitDepth" 51 #define kParamGeneratorOutputBitDepthLabel "Output Bit Depth" 52 #define kParamGeneratorOutputBitDepthHint "Bit depth of the output.\n8 bits uses the sRGB colorspace, 16-bits uses Rec.709." 53 #define kParamGeneratorOutputBitDepthOptionByte "Byte (8 bits)", "", "8u" 54 #define kParamGeneratorOutputBitDepthOptionShort "Short (16 bits)", "", "16u" 55 #define kParamGeneratorOutputBitDepthOptionHalf "Half (16 bits)", "", "16f" 56 #define kParamGeneratorOutputBitDepthOptionFloat "Float (32 bits)", "", "32f" 57 58 #define kParamGeneratorRange "frameRange" 59 #define kParamGeneratorRangeLabel "Frame Range" 60 #define kParamGeneratorRangeHint "Time domain." 61 62 enum GeneratorExtentEnum 63 { 64 eGeneratorExtentFormat = 0, 65 eGeneratorExtentSize, 66 eGeneratorExtentProject, 67 eGeneratorExtentDefault, 68 }; 69 70 #define kParamGeneratorFormat kNatronParamFormatChoice 71 #define kParamGeneratorFormatLabel "Format" 72 #define kParamGeneratorFormatHint "The output format" 73 74 #define kParamGeneratorSize kNatronParamFormatSize 75 #define kParamGeneratorSizeLabel "Size" 76 #define kParamGeneratorSizeHint "The output dimensions of the image in pixels." 77 78 #define kParamGeneratorPAR kNatronParamFormatPar 79 #define kParamGeneratorPARLabel "Pixel Aspect Ratio" 80 #define kParamGeneratorPARHint "Output pixel aspect ratio." 81 82 #define kParamGeneratorCenter "recenter" 83 #define kParamGeneratorCenterLabel "Center" 84 #define kParamGeneratorCenterHint "Centers the region of definition to the input region of definition. " \ 85 "If there is no input, then the region of definition is centered to the project window." 86 87 #define kParamGeneratorReformat "reformat" 88 #define kParamGeneratorReformatLabel "Reformat" 89 #define kParamGeneratorReformatHint "Set the output format to the given extent, except if the Bottom Left or Size parameters is animated." 90 91 92 class GeneratorPlugin 93 : public OFX::ImageEffect 94 { 95 protected: 96 // do not need to delete these, the ImageEffect is managing them for us 97 OFX::Clip *_dstClip; 98 OFX::ChoiceParam* _extent; 99 OFX::ChoiceParam* _format; 100 OFX::Int2DParam* _formatSize; 101 OFX::DoubleParam* _formatPar; 102 OFX::BooleanParam* _reformat; 103 OFX::Double2DParam* _btmLeft; 104 OFX::Double2DParam* _size; 105 OFX::BooleanParam* _interactive; 106 OFX::ChoiceParam *_outputComponents; 107 OFX::ChoiceParam *_outputBitDepth; 108 OFX::Int2DParam *_range; 109 OFX::PushButtonParam *_recenter; 110 bool _useOutputComponentsAndDepth; 111 112 public: 113 114 GeneratorPlugin(OfxImageEffectHandle handle, 115 bool useOutputComponentsAndDepth, 116 bool supportsBitDepthByte, 117 bool supportsBitDepthUShort, 118 bool supportsBitDepthHalf, 119 bool supportsBitDepthFloat); 120 121 protected: 122 123 // Override to return the source clip if there's any. getSrcClip()124 virtual OFX::Clip* getSrcClip() const { return 0; } 125 126 void checkComponents(OFX::BitDepthEnum dstBitDepth, OFX::PixelComponentEnum dstComponents); 127 bool getRegionOfDefinition(double time, OfxRectD &rod); 128 virtual void getClipPreferences(OFX::ClipPreferencesSetter &clipPreferences) OVERRIDE; 129 130 131 private: 132 133 virtual void changedParam(const OFX::InstanceChangedArgs &args, const std::string ¶mName) OVERRIDE; 134 135 /** @brief The sync private data action, called when the effect needs to sync any private data to persistent parameters */ syncPrivateData(void)136 virtual void syncPrivateData(void) OVERRIDE 137 { 138 updateParamsVisibility(); 139 } 140 getRegionOfDefinition(const OFX::RegionOfDefinitionArguments & args,OfxRectD & rod)141 virtual bool getRegionOfDefinition(const OFX::RegionOfDefinitionArguments & args, 142 OfxRectD &rod) OVERRIDE 143 { 144 return getRegionOfDefinition(args.time, rod); 145 } 146 147 /* override the time domain action, only for the general context */ 148 virtual bool getTimeDomain(OfxRangeD &range) OVERRIDE FINAL; 149 150 151 void updateParamsVisibility(); 152 153 private: 154 OFX::PixelComponentEnum _outputComponentsMap[10]; 155 OFX::BitDepthEnum _outputBitDepthMap[10]; 156 bool _supportsByte; 157 bool _supportsUShort; 158 bool _supportsHalf; 159 bool _supportsFloat; 160 bool _supportsRGBA; 161 bool _supportsRGB; 162 bool _supportsXY; 163 bool _supportsAlpha; 164 }; 165 166 167 class GeneratorInteract 168 : public OFX::RectangleInteract 169 { 170 public: 171 172 GeneratorInteract(OfxInteractHandle handle, 173 OFX::ImageEffect* effect); 174 175 virtual bool draw(const OFX::DrawArgs &args) OVERRIDE FINAL; 176 virtual bool penMotion(const OFX::PenArgs &args) OVERRIDE FINAL; 177 virtual bool penDown(const OFX::PenArgs &args) OVERRIDE FINAL; 178 virtual bool penUp(const OFX::PenArgs &args) OVERRIDE FINAL; 179 virtual bool keyDown(const OFX::KeyArgs &args) OVERRIDE FINAL; 180 virtual bool keyUp(const OFX::KeyArgs & args) OVERRIDE FINAL; 181 virtual void loseFocus(const OFX::FocusArgs &args) OVERRIDE FINAL; 182 183 private: 184 185 virtual void aboutToCheckInteractivity(OfxTime time) OVERRIDE FINAL; 186 virtual bool allowTopLeftInteraction() const OVERRIDE FINAL; 187 virtual bool allowBtmRightInteraction() const OVERRIDE FINAL; 188 virtual bool allowBtmLeftInteraction() const OVERRIDE FINAL; 189 virtual bool allowBtmMidInteraction() const OVERRIDE FINAL; 190 virtual bool allowMidLeftInteraction() const OVERRIDE FINAL; 191 virtual bool allowCenterInteraction() const OVERRIDE FINAL; 192 OFX::ChoiceParam* _extent; 193 GeneratorExtentEnum _extentValue; 194 }; 195 196 197 namespace OFX { 198 class GeneratorOverlayDescriptor 199 : public DefaultEffectOverlayDescriptor<GeneratorOverlayDescriptor, GeneratorInteract> 200 { 201 }; 202 203 void generatorDescribe(OFX::ImageEffectDescriptor &desc); 204 205 void generatorDescribeInContext(PageParamDescriptor *page, 206 OFX::ImageEffectDescriptor &desc, 207 OFX::ClipDescriptor &dstClip, 208 GeneratorExtentEnum defaultType, 209 PixelComponentEnum defaultComponents, // either RGBA, RGB, XY or Alpha 210 bool useOutputComponentsAndDepth, 211 ContextEnum context, 212 bool reformat = true); 213 } // OFX 214 215 #endif // ifndef openfx_supportext_ofxsGenerator_h 216