TuttleOFX
1
|
00001 #include "CropPlugin.hpp" 00002 00003 #include <tuttle/plugin/numeric/rectOp.hpp> 00004 #include <tuttle/plugin/ofxToGil/rect.hpp> 00005 00006 #include <terry/math/Rect.hpp> 00007 #include <terry/draw/fill.hpp> 00008 #include <terry/basic_colors.hpp> 00009 #include <terry/globals.hpp> 00010 00011 #include <boost/gil/gil_all.hpp> 00012 00013 namespace tuttle { 00014 namespace plugin { 00015 namespace crop { 00016 00017 template<class View> 00018 CropProcess<View>::CropProcess( CropPlugin& instance ) 00019 : ImageGilFilterProcessor<View>( instance, eImageOrientationFromBottomToTop ) 00020 , _plugin( instance ) 00021 { 00022 } 00023 00024 template<class View> 00025 void CropProcess<View>::setup( const OFX::RenderArguments& args ) 00026 { 00027 ImageGilFilterProcessor<View>::setup( args ); 00028 00029 _params = _plugin.getProcessParams<Pixel>( args.time, args.renderScale ); 00030 } 00031 00032 /** 00033 * @brief Function called by rendering thread each time a process must be done. 00034 * @param[in] procWindowRoW Processing window in RoW 00035 */ 00036 template<class View> 00037 void CropProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW ) 00038 { 00039 using namespace boost::gil; 00040 // Currently, it's not possible to place the crop depending on the RoW and not on image source RoD. 00041 00042 const OfxRectI procWindowOutput = translateRegion( procWindowRoW, this->_dstPixelRod ); 00043 00044 terry::draw::fill_pixels( this->_dstView, ofxToGil(procWindowOutput), _params._color ); 00045 00046 // proc region of source image to copy 00047 const OfxRectI procCropRoW = rectanglesIntersection( 00048 rectanglesIntersection( 00049 _params._cropRegion, 00050 procWindowRoW ), 00051 this->_srcPixelRod ); 00052 00053 const OfxRectI procCropOutput = translateRegion( procCropRoW, this->_dstPixelRod ); 00054 const OfxRectI procCropSrc = translateRegion( procCropRoW, this->_srcPixelRod ); 00055 const OfxPointI procCropSize = { 00056 procCropRoW.x2 - procCropRoW.x1, 00057 procCropRoW.y2 - procCropRoW.y1 }; 00058 00059 View src = subimage_view( this->_srcView, procCropSrc.x1, procCropSrc.y1, 00060 procCropSize.x, procCropSize.y ); 00061 View dst = subimage_view( this->_dstView, procCropOutput.x1, procCropOutput.y1, 00062 procCropSize.x, procCropSize.y ); 00063 00064 copy_pixels( src, dst ); 00065 } 00066 00067 } 00068 } 00069 }