TuttleOFX
1
|
00001 #if defined( _MSC_VER ) 00002 #pragma warning( disable : 4244 ) 00003 #endif 00004 00005 #include "LutProcess.hpp" 00006 #include "LutDefinitions.hpp" 00007 #include "lutEngine/LutReader.hpp" 00008 #include "lutEngine/Lut.hpp" 00009 #include "lutEngine/TetraInterpolator.hpp" 00010 00011 #include <tuttle/plugin/global.hpp> 00012 #include <tuttle/plugin/ImageGilProcessor.hpp> 00013 #include <tuttle/plugin/exceptions.hpp> 00014 #include <terry/globals.hpp> 00015 00016 #include <ofxsImageEffect.h> 00017 #include <ofxsMultiThread.h> 00018 00019 #include <boost/gil/gil_all.hpp> 00020 #include <boost/filesystem/fstream.hpp> 00021 00022 namespace tuttle { 00023 namespace plugin { 00024 namespace lut { 00025 00026 using namespace boost::filesystem; 00027 00028 template<class View> 00029 LutProcess<View>::LutProcess( LutPlugin& instance ) 00030 : ImageGilFilterProcessor<View>( instance, eImageOrientationIndependant ) 00031 , _plugin( instance ) 00032 { 00033 _lut3D = &_plugin._lut3D; 00034 } 00035 00036 /** 00037 * @brief Function called by rendering thread each time a process must be done. 00038 * @param[in] procWindowRoW Processing window in RoW 00039 */ 00040 template<class View> 00041 void LutProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW ) 00042 { 00043 OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW ); 00044 00045 applyLut( this->_dstView, this->_srcView, procWindowOutput ); 00046 } 00047 00048 template<class View> 00049 void LutProcess<View>::applyLut( View& dst, View& src, const OfxRectI& procWindow ) 00050 { 00051 using namespace terry; 00052 typedef typename View::x_iterator vIterator; 00053 typedef typename channel_type<View>::type Pixel; 00054 const OfxPointI procWindowSize = { 00055 procWindow.x2 - procWindow.x1, 00056 procWindow.y2 - procWindow.y1 }; 00057 00058 for( int y = procWindow.y1; y < procWindow.y2; ++y ) 00059 { 00060 vIterator sit = src.row_begin( y ); 00061 vIterator dit = dst.row_begin( y ); 00062 for( int x = procWindow.x1; x < procWindow.x2; ++x ) 00063 { 00064 tuttle::Color col = _lut3D->getColor( ( *sit )[0], ( *sit )[1], ( *sit )[2] ); 00065 ( *dit )[0] = static_cast<Pixel>( col.x ); 00066 ( *dit )[1] = static_cast<Pixel>( col.y ); 00067 ( *dit )[2] = static_cast<Pixel>( col.z ); 00068 if( dst.num_channels() > 3 ) 00069 ( *dit )[3] = channel_traits< typename channel_type< View >::type >::max_value(); 00070 ++sit; 00071 ++dit; 00072 } 00073 if( this->progressForward( procWindowSize.x ) ) 00074 return; 00075 } 00076 } 00077 00078 } 00079 } 00080 }