TuttleOFX
1
|
00001 #include "PngReaderPlugin.hpp" 00002 #include "PngReaderProcess.hpp" 00003 #include "PngReaderDefinitions.hpp" 00004 00005 #include "PngEngine/png_adds.hpp" 00006 00007 #include <tuttle/plugin/context/ReaderPlugin.hpp> 00008 00009 #include <boost/gil/gil_all.hpp> 00010 #include <boost/filesystem.hpp> 00011 #include <boost/exception/all.hpp> 00012 00013 namespace tuttle { 00014 namespace plugin { 00015 namespace png { 00016 namespace reader { 00017 00018 namespace bfs = boost::filesystem; 00019 00020 PngReaderPlugin::PngReaderPlugin( OfxImageEffectHandle handle ) 00021 : ReaderPlugin( handle ) 00022 {} 00023 00024 PngReaderProcessParams PngReaderPlugin::getProcessParams( const OfxTime time ) 00025 { 00026 PngReaderProcessParams params; 00027 00028 params._filepath = getAbsoluteFilenameAt( time ); 00029 return params; 00030 } 00031 00032 void PngReaderPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName ) 00033 { 00034 ReaderPlugin::changedParam( args, paramName ); 00035 } 00036 00037 bool PngReaderPlugin::getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod ) 00038 { 00039 const std::string filename( getAbsoluteFilenameAt( args.time ) ); 00040 if( ! boost::filesystem::exists( filename ) ) 00041 { 00042 BOOST_THROW_EXCEPTION( exception::FileInSequenceNotExist() 00043 << exception::user( "PNG: Unable to open file" ) 00044 << exception::filename( filename ) ); 00045 } 00046 00047 try 00048 { 00049 point2<ptrdiff_t> pngDims = png_read_dimensions( filename ); 00050 rod.x1 = 0; 00051 rod.x2 = pngDims.x * this->_clipDst->getPixelAspectRatio(); 00052 rod.y1 = 0; 00053 rod.y2 = pngDims.y; 00054 TUTTLE_TLOG_VAR( TUTTLE_INFO, rod ); 00055 } 00056 catch( std::exception& e ) 00057 { 00058 BOOST_THROW_EXCEPTION( exception::FileNotExist() 00059 << exception::user( "PNG: Unable to open file" ) 00060 << exception::dev( e.what() ) 00061 << exception::filename( filename ) ); 00062 } 00063 return true; 00064 } 00065 00066 void PngReaderPlugin::getClipPreferences( OFX::ClipPreferencesSetter& clipPreferences ) 00067 { 00068 ReaderPlugin::getClipPreferences( clipPreferences ); 00069 const std::string filename( getAbsoluteFirstFilename() ); 00070 00071 if( getExplicitBitDepthConversion() == eParamReaderBitDepthAuto ) 00072 { 00073 OFX::EBitDepth bd = OFX::eBitDepthNone; 00074 if( ! boost::filesystem::exists( filename ) ) 00075 { 00076 BOOST_THROW_EXCEPTION( exception::FileNotExist() 00077 << exception::user( "PNG: Unable to open file" ) 00078 << exception::filename( filename ) ); 00079 } 00080 int bitDepth; 00081 bitDepth = png_read_precision( filename ); 00082 00083 switch( bitDepth ) 00084 { 00085 case 8: 00086 bd = OFX::eBitDepthUByte; 00087 break; 00088 case 16: 00089 bd = OFX::eBitDepthUShort; 00090 break; 00091 default: 00092 BOOST_THROW_EXCEPTION( exception::ImageFormat() ); 00093 } 00094 clipPreferences.setClipBitDepth( *this->_clipDst, bd ); 00095 } 00096 00097 if( getExplicitChannelConversion() == eParamReaderChannelAuto ) 00098 { 00099 switch( png_read_color_type( filename ) ) 00100 { 00101 case 0 : 00102 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentAlpha ); 00103 break; 00104 case 2 : 00105 if( OFX::getImageEffectHostDescription()->supportsPixelComponent( OFX::ePixelComponentRGB ) ) 00106 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGB ); 00107 else 00108 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGBA ); 00109 break; 00110 case 6 : 00111 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGBA ); 00112 break; 00113 default: 00114 clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGBA ); 00115 break; 00116 } 00117 } 00118 00119 clipPreferences.setPixelAspectRatio( *this->_clipDst, 1.0 ); 00120 00121 } 00122 00123 /** 00124 * @brief The overridden render function 00125 * @param[in] args Rendering parameters 00126 */ 00127 void PngReaderPlugin::render( const OFX::RenderArguments& args ) 00128 { 00129 ReaderPlugin::render( args ); 00130 doGilRender<PngReaderProcess>( *this, args ); 00131 } 00132 00133 } 00134 } 00135 } 00136 }