TuttleOFX
1
|
00001 #include "CropPluginFactory.hpp" 00002 #include "CropDefinitions.hpp" 00003 #include "CropPlugin.hpp" 00004 #include "CropMargin.hpp" 00005 00006 #include <tuttle/plugin/exceptions.hpp> 00007 00008 #include <ofxsParam.h> 00009 #include <ofxsImageEffect.h> 00010 #include <ofxsMultiThread.h> 00011 00012 #include <limits> 00013 00014 namespace tuttle { 00015 namespace plugin { 00016 namespace crop { 00017 00018 /** 00019 * @brief Function called to describe the plugin main features. 00020 * @param[in, out] desc Effect descriptor 00021 */ 00022 void CropPluginFactory::describe( OFX::ImageEffectDescriptor& desc ) 00023 { 00024 desc.setLabels( "TuttleCrop", "Crop", 00025 "Image crop" ); 00026 desc.setPluginGrouping( "tuttle/image/process/geometry" ); 00027 00028 desc.setDescription( "Crop\n" 00029 "Plugin is used to crop an image." ); 00030 00031 // add the supported contexts 00032 desc.addSupportedContext( OFX::eContextFilter ); 00033 desc.addSupportedContext( OFX::eContextGeneral ); 00034 00035 // add supported pixel depths 00036 desc.addSupportedBitDepth( OFX::eBitDepthUByte ); 00037 desc.addSupportedBitDepth( OFX::eBitDepthUShort ); 00038 desc.addSupportedBitDepth( OFX::eBitDepthFloat ); 00039 00040 // plugin flags 00041 desc.setSupportsTiles( kSupportTiles ); 00042 desc.setRenderThreadSafety( OFX::eRenderFullySafe ); 00043 00044 desc.setOverlayInteractDescriptor( new OFX::DefaultEffectOverlayWrap<CropEffectOverlay>() ); 00045 } 00046 00047 /** 00048 * @brief Function called to describe the plugin controls and features. 00049 * @param[in, out] desc Effect descriptor 00050 * @param[in] context Application context 00051 */ 00052 void CropPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc, 00053 OFX::EContext context ) 00054 { 00055 OFX::ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName ); 00056 00057 srcClip->addSupportedComponent( OFX::ePixelComponentRGBA ); 00058 srcClip->addSupportedComponent( OFX::ePixelComponentRGB ); 00059 srcClip->addSupportedComponent( OFX::ePixelComponentAlpha ); 00060 srcClip->setSupportsTiles( kSupportTiles ); 00061 00062 OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName ); 00063 dstClip->addSupportedComponent( OFX::ePixelComponentRGBA ); 00064 dstClip->addSupportedComponent( OFX::ePixelComponentRGB ); 00065 dstClip->addSupportedComponent( OFX::ePixelComponentAlpha ); 00066 dstClip->setSupportsTiles( kSupportTiles ); 00067 00068 OFX::ChoiceParamDescriptor* mode = desc.defineChoiceParam( kParamMode ); 00069 mode->setLabel( "Mode" ); 00070 mode->appendOption( kParamModeCrop ); 00071 mode->appendOption( kParamModeFillColor ); 00072 // mode->appendOption( kParamModeResize ); // good idea or not? 00073 mode->setDefault( eParamModeFillColor ); 00074 00075 OFX::RGBAParamDescriptor* fillColor = desc.defineRGBAParam( kParamFillColor ); 00076 fillColor->setLabel( "Color" ); 00077 fillColor->setHint( "Color to fill bands" ); 00078 fillColor->setDefault( 0.0, 0.0, 0.0, 1.0 ); 00079 00080 OFX::ChoiceParamDescriptor* axis = desc.defineChoiceParam( kParamAxis ); 00081 axis->setLabel( "Axis" ); 00082 axis->appendOption( kParamAxisXY ); 00083 axis->appendOption( kParamAxisX ); 00084 axis->appendOption( kParamAxisY ); 00085 axis->setDefault( eParamAxisY ); 00086 axis->setEvaluateOnChange( false ); 00087 00088 OFX::ChoiceParamDescriptor* symmetric = desc.defineChoiceParam( kParamSymmetric ); 00089 symmetric->setLabel( "Symmetric" ); 00090 symmetric->appendOption( kParamSymmetricNone ); 00091 symmetric->appendOption( kParamSymmetricXY ); 00092 symmetric->appendOption( kParamSymmetricX ); 00093 symmetric->appendOption( kParamSymmetricY ); 00094 symmetric->setHint( "Is the crop region symmetric around image center?" ); 00095 symmetric->setDefault( true ); 00096 symmetric->setEvaluateOnChange( false ); 00097 00098 OFX::BooleanParamDescriptor* fixedRatio = desc.defineBooleanParam( kParamFixedRatio ); 00099 fixedRatio->setLabel( "Fixed ratio" ); 00100 fixedRatio->setHint( "Constrain the cropped region to this ratio." ); 00101 fixedRatio->setDefault( true ); 00102 fixedRatio->setEvaluateOnChange( false ); 00103 00104 OFX::ChoiceParamDescriptor* preset = desc.defineChoiceParam( kParamPreset ); 00105 preset->setLabel( "Preset" ); 00106 preset->appendOption( kParamPreset_custom ); 00107 preset->appendOption( kParamPreset_1_33 ); 00108 preset->appendOption( kParamPreset_1_77 ); 00109 preset->appendOption( kParamPreset_1_85 ); 00110 preset->appendOption( kParamPreset_2_35 ); 00111 preset->appendOption( kParamPreset_2_40 ); 00112 preset->setDefault( 0 ); 00113 preset->setEvaluateOnChange( false ); 00114 00115 OFX::DoubleParamDescriptor* ratio = desc.defineDoubleParam( kParamRatio ); 00116 ratio->setLabel( "Ratio" ); 00117 ratio->setRange( 0, std::numeric_limits<double>::max() ); 00118 ratio->setDisplayRange( 0, 3 ); 00119 ratio->setDefault( 2.0 ); 00120 ratio->setHint( "Ratio X/Y of the cropped region." ); 00121 00122 OFX::BooleanParamDescriptor* overlay = desc.defineBooleanParam( kParamOverlay ); 00123 overlay->setLabel( "Overlay" ); 00124 overlay->setHint( "Display overlay rectangle" ); 00125 overlay->setDefault( false ); 00126 overlay->setEvaluateOnChange( false ); 00127 00128 OFX::GroupParamDescriptor* cropRegion = desc.defineGroupParam( kParamGroupCropRegion ); 00129 00130 OFX::IntParamDescriptor* xMin = desc.defineIntParam( kParamXMin ); 00131 xMin->setLabel( "X min" ); 00132 // xMin->setRange( 0, std::numeric_limits<int>::max() ); 00133 xMin->setDisplayRange( 0, 3000 ); 00134 xMin->setDefault( 0 ); 00135 xMin->setParent( *cropRegion ); 00136 00137 OFX::IntParamDescriptor* yMin = desc.defineIntParam( kParamYMin ); 00138 yMin->setLabel( "Y min" ); 00139 // yMin->setRange( 0, std::numeric_limits<int>::max() ); 00140 yMin->setDisplayRange( 0, 3000 ); 00141 yMin->setDefault( 0 ); 00142 yMin->setParent( *cropRegion ); 00143 00144 OFX::IntParamDescriptor* xMax = desc.defineIntParam( kParamXMax ); 00145 xMax->setLabel( "X max" ); 00146 // xMax->setRange( 0, std::numeric_limits<int>::max() ); 00147 xMax->setDisplayRange( 0, 3000 ); 00148 xMax->setDefault( 0 ); 00149 xMax->setParent( *cropRegion ); 00150 00151 OFX::IntParamDescriptor* yMax = desc.defineIntParam( kParamYMax ); 00152 yMax->setLabel( "Y max" ); 00153 // yMax->setRange( 0, std::numeric_limits<int>::max() ); 00154 yMax->setDisplayRange( 0, 3000 ); 00155 yMax->setDefault( 0 ); 00156 yMax->setParent( *cropRegion ); 00157 } 00158 00159 /** 00160 * @brief Function called to create a plugin effect instance 00161 * @param[in] handle effect handle 00162 * @param[in] context Application context 00163 * @return plugin instance 00164 */ 00165 OFX::ImageEffect* CropPluginFactory::createInstance( OfxImageEffectHandle handle, 00166 OFX::EContext context ) 00167 { 00168 return new CropPlugin( handle ); 00169 } 00170 00171 } 00172 } 00173 }