TuttleOFX  1
Jpeg2000WriterProcess.tcc
Go to the documentation of this file.
00001 #include "Jpeg2000WriterPlugin.hpp"
00002 
00003 #include <boost/assert.hpp>
00004 
00005 namespace tuttle {
00006 namespace plugin {
00007 namespace jpeg2000 {
00008 namespace writer {
00009 
00010 template<class View>
00011 Jpeg2000WriterProcess<View>::Jpeg2000WriterProcess( Jpeg2000WriterPlugin &instance )
00012 : ImageGilFilterProcessor<View>( instance, eImageOrientationFromTopToBottom )
00013 , _plugin( instance )
00014 {
00015         this->setNoMultiThreading();
00016 }
00017 
00018 template<class View>
00019 Jpeg2000WriterProcess<View>::~Jpeg2000WriterProcess()
00020 {
00021         _writer.close();
00022 }
00023 
00024 template<class View>
00025 void Jpeg2000WriterProcess<View>::setup( const OFX::RenderArguments& args )
00026 {
00027         ImageGilFilterProcessor<View>::setup( args );
00028 
00029         _params = _plugin.getProcessParams( args.time );
00030 }
00031 
00032 /**
00033  * @brief Function called by rendering thread each time a process must be done.
00034  * @param[in] procWindowRoW  Processing window in RoW
00035  */
00036 template<class View>
00037 void Jpeg2000WriterProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW )
00038 {
00039         using namespace boost::gil;
00040         using namespace terry;
00041         BOOST_ASSERT( procWindowRoW == this->_srcPixelRod );
00042 
00043         _writer.setCinemaMode( (OPJ_CINEMA_MODE)_params._cineProfil );
00044         _writer.setLossless( _params._lossless );
00045 
00046         View srcView = this->_srcView;
00047 
00048 //      TUTTLE_LOG_VAR( TUTTLE_INFO, this->_srcView.dimensions() );
00049 //      TUTTLE_LOG_VAR( TUTTLE_INFO, srcView.dimensions() );
00050 
00051         switch(_params._bitDepth)
00052         {
00053                 case eTuttlePluginBitDepthAuto:
00054                 {
00055                         switch( _plugin._clipSrc->getPixelDepth() )
00056                         {
00057                                 case OFX::eBitDepthUByte:
00058                                 {
00059                                         writeImage<rgb8_image_t>( srcView, 8 );
00060                                         break;
00061                                 }
00062                                 case OFX::eBitDepthUShort:
00063                                 {
00064                                         writeImage<rgb16_image_t>( srcView, 16 );
00065                                         break;
00066                                 }
00067                                 case OFX::eBitDepthFloat:
00068                                 {
00069                                         writeImage<rgb16_image_t>( srcView, 16 );
00070                                         //writeImage<rgb32_image_t>( srcView, 32 );
00071                                         break;
00072                                 }
00073                                 case OFX::eBitDepthCustom:
00074                                 case OFX::eBitDepthNone:
00075                                         BOOST_THROW_EXCEPTION( exception::Unsupported()
00076                                             << exception::user( "Jpeg2000 Writer: bit depth not supported" ) );
00077                         }
00078                         break;
00079                 }
00080                 case eTuttlePluginBitDepth8:
00081                 {
00082                         writeImage<rgb8_image_t>( srcView, 8 );
00083                         break;
00084                 }
00085                 case eTuttlePluginBitDepth12:
00086                 case eTuttlePluginBitDepth16:
00087                 {
00088                         writeImage<rgb16_image_t>( srcView, 16 );
00089                         break;
00090                 }
00091                 case eTuttlePluginBitDepth32:
00092                 {
00093                         writeImage<rgb32_image_t>( srcView, 32 );
00094                         break;
00095                 }
00096         }
00097         // Convert pixels to destination
00098         copy_and_convert_pixels( this->_srcView, this->_dstView );
00099 }
00100 
00101 template< typename View >
00102 template< typename SImg >
00103 void Jpeg2000WriterProcess<View>::writeImage( const View& srcView, const int& bitDepth )
00104 {
00105         using namespace terry;
00106         SImg img( srcView.dimensions() );
00107         typename SImg::view_t vw( view(img) );
00108 
00109         copy_and_convert_pixels( srcView, vw );
00110 
00111         uint8_t* pixels = (uint8_t*)boost::gil::interleaved_view_get_raw_data( vw );
00112 
00113         _writer.open( _params._filepath, srcView.width(), srcView.height(), num_channels<typename SImg::view_t::value_type>::type::value, bitDepth );
00114         _writer.encode( pixels, bitDepth );
00115 }
00116 
00117 }
00118 }
00119 }
00120 }