TuttleOFX  1
CropPlugin.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_PLUGIN_CROP_PLUGIN_HPP_
00002 #define _TUTTLE_PLUGIN_CROP_PLUGIN_HPP_
00003 
00004 #include <tuttle/plugin/ImageEffectGilPlugin.hpp>
00005 
00006 #include "CropDefinitions.hpp"
00007 
00008 namespace tuttle {
00009 namespace plugin {
00010 namespace crop {
00011 
00012 template<class Pixel>
00013 struct CropProcessParams
00014 {
00015         EParamMode _mode;
00016         OfxRectI _cropRegion;
00017 //      boost::gil::rgba32f_pixel_t _color;
00018         Pixel _color;
00019 };
00020 
00021 /**
00022  * @brief
00023  *
00024  */
00025 class CropPlugin : public ImageEffectGilPlugin
00026 {
00027 public:
00028         CropPlugin( OfxImageEffectHandle handle );
00029 
00030 public:
00031         template<class Pixel>
00032         CropProcessParams<Pixel> getProcessParams( const OfxTime time, const OfxPointD& renderScale = OFX::kNoRenderScale ) const;
00033 
00034         OfxRectI getCropRegionValue() const;
00035         OfxRectI computeCropRegion( const OfxTime time, const bool fromRatio = false ) const;
00036 
00037         void         changedClip( const OFX::InstanceChangedArgs& args, const std::string& clipName );
00038         void         changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName );
00039         bool         getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod );
00040         
00041         void render( const OFX::RenderArguments& args );
00042 
00043 public:
00044         OFX::ChoiceParam* _paramMode;
00045         OFX::RGBAParam* _paramFillColor;
00046         OFX::ChoiceParam* _paramAxis;
00047         OFX::ChoiceParam* _paramSymmetric;
00048         OFX::BooleanParam* _paramFixedRatio;
00049         OFX::DoubleParam* _paramRatio;
00050         OFX::ChoiceParam* _paramPreset;
00051         OFX::BooleanParam* _paramOverlay;
00052         OFX::GroupParam* _paramCropRegion;
00053         OFX::IntParam* _paramXMin;
00054         OFX::IntParam* _paramYMin;
00055         OFX::IntParam* _paramXMax;
00056         OFX::IntParam* _paramYMax;
00057         
00058 private:
00059         OFX::InstanceChangedArgs _changedArgs;
00060         static int safeModulo(const int &cropValue, const int &rodValue);
00061 };
00062 
00063 template<class Pixel>
00064 CropProcessParams<Pixel> CropPlugin::getProcessParams( const OfxTime time, const OfxPointD& renderScale ) const
00065 {
00066         CropProcessParams<Pixel> params;
00067 
00068         params._mode = static_cast<EParamMode>(_paramMode->getValue());
00069 
00070         const OfxRGBAColourD color = _paramFillColor->getValue();
00071         color_convert( ofxToGil( color ), params._color );
00072 
00073         params._cropRegion = computeCropRegion( time );
00074         params._cropRegion.x1 *= renderScale.x;
00075         params._cropRegion.x2 *= renderScale.x;
00076         params._cropRegion.y1 *= renderScale.y;
00077         params._cropRegion.y2 *= renderScale.y;
00078 
00079         return params;
00080 }
00081 
00082 }
00083 }
00084 }
00085 
00086 #endif