TuttleOFX
1
|
00001 #include "ColorSpacePluginFactory.hpp" 00002 #include "ColorSpacePlugin.hpp" 00003 #include "ColorSpaceDefinitions.hpp" 00004 00005 #include <tuttle/plugin/exceptions.hpp> 00006 00007 #include <ofxsImageEffect.h> 00008 #include <ofxsMultiThread.h> 00009 00010 00011 namespace tuttle { 00012 namespace plugin { 00013 namespace colorspace { 00014 00015 namespace ttlc = tuttle::plugin::color; 00016 00017 /** 00018 * @brief Function called to describe the plugin main features. 00019 * @param[in, out] desc Effect descriptor 00020 */ 00021 void ColorSpacePluginFactory::describe( OFX::ImageEffectDescriptor& desc ) 00022 { 00023 desc.setLabels ( "TuttleColorSpace", "ColorSpace", 00024 "Color convertions" ); 00025 desc.setPluginGrouping ( "tuttle/image/process/color" ); 00026 00027 // add the supported contexts 00028 desc.addSupportedContext ( OFX::eContextFilter ); 00029 desc.addSupportedContext ( OFX::eContextGeneral ); 00030 00031 // add supported pixel depths 00032 desc.addSupportedBitDepth ( OFX::eBitDepthUByte ); 00033 desc.addSupportedBitDepth ( OFX::eBitDepthUShort ); 00034 desc.addSupportedBitDepth ( OFX::eBitDepthFloat ); 00035 00036 // plugin flags 00037 desc.setSupportsTiles ( kSupportTiles ); 00038 desc.setRenderThreadSafety ( OFX::eRenderFullySafe ); 00039 } 00040 00041 /** 00042 * @brief Function called to describe the plugin controls and features. 00043 * @param[in, out] desc Effect descriptor 00044 * @param[in] context Application context 00045 */ 00046 void ColorSpacePluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc, 00047 OFX::EContext context ) 00048 { 00049 OFX::ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName ); 00050 srcClip->addSupportedComponent ( OFX::ePixelComponentRGBA ); 00051 srcClip->addSupportedComponent ( OFX::ePixelComponentRGB ); 00052 srcClip->addSupportedComponent ( OFX::ePixelComponentAlpha ); 00053 srcClip->setSupportsTiles ( kSupportTiles ); 00054 00055 // Create the mandated output clip 00056 OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName ); 00057 dstClip->addSupportedComponent ( OFX::ePixelComponentRGBA ); 00058 dstClip->addSupportedComponent ( OFX::ePixelComponentRGB ); 00059 dstClip->addSupportedComponent ( OFX::ePixelComponentAlpha ); 00060 dstClip->setSupportsTiles ( kSupportTiles ); 00061 00062 /* ----------------------- INPUT PARAMETERS -------------------------- */ 00063 00064 OFX::GroupParamDescriptor* inGroup = desc.defineGroupParam( kColorSpaceIn ); 00065 inGroup->setLabel ( "Input configuration" ); 00066 00067 OFX::ChoiceParamDescriptor* inReferenceSpace = desc.defineChoiceParam( kColorSpaceReferenceSpaceIn ); 00068 inReferenceSpace->setLabel ( "Reference Space" ); 00069 inReferenceSpace->setParent ( inGroup ); 00070 00071 OFX::GroupParamDescriptor* inCustom = desc.defineGroupParam( kColorSpaceCustomizedIn ); 00072 inCustom->setLabel ( "Custom" ); 00073 inCustom->setOpen ( false ); 00074 inCustom->setParent ( inGroup ); 00075 00076 OFX::ChoiceParamDescriptor* inGradationLaw = desc.defineChoiceParam( kColorSpaceGradationLawIn ); 00077 inGradationLaw->setLabel ( "Gradation Law" ); 00078 inGradationLaw->setParent ( inCustom ); 00079 00080 OFX::DoubleParamDescriptor* inGammaValue = desc.defineDoubleParam( kColorSpaceInGammaValue ); 00081 inGammaValue->setLabel ( "Gamma" ); 00082 inGammaValue->setDefault ( 1.0 ); 00083 inGammaValue->setRange ( 0.0, std::numeric_limits<double>::max() ); 00084 inGammaValue->setDisplayRange ( 0.0, 5.0 ); 00085 inGammaValue->setHint ( "Adjust the Gamma." ); 00086 inGammaValue->setParent ( inCustom ); 00087 00088 OFX::DoubleParamDescriptor* inBlackPoint = desc.defineDoubleParam( kColorSpaceInBlackPoint ); 00089 inBlackPoint->setLabel ( "Black Point" ); 00090 inBlackPoint->setDefault ( 0.0 ); 00091 inBlackPoint->setRange ( 0.0, 1.0 ); 00092 inBlackPoint->setDisplayRange ( 0.0, 1.0 ); 00093 inBlackPoint->setHint ( "Adjust the Black Point." ); 00094 inBlackPoint->setParent ( inCustom ); 00095 00096 OFX::DoubleParamDescriptor* inWhitePoint = desc.defineDoubleParam( kColorSpaceInWhitePoint ); 00097 inWhitePoint->setLabel ( "White Point" ); 00098 inWhitePoint->setDefault ( 1.0 ); 00099 inWhitePoint->setRange ( 0.0, 1.0 ); 00100 inWhitePoint->setDisplayRange ( 0.0, 1.0 ); 00101 inWhitePoint->setHint ( "Adjust the White Point." ); 00102 inWhitePoint->setParent ( inCustom ); 00103 00104 OFX::DoubleParamDescriptor* inGammaSensito = desc.defineDoubleParam( kColorSpaceInGammaSensito ); 00105 inGammaSensito->setLabel ( "Gamma Sensito" ); 00106 inGammaSensito->setDefault ( 1.0 ); 00107 inGammaSensito->setRange ( 0.0, std::numeric_limits<double>::max() ); 00108 inGammaSensito->setDisplayRange ( 0.0, 5.0 ); 00109 inGammaSensito->setHint ( "Adjust the Gamma Sensito." ); 00110 inGammaSensito->setParent ( inCustom ); 00111 00112 OFX::ChoiceParamDescriptor* inLayout = desc.defineChoiceParam( kColorSpaceLayoutIn ); 00113 inLayout->setLabel ( "Layout" ); 00114 inLayout->setParent ( inCustom ); 00115 00116 OFX::ChoiceParamDescriptor* inTempColor = desc.defineChoiceParam( kColorSpaceTempColorIn ); 00117 inTempColor->setLabel ( "Color Temperature" ); 00118 inTempColor->setHint ( "Select the color temperature." ); 00119 inTempColor->setParent ( inCustom ); 00120 00121 OFX::GroupParamDescriptor* inPrimaries = desc.defineGroupParam( kColorSpacePrimariesIn ); 00122 inPrimaries->setLabel ( "Primaries color" ); 00123 inPrimaries->setOpen ( false ); 00124 inPrimaries->setParent ( inCustom ); 00125 00126 OFX::DoubleParamDescriptor* inXr = desc.defineDoubleParam( kColorSpaceXrIn ); 00127 inXr->setLabel ( "X red" ); 00128 inXr->setDefault ( 1.0 ); 00129 inXr->setRange ( 0.0, 1.0 ); 00130 inXr->setDisplayRange ( 0.0, 1.0 ); 00131 inXr->setHint ( "Adjust the X red primary color." ); 00132 inXr->setParent ( inPrimaries ); 00133 00134 OFX::DoubleParamDescriptor* inYr = desc.defineDoubleParam( kColorSpaceYrIn ); 00135 inYr->setLabel ( "Y red" ); 00136 inYr->setDefault ( 1.0 ); 00137 inYr->setRange ( 0.0, 1.0 ); 00138 inYr->setDisplayRange ( 0.0, 1.0 ); 00139 inYr->setHint ( "Adjust the Y red primary color." ); 00140 inYr->setParent ( inPrimaries ); 00141 00142 OFX::DoubleParamDescriptor* inXg = desc.defineDoubleParam( kColorSpaceXgIn ); 00143 inXg->setLabel ( "X green" ); 00144 inXg->setDefault ( 1.0 ); 00145 inXg->setRange ( 0.0, 1.0 ); 00146 inXg->setDisplayRange ( 0.0, 1.0 ); 00147 inXg->setHint ( "Adjust the X green primary color." ); 00148 inXg->setParent ( inPrimaries ); 00149 00150 OFX::DoubleParamDescriptor* inYg = desc.defineDoubleParam( kColorSpaceYgIn ); 00151 inYg->setLabel ( "Y green" ); 00152 inYg->setDefault ( 1.0 ); 00153 inYg->setRange ( 0.0, 1.0 ); 00154 inYg->setDisplayRange ( 0.0, 1.0 ); 00155 inYg->setHint ( "Adjust the Y green primary color." ); 00156 inYg->setParent ( inPrimaries ); 00157 00158 OFX::DoubleParamDescriptor* inXb = desc.defineDoubleParam( kColorSpaceXbIn ); 00159 inXb->setLabel ( "X blue" ); 00160 inXb->setDefault ( 1.0 ); 00161 inXb->setRange ( 0.0, 1.0 ); 00162 inXb->setDisplayRange ( 0.0, 1.0 ); 00163 inXb->setHint ( "Adjust the X blue primary color." ); 00164 inXb->setParent ( inPrimaries ); 00165 00166 OFX::DoubleParamDescriptor* inYb = desc.defineDoubleParam( kColorSpaceYbIn ); 00167 inYb->setLabel ( "Y blue" ); 00168 inYb->setDefault ( 1.0 ); 00169 inYb->setRange ( 0.0, 1.0 ); 00170 inYb->setDisplayRange ( 0.0, 1.0 ); 00171 inYb->setHint ( "Adjust the Y blue primary color." ); 00172 inYb->setParent ( inPrimaries ); 00173 00174 /* ----------------------- OUTPUT PARAMETERS -------------------------- */ 00175 00176 OFX::GroupParamDescriptor* outGroup = desc.defineGroupParam( kColorSpaceOut ); 00177 outGroup->setLabel ( "Output configuration" ); 00178 00179 OFX::ChoiceParamDescriptor* outReferenceSpace = desc.defineChoiceParam( kColorSpaceReferenceSpaceOut ); 00180 outReferenceSpace->setLabel ( "Reference Space" ); 00181 outReferenceSpace->setParent ( outGroup ); 00182 00183 OFX::GroupParamDescriptor* outCustom = desc.defineGroupParam( kColorSpaceCustomizedOut ); 00184 outCustom->setLabel ( "Custom" ); 00185 outCustom->setOpen ( false ); 00186 outCustom->setParent ( outGroup ); 00187 00188 OFX::ChoiceParamDescriptor* outGradationLaw = desc.defineChoiceParam( kColorSpaceGradationLawOut ); 00189 outGradationLaw->setLabel ( "Gradation Law" ); 00190 outGradationLaw->setParent ( outCustom ); 00191 00192 OFX::DoubleParamDescriptor* outGammaValue = desc.defineDoubleParam( kColorSpaceOutGammaValue ); 00193 outGammaValue->setLabel ( "Gamma" ); 00194 outGammaValue->setDefault ( 1.0 ); 00195 outGammaValue->setRange ( 0.0, std::numeric_limits<double>::max() ); 00196 outGammaValue->setDisplayRange ( 0.0, 5.0 ); 00197 outGammaValue->setHint ( "Adjust the Gamma." ); 00198 outGammaValue->setParent ( outCustom ); 00199 00200 OFX::DoubleParamDescriptor* outBlackPoint = desc.defineDoubleParam( kColorSpaceOutBlackPoint ); 00201 outBlackPoint->setLabel ( "Black Point" ); 00202 outBlackPoint->setDefault ( 0.0 ); 00203 outBlackPoint->setRange ( 0.0, 1.0 ); 00204 outBlackPoint->setDisplayRange ( 0.0, 1.0 ); 00205 outBlackPoint->setHint ( "Adjust the Black Point." ); 00206 outBlackPoint->setParent ( outCustom ); 00207 00208 OFX::DoubleParamDescriptor* outWhitePoint = desc.defineDoubleParam( kColorSpaceOutWhitePoint ); 00209 outWhitePoint->setLabel ( "White Point" ); 00210 outWhitePoint->setDefault ( 1.0 ); 00211 outWhitePoint->setRange ( 0.0, 1.0 ); 00212 outWhitePoint->setDisplayRange ( 0.0, 1.0 ); 00213 outWhitePoint->setHint ( "Adjust the White Point." ); 00214 outWhitePoint->setParent ( outCustom ); 00215 00216 OFX::DoubleParamDescriptor* outGammaSensito = desc.defineDoubleParam( kColorSpaceOutGammaSensito ); 00217 outGammaSensito->setLabel ( "Gamma Sensito" ); 00218 outGammaSensito->setDefault ( 1.0 ); 00219 outGammaSensito->setRange ( 0.0, std::numeric_limits<double>::max() ); 00220 outGammaSensito->setDisplayRange ( 0.0, 5.0 ); 00221 outGammaSensito->setHint ( "Adjust the Gamma Sensito." ); 00222 outGammaSensito->setParent ( outCustom ); 00223 00224 OFX::ChoiceParamDescriptor* outLayout = desc.defineChoiceParam( kColorSpaceLayoutOut ); 00225 outLayout->setLabel ( "Layout" ); 00226 outLayout->setParent ( outCustom ); 00227 00228 OFX::ChoiceParamDescriptor* outTempColor = desc.defineChoiceParam( kColorSpaceTempColorOut ); 00229 outTempColor->setLabel ( "Color Temperature" ); 00230 outTempColor->setHint ( "Select the color temperature." ); 00231 outTempColor->setParent ( outCustom ); 00232 00233 OFX::GroupParamDescriptor* outPrimaries = desc.defineGroupParam( kColorSpacePrimariesOut ); 00234 outPrimaries->setLabel ( "Primaries color" ); 00235 outPrimaries->setOpen ( false ); 00236 outPrimaries->setParent ( outCustom ); 00237 00238 OFX::DoubleParamDescriptor* outXr = desc.defineDoubleParam( kColorSpaceXrOut ); 00239 outXr->setLabel ( "X red" ); 00240 outXr->setDefault ( 1.0 ); 00241 outXr->setRange ( 0.0, 1.0 ); 00242 outXr->setDisplayRange ( 0.0, 1.0 ); 00243 outXr->setHint ( "Adjust the X red primary color." ); 00244 outXr->setParent ( outPrimaries ); 00245 00246 OFX::DoubleParamDescriptor* outYr = desc.defineDoubleParam( kColorSpaceYrOut ); 00247 outYr->setLabel ( "Y red" ); 00248 outYr->setDefault ( 1.0 ); 00249 outYr->setRange ( 0.0, 1.0 ); 00250 outYr->setDisplayRange ( 0.0, 1.0 ); 00251 outYr->setHint ( "Adjust the Y red primary color." ); 00252 outYr->setParent ( outPrimaries ); 00253 00254 OFX::DoubleParamDescriptor* outXg = desc.defineDoubleParam( kColorSpaceXgOut ); 00255 outXg->setLabel ( "X green" ); 00256 outXg->setDefault ( 1.0 ); 00257 outXg->setRange ( 0.0, 1.0 ); 00258 outXg->setDisplayRange ( 0.0, 1.0 ); 00259 outXg->setHint ( "Adjust the X green primary color." ); 00260 outXg->setParent ( outPrimaries ); 00261 00262 OFX::DoubleParamDescriptor* outYg = desc.defineDoubleParam( kColorSpaceYgOut ); 00263 outYg->setLabel ( "Y green" ); 00264 outYg->setDefault ( 1.0 ); 00265 outYg->setRange ( 0.0, 1.0 ); 00266 outYg->setDisplayRange ( 0.0, 1.0 ); 00267 outYg->setHint ( "Adjust the Y green primary color." ); 00268 outYg->setParent ( outPrimaries ); 00269 00270 OFX::DoubleParamDescriptor* outXb = desc.defineDoubleParam( kColorSpaceXbOut ); 00271 outXb->setLabel ( "X blue" ); 00272 outXb->setDefault ( 1.0 ); 00273 outXb->setRange ( 0.0, 1.0 ); 00274 outXb->setDisplayRange ( 0.0, 1.0 ); 00275 outXb->setHint ( "Adjust the X blue primary color." ); 00276 outXb->setParent ( outPrimaries ); 00277 00278 OFX::DoubleParamDescriptor* outYb = desc.defineDoubleParam( kColorSpaceYbOut ); 00279 outYb->setLabel ( "Y blue" ); 00280 outYb->setDefault ( 1.0 ); 00281 outYb->setRange ( 0.0, 1.0 ); 00282 outYb->setDisplayRange ( 0.0, 1.0 ); 00283 outYb->setHint ( "Adjust the Y blue primary color." ); 00284 outYb->setParent ( outPrimaries ); 00285 00286 /* -------------- ENUMS FILLING ----------------*/ 00287 00288 ttlc::ColorSpaceMaps csMaps; 00289 ttlc::ColorSpaceMap mapReferenceSpace = csMaps.getMapReferenceSpaces(); 00290 ttlc::ColorSpaceMap mapGradationLaw = csMaps.getMapGradationLaw(); 00291 ttlc::ColorSpaceMap mapLayout = csMaps.getMapLayout(); 00292 ttlc::ColorSpaceMap mapColourTemp = csMaps.getMapColourTemp(); 00293 ttlc::ColorSpaceMap::iterator it; 00294 ttlc::ColorSpacePair highest; 00295 00296 /* Reference Space */ 00297 highest = *mapReferenceSpace.rbegin(); // last element 00298 it = mapReferenceSpace.begin(); 00299 do { 00300 inReferenceSpace->appendOption ( (*it).second ); 00301 outReferenceSpace->appendOption ( (*it).second ); 00302 00303 } while ( mapReferenceSpace.value_comp()(*it++, highest) ); 00304 00305 it = mapReferenceSpace.begin(); 00306 inReferenceSpace->setDefault ( (*it).first ); 00307 outReferenceSpace->setDefault ( (*it).first ); 00308 00309 /* Gradation */ 00310 highest = *mapGradationLaw.rbegin(); 00311 it = mapGradationLaw.begin(); 00312 do { 00313 inGradationLaw->appendOption ( (*it).second ); 00314 outGradationLaw->appendOption ( (*it).second ); 00315 00316 } while ( mapGradationLaw.value_comp()(*it++, highest) ); 00317 00318 it = mapGradationLaw.begin(); 00319 inGradationLaw->setDefault ( (*it).first ); 00320 outGradationLaw->setDefault ( (*it).first ); 00321 00322 /* Layout */ 00323 highest = *mapLayout.rbegin(); 00324 it = mapLayout.begin(); 00325 do { 00326 inLayout->appendOption ( (*it).second ); 00327 outLayout->appendOption ( (*it).second ); 00328 00329 } while ( mapLayout.value_comp()(*it++, highest) ); 00330 00331 it = mapLayout.begin(); 00332 inLayout->setDefault ( (*it).first ); 00333 outLayout->setDefault ( (*it).first ); 00334 00335 /* Colour temperature */ 00336 highest = *mapColourTemp.rbegin(); 00337 it = mapColourTemp.begin(); 00338 do { 00339 inTempColor->appendOption ( (*it).second ); 00340 outTempColor->appendOption ( (*it).second ); 00341 00342 } while ( mapColourTemp.value_comp()(*it++, highest) ); 00343 00344 it = mapColourTemp.begin(); 00345 inTempColor->setDefault ( (*it).first ); 00346 outTempColor->setDefault ( (*it).first ); 00347 } 00348 00349 /** 00350 * @brief Function called to create a plugin effect instance 00351 * @param[in] handle effect handle 00352 * @param[in] context Application context 00353 * @return plugin instance 00354 */ 00355 OFX::ImageEffect* ColorSpacePluginFactory::createInstance( OfxImageEffectHandle handle, 00356 OFX::EContext context ) 00357 { 00358 return new ColorSpacePlugin( handle ); 00359 } 00360 00361 } 00362 } 00363 }