TuttleOFX  1
JpegWriterProcess.tcc
Go to the documentation of this file.
00001 #include "JpegWriterDefinitions.hpp"
00002 #include "JpegWriterPlugin.hpp"
00003 
00004 #include <terry/globals.hpp>
00005 #include <tuttle/plugin/exceptions.hpp>
00006 
00007 #include <boost/gil/gil_all.hpp>
00008 #include <boost/scoped_ptr.hpp>
00009 #include <boost/gil/extension/io/jpeg_io.hpp>
00010 #include <boost/filesystem/fstream.hpp>
00011 
00012 namespace tuttle {
00013 namespace plugin {
00014 namespace jpeg {
00015 namespace writer {
00016 
00017 template<class View>
00018 JpegWriterProcess<View>::JpegWriterProcess( JpegWriterPlugin& instance )
00019         : ImageGilFilterProcessor<View>( instance, eImageOrientationFromTopToBottom )
00020         , _plugin( instance )
00021 {
00022         this->setNoMultiThreading();
00023 }
00024 
00025 template<class View>
00026 void JpegWriterProcess<View>::setup( const OFX::RenderArguments& args )
00027 {
00028         ImageGilFilterProcessor<View>::setup( args );
00029 
00030         _params = _plugin.getProcessParams( args.time );
00031 }
00032 
00033 
00034 /**
00035  * @brief Function called by rendering thread each time a process must be done.
00036  * @param[in] procWindowRoW  Processing window in RoW
00037  * @warning no multithread here !
00038  */
00039 template<class View>
00040 void JpegWriterProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW )
00041 {
00042         BOOST_ASSERT( procWindowRoW == this->_srcPixelRod );
00043         using namespace boost::gil;
00044 
00045         View srcView = this->_srcView;
00046 
00047         try
00048         {
00049                 writeImage<bits8>( srcView );
00050         }
00051         catch( exception::Common& e )
00052         {
00053                 e << exception::filename( _params._filepath );
00054                 throw;
00055         }
00056         catch(...)
00057         {
00058                 BOOST_THROW_EXCEPTION( exception::Unknown()
00059                         << exception::user( "Unable to write image" )
00060                         << exception::dev( boost::current_exception_diagnostic_information() )
00061                         << exception::filename( _params._filepath ) );
00062         }
00063         copy_pixels( this->_srcView, this->_dstView ); // @todo ?
00064 }
00065 
00066 /**
00067  *
00068  */
00069 template<class View>
00070 template<class Bits>
00071 void JpegWriterProcess<View>::writeImage( View& src )
00072 {
00073         using namespace boost::gil;
00074         using namespace terry;
00075 
00076         typedef pixel<Bits, rgb_layout_t> OutPixelType;
00077         jpeg_write_view( _params._filepath, color_converted_view<OutPixelType>( src ), _params._quality );
00078 
00079 }
00080 
00081 }
00082 }
00083 }
00084 }