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