TuttleOFX
1
|
00001 #include "ColorCubeAlgorithm.hpp" 00002 00003 #include <tuttle/plugin/ofxToGil/point.hpp> 00004 00005 #include <boost/numeric/conversion/cast.hpp> 00006 00007 namespace tuttle { 00008 namespace plugin { 00009 namespace colorCube { 00010 00011 template<class View> 00012 ColorCubeProcess<View>::ColorCubeProcess( ColorCubePlugin &effect ) 00013 : ImageGilProcessor<View>( effect, eImageOrientationIndependant ) 00014 , _plugin( effect ) 00015 { 00016 } 00017 00018 template<class View> 00019 void ColorCubeProcess<View>::setup( const OFX::RenderArguments& args ) 00020 { 00021 using namespace terry; 00022 boost::function_requires<PixelLocatorConcept<ColorCubeLocator> >(); 00023 gil_function_requires < StepIteratorConcept<typename ColorCubeLocator::x_iterator> >(); 00024 00025 ImageGilProcessor<View>::setup( args ); 00026 _params = _plugin.getProcessParams( ); 00027 00028 OfxRectD rod = _plugin._clipDst->getCanonicalRod( args.time ); 00029 00030 int xshift = 0.0; 00031 int yshift = 0.0; 00032 00033 ColorCubePoint dims( rod.x2 - rod.x1, rod.y2 - rod.y1 ); 00034 float size = std::min( dims.x, dims.y ); 00035 00036 if( size == dims.x ) 00037 yshift = - boost::numeric_cast<int>( ( dims.y - dims.x ) * 0.5 ); 00038 else 00039 xshift = - boost::numeric_cast<int>( ( dims.x - dims.y ) * 0.5 ); 00040 00041 ColorCubePoint tileSize( size, size ); 00042 00043 // create a squared color Cube 00044 ColorCubeVirtualView colorCube( ColorCubePoint( size, size ), ColorCubeLocator( ColorCubePoint( 0, 0 ), ColorCubePoint( 1, 1 ), ColorCubeFunctorT( tileSize, _params.step ) ) ); 00045 // create a subview depending on the image ratio 00046 _srcColorCubeView = subimage_view<>( colorCube, xshift, yshift, boost::numeric_cast<int>( dims.x ), boost::numeric_cast<int>( dims.y ) ); 00047 } 00048 00049 /** 00050 * @brief Function called by rendering thread each time a process must be done. 00051 * @param[in] procWindowRoW Processing window 00052 */ 00053 template<class View> 00054 void ColorCubeProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW ) 00055 { 00056 using namespace boost::gil; 00057 OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW ); 00058 const OfxPointI procWindowSize = { 00059 procWindowRoW.x2 - procWindowRoW.x1, 00060 procWindowRoW.y2 - procWindowRoW.y1 00061 }; 00062 00063 for( int y = procWindowOutput.y1; 00064 y < procWindowOutput.y2; 00065 ++y ) 00066 { 00067 typename ColorCubeVirtualView::x_iterator src_it = this->_srcColorCubeView.x_at( procWindowOutput.x1, y ); 00068 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00069 for( int x = procWindowOutput.x1; 00070 x < procWindowOutput.x2; 00071 ++x, ++src_it, ++dst_it ) 00072 { 00073 (*dst_it) = (*src_it); 00074 } 00075 if( this->progressForward( procWindowSize.x ) ) 00076 return; 00077 } 00078 } 00079 00080 } 00081 } 00082 }