TuttleOFX  1
CheckerboardProcess.tcc
Go to the documentation of this file.
00001 #include "CheckerboardProcess.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 checkerboard {
00010 
00011 template<class View>
00012 CheckerboardProcess<View>::CheckerboardProcess( CheckerboardPlugin& instance )
00013 : ImageGilProcessor<View>( instance, eImageOrientationFromBottomToTop )
00014 , _plugin( instance )
00015 {}
00016 
00017 template<class View>
00018 CheckerboardParams<View> CheckerboardProcess<View>::getParams()
00019 {
00020         using namespace boost::gil;
00021         CheckerboardParams<View> params;
00022         params._boxes = ofxToGil( _plugin._boxes->getValue() );
00023 
00024         OfxRGBAColourD c1 = _plugin._color1->getValue();
00025         color_convert( rgba32f_pixel_t( c1.r, c1.g, c1.b, c1.a ), params._color1 );
00026         OfxRGBAColourD c2 = _plugin._color2->getValue();
00027         color_convert( rgba32f_pixel_t( c2.r, c2.g, c2.b, c2.a ), params._color2 );
00028         return params;
00029 }
00030 
00031 template<class View>
00032 void CheckerboardProcess<View>::setup( const OFX::RenderArguments& args )
00033 {
00034         using namespace boost::gil;
00035         ImageGilProcessor<View>::setup( args );
00036         
00037         boost::function_requires<PixelLocatorConcept<Locator> >();
00038         gil_function_requires < StepIteratorConcept<typename Locator::x_iterator> >();
00039 
00040         // params
00041         CheckerboardParams<View> params = getParams();
00042 
00043         OfxRectD rod = _plugin._clipDst->getCanonicalRod( args.time );
00044         
00045         Point dims( rod.x2 - rod.x1, rod.y2 - rod.y1 );
00046         Point tileSize( dims.x / params._boxes.x, dims.y / params._boxes.y );
00047         
00048         // create a squared color wheel
00049         CheckerboardVirtualView checker( Point( dims.x, dims.y ), Locator( Point( 0, 0 ), Point( 1, 1 ), CheckerboardFunctorT( tileSize, params._color1, params._color2 ) ) );
00050         // create a subview depending on the image ratio
00051         _srcView = subimage_view<>( checker, 0, 0, boost::numeric_cast<int>( dims.x ), boost::numeric_cast<int>( dims.y ) );
00052 }
00053 
00054 /**
00055  * @brief Function called by rendering thread each time a process must be done.
00056  * @param[in] procWindowRoW  Processing window in RoW
00057  */
00058 template<class View>
00059 void CheckerboardProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW )
00060 {
00061         using namespace boost::gil;
00062         OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW );
00063         const OfxPointI procWindowSize = {
00064                 procWindowRoW.x2 - procWindowRoW.x1,
00065                 procWindowRoW.y2 - procWindowRoW.y1 };
00066 
00067         for( int y = procWindowOutput.y1;
00068              y < procWindowOutput.y2;
00069              ++y )
00070         {
00071                 typename CheckerboardVirtualView::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y );
00072                 typename View::x_iterator dst_it                    = this->_dstView.x_at( procWindowOutput.x1, y );
00073                 for( int x = procWindowOutput.x1;
00074                      x < procWindowOutput.x2;
00075                      ++x, ++src_it, ++dst_it )
00076                 {
00077                         *dst_it = *src_it;
00078                 }
00079                 if( this->progressForward( procWindowSize.x ) )
00080                         return;
00081         }
00082 }
00083 
00084 }
00085 }
00086 }