TuttleOFX
1
|
00001 #include "RampAlgorithm.hpp" 00002 #include "RampPlugin.hpp" 00003 00004 namespace tuttle { 00005 namespace plugin { 00006 namespace ramp { 00007 00008 template<class View> 00009 RampProcess<View>::RampProcess( RampPlugin &effect ) 00010 : ImageGilProcessor<View>( effect, eImageOrientationIndependant ) 00011 , _plugin( effect ) 00012 { 00013 } 00014 00015 template<class View> 00016 RampProcessParams<View> RampProcess<View>::getProcessParams( ) const 00017 { 00018 using namespace terry; 00019 RampProcessParams<View> params; 00020 00021 params.direction = ( _plugin._direction->getValue() == 0 ); 00022 params.color = _plugin._color->getValue(); 00023 00024 OfxRGBAColourD cStart = _plugin._colorStart->getValue(); 00025 color_convert( rgba32f_pixel_t( cStart.r, cStart.g, cStart.b, cStart.a ), params.colorStart ); 00026 OfxRGBAColourD cEnd = _plugin._colorEnd->getValue(); 00027 color_convert( rgba32f_pixel_t( cEnd.r, cEnd.g, cEnd.b, cEnd.a ), params.colorEnd ); 00028 00029 return params; 00030 } 00031 00032 template<class View> 00033 void RampProcess<View>::setup( const OFX::RenderArguments& args ) 00034 { 00035 using namespace terry; 00036 ImageGilProcessor<View>::setup( args ); 00037 RampProcessParams<View> params = getProcessParams( ); 00038 00039 boost::function_requires<PixelLocatorConcept<Locator> >(); 00040 gil_function_requires < StepIteratorConcept<typename Locator::x_iterator> >(); 00041 00042 OfxRectD rod = _plugin._clipDst->getCanonicalRod( args.time ); 00043 Point dims( rod.x2 - rod.x1, rod.y2 - rod.y1 ); 00044 00045 // create a ramp view 00046 RampVirtualView checker( dims, Locator( Point( 0, 0 ), Point( 1, 1 ), RampFunctorT( dims, params.colorStart, params.colorEnd, params.direction, params.color ) ) ); 00047 // create a subview depending on the image ratio 00048 _srcView = subimage_view<>( checker, 0.0, 0.0, boost::numeric_cast<int>( dims.x ), boost::numeric_cast<int>( dims.y ) ); 00049 } 00050 00051 /** 00052 * @brief Function called by rendering thread each time a process must be done. 00053 * @param[in] procWindowRoW Processing window 00054 */ 00055 template<class View> 00056 void RampProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW ) 00057 { 00058 using namespace boost::gil; 00059 OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW ); 00060 const OfxPointI procWindowSize = { 00061 procWindowRoW.x2 - procWindowRoW.x1, 00062 procWindowRoW.y2 - procWindowRoW.y1 00063 }; 00064 00065 for( int y = procWindowOutput.y1; 00066 y < procWindowOutput.y2; 00067 ++y ) 00068 { 00069 typename RampVirtualView::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); 00070 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00071 for( int x = procWindowOutput.x1; 00072 x < procWindowOutput.x2; 00073 ++x, ++src_it, ++dst_it ) 00074 { 00075 (*dst_it) = (*src_it); 00076 } 00077 if( this->progressForward( procWindowSize.x ) ) 00078 return; 00079 } 00080 } 00081 00082 } 00083 } 00084 }