From 4bdf4913ea4f4dd1fbdd8a98b0eb81bd78591f5d Mon Sep 17 00:00:00 2001 From: "Guido (Assimilate)" <121864985+Guido-assim@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:08:33 +0200 Subject: [PATCH] Update colourspace.cpp Do not set kOfxImageClipPropPreferredColourspaces for the output clip. Handle kOfxImageEffectActionGetOutputColourspace to set the output colourspace. Signed-off-by: Guido Veldkamp --- Examples/ColourSpace/colourspace.cpp | 80 ++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/Examples/ColourSpace/colourspace.cpp b/Examples/ColourSpace/colourspace.cpp index 57354e48..dbb4ecc8 100644 --- a/Examples/ColourSpace/colourspace.cpp +++ b/Examples/ColourSpace/colourspace.cpp @@ -358,11 +358,8 @@ getClipPreferences( OfxImageEffectHandle effect, OfxPropertySetHandle /*inArgs const char *componentStr = isRGBA ? kOfxImageComponentRGBA : kOfxImageComponentAlpha; std::string preferredInputSpace; - std::string preferredOutputSpace; int preferredInputSpaceIndex; - int preferredOutputSpaceIndex; gParamHost->paramGetValue(myData->inputSpaceParam, &preferredInputSpaceIndex); - gParamHost->paramGetValue(myData->outputSpaceParam, &preferredOutputSpaceIndex); switch (preferredInputSpaceIndex) { case 0: @@ -379,21 +376,6 @@ getClipPreferences( OfxImageEffectHandle effect, OfxPropertySetHandle /*inArgs break; } - switch (preferredOutputSpaceIndex) { - case 0: - preferredOutputSpace = kOfxColourspaceACEScg; - break; - case 1: - preferredOutputSpace = kOfxColourspaceLinRec2020; - break; - case 2: - preferredOutputSpace = kOfxColourspaceSrgbTx; - break; - case 3: - preferredOutputSpace = kOfxColourspaceACEScct; - break; - } - // set our output to be the same same as the input, component and bitdepth gPropHost->propSetString(outArgs, "OfxImageClipPropComponents_Output", 0, componentStr); if(gHostSupportsMultipleBitDepths) @@ -415,10 +397,6 @@ getClipPreferences( OfxImageEffectHandle effect, OfxPropertySetHandle /*inArgs i, colourSpaces[i]); } } - - if (!preferredOutputSpace.empty()) - gPropHost->propSetString(outArgs, kOfxImageClipPropPreferredColourspaces "_Output", 0, preferredOutputSpace.c_str()); - } else { spdlog::info("Host does not support colour management (this example won't be very interesting)"); } @@ -427,6 +405,60 @@ getClipPreferences( OfxImageEffectHandle effect, OfxPropertySetHandle /*inArgs return kOfxStatOK; } +static void setClipColourspace(const OfxImageClipHandle clip, const std::string &colourspace) { + OfxPropertySetHandle clipProps; + gEffectHost->clipGetPropertySet(clip, &clipProps); + gPropHost->propSetString(clipProps, kOfxImageClipPropColourspace, 0, colourspace.c_str()); +} + +static OfxStatus +getOutputColourspace( OfxImageEffectHandle effect, OfxPropertySetHandle /*inArgs*/, OfxPropertySetHandle outArgs) +{ + // retrieve any instance data associated with this effect + MyInstanceData *myData = getMyInstanceData(effect); + + OfxStatus status = kOfxStatReplyDefault; + + if (gHostColourManagementStyle != kOfxImageEffectPropColourManagementNone) { + + // We could check kOfxImageClipPropPreferredColourspaces from inArgs here + + // Get the colourspace from the parameter + std::string preferredOutputSpace; + int preferredOutputSpaceIndex; + gParamHost->paramGetValue(myData->outputSpaceParam, &preferredOutputSpaceIndex); + + switch (preferredOutputSpaceIndex) { + case 0: + preferredOutputSpace = kOfxColourspaceACEScg; + break; + case 1: + preferredOutputSpace = kOfxColourspaceLinRec2020; + break; + case 2: + preferredOutputSpace = kOfxColourspaceSrgbTx; + break; + case 3: + preferredOutputSpace = kOfxColourspaceACEScct; + break; + } + + if (!preferredOutputSpace.empty()) { + spdlog::info("Specifying output colourspaces since ={}", preferredOutputSpace); + // Set the selected colourspace in outArgs + gPropHost->propSetString(outArgs, kOfxImageClipPropColourspace, 0, preferredOutputSpace.c_str()); + // Set the selected colourspace in the clip properties to have it available in the render action + setClipColourspace(myData->outputClip, preferredOutputSpace); + status = kOfxStatOK; + } + } else { + spdlog::info("Host does not support colour management (this example won't be very interesting)"); + status = kOfxStatFailed; + } + + return status; +} + // are the settings of the effect performing an identity operation static OfxStatus isIdentity( OfxImageEffectHandle effect, @@ -744,6 +776,10 @@ pluginMain(const char *action, const void *handle, OfxPropertySetHandle inArgs, else if(strcmp(action, kOfxImageEffectActionGetTimeDomain) == 0) { stat = getTemporalDomain(effect, inArgs, outArgs); } + else if(strcmp(action, kOfxImageEffectActionGetOutputColourspace) == 0) { + stat = getOutputColourspace(effect, inArgs, outArgs); + } + } catch (const std::bad_alloc&) { // catch memory spdlog::error("Caught OFX Plugin Memory error");