TuttleOFX  1
DPXReaderPlugin.cpp
Go to the documentation of this file.
00001 #include "DPXReaderPlugin.hpp"
00002 #include "DPXReaderProcess.hpp"
00003 #include "DPXReaderDefinitions.hpp"
00004 
00005 #include <boost/gil/gil_all.hpp>
00006 #include <boost/filesystem.hpp>
00007 
00008 namespace tuttle {
00009 namespace plugin {
00010 namespace dpx {
00011 namespace reader {
00012 
00013 using namespace boost::filesystem;
00014 using namespace tuttle::io;
00015 using namespace boost::gil;
00016 
00017 DPXReaderPlugin::DPXReaderPlugin( OfxImageEffectHandle handle )
00018         : ReaderPlugin( handle )
00019 {}
00020 
00021 DPXReaderProcessParams DPXReaderPlugin::getProcessParams( const OfxTime time )
00022 {
00023         DPXReaderProcessParams params;
00024 
00025         params._filepath = getAbsoluteFilenameAt( time );
00026 
00027         return params;
00028 }
00029 
00030 void DPXReaderPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName )
00031 {
00032         ReaderPlugin::changedParam( args, paramName );
00033         if( paramName == kParamDisplayHeader )
00034         {
00035                 tuttle::io::DpxImage dpxImg;
00036                 dpxImg.readHeader( getAbsoluteFilenameAt( args.time ) );
00037                 std::ostringstream headerStr;
00038                 headerStr << "DPX HEADER:" << std::endl;
00039                 headerStr << dpxImg.getHeader();
00040 
00041                 TUTTLE_TLOG( TUTTLE_INFO, headerStr.str() );
00042 
00043                 sendMessage( OFX::Message::eMessageMessage,
00044                                          "", // No XML resources
00045                                          headerStr.str() );
00046         }
00047 }
00048 
00049 bool DPXReaderPlugin::getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod )
00050 {
00051         tuttle::io::DpxImage dpxImg;
00052 
00053         dpxImg.readHeader( getAbsoluteFilenameAt( args.time ) );
00054         rod.x1 = 0;
00055         rod.x2 = dpxImg.width() * this->_clipDst->getPixelAspectRatio();
00056         rod.y1 = 0;
00057         rod.y2 = dpxImg.height();
00058         return true;
00059 }
00060 
00061 void DPXReaderPlugin::getClipPreferences( OFX::ClipPreferencesSetter& clipPreferences )
00062 {
00063         ReaderPlugin::getClipPreferences( clipPreferences );
00064         const std::string filename( getAbsoluteFirstFilename() );
00065 
00066         DpxImage dpxImg;
00067         dpxImg.readHeader( filename );
00068 
00069         if( getExplicitConversion() == eParamReaderExplicitConversionAuto )
00070         {
00071                 OFX::EBitDepth bd = OFX::eBitDepthNone;
00072                 switch( dpxImg.componentsType() )
00073                 {
00074                         case DpxImage::eCompTypeR8G8B8:
00075                         case DpxImage::eCompTypeR8G8B8A8:
00076                         case DpxImage::eCompTypeA8B8G8R8:
00077                         {
00078                                 bd = OFX::eBitDepthUByte;
00079                                 break;
00080                         }
00081                         case DpxImage::eCompTypeR10G10B10:
00082                         case DpxImage::eCompTypeR10G10B10A10:
00083                         case DpxImage::eCompTypeA10B10G10R10:
00084                         case DpxImage::eCompTypeR12G12B12:
00085                         case DpxImage::eCompTypeR12G12B12A12:
00086                         case DpxImage::eCompTypeA12B12G12R12:
00087                         case DpxImage::eCompTypeR16G16B16:
00088                         case DpxImage::eCompTypeR16G16B16A16:
00089                         case DpxImage::eCompTypeA16B16G16R16:
00090                         {
00091                                 bd = OFX::eBitDepthUShort;
00092                                 break;
00093                         }
00094                         default:
00095                                 bd = OFX::eBitDepthFloat;
00096                 }
00097 
00098                 clipPreferences.setClipBitDepth( *_clipDst, bd );
00099         }
00100         switch( dpxImg.components() )
00101         {
00102                 case 3:
00103                 {
00104                         clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGB );
00105                         break;
00106                 }
00107 
00108                 case 4:
00109                 {
00110                         clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGBA );
00111                         break;
00112                 }
00113                 default:
00114                 {
00115                         clipPreferences.setClipComponents( *this->_clipDst, OFX::ePixelComponentRGBA );
00116                         break;
00117                 }
00118         }
00119 
00120         clipPreferences.setPixelAspectRatio( *this->_clipDst, 1.0 );
00121 }
00122 /**
00123  * @brief The overridden render function
00124  * @param[in]   args     Rendering parameters
00125  */
00126 void DPXReaderPlugin::render( const OFX::RenderArguments& args )
00127 {
00128         ReaderPlugin::render( args );
00129 
00130         // instantiate the render code based on the pixel depth of the dst clip
00131         OFX::EBitDepth bitDepth         = _clipDst->getPixelDepth();
00132         OFX::EPixelComponent components = _clipDst->getPixelComponents();
00133 
00134         switch( components )
00135         {
00136                 case OFX::ePixelComponentRGBA:
00137                 {
00138                         doGilRender<DPXReaderProcess, false, rgba_layout_t>( *this, args, bitDepth );
00139                         return;
00140                 }
00141                 case OFX::ePixelComponentRGB:
00142                 {
00143                         doGilRender<DPXReaderProcess, false, rgb_layout_t>( *this, args, bitDepth );
00144                         return;
00145                 }
00146                 case OFX::ePixelComponentAlpha:
00147                 case OFX::ePixelComponentCustom:
00148                 case OFX::ePixelComponentNone:
00149                 {
00150                         BOOST_THROW_EXCEPTION( exception::Unsupported()
00151                                 << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(components) + ") not supported by the plugin." );
00152                 }
00153         }
00154         BOOST_THROW_EXCEPTION( exception::Unknown() );
00155 }
00156 
00157 }
00158 }
00159 }
00160 }