TuttleOFX  1
PngReaderProcess.tcc
Go to the documentation of this file.
00001 #include "PngReaderDefinitions.hpp"
00002 #include "PngReaderProcess.hpp"
00003 #include "PngReaderPlugin.hpp"
00004 
00005 #include <terry/globals.hpp>
00006 #include <tuttle/plugin/exceptions.hpp>
00007 
00008 #include <boost/gil/gil_all.hpp>
00009 #include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
00010 #include <boost/gil/extension/io/png_io.hpp>
00011 #include <boost/gil/extension/io/png_dynamic_io.hpp>
00012 #include <boost/filesystem/fstream.hpp>
00013 
00014 #include <boost/scoped_ptr.hpp>
00015 #include <boost/assert.hpp>
00016 
00017 namespace tuttle {
00018 namespace plugin {
00019 namespace png {
00020 namespace reader {
00021 
00022 using namespace boost::gil;
00023 namespace bfs = boost::filesystem;
00024 
00025 typedef any_image < boost::mpl::vector
00026                     < gray8_image_t, gray16_image_t, gray32f_image_t,
00027                       rgba8_image_t, rgba16_image_t, rgba32f_image_t,
00028                       rgb8_image_t,  rgb16_image_t,  rgb32f_image_t >
00029                     > any_image_t;
00030 typedef any_image_t::view_t any_view_t;
00031 
00032 template<class View>
00033 PngReaderProcess<View>::PngReaderProcess( PngReaderPlugin& instance )
00034         : ImageGilProcessor<View>( instance, eImageOrientationFromTopToBottom )
00035         , _plugin( instance )
00036 {
00037         this->setNoMultiThreading();
00038 }
00039 
00040 
00041 template<class View>
00042 void PngReaderProcess<View>::setup( const OFX::RenderArguments& args )
00043 {
00044         ImageGilProcessor<View>::setup( args );
00045 
00046         _params = _plugin.getProcessParams( args.time );
00047 }
00048 
00049 
00050 /**
00051  * @brief Function called by rendering thread each time a process must be done.
00052  * @param[in] procWindowRoW  Processing window in RoW
00053  */
00054 template<class View>
00055 void PngReaderProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW )
00056 {
00057         // no tiles and no multithreading supported
00058         BOOST_ASSERT( procWindowRoW == this->_dstPixelRod );
00059         readImage( this->_dstView );
00060 }
00061 
00062 /**
00063  */
00064 template<class View>
00065 View& PngReaderProcess<View>::readImage( View& dst )
00066 {
00067         any_image_t anyImg;
00068 
00069         try
00070         {
00071                 png_read_image( _params._filepath, anyImg );
00072                 any_view_t srcView = view( anyImg );
00073                 srcView = subimage_view( srcView, 0, 0, dst.width(), dst.height() );
00074                 copy_and_convert_pixels( srcView, dst );
00075         }
00076         catch( boost::exception& e )
00077         {
00078                 e << exception::user( "Png: Unable to read information in file." );
00079                 e << exception::filename( _params._filepath );
00080                 throw;
00081         }
00082         catch( ... )
00083         {
00084                 BOOST_THROW_EXCEPTION( exception::File()
00085                         << exception::user( "Png: Unable to read information in file." )
00086                         << exception::dev( boost::current_exception_diagnostic_information() )
00087                         << exception::filename( _params._filepath ) );
00088         }
00089         return dst;
00090 }
00091 
00092 }
00093 }
00094 }
00095 }