TuttleOFX
1
|
00001 #include "ColorWheelAlgorithm.hpp" 00002 00003 #include <tuttle/plugin/ofxToGil/point.hpp> 00004 00005 #include <boost/numeric/conversion/cast.hpp> 00006 00007 #include <algorithm> 00008 00009 namespace tuttle { 00010 namespace plugin { 00011 namespace colorWheel { 00012 00013 template<class View> 00014 ColorWheelProcess<View>::ColorWheelProcess( ColorWheelPlugin &effect ) 00015 : ImageGilProcessor<View>( effect, eImageOrientationIndependant ) 00016 , _plugin( effect ) 00017 { 00018 } 00019 00020 template<class View> 00021 void ColorWheelProcess<View>::setup( const OFX::RenderArguments& args ) 00022 { 00023 using namespace terry; 00024 ImageGilProcessor<View>::setup( args ); 00025 _params = _plugin.getProcessParams( ); 00026 00027 OfxRectD rod = _plugin._clipDst->getCanonicalRod( args.time ); 00028 00029 int xshift = 0.0; 00030 int yshift = 0.0; 00031 00032 if( _params.mode == eColorWheelModeRainbow ) 00033 { 00034 boost::function_requires<PixelLocatorConcept<RainbowLocator> >(); 00035 gil_function_requires < StepIteratorConcept<typename RainbowLocator::x_iterator> >(); 00036 00037 RainbowPoint dims( rod.x2 - rod.x1, rod.y2 - rod.y1 ); 00038 00039 // create a squared color wheel 00040 RainbowVirtualView rainbow( dims, RainbowLocator( RainbowPoint( 0, 0 ), RainbowPoint( 1, 1 ), RainbowFunctorT( dims ) ) ); 00041 // create a subview depending on the image ratio 00042 _srcRainbowView = subimage_view<>( rainbow, 0, 0, boost::numeric_cast<int>( dims.x ), boost::numeric_cast<int>( dims.y ) ); 00043 } 00044 else 00045 { 00046 boost::function_requires<PixelLocatorConcept<ColorWheelLocator> >(); 00047 gil_function_requires < StepIteratorConcept<typename ColorWheelLocator::x_iterator> >(); 00048 00049 ColorWheelPoint dims( rod.x2 - rod.x1, rod.y2 - rod.y1 ); 00050 float size = std::min( dims.x, dims.y ); 00051 00052 if( size == dims.x ) 00053 yshift = - boost::numeric_cast<int>( ( dims.y - dims.x ) * 0.5 ); 00054 else 00055 xshift = - boost::numeric_cast<int>( ( dims.x - dims.y ) * 0.5 ); 00056 00057 ColorWheelPoint tileSize( size, size ); 00058 00059 // create a squared color wheel 00060 ColorWheelVirtualView colorWheel( ColorWheelPoint( size, size ), ColorWheelLocator( ColorWheelPoint( 0, 0 ), ColorWheelPoint( 1, 1 ), ColorWheelFunctorT( tileSize, _params.mode == eColorWheelModeBlack ) ) ); 00061 // create a subview depending on the image ratio 00062 _srcColorWheelView = subimage_view<>( colorWheel, xshift, yshift, boost::numeric_cast<int>( dims.x ), boost::numeric_cast<int>( dims.y ) ); 00063 } 00064 } 00065 00066 /** 00067 * @brief Function called by rendering thread each time a process must be done. 00068 * @param[in] procWindowRoW Processing window 00069 */ 00070 template<class View> 00071 void ColorWheelProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW ) 00072 { 00073 using namespace boost::gil; 00074 OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW ); 00075 const OfxPointI procWindowSize = { 00076 procWindowRoW.x2 - procWindowRoW.x1, 00077 procWindowRoW.y2 - procWindowRoW.y1 00078 }; 00079 if( _params.mode == eColorWheelModeRainbow ) 00080 { 00081 for( int y = procWindowOutput.y1; 00082 y < procWindowOutput.y2; 00083 ++y ) 00084 { 00085 typename RainbowVirtualView::x_iterator src_it = this->_srcRainbowView.x_at( procWindowOutput.x1, y ); 00086 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00087 for( int x = procWindowOutput.x1; 00088 x < procWindowOutput.x2; 00089 ++x, ++src_it, ++dst_it ) 00090 { 00091 (*dst_it) = (*src_it); 00092 } 00093 if( this->progressForward( procWindowSize.x ) ) 00094 return; 00095 } 00096 } 00097 else 00098 { 00099 for( int y = procWindowOutput.y1; 00100 y < procWindowOutput.y2; 00101 ++y ) 00102 { 00103 typename ColorWheelVirtualView::x_iterator src_it = this->_srcColorWheelView.x_at( procWindowOutput.x1, y ); 00104 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00105 for( int x = procWindowOutput.x1; 00106 x < procWindowOutput.x2; 00107 ++x, ++src_it, ++dst_it ) 00108 { 00109 (*dst_it) = (*src_it); 00110 } 00111 if( this->progressForward( procWindowSize.x ) ) 00112 return; 00113 } 00114 } 00115 } 00116 00117 } 00118 } 00119 }