TuttleOFX
1
|
00001 #include "PngWriterDefinitions.hpp" 00002 #include "PngWriterPlugin.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/png_io.hpp> 00010 #include <boost/filesystem/fstream.hpp> 00011 #include <boost/filesystem/path.hpp> 00012 00013 namespace tuttle { 00014 namespace plugin { 00015 namespace png { 00016 namespace writer { 00017 00018 template<class View> 00019 PngWriterProcess<View>::PngWriterProcess( PngWriterPlugin& instance ) 00020 : ImageGilFilterProcessor<View>( instance, eImageOrientationFromTopToBottom ) 00021 , _plugin( instance ) 00022 { 00023 this->setNoMultiThreading(); 00024 } 00025 00026 template<class View> 00027 void PngWriterProcess<View>::setup( const OFX::RenderArguments& args ) 00028 { 00029 ImageGilFilterProcessor<View>::setup( args ); 00030 00031 _params = _plugin.getProcessParams( args.time ); 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 PngWriterProcess<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 switch( _params._bitDepth ) 00050 { 00051 case eTuttlePluginBitDepth8: 00052 writeImage<bits8>( srcView ); 00053 break; 00054 case eTuttlePluginBitDepth16: 00055 writeImage<bits16>( srcView ); 00056 break; 00057 } 00058 } 00059 catch( exception::Common& e ) 00060 { 00061 e << exception::filename( _params._filepath ); 00062 throw; 00063 } 00064 catch(... ) 00065 { 00066 BOOST_THROW_EXCEPTION( exception::Unknown() 00067 << exception::user( "Unable to write image") 00068 << exception::dev( boost::current_exception_diagnostic_information() ) 00069 << exception::filename( _params._filepath ) ); 00070 } 00071 copy_pixels( this->_srcView, this->_dstView ); /// @todo ? 00072 } 00073 00074 /** 00075 * 00076 */ 00077 template<class View> 00078 template<class Bits> 00079 void PngWriterProcess<View>::writeImage( View& src ) 00080 { 00081 using namespace boost::gil; 00082 using namespace terry; 00083 00084 switch( _params._components ) 00085 { 00086 case eTuttlePluginComponentsAuto: 00087 { 00088 switch ( _plugin._clipSrc->getPixelComponents() ) 00089 { 00090 case OFX::ePixelComponentAlpha: 00091 { 00092 typedef pixel<Bits, gray_layout_t> OutPixelType; 00093 png_write_view( _params._filepath, color_converted_view<OutPixelType>( src ) ); 00094 break; 00095 } 00096 case OFX::ePixelComponentRGB: 00097 { 00098 typedef pixel<Bits, rgb_layout_t> OutPixelType; 00099 png_write_view( _params._filepath, color_converted_view<OutPixelType>( src ) ); 00100 break; 00101 } 00102 case OFX::ePixelComponentRGBA: 00103 { 00104 typedef pixel<Bits, rgba_layout_t> OutPixelType; 00105 png_write_view( _params._filepath, color_converted_view<OutPixelType>( src ) ); 00106 break; 00107 } 00108 default: 00109 { 00110 BOOST_THROW_EXCEPTION( exception::Unsupported() 00111 << exception::user( "Png Writer: components not supported" ) ); 00112 break; 00113 } 00114 } 00115 break; 00116 } 00117 case eTuttlePluginComponentsRGBA: 00118 { 00119 typedef pixel<Bits, rgba_layout_t> OutPixelType; 00120 png_write_view( _params._filepath, color_converted_view<OutPixelType>( src ) ); 00121 break; 00122 } 00123 case eTuttlePluginComponentsRGB: 00124 { 00125 typedef pixel<Bits, rgb_layout_t> OutPixelType; 00126 png_write_view( _params._filepath, color_converted_view<OutPixelType>( src ) ); 00127 break; 00128 } 00129 case eTuttlePluginComponentsGray: 00130 { 00131 typedef pixel<Bits, gray_layout_t> OutPixelType; 00132 png_write_view( _params._filepath, color_converted_view<OutPixelType>( src ) ); 00133 break; 00134 } 00135 } 00136 } 00137 00138 } 00139 } 00140 } 00141 }