Пример #1
0
bool
GenericOCIO::isIdentity(double time)
{
    assert(_created);
#ifdef OFX_IO_USING_OCIO
    if (!_config) {
        return true;
    }
    std::string inputSpace;
    getInputColorspaceAtTime(time, inputSpace);
    std::string outputSpace;
    getOutputColorspaceAtTime(time, outputSpace);
    if (inputSpace == outputSpace) {
        return true;
    }
    // must clear persistent message in isIdentity, or render() is not called by Nuke after an error
    _parent->clearPersistentMessage();
    try {
        // maybe the names are not the same, but it's still a no-op (e.g. "scene_linear" and "linear")
        OCIO::ConstContextRcPtr context = getLocalContext(time);//_config->getCurrentContext();
        OCIO_NAMESPACE::ConstProcessorRcPtr proc = _config->getProcessor(context, inputSpace.c_str(), outputSpace.c_str());
        return proc->isNoOp();
    } catch (const std::exception& e) {
        _parent->setPersistentMessage(OFX::Message::eMessageError, "", e.what());
        OFX::throwSuiteStatusException(kOfxStatFailed);
        return false;
    }
#else
    return true;
#endif
}
Пример #2
0
ColorProcessor*
ColorConfig::createColorProcessor (string_view inputColorSpace,
                                   string_view outputColorSpace,
                                   string_view context_key,
                                   string_view context_value) const
{
    string_view inputrole, outputrole;
    std::string pending_error;
#ifdef USE_OCIO
    // Ask OCIO to make a Processor that can handle the requested
    // transformation.
    OCIO::ConstProcessorRcPtr p;
    if (getImpl()->config_) {
        // If the names are roles, convert them to color space names
        string_view name;
        name = getColorSpaceNameByRole (inputColorSpace);
        if (! name.empty()) {
            inputrole = inputColorSpace;
            inputColorSpace = name;
        }
        name = getColorSpaceNameByRole (outputColorSpace);
        if (! name.empty()) {
            outputrole = outputColorSpace;
            outputColorSpace = name;
        }

        OCIO::ConstConfigRcPtr config = getImpl()->config_;
        OCIO::ConstContextRcPtr context = config->getCurrentContext();
        std::vector<string_view> keys, values;
        Strutil::split (context_key, keys, ",");
        Strutil::split (context_value, values, ",");
        if (keys.size() && values.size() && keys.size() == values.size()) {
            OCIO::ContextRcPtr ctx = context->createEditableCopy();
            for (size_t i = 0; i < keys.size(); ++i)
                ctx->setStringVar (keys[i].c_str(), values[i].c_str());
            context = ctx;
        }

        try {
            // Get the processor corresponding to this transform.
            p = getImpl()->config_->getProcessor(context, inputColorSpace.c_str(),
                                                 outputColorSpace.c_str());
        }
        catch(OCIO::Exception &e) {
            // Don't quit yet, remember the error and see if any of our
            // built-in knowledge of some generic spaces will save us.
            p.reset();
            pending_error = e.what();
        }
        catch(...) {
            getImpl()->error_ = "An unknown error occurred in OpenColorIO, getProcessor";
            return NULL;
        }
    
        getImpl()->error_ = "";
        if (p && ! p->isNoOp()) {
            // If we got a valid processor that does something useful,
            // return it now. If it boils down to a no-op, give a second
            // chance below to recognize it as a special case.
            return new ColorProcessor_OCIO(p);
        }
    }
#endif

    // Either not compiled with OCIO support, or no OCIO configuration
    // was found at all.  There are a few color conversions we know
    // about even in such dire conditions.
    using namespace Strutil;
    if (iequals(inputColorSpace,outputColorSpace)) {
        return new ColorProcessor_Ident;
    }
    if ((iequals(inputColorSpace,"linear") || iequals(inputrole,"linear") ||
         iequals(inputColorSpace,"lnf") || iequals(inputColorSpace,"lnh"))
        && iequals(outputColorSpace,"sRGB")) {
        return new ColorProcessor_linear_to_sRGB;
    }
    if (iequals(inputColorSpace,"sRGB") &&
        (iequals(outputColorSpace,"linear") || iequals(outputrole,"linear") ||
         iequals(outputColorSpace,"lnf") || iequals(outputColorSpace,"lnh"))) {
        return new ColorProcessor_sRGB_to_linear;
    }
    if ((iequals(inputColorSpace,"linear") || iequals(inputrole,"linear") ||
         iequals(inputColorSpace,"lnf") || iequals(inputColorSpace,"lnh")) &&
        iequals(outputColorSpace,"Rec709")) {
        return new ColorProcessor_linear_to_Rec709;
    }
    if (iequals(inputColorSpace,"Rec709") &&
        (iequals(outputColorSpace,"linear") || iequals(outputrole,"linear") ||
         iequals(outputColorSpace,"lnf") || iequals(outputColorSpace,"lnh"))) {
        return new ColorProcessor_Rec709_to_linear;
    }

#ifdef USE_OCIO
    if (p) {
        // If we found a procesor from OCIO, even if it was a NoOp, and we
        // still don't have a better idea, return it.
        return new ColorProcessor_OCIO(p);
    }
#endif

    if (pending_error.size())
        getImpl()->error_ = pending_error;
    return NULL;    // if we get this far, we've failed
}
Пример #3
0
ColorProcessor*
ColorConfig::createColorProcessor (string_view inputColorSpace,
                                   string_view outputColorSpace) const
{
    string_view inputrole, outputrole;
#ifdef USE_OCIO
    // Ask OCIO to make a Processor that can handle the requested
    // transformation.
    OCIO::ConstProcessorRcPtr p;
    if (getImpl()->config_) {
        // If the names are roles, convert them to color space names
        string_view name;
        name = getColorSpaceNameByRole (inputColorSpace);
        if (! name.empty()) {
            inputrole = inputColorSpace;
            inputColorSpace = name;
        }
        name = getColorSpaceNameByRole (outputColorSpace);
        if (! name.empty()) {
            outputrole = outputColorSpace;
            outputColorSpace = name;
        }
        try {
            // Get the processor corresponding to this transform.
            p = getImpl()->config_->getProcessor(inputColorSpace.c_str(),
                                                 outputColorSpace.c_str());
        }
        catch(OCIO::Exception &e) {
            getImpl()->error_ = e.what();
            return NULL;
        }
        catch(...) {
            getImpl()->error_ = "An unknown error occurred in OpenColorIO, getProcessor";
            return NULL;
        }
    
        getImpl()->error_ = "";
        if (p && ! p->isNoOp()) {
            // If we got a valid processor that does something useful,
            // return it now. If it boils down to a no-op, give a second
            // chance below to recognize it as a special case.
            return new ColorProcessor_OCIO(p);
        }
    }
#endif

    // Either not compiled with OCIO support, or no OCIO configuration
    // was found at all.  There are a few color conversions we know
    // about even in such dire conditions.
    using namespace Strutil;
    if ((iequals(inputColorSpace,"linear") || iequals(inputrole,"linear")) &&
        iequals(outputColorSpace,"sRGB")) {
        return new ColorProcessor_linear_to_sRGB;
    }
    if (iequals(inputColorSpace,"sRGB") &&
        (iequals(outputColorSpace,"linear") || iequals(outputrole,"linear"))) {
        return new ColorProcessor_sRGB_to_linear;
    }
    if ((iequals(inputColorSpace,"linear") || iequals(inputrole,"linear")) &&
        iequals(outputColorSpace,"Rec709")) {
        return new ColorProcessor_linear_to_Rec709;
    }
    if (iequals(inputColorSpace,"Rec709") &&
        (iequals(outputColorSpace,"linear") || iequals(outputrole,"linear"))) {
        // No OCIO, or the OCIO config doesn't know linear->sRGB
        return new ColorProcessor_Rec709_to_linear;
    }
    if (iequals(inputColorSpace, outputColorSpace))
    {
        // Color spaces are equal, and nothing found by OCIO
        return new ColorProcessor_pass_through;
    }

#ifdef USE_OCIO
    if (p) {
        // If we found a procesor from OCIO, even if it was a NoOp, and we
        // still don't have a better idea, return it.
        return new ColorProcessor_OCIO(p);
    }
#endif

    return NULL;    // if we get this far, we've failed
}