TuttleOFX
1
|
00001 #include "BitDepthPlugin.hpp" 00002 #include "BitDepthProcess.hpp" 00003 #include "BitDepthDefinitions.hpp" 00004 00005 #include <tuttle/plugin/global.hpp> 00006 #include <ofxsImageEffect.h> 00007 #include <ofxsMultiThread.h> 00008 00009 namespace tuttle { 00010 namespace plugin { 00011 namespace bitDepth { 00012 00013 using namespace boost; 00014 using namespace boost::gil; 00015 00016 BitDepthPlugin::BitDepthPlugin( OfxImageEffectHandle handle ) 00017 : ImageEffectGilPlugin( handle ) 00018 { 00019 _paramOutBitDepth = fetchChoiceParam( kParamOutputBitDepth ); 00020 } 00021 00022 void BitDepthPlugin::getClipPreferences( OFX::ClipPreferencesSetter& clipPreferences ) 00023 { 00024 if( _paramOutBitDepth->getValue() != 0 ) 00025 { 00026 clipPreferences.setClipBitDepth( *_clipDst, static_cast<OFX::EBitDepth>( _paramOutBitDepth->getValue() ) ); 00027 } 00028 } 00029 00030 /** 00031 * @brief The overridden render function 00032 * @param[in] args Rendering parameters 00033 */ 00034 void BitDepthPlugin::render( const OFX::RenderArguments& args ) 00035 { 00036 // instantiate the render code based on the pixel depth of the dst clip 00037 const OFX::EBitDepth srcBitDepth = _clipSrc->getPixelDepth(); 00038 const OFX::EPixelComponent srcComponents = _clipSrc->getPixelComponents(); 00039 00040 switch( srcComponents ) 00041 { 00042 case OFX::ePixelComponentRGBA: 00043 { 00044 switch( srcBitDepth ) 00045 { 00046 case OFX::eBitDepthUByte: 00047 { 00048 setupDestView<rgba8_view_t>( args ); 00049 return; 00050 } 00051 case OFX::eBitDepthUShort: 00052 { 00053 setupDestView<rgba16_view_t>( args ); 00054 return; 00055 } 00056 case OFX::eBitDepthFloat: 00057 { 00058 setupDestView<rgba32f_view_t>( args ); 00059 return; 00060 } 00061 case OFX::eBitDepthCustom: 00062 case OFX::eBitDepthNone: 00063 { 00064 BOOST_THROW_EXCEPTION( OFX::Exception::Suite(kOfxStatErrUnsupported, "Bit depth (" + mapBitDepthEnumToString(srcBitDepth) + ") not recognized by the plugin." ) ); 00065 } 00066 } 00067 break; 00068 } 00069 case OFX::ePixelComponentRGB: 00070 { 00071 switch( srcBitDepth ) 00072 { 00073 case OFX::eBitDepthUByte: 00074 { 00075 setupDestView<rgb8_view_t>( args ); 00076 return; 00077 } 00078 case OFX::eBitDepthUShort: 00079 { 00080 setupDestView<rgb16_view_t>( args ); 00081 return; 00082 } 00083 case OFX::eBitDepthFloat: 00084 { 00085 setupDestView<rgb32f_view_t>( args ); 00086 return; 00087 } 00088 case OFX::eBitDepthCustom: 00089 case OFX::eBitDepthNone: 00090 { 00091 BOOST_THROW_EXCEPTION( exception::Unsupported() 00092 << exception::user() + "Bit depth (" + mapBitDepthEnumToString(srcBitDepth) + ") not recognized by the plugin." ); 00093 } 00094 } 00095 break; 00096 } 00097 case OFX::ePixelComponentAlpha: 00098 { 00099 switch( srcBitDepth ) 00100 { 00101 case OFX::eBitDepthUByte: 00102 { 00103 setupDestView<gray8_view_t>( args ); 00104 return; 00105 } 00106 case OFX::eBitDepthUShort: 00107 { 00108 setupDestView<gray16_view_t>( args ); 00109 return; 00110 } 00111 case OFX::eBitDepthFloat: 00112 { 00113 setupDestView<gray32f_view_t>( args ); 00114 return; 00115 } 00116 case OFX::eBitDepthCustom: 00117 case OFX::eBitDepthNone: 00118 { 00119 BOOST_THROW_EXCEPTION( exception::Unsupported() 00120 << exception::user() + "Bit depth (" + mapBitDepthEnumToString(srcBitDepth) + ") not recognized by the plugin." ); 00121 } 00122 } 00123 break; 00124 } 00125 case OFX::ePixelComponentCustom: 00126 case OFX::ePixelComponentNone: 00127 { 00128 BOOST_THROW_EXCEPTION( exception::Unsupported() 00129 << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(srcComponents) + ") not supported by the plugin." ); 00130 } 00131 } 00132 BOOST_THROW_EXCEPTION( exception::Unknown() ); 00133 } 00134 00135 /** 00136 * @brief Interpret source and then destination 00137 * @param[in] args Rendering parameters 00138 */ 00139 template<class sview_t> 00140 void BitDepthPlugin::setupDestView( const OFX::RenderArguments& args ) 00141 { 00142 const OFX::EBitDepth dstBitDepth = _clipDst->getPixelDepth(); 00143 const OFX::EPixelComponent dstComponents = _clipDst->getPixelComponents(); 00144 00145 switch( dstComponents ) 00146 { 00147 case OFX::ePixelComponentRGBA: 00148 { 00149 switch( dstBitDepth ) 00150 { 00151 case OFX::eBitDepthUByte: 00152 { 00153 BitDepthProcess<sview_t, rgba8_view_t> fred( *this ); 00154 fred.setupAndProcess( args ); 00155 return; 00156 } 00157 case OFX::eBitDepthUShort: 00158 { 00159 BitDepthProcess<sview_t, rgba16_view_t> fred( *this ); 00160 fred.setupAndProcess( args ); 00161 return; 00162 } 00163 case OFX::eBitDepthFloat: 00164 { 00165 BitDepthProcess<sview_t, rgba32f_view_t> fred( *this ); 00166 fred.setupAndProcess( args ); 00167 return; 00168 } 00169 case OFX::eBitDepthCustom: 00170 case OFX::eBitDepthNone: 00171 { 00172 BOOST_THROW_EXCEPTION( exception::Unsupported() 00173 << exception::user() + "Bit depth (" + mapBitDepthEnumToString(dstBitDepth) + ") not recognized by the plugin." ); 00174 } 00175 } 00176 break; 00177 } 00178 case OFX::ePixelComponentRGB: 00179 { 00180 switch( dstBitDepth ) 00181 { 00182 case OFX::eBitDepthUByte: 00183 { 00184 BitDepthProcess<sview_t, rgb8_view_t> fred( *this ); 00185 fred.setupAndProcess( args ); 00186 return; 00187 } 00188 case OFX::eBitDepthUShort: 00189 { 00190 BitDepthProcess<sview_t, rgb16_view_t> fred( *this ); 00191 fred.setupAndProcess( args ); 00192 return; 00193 } 00194 case OFX::eBitDepthFloat: 00195 { 00196 BitDepthProcess<sview_t, rgb32f_view_t> fred( *this ); 00197 fred.setupAndProcess( args ); 00198 return; 00199 } 00200 case OFX::eBitDepthCustom: 00201 case OFX::eBitDepthNone: 00202 { 00203 BOOST_THROW_EXCEPTION( exception::Unsupported() 00204 << exception::user() + "Bit depth (" + mapBitDepthEnumToString(dstBitDepth) + ") not recognized by the plugin." ); 00205 } 00206 } 00207 break; 00208 } 00209 case OFX::ePixelComponentAlpha: 00210 { 00211 switch( dstBitDepth ) 00212 { 00213 case OFX::eBitDepthUByte: 00214 { 00215 BitDepthProcess<sview_t, gray8_view_t> fred( *this ); 00216 fred.setupAndProcess( args ); 00217 return; 00218 } 00219 case OFX::eBitDepthUShort: 00220 { 00221 BitDepthProcess<sview_t, gray16_view_t> fred( *this ); 00222 fred.setupAndProcess( args ); 00223 return; 00224 } 00225 case OFX::eBitDepthFloat: 00226 { 00227 BitDepthProcess<sview_t, gray32f_view_t> fred( *this ); 00228 fred.setupAndProcess( args ); 00229 return; 00230 } 00231 case OFX::eBitDepthCustom: 00232 case OFX::eBitDepthNone: 00233 { 00234 BOOST_THROW_EXCEPTION( exception::Unsupported() 00235 << exception::user() + "Bit depth (" + mapBitDepthEnumToString(dstBitDepth) + ") not recognized by the plugin." ); 00236 } 00237 } 00238 break; 00239 } 00240 case OFX::ePixelComponentCustom: 00241 case OFX::ePixelComponentNone: 00242 { 00243 BOOST_THROW_EXCEPTION( exception::Unsupported() 00244 << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(dstComponents) + ") not supported by the plugin." ); 00245 } 00246 } 00247 BOOST_THROW_EXCEPTION( exception::Unknown() ); 00248 } 00249 00250 } 00251 } 00252 }