TuttleOFX  1
ColorGradientProcess.tcc
Go to the documentation of this file.
00001 #include <boost/numeric/conversion/cast.hpp>
00002 
00003 namespace tuttle {
00004 namespace plugin {
00005 namespace colorGradient {
00006 
00007 template<class View, template<typename> class ColorGradientFunctor>
00008 ColorGradientProcess<View, ColorGradientFunctor>::ColorGradientProcess( ColorGradientPlugin& instance )
00009         : ImageGilProcessor<View>( instance, eImageOrientationFromBottomToTop )
00010         , _plugin( instance )
00011 {}
00012 
00013 template<class View, template<typename> class ColorGradientFunctor>
00014 void ColorGradientProcess<View, ColorGradientFunctor>::setup( const OFX::RenderArguments& args )
00015 {
00016         using namespace boost::gil;
00017         ImageGilProcessor<View>::setup( args );
00018 
00019         boost::function_requires<PixelLocatorConcept<Locator> >();
00020         gil_function_requires < StepIteratorConcept<typename Locator::x_iterator> >();
00021 
00022         // params
00023         ColorGradientProcessParams<View> params = _plugin.getProcessParams<View>();
00024 
00025         OfxRectD rod = _plugin._clipDst->getCanonicalRod( args.time );
00026         Point dims( rod.x2 - rod.x1, rod.y2 - rod.y1 );
00027         int yshift = boost::numeric_cast<int>( ( dims.x - dims.y ) * 0.5 );
00028 
00029         ColorGradientVirtualView colorGradient( Point( dims.x, dims.x ), Locator( Point( 0, 0 ), Point( 1, 1 ), ColorGradientFunctorT( dims, params._points, params._colors ) ) );
00030         // create a subview depending on the image ratio
00031         _srcView = subimage_view<>( colorGradient, 0, yshift, boost::numeric_cast<int>( dims.x ), boost::numeric_cast<int>( dims.y ) );
00032 }
00033 
00034 /**
00035  * @brief Function called by rendering thread each time a process must be done.
00036  * @param[in] procWindowRoW  Processing window in RoW
00037  */
00038 template<class View, template<typename> class ColorGradientFunctor>
00039 void ColorGradientProcess<View, ColorGradientFunctor>::multiThreadProcessImages( const OfxRectI& procWindowRoW )
00040 {
00041         using namespace boost::gil;
00042         OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW );
00043         const OfxPointI procWindowSize = {
00044                 procWindowRoW.x2 - procWindowRoW.x1,
00045                 procWindowRoW.y2 - procWindowRoW.y1 };
00046 
00047         for( int y = procWindowOutput.y1;
00048              y < procWindowOutput.y2;
00049              ++y )
00050         {
00051                 typename ColorGradientVirtualView::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y );
00052                 typename View::x_iterator dst_it                     = this->_dstView.x_at( procWindowOutput.x1, y );
00053                 for( int x = procWindowOutput.x1;
00054                      x < procWindowOutput.x2;
00055                      ++x, ++src_it, ++dst_it )
00056                 {
00057                         *dst_it = *src_it;
00058                 }
00059                 if( this->progressForward( procWindowSize.x ) )
00060                         return;
00061         }
00062 }
00063 
00064 }
00065 }
00066 }