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 _srcPixelRod.x1 = _srcPixelRod.y1 = _srcPixelRod.x2 = _srcPixelRod.y2 = 0; 00035 00036 _clipSrc = effect.fetchClip( kOfxImageEffectSimpleSourceClipName ); 00037 00038 if( ! _clipSrc->isConnected() ) 00039 BOOST_THROW_EXCEPTION( exception::ImageNotConnected() ); 00040 } 00041 00042 template<class SView, class DView> 00043 ImageGilFilterProcessor<SView, DView>::~ImageGilFilterProcessor() 00044 {} 00045 00046 template<class SView, class DView> 00047 void ImageGilFilterProcessor<SView, DView>::setup( const OFX::RenderArguments& args ) 00048 { 00049 ImageGilProcessor<DView>::setup( args ); 00050 00051 // source view 00052 // TUTTLE_LOG_INFOS; 00053 // TUTTLE_LOG_VAR( TUTTLE_INFO, "src - fetchImage " << time ); 00054 _src.reset( _clipSrc->fetchImage( args.time ) ); 00055 if( ! _src.get() ) 00056 BOOST_THROW_EXCEPTION( exception::ImageNotReady() 00057 << exception::dev() + "Error on clip " + quotes(_clipSrc->name()) 00058 << exception::time( args.time ) ); 00059 if( _src->getRowDistanceBytes() == 0 ) 00060 BOOST_THROW_EXCEPTION( exception::WrongRowBytes() 00061 << exception::dev() + "Error on clip " + quotes(_clipSrc->name()) 00062 << exception::time( args.time ) ); 00063 00064 if( OFX::getImageEffectHostDescription()->hostName == "uk.co.thefoundry.nuke" ) 00065 { 00066 // bug in nuke, getRegionOfDefinition() on OFX::Image returns bounds 00067 _srcPixelRod = _clipSrc->getPixelRod( args.time, args.renderScale ); 00068 } 00069 else 00070 { 00071 _srcPixelRod = _src->getRegionOfDefinition(); 00072 } 00073 _srcView = ImageGilProcessor<DView>::template getCustomView<SView>( _src.get(), _srcPixelRod ); 00074 00075 // // Make sure bit depths are same 00076 // if( this->_src->getPixelDepth() != this->_dst->getPixelDepth() || 00077 // this->_src->getPixelComponents() != this->_dst->getPixelComponents() ) 00078 // BOOST_THROW_EXCEPTION( exception::BitDepthMismatch() ); 00079 } 00080 00081 } 00082 } 00083 00084 #endif 00085