TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_IMAGEGILFILTERPROCESSOR_HPP_ 00002 #define _TUTTLE_PLUGIN_IMAGEGILFILTERPROCESSOR_HPP_ 00003 00004 #include "ImageGilProcessor.hpp" 00005 00006 #include <boost/scoped_ptr.hpp> 00007 00008 namespace tuttle { 00009 namespace plugin { 00010 00011 /** 00012 * @brief Base class that can be used to process images of any type using boost::gil library view to access images. 00013 */ 00014 template <class SView, class DView = SView> 00015 class ImageGilFilterProcessor : public ImageGilProcessor<DView> 00016 { 00017 protected: 00018 OFX::Clip* _clipSrc; ///< Source image clip 00019 boost::scoped_ptr<OFX::Image> _src; 00020 OfxRectI _srcPixelRod; 00021 SView _srcView; ///< @brief source clip (filters have only one input) 00022 00023 public: 00024 ImageGilFilterProcessor( OFX::ImageEffect& effect, const EImageOrientation imageOrientation ); 00025 virtual ~ImageGilFilterProcessor(); 00026 00027 virtual void setup( const OFX::RenderArguments& args ); 00028 }; 00029 00030 template<class SView, class DView> 00031 ImageGilFilterProcessor<SView, DView>::ImageGilFilterProcessor( OFX::ImageEffect& effect, const EImageOrientation imageOrientation ) 00032 : ImageGilProcessor<DView>( effect, imageOrientation ) 00033 { 00034 _clipSrc = effect.fetchClip( kOfxImageEffectSimpleSourceClipName ); 00035 00036 if( ! _clipSrc->isConnected() ) 00037 BOOST_THROW_EXCEPTION( exception::ImageNotConnected() ); 00038 } 00039 00040 template<class SView, class DView> 00041 ImageGilFilterProcessor<SView, DView>::~ImageGilFilterProcessor() 00042 {} 00043 00044 template<class SView, class DView> 00045 void ImageGilFilterProcessor<SView, DView>::setup( const OFX::RenderArguments& args ) 00046 { 00047 ImageGilProcessor<DView>::setup( args ); 00048 00049 // source view 00050 // TUTTLE_LOG_INFOS; 00051 // TUTTLE_LOG_VAR( TUTTLE_INFO, "src - fetchImage " << time ); 00052 _src.reset( _clipSrc->fetchImage( args.time ) ); 00053 if( ! _src.get() ) 00054 BOOST_THROW_EXCEPTION( exception::ImageNotReady() 00055 << exception::dev() + "Error on clip " + quotes(_clipSrc->name()) 00056 << exception::time( args.time ) ); 00057 if( _src->getRowDistanceBytes() == 0 ) 00058 BOOST_THROW_EXCEPTION( exception::WrongRowBytes() 00059 << exception::dev() + "Error on clip " + quotes(_clipSrc->name()) 00060 << exception::time( args.time ) ); 00061 00062 if( OFX::getImageEffectHostDescription()->hostName == "uk.co.thefoundry.nuke" ) 00063 { 00064 // bug in nuke, getRegionOfDefinition() on OFX::Image returns bounds 00065 _srcPixelRod = _clipSrc->getPixelRod( args.time, args.renderScale ); 00066 } 00067 else 00068 { 00069 _srcPixelRod = _src->getRegionOfDefinition(); 00070 } 00071 _srcView = ImageGilProcessor<DView>::template getCustomView<SView>( _src.get(), _srcPixelRod ); 00072 00073 // // Make sure bit depths are same 00074 // if( this->_src->getPixelDepth() != this->_dst->getPixelDepth() || 00075 // this->_src->getPixelComponents() != this->_dst->getPixelComponents() ) 00076 // BOOST_THROW_EXCEPTION( exception::BitDepthMismatch() ); 00077 } 00078 00079 } 00080 } 00081 00082 #endif 00083