TuttleOFX
1
|
00001 #include "OCIOColorSpacePlugin.hpp" 00002 #include "OCIOColorSpaceProcess.hpp" 00003 00004 #include <tuttle/common/utils/color.hpp> 00005 00006 #include <boost/filesystem/operations.hpp> 00007 #include <boost/gil/gil_all.hpp> 00008 #include <boost/filesystem.hpp> 00009 00010 namespace OCIO = OCIO_NAMESPACE; 00011 00012 namespace bfs = boost::filesystem; 00013 00014 namespace tuttle 00015 { 00016 namespace plugin 00017 { 00018 namespace ocio 00019 { 00020 namespace colorspace 00021 { 00022 00023 using namespace boost::gil; 00024 00025 OCIOColorSpacePlugin::OCIOColorSpacePlugin(OfxImageEffectHandle handle, 00026 bool wasOCIOVarFund) : 00027 ImageEffectGilPlugin(handle), _wasOCIOVarFund(wasOCIOVarFund) 00028 { 00029 _paramFilename = fetchStringParam(kTuttlePluginFilename); 00030 _paramInputSpace = fetchChoiceParam(kParamInputSpace); 00031 _paramOutputSpace = fetchChoiceParam(kParamOutputSpace); 00032 00033 } 00034 00035 /** 00036 * @brief The overridden render function 00037 * @param[in] args Rendering parameters 00038 */ 00039 void 00040 OCIOColorSpacePlugin::render(const OFX::RenderArguments& args) 00041 { 00042 if (!_wasOCIOVarFund) 00043 { 00044 BOOST_THROW_EXCEPTION( 00045 exception::Unsupported() << exception::user() + "Tuttle.ocio.colorspace : an OCIO environnement variable must be set with a path to an OpenColorIO configuration file.\n "); 00046 } 00047 00048 using namespace boost::gil; 00049 // instantiate the render code based on the pixel depth of the dst clip 00050 OFX::EBitDepth bitDepth = _clipDst->getPixelDepth(); 00051 OFX::EPixelComponent components = _clipDst->getPixelComponents(); 00052 00053 // do the rendering 00054 switch (components) 00055 { 00056 case OFX::ePixelComponentRGBA: 00057 { 00058 switch (bitDepth) 00059 { 00060 case OFX::eBitDepthFloat: 00061 { 00062 doGilRender<OCIOColorSpaceProcess, false, rgba_layout_t, 00063 bits32f>(*this, args); 00064 return; 00065 } 00066 case OFX::eBitDepthUByte: 00067 case OFX::eBitDepthUShort: 00068 case OFX::eBitDepthCustom: 00069 case OFX::eBitDepthNone: 00070 { 00071 BOOST_THROW_EXCEPTION( 00072 exception::Unsupported() << exception::user() + "Bit depth (" + mapBitDepthEnumToString(bitDepth) + ") not recognized by the plugin."); 00073 } 00074 } 00075 break; 00076 } 00077 case OFX::ePixelComponentRGB: 00078 { 00079 switch (bitDepth) 00080 { 00081 case OFX::eBitDepthFloat: 00082 { 00083 doGilRender<OCIOColorSpaceProcess, false, rgb_layout_t, 00084 bits32f>(*this, args); 00085 return; 00086 } 00087 case OFX::eBitDepthUByte: 00088 case OFX::eBitDepthUShort: 00089 case OFX::eBitDepthCustom: 00090 case OFX::eBitDepthNone: 00091 { 00092 BOOST_THROW_EXCEPTION( 00093 exception::Unsupported() << exception::user() + "Bit depth (" + mapBitDepthEnumToString(bitDepth) + ") not recognized by the plugin."); 00094 } 00095 } 00096 break; 00097 } 00098 case OFX::ePixelComponentAlpha: //@todo support Alpha (mfe) 00099 case OFX::ePixelComponentCustom: 00100 case OFX::ePixelComponentNone: 00101 { 00102 BOOST_THROW_EXCEPTION( 00103 exception::Unsupported() << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(components) + ") not supported by the plugin."); 00104 } 00105 } 00106 BOOST_THROW_EXCEPTION( exception::Unknown()); 00107 } 00108 00109 OCIOColorSpaceProcessParams 00110 OCIOColorSpacePlugin::getProcessParams( 00111 const OfxPointD& renderScale) const 00112 { 00113 using namespace boost::filesystem; 00114 00115 OCIOColorSpaceProcessParams params; 00116 00117 ///Here change config Path if needed 00118 std::string str; 00119 _paramFilename->getValue(str); 00120 if (!bfs::exists(str)) 00121 { 00122 BOOST_THROW_EXCEPTION( 00123 exception::FileNotExist( ) << exception::filename( str )); 00124 } 00125 00126 // Get the OCIO configuration processor. 00127 params._config = OCIO::Config::CreateFromFile(str.c_str()); 00128 00129 int index; 00130 _paramInputSpace->getValue(index); 00131 params._inputSpace = params._config->getColorSpaceNameByIndex(index); 00132 _paramOutputSpace->getValue(index); 00133 params._outputSpace = params._config->getColorSpaceNameByIndex(index); 00134 00135 return params; 00136 } 00137 00138 } 00139 } 00140 } 00141 }