TuttleOFX
1
|
00001 #include "LensDistortPlugin.hpp" 00002 00003 #include <tuttle/plugin/ImageGilProcessor.hpp> 00004 #include <tuttle/plugin/numeric/rectOp.hpp> 00005 #include <tuttle/plugin/ofxToGil/rect.hpp> 00006 00007 #include <terry/sampler/resample_progress.hpp> 00008 00009 namespace tuttle { 00010 namespace plugin { 00011 namespace lens { 00012 00013 template<class View> 00014 LensDistortProcess<View>::LensDistortProcess( LensDistortPlugin& instance ) 00015 : ImageGilFilterProcessor<View>( instance, eImageOrientationIndependant ) 00016 , _plugin( instance ) 00017 {} 00018 00019 template<class View> 00020 void LensDistortProcess<View>::setup( const OFX::RenderArguments& args ) 00021 { 00022 ImageGilFilterProcessor<View>::setup( args ); 00023 00024 _params = _plugin.getProcessParams(); 00025 00026 OfxRectD srcRod = rectIntToDouble( this->_srcPixelRod ); 00027 OfxRectD dstRod = rectIntToDouble( this->_dstPixelRod ); 00028 if( _plugin._srcRefClip->isConnected() ) 00029 { 00030 OfxRectD srcRefRod = rectIntToDouble( _plugin._srcRefClip->getPixelRod( args.time, args.renderScale ) ); 00031 _p = _plugin.getProcessParams( srcRod, dstRod, srcRefRod, this->_clipDst->getPixelAspectRatio() ); 00032 } 00033 else 00034 { 00035 _p = _plugin.getProcessParams( srcRod, dstRod, this->_clipDst->getPixelAspectRatio() ); 00036 } 00037 } 00038 00039 /** 00040 * @brief Function called by rendering thread each time a process must be done. 00041 * @param[in] procWindowRoW Processing window 00042 */ 00043 template<class View> 00044 void LensDistortProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW ) 00045 { 00046 using namespace boost::gil; 00047 using namespace terry::sampler; 00048 OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW ); 00049 00050 switch( _params._samplerProcessParams._filter ) 00051 { 00052 case eParamFilterNearest: 00053 { 00054 lensDistort<terry::sampler::nearest_neighbor_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00055 return; 00056 } 00057 case eParamFilterBilinear: 00058 { 00059 lensDistort<terry::sampler::bilinear_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00060 return; 00061 } 00062 case eParamFilterBC: 00063 { 00064 bc_sampler BCsampler ( _params._samplerProcessParams._paramB, _params._samplerProcessParams._paramC ); 00065 lensDistort( this->_srcView, this->_dstView, procWindowOutput, BCsampler ); 00066 return; 00067 } 00068 case eParamFilterBicubic: 00069 { 00070 lensDistort<terry::sampler::bicubic_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00071 return; 00072 } 00073 case eParamFilterCatrom: 00074 { 00075 lensDistort<terry::sampler::catrom_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00076 return; 00077 } 00078 case eParamFilterMitchell: 00079 { 00080 lensDistort<terry::sampler::mitchell_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00081 return; 00082 } 00083 case eParamFilterParzen: 00084 { 00085 lensDistort<terry::sampler::parzen_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00086 return; 00087 } 00088 case eParamFilterKeys: 00089 { 00090 lensDistort<terry::sampler::keys_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00091 return; 00092 } 00093 case eParamFilterSimon: 00094 { 00095 lensDistort<terry::sampler::simon_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00096 return; 00097 } 00098 case eParamFilterRifman: 00099 { 00100 lensDistort<terry::sampler::rifman_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00101 return; 00102 } 00103 case eParamFilterLanczos: 00104 { 00105 lanczos_sampler lanczosSampler ( _params._samplerProcessParams._filterSize, _params._samplerProcessParams._filterSharpen ); 00106 lensDistort( this->_srcView, this->_dstView, procWindowOutput, lanczosSampler ); 00107 return; 00108 } 00109 case eParamFilterLanczos3: 00110 { 00111 lensDistort<terry::sampler::lanczos3_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00112 return; 00113 } 00114 case eParamFilterLanczos4: 00115 { 00116 lensDistort<terry::sampler::lanczos4_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00117 return; 00118 } 00119 case eParamFilterLanczos6: 00120 { 00121 lensDistort<terry::sampler::lanczos6_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00122 return; 00123 } 00124 case eParamFilterLanczos12: 00125 { 00126 lensDistort<terry::sampler::lanczos12_sampler>( this->_srcView, this->_dstView, procWindowOutput ); 00127 return; 00128 } 00129 case eParamFilterGaussian: 00130 { 00131 gaussian_sampler gaussianSampler ( _params._samplerProcessParams._filterSize, _params._samplerProcessParams._filterSigma ); 00132 lensDistort( this->_srcView, this->_dstView, procWindowOutput, gaussianSampler ); 00133 return; 00134 } 00135 } 00136 BOOST_THROW_EXCEPTION( exception::Bug() 00137 << exception::user( "Interpolation method not recognize." ) ); 00138 } 00139 00140 template<class View> 00141 template<class Sampler> 00142 void LensDistortProcess<View>::lensDistort( View& srcView, View& dstView, const OfxRectI& procWindow, const Sampler& sampler ) 00143 { 00144 using namespace terry::sampler; 00145 EParamFilterOutOfImage outOfImageProcess = _params._samplerProcessParams._outOfImageProcess; 00146 terry::Rect<std::ssize_t> procWin = ofxToGil(procWindow); 00147 switch( _params._lensType ) 00148 { 00149 case eParamLensTypeStandard: 00150 { 00151 if( _p._distort ) 00152 { 00153 resample_pixels_progress( srcView, dstView, static_cast<NormalLensDistortParams<double>&>( _p ), procWin, outOfImageProcess, this->getOfxProgress(), sampler ); 00154 } 00155 else 00156 { 00157 resample_pixels_progress( srcView, dstView, static_cast<NormalLensUndistortParams<double>&>( _p ), procWin, outOfImageProcess, this->getOfxProgress(), sampler ); 00158 } 00159 return; 00160 } 00161 case eParamLensTypeFisheye: 00162 { 00163 if( _p._distort ) 00164 resample_pixels_progress( srcView, dstView, static_cast<FisheyeLensDistortParams<double>&>( _p ), procWin, outOfImageProcess, this->getOfxProgress(), sampler ); 00165 else 00166 resample_pixels_progress( srcView, dstView, static_cast<FisheyeLensUndistortParams<double>&>( _p ), procWin, outOfImageProcess, this->getOfxProgress(), sampler ); 00167 return; 00168 } 00169 case eParamLensTypeAdvanced: 00170 { 00171 if( _p._distort ) 00172 resample_pixels_progress( srcView, dstView, static_cast<AdvancedLensDistortParams<double>&>( _p ), procWin, outOfImageProcess, this->getOfxProgress(), sampler ); 00173 else 00174 resample_pixels_progress( srcView, dstView, static_cast<AdvancedLensUndistortParams<double>&>( _p ), procWin, outOfImageProcess, this->getOfxProgress(), sampler ); 00175 return; 00176 } 00177 } 00178 BOOST_THROW_EXCEPTION( exception::Bug() 00179 << exception::user( "Lens type not recognize." ) ); 00180 } 00181 00182 } 00183 } 00184 } 00185 00186