コード例 #1
0
ファイル: GenericOCIO.cpp プロジェクト: theomission/openfx-io
void
GenericOCIO::changedParam(const OFX::InstanceChangedArgs &args, const std::string &paramName)
{
    assert(_created);
#ifdef OFX_IO_USING_OCIO
    if (paramName == kOCIOParamConfigFile) {
        // compute canonical inputSpace and outputSpace before changing the config,
        // if different from inputSpace and outputSpace they must be set to the canonical value after changing ocio config
        std::string inputSpace;
        getInputColorspaceAtTime(args.time, inputSpace);
        std::string inputSpaceCanonical = canonicalizeColorSpace(_config, inputSpace);
        if (inputSpaceCanonical != inputSpace) {
            _inputSpace->setValue(inputSpaceCanonical);
        }
        std::string outputSpace;
        getOutputColorspaceAtTime(args.time, outputSpace);
        std::string outputSpaceCanonical = canonicalizeColorSpace(_config, outputSpace);
        if (outputSpaceCanonical != outputSpace) {
            _outputSpace->setValue(outputSpaceCanonical);
        }

        loadConfig(); // re-load the new OCIO config
        //if inputspace or outputspace are not valid in the new config, reset them to "default"
        if (_config) {
            std::string inputSpaceName;
            getInputColorspaceAtTime(args.time, inputSpaceName);
            int inputSpaceIndex = _config->getIndexForColorSpace(inputSpaceName.c_str());
            if (inputSpaceIndex < 0) {
                _inputSpace->setValue(OCIO_NAMESPACE::ROLE_DEFAULT);
            }
        }
        inputCheck(args.time);
        if (_config) {
            std::string outputSpaceName;
            getOutputColorspaceAtTime(args.time, outputSpaceName);
            int outputSpaceIndex = _config->getIndexForColorSpace(outputSpaceName.c_str());
            if (outputSpaceIndex < 0) {
                _outputSpace->setValue(OCIO_NAMESPACE::ROLE_DEFAULT);
            }
        }
        outputCheck(args.time);

        if (!_config && args.reason == OFX::eChangeUserEdit) {
            std::string filename;
            _ocioConfigFile->getValue(filename);
            _parent->sendMessage(OFX::Message::eMessageError, "", std::string("Cannot load OCIO config file \"") + filename + '"');
        }
    } else if (paramName == kOCIOHelpButton || paramName == kOCIOHelpLooksButton || paramName == kOCIOHelpDisplaysButton) {
        std::string msg = "OpenColorIO Help\n"
            "The OCIO configuration file can be set using the \"OCIO\" environment variable, which should contain the full path to the .ocio file.\n"
            "OpenColorIO version (compiled with / running with): " OCIO_VERSION "/";
        msg += OCIO_NAMESPACE::GetVersion();
        msg += '\n';
        if (_config) {
            std::string configdesc = _config->getDescription();
            configdesc = whitespacify(trim(configdesc));
            if ( configdesc.size() > 0 ) {
                msg += "\nThis OCIO configuration is ";
                msg += configdesc;
                msg += '\n';
            }
            msg += '\n';
            if (paramName == kOCIOHelpLooksButton) {
                msg += (_config->getNumLooks() <= 0 ? "No look available in this OCIO configuration.\n" : "Available looks in this OCIO Configuration (applied in the given colorspace):\n");
                for (int i = 0; i < _config->getNumLooks(); ++i) {
                    const char* lkname = _config->getLookNameByIndex(i);
                    OCIO_NAMESPACE::ConstLookRcPtr lk = _config->getLook(lkname);
                    msg += "- ";
                    msg += lkname;
                    std::string lkspace = lk->getProcessSpace();
                    msg += " (" + lkspace + ")\n";
                }
                msg += '\n';
            }
            if (paramName == kOCIOHelpDisplaysButton) {
                if (_config->getNumDisplays() <= 0) {
                    msg += "No display available in this OCIO configuration.\n";
                } else {
                    msg += "Available displays and views in this OCIO Configuration:\n";
                    std::string defaultdisplay = _config->getDefaultDisplay();
                    for (int i = 0; i < _config->getNumDisplays(); ++i) {
                        const char* display = _config->getDisplay(i);
                        msg += "- ";
                        msg += display;
                        if (display == defaultdisplay) {
                            msg += " (default)";
                        }
                        int numViews = _config->getNumViews(display);
                        if (numViews <= 0) {
                            msg += ", no view available.\n";
                        } else {
                            msg += ", views: ";
                            std::string defaultview = _config->getDefaultView(display);
                            for (int j = 0; j < numViews; ++j) {
                                const char* view = _config->getView(display, j);
                                msg += view;
                                if (view == defaultview) {
                                    msg += " (default)";
                                }
                                if (j < numViews-1) {
                                    msg += ", ";
                                }
                            }
                            msg += '\n';
                        }
                    }
                }
                msg += '\n';
            }
            msg += "Available colorspaces in this OCIO Configuration:\n";
            int defaultcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_DEFAULT);
            int referencecs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_REFERENCE);
            int datacs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_DATA);
            int colorpickingcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COLOR_PICKING);
            int scenelinearcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_SCENE_LINEAR);
            int compositinglogcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COMPOSITING_LOG);
            int colortimingcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COLOR_TIMING);
            int texturepaintcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_TEXTURE_PAINT);
            int mattepaintcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_MATTE_PAINT);

            for (int i = 0; i < _config->getNumColorSpaces(); ++i) {
                const char* csname = _config->getColorSpaceNameByIndex(i);;
                OCIO_NAMESPACE::ConstColorSpaceRcPtr cs = _config->getColorSpace(csname);
                msg += "- ";
                msg += csname;
                bool first = true;
                //int roles = 0;
                if (i == defaultcs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_DEFAULT;
                    first = false;
                    //++roles;
                }
                if (i == referencecs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_REFERENCE;
                    first = false;
                    //++roles;
                }
                if (i == datacs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_DATA;
                    first = false;
                    //++roles;
                }
                if (i == colorpickingcs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_COLOR_PICKING;
                    first = false;
                    //++roles;
                }
                if (i == scenelinearcs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_SCENE_LINEAR;
                    first = false;
                    //++roles;
                }
                if (i == compositinglogcs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_COMPOSITING_LOG;
                    first = false;
                    //++roles;
                }
                if (i == colortimingcs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_COLOR_TIMING;
                    first = false;
                    //++roles;
                }
                if (i == texturepaintcs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_TEXTURE_PAINT;
                    first = false;
                    //++roles;
                }
                if (i == mattepaintcs) {
                    msg += first ? " (" : ", ";
                    msg += OCIO_NAMESPACE::ROLE_MATTE_PAINT;
                    first = false;
                    //++roles;
                }
                if (!first /*&& roles > 0*/) {
                    msg += ')';
                }
                std::string csdesc = cs ? cs->getDescription() : "(no colorspace)";
                csdesc = whitespacify(trim(csdesc));
                if ( !csdesc.empty() ) {
                    msg += ": ";
                    msg += csdesc;
                    msg += '\n';
                } else {
                    msg += '\n';
                }
            }
        }
        _parent->sendMessage(OFX::Message::eMessageMessage, "", msg);
    } else if (!_config) {
        // the other parameters assume there is a valid config
        return;
    } else if (paramName == kOCIOParamInputSpace) {
        assert(_inputSpace);
        if (args.reason == OFX::eChangeUserEdit) {
            // if the inputspace doesn't correspond to a valid one, reset to default.
            // first, canonicalize.
            std::string inputSpace;
            getInputColorspaceAtTime(args.time, inputSpace);
            std::string inputSpaceCanonical = canonicalizeColorSpace(_config, inputSpace);
            if (inputSpaceCanonical != inputSpace) {
                _inputSpace->setValue(inputSpaceCanonical);
                inputSpace = inputSpaceCanonical;
            }
            int inputSpaceIndex = _config->getIndexForColorSpace(inputSpace.c_str());
            if (inputSpaceIndex < 0) {
                if (args.reason == OFX::eChangeUserEdit) {
                    _parent->sendMessage(OFX::Message::eMessageWarning, "", std::string("Unknown OCIO colorspace \"")+inputSpace+"\"");
                }
                OCIO::ConstColorSpaceRcPtr colorspace = _config->getColorSpace(OCIO_NAMESPACE::ROLE_DEFAULT);
                if (colorspace) {
                    inputSpace = colorspace->getName();
                    _inputSpace->setValue(inputSpace);
                } 
            }
        }
        inputCheck(args.time);
    }
#ifdef OFX_OCIO_CHOICE
    else if ( paramName == kOCIOParamInputSpaceChoice && args.reason == OFX::eChangeUserEdit) {
        assert(_inputSpace);
        int inputSpaceIndex;
        _inputSpaceChoice->getValueAtTime(args.time, inputSpaceIndex);
        std::string inputSpaceOld;
        getInputColorspaceAtTime(args.time, inputSpaceOld);
        std::string inputSpace = canonicalizeColorSpace(_config, _config->getColorSpaceNameByIndex(inputSpaceIndex));
        // avoid an infinite loop on bad hosts (for examples those which don't set args.reason correctly)
        if (inputSpace != inputSpaceOld) {
            _inputSpace->setValue(inputSpace);
        }
    }
#endif
    else if (paramName == kOCIOParamOutputSpace) {
        assert(_outputSpace);
        if (args.reason == OFX::eChangeUserEdit) {
            // if the outputspace doesn't correspond to a valid one, reset to default.
            // first, canonicalize.
            std::string outputSpace;
            getOutputColorspaceAtTime(args.time, outputSpace);
            std::string outputSpaceCanonical = canonicalizeColorSpace(_config, outputSpace);
            if (outputSpaceCanonical != outputSpace) {
                _outputSpace->setValue(outputSpaceCanonical);
                outputSpace = outputSpaceCanonical;
            }
            int outputSpaceIndex = _config->getIndexForColorSpace(outputSpace.c_str());
            if (outputSpaceIndex < 0) {
                if (args.reason == OFX::eChangeUserEdit) {
                    _parent->sendMessage(OFX::Message::eMessageWarning, "", std::string("Unknown OCIO colorspace \"")+outputSpace+"\"");
                }
                outputSpace = _config->getColorSpace(OCIO_NAMESPACE::ROLE_DEFAULT)->getName();
                _outputSpace->setValue(outputSpace);
                outputSpaceIndex = _config->getIndexForColorSpace(outputSpace.c_str());
                assert(outputSpaceIndex >= 0);
            }
        }
        outputCheck(args.time);
    }
#ifdef OFX_OCIO_CHOICE
    else if ( paramName == kOCIOParamOutputSpaceChoice && args.reason == OFX::eChangeUserEdit) {
        assert(_outputSpace);
        int outputSpaceIndex;
        _outputSpaceChoice->getValueAtTime(args.time, outputSpaceIndex);
        std::string outputSpaceOld;
        getOutputColorspaceAtTime(args.time, outputSpaceOld);
        std::string outputSpace = canonicalizeColorSpace(_config, _config->getColorSpaceNameByIndex(outputSpaceIndex));
        // avoid an infinite loop on bad hosts (for examples those which don't set args.reason correctly)
        if (outputSpace != outputSpaceOld) {
            _outputSpace->setValue(outputSpace);
        }
    }
#endif // OFX_OCIO_CHOICE


#endif
}
コード例 #2
0
ファイル: GenericOCIO.cpp プロジェクト: theomission/openfx-io
static void
buildChoiceMenu(OCIO::ConstConfigRcPtr config,
                ChoiceParamType* choice,
                bool cascading,
                const std::string& name = "")
{
#ifdef DEBUG
    //printf("%p->resetOptions\n", (void*)choice);
#endif
    choice->resetOptions();
    assert(choice->getNOptions() == 0);
    if (!config) {
        return;
    }
    int def = -1;
    int defaultcs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_DEFAULT);
    int referencecs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_REFERENCE);
    int datacs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_DATA);
    int colorpickingcs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COLOR_PICKING);
    int scenelinearcs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_SCENE_LINEAR);
    int compositinglogcs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COMPOSITING_LOG);
    int colortimingcs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COLOR_TIMING);
    int texturepaintcs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_TEXTURE_PAINT);
    int mattepaintcs = config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_MATTE_PAINT);
    for (int i = 0; i < config->getNumColorSpaces(); ++i) {
        std::string csname = config->getColorSpaceNameByIndex(i);
        std::string msg;
        // set the default value, in case the GUI uses it
        if (!name.empty() && csname == name) {
            def = i;
        }
        OCIO_NAMESPACE::ConstColorSpaceRcPtr cs = config->getColorSpace(csname.c_str());
        if (cascading) {
            std::string family = config->getColorSpace(csname.c_str())->getFamily();
            if (!family.empty()) {
                csname = family + "/" + csname;
            }
        }
        std::string csdesc = cs ? cs->getDescription() : "(no colorspace)";
        csdesc = whitespacify(trim(csdesc));
        int csdesclen = csdesc.size();
        if ( csdesclen > 0 ) {
            msg += csdesc;
        }
        bool first = true;
        int roles = 0;
        if (i == defaultcs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_DEFAULT;
            first = false;
            ++roles;
        }
        if (i == referencecs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_REFERENCE;
            first = false;
            ++roles;
        }
        if (i == datacs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_DATA;
            first = false;
            ++roles;
        }
        if (i == colorpickingcs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_COLOR_PICKING;
            first = false;
            ++roles;
        }
        if (i == scenelinearcs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_SCENE_LINEAR;
            first = false;
            ++roles;
        }
        if (i == compositinglogcs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_COMPOSITING_LOG;
            first = false;
            ++roles;
        }
        if (i == colortimingcs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_COLOR_TIMING;
            first = false;
            ++roles;
        }
        if (i == texturepaintcs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_TEXTURE_PAINT;
            first = false;
            ++roles;
        }
        if (i == mattepaintcs) {
            msg += first ? " (" : ", ";
            msg += OCIO_NAMESPACE::ROLE_MATTE_PAINT;
            first = false;
            ++roles;
        }
        if (roles > 0) {
            msg += ')';
        }
#ifdef DEBUG
        //printf("%p->appendOption(\"%s\",\"%s\") (%d->%d options)\n", (void*)choice, csname.c_str(), msg.c_str(), i, i+1);
#endif
        assert(choice->getNOptions() == i);
        choice->appendOption(csname, msg);
        assert(choice->getNOptions() == i+1);
    }
    if (def != -1) {
        choice->setDefault(def);
    }
}