TuttleOFX
1
|
00001 #include <tuttle/plugin/ofxToGil/rect.hpp> 00002 #include <terry/sampler/resample_progress.hpp> 00003 #include <terry/geometry/affine.hpp> 00004 00005 namespace tuttle { 00006 namespace plugin { 00007 namespace resize { 00008 00009 template<class View> 00010 ResizeProcess<View>::ResizeProcess( ResizePlugin &effect ) 00011 : ImageGilFilterProcessor<View>( effect, eImageOrientationFromBottomToTop ) 00012 , _plugin( effect ) 00013 { 00014 this->setNoMultiThreading(); 00015 } 00016 00017 template<class View> 00018 void ResizeProcess<View>::setup( const OFX::RenderArguments& args ) 00019 { 00020 ImageGilFilterProcessor<View>::setup( args ); 00021 _params = _plugin.getProcessParams( args.renderScale ); 00022 } 00023 00024 /** 00025 * @brief Function called by rendering thread each time a process must be done. 00026 * @param[in] procWindowRoW Processing window 00027 */ 00028 template<class View> 00029 void ResizeProcess<View>::multiThreadProcessImages( const OfxRectI& procWindow ) 00030 { 00031 using namespace terry; 00032 using namespace terry::sampler; 00033 00034 const terry::Rect<std::ssize_t> procWin = ofxToGil(procWindow); 00035 00036 const double src_width = std::max<double>(this->_srcView.width () -1,1); 00037 const double src_height = std::max<double>(this->_srcView.height() -1,1); 00038 const double dst_width = std::max<double>(this->_dstView.width () -1,1); 00039 const double dst_height = std::max<double>(this->_dstView.height() -1,1); 00040 00041 //TUTTLE_LOG_INFO("\E[1;31mResize Position = " << -( _params._centerPoint.x - dst_width * 0.5) << "x" << -( _params._centerPoint.y - dst_height * 0.5) << "\E[0;0m"); 00042 00043 const EParamFilterOutOfImage outOfImageProcess = static_cast<EParamFilterOutOfImage>(_params._samplerProcessParams._outOfImageProcess); 00044 00045 matrix3x2<double> mat; 00046 00047 #ifndef TUTTLE_PRODUCTION 00048 if( _params._changeCenter ) 00049 { 00050 mat = matrix3x2<double>::get_translate( -( _params._centerPoint.x - dst_width * 0.5) , -( _params._centerPoint.y - dst_height * 0.5) ) * 00051 matrix3x2<double>::get_translate( - dst_width * 0.5, - dst_height * 0.5 ) * 00052 matrix3x2<double>::get_scale ( (src_width + 1) / (dst_width + 1 ), (src_height + 1) / (dst_height + 1) ) * 00053 matrix3x2<double>::get_translate( src_width * 0.5 , src_height * 0.5 ) 00054 ; 00055 } 00056 else 00057 #endif 00058 { 00059 mat = matrix3x2<double>::get_translate( - dst_width * 0.5, - dst_height * 0.5 ) * 00060 matrix3x2<double>::get_scale ( (src_width + 1) / (dst_width + 1 ), (src_height + 1) / (dst_height + 1) ) * 00061 matrix3x2<double>::get_translate( src_width * 0.5 , src_height * 0.5 ) 00062 ; 00063 } 00064 00065 switch( _params._samplerProcessParams._filter ) 00066 { 00067 case eParamFilterNearest : resample_pixels_progress< ::terry::sampler::nearest_neighbor_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00068 case eParamFilterBilinear : resample_pixels_progress< ::terry::sampler::bilinear_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00069 case eParamFilterBC : 00070 { 00071 bc_sampler BCsampler( _params._samplerProcessParams._paramB, _params._samplerProcessParams._paramC ); 00072 resample_pixels_progress( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress(), BCsampler ); 00073 break; 00074 } 00075 case eParamFilterBicubic : resample_pixels_progress< bicubic_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00076 case eParamFilterCatrom : resample_pixels_progress< catrom_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00077 case eParamFilterKeys : resample_pixels_progress< keys_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00078 case eParamFilterSimon : resample_pixels_progress< simon_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00079 case eParamFilterRifman : resample_pixels_progress< rifman_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00080 case eParamFilterMitchell : resample_pixels_progress< mitchell_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00081 case eParamFilterParzen : resample_pixels_progress< parzen_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00082 case eParamFilterGaussian : 00083 { 00084 gaussian_sampler gaussianSampler ( _params._samplerProcessParams._filterSize, _params._samplerProcessParams._filterSigma ); 00085 resample_pixels_progress( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress(), gaussianSampler ); 00086 break; 00087 } 00088 case eParamFilterLanczos : 00089 { 00090 lanczos_sampler lanczosSampler ( _params._samplerProcessParams._filterSize, _params._samplerProcessParams._filterSharpen ); 00091 resample_pixels_progress( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress(), lanczosSampler ); 00092 break; 00093 } 00094 case eParamFilterLanczos3 : resample_pixels_progress< lanczos3_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00095 case eParamFilterLanczos4 : resample_pixels_progress< lanczos4_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00096 case eParamFilterLanczos6 : resample_pixels_progress< lanczos6_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00097 case eParamFilterLanczos12 : resample_pixels_progress< lanczos12_sampler >( this->_srcView, this->_dstView, mat, procWin, outOfImageProcess, this->getOfxProgress() ); break; 00098 } 00099 } 00100 00101 } 00102 } 00103 }