Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper methods to ViewingRules class #2050

Open
doug-walker opened this issue Sep 20, 2024 · 0 comments
Open

Add helper methods to ViewingRules class #2050

doug-walker opened this issue Sep 20, 2024 · 0 comments
Labels
Feature Request New addition to OCIO functionality. good first issue Standard label for new developers to locate good issues to tackle to learn about OCIO development. help wanted Issues that the TSC has decided are worth implementing, but don't currently have the dev resources.

Comments

@doug-walker
Copy link
Collaborator

Here are some helper functions that contain useful functionality to add to the ViewingRules class. The API of the functions below should be altered, as appropriate. As always, unit tests must be added.

bool viewingRulesAreEqual(const ConstViewingRulesRcPtr & r1,
                          size_t r1Idx,
                          const ConstViewingRulesRcPtr & r2,
                          size_t r2Idx)
{
    // NB: No need to compare the name of the rules, that should be done in the caller.

    // Compare color space tokens, handling the case where they may be in a different order.

    if (r1->getNumColorSpaces(r1Idx) != r2->getNumColorSpaces(r2Idx))
    {
        return false;
    }

    TokensManager r1ColorSpaces;
    for (size_t m = 0; m < r1->getNumColorSpaces(r1Idx); m++)
    {
        r1ColorSpaces.addToken(r1->getColorSpace(r1Idx, m));
    }

    for (size_t m = 0; m < r2->getNumColorSpaces(r2Idx); m++)
    {
        if (!r1ColorSpaces.hasToken(r2->getColorSpace(r2Idx, m)))
        {
            return false;
        }
    }

    // Compare encoding tokens, handling the case where they may be in a different order.

    if (r1->getNumEncodings(r1Idx) != r2->getNumEncodings(r2Idx))
    {
        return false;
    }

    TokensManager r1Encodings;
    for (size_t m = 0; m < r1->getNumEncodings(r1Idx); m++)
    {
        r1Encodings.addToken(r1->getEncoding(r1Idx, m));
    }

    for (size_t m = 0; m < r2->getNumEncodings(r2Idx); m++)
    {
        if(!r1Encodings.hasToken(r2->getEncoding(r2Idx, m)))
        {
            return false;
        }
    }

    // Compare the custom keys, handling the case where they may be in a different order.

    if (r1->getNumCustomKeys(r1Idx) != r2->getNumCustomKeys(r2Idx))
    {
        return false;
    }

    CustomKeysContainer r1CustomKeys;
    for (size_t m = 0; m < r1->getNumCustomKeys(r1Idx); m++)
    {
        r1CustomKeys.set(r1->getCustomKeyName(r1Idx, m), r1->getCustomKeyValue(r1Idx, m));
    }

    for (size_t m = 0; m < r2->getNumCustomKeys(r2Idx); m++)
    {
        if (!r1CustomKeys.hasKey(r2->getCustomKeyName(r2Idx, m)))
        {
            return false;
        }
        else
        {
            if (Platform::Strcasecmp(r1CustomKeys.getValueForKey(r2->getCustomKeyName(r2Idx, m)),
                                     r2->getCustomKeyValue(r2Idx, m)) != 0)
            {
                return false;
            }
        }
    }

    return true;
}
void copyViewingRule(const ConstViewingRulesRcPtr & src,
                     size_t srcIdx,
                     size_t dstIdx,
                     ViewingRulesRcPtr & rules)
{
        rules->insertRule(dstIdx, src->getName(srcIdx));

        for (int j = 0; j < static_cast<int>(src->getNumColorSpaces(srcIdx)); j++)
        {
            rules->addColorSpace(dstIdx, src->getColorSpace(srcIdx, j));
        }

        for (int k = 0; k < static_cast<int>(src->getNumEncodings(srcIdx)); k++)
        {
            rules->addEncoding(dstIdx, src->getEncoding(srcIdx, k));
        }

        for (int l = 0; l < static_cast<int>(src->getNumCustomKeys(srcIdx)); l++)
        {
            rules->setCustomKey(dstIdx, src->getCustomKeyName(srcIdx, l), src->getCustomKeyValue(srcIdx, l));
        }
}
@doug-walker doug-walker added Feature Request New addition to OCIO functionality. good first issue Standard label for new developers to locate good issues to tackle to learn about OCIO development. help wanted Issues that the TSC has decided are worth implementing, but don't currently have the dev resources. labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New addition to OCIO functionality. good first issue Standard label for new developers to locate good issues to tackle to learn about OCIO development. help wanted Issues that the TSC has decided are worth implementing, but don't currently have the dev resources.
Projects
None yet
Development

No branches or pull requests

1 participant