From f135b8f836850666961604969a35ecb0db36d941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 1 Nov 2022 13:25:42 -0400 Subject: [PATCH 1/8] For Looks that has a FileTransform and for Colorspace with FileTransfrom, add the CCCID to the processor's cache key for that transform. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/Config.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index bdf9994756..40e4ecf79d 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -4758,6 +4758,41 @@ ConstProcessorRcPtr Config::getProcessor(const ConstContextRcPtr & context, << *transform << direction; + if (transform->getTransformType() == TRANSFORM_TYPE_FILE) + { + // Since the CCCID could change between getProcessor's call, the CCCID must + // included in the key string for the processor cache when the transform is a + // File Transform. + ConstFileTransformRcPtr fileTransform = DynamicPtrCast(transform); + if (fileTransform) + { + // Add the CCCID to the processor cache key. + oss << context->resolveStringVar(fileTransform->getCCCId(), usedContext); + } + } + else if (transform->getTransformType() == TRANSFORM_TYPE_LOOK) + { + // Check if the look's transform is a File Transform. If that's the case, add the + // CCCID to the processor cache key for that transform. + ConstLookTransformRcPtr lookTransform = DynamicPtrCast(transform); + if (lookTransform) + { + ConstTransformRcPtr transform = getLook(lookTransform->getLooks())->getTransform(); + if (transform) + { + // Since the CCCID could change between getProcessor's call, the CCCID must + // included in the key string for the processor cache when the transform is a + // File Transform. + ConstFileTransformRcPtr fileTransform = DynamicPtrCast(transform); + if (fileTransform) + { + // Add the CCCID to the processor cache key. + oss << context->resolveStringVar(fileTransform->getCCCId(), usedContext); + } + } + } + } + const std::size_t key = std::hash{}(oss.str()); // As the entry is a shared pointer instance, having an empty one means that the entry does From df68b9641dd958f289866176eb3e13640d934c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 2 Nov 2022 13:23:45 -0400 Subject: [PATCH 2/8] Removing the workaround in the related unit tests and fixing the issue by adding the environment variable to the context using setStringVar. The processor's cache key is using the context cache ID which has all the context variables taken into account. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/Config.cpp | 35 -------------------- src/OpenColorIO/transforms/FileTransform.cpp | 9 +++++ tests/python/OCIOZArchiveTest.py | 6 ---- 3 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 40e4ecf79d..bdf9994756 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -4758,41 +4758,6 @@ ConstProcessorRcPtr Config::getProcessor(const ConstContextRcPtr & context, << *transform << direction; - if (transform->getTransformType() == TRANSFORM_TYPE_FILE) - { - // Since the CCCID could change between getProcessor's call, the CCCID must - // included in the key string for the processor cache when the transform is a - // File Transform. - ConstFileTransformRcPtr fileTransform = DynamicPtrCast(transform); - if (fileTransform) - { - // Add the CCCID to the processor cache key. - oss << context->resolveStringVar(fileTransform->getCCCId(), usedContext); - } - } - else if (transform->getTransformType() == TRANSFORM_TYPE_LOOK) - { - // Check if the look's transform is a File Transform. If that's the case, add the - // CCCID to the processor cache key for that transform. - ConstLookTransformRcPtr lookTransform = DynamicPtrCast(transform); - if (lookTransform) - { - ConstTransformRcPtr transform = getLook(lookTransform->getLooks())->getTransform(); - if (transform) - { - // Since the CCCID could change between getProcessor's call, the CCCID must - // included in the key string for the processor cache when the transform is a - // File Transform. - ConstFileTransformRcPtr fileTransform = DynamicPtrCast(transform); - if (fileTransform) - { - // Add the CCCID to the processor cache key. - oss << context->resolveStringVar(fileTransform->getCCCId(), usedContext); - } - } - } - } - const std::size_t key = std::hash{}(oss.str()); // As the entry is a shared pointer instance, having an empty one means that the entry does diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index 172c242470..3dc22a6378 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -282,6 +282,15 @@ bool CollectContextVariables(const Config &, usedContextVars->addStringVars(ctxFilepath); } + // Check if the CCCID is using a context variable and add it to the context if that's the case. + const char * cccid = tr.getCCCId(); + std::string resolvedCCCID = context.resolveStringVar(cccid, ctxFilename); + if (!resolvedCCCID.empty() && Platform::Strcasecmp(cccid, resolvedCCCID.c_str()) != 0) + { + foundContextVars = true; + usedContextVars->setStringVar(tr.getCCCId(), resolvedCCCID.c_str()); + } + return foundContextVars; } diff --git a/tests/python/OCIOZArchiveTest.py b/tests/python/OCIOZArchiveTest.py index 1f364101cb..b649badc93 100644 --- a/tests/python/OCIOZArchiveTest.py +++ b/tests/python/OCIOZArchiveTest.py @@ -282,9 +282,6 @@ def test_cccid(self): cdl = processor.createGroupTransform()[0] self.assertEqual(cdl.getSlope()[0], 0.9) - # FIXME: There is a bug with the Processor cache, this clears it. - self.CONFIG.setStrictParsingEnabled(False) - self.CONTEXT['CCCID'] = 'look-03' processor = self.CONFIG.getProcessor(self.CONTEXT, look_transform, @@ -292,9 +289,6 @@ def test_cccid(self): cdl = processor.createGroupTransform()[0] self.assertEqual(cdl.getSlope()[0], 1.2) - # FIXME: There is a bug with the Processor cache, this clears it. - self.CONFIG.setStrictParsingEnabled(False) - self.CONTEXT['CCCID'] = 'look-01' processor = self.CONFIG.getProcessor(self.CONTEXT, look_transform, From ebfc11672d37cbf77cd4d3fd74fd79f5c64c2ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 3 Nov 2022 08:16:35 -0400 Subject: [PATCH 3/8] Now using addStringVars and creating a new context instead of reusing the one used for the filename. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/transforms/FileTransform.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index 3dc22a6378..a71e424e65 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -283,12 +283,12 @@ bool CollectContextVariables(const Config &, } // Check if the CCCID is using a context variable and add it to the context if that's the case. - const char * cccid = tr.getCCCId(); - std::string resolvedCCCID = context.resolveStringVar(cccid, ctxFilename); - if (!resolvedCCCID.empty() && Platform::Strcasecmp(cccid, resolvedCCCID.c_str()) != 0) + ContextRcPtr ctxCCCID = Context::Create(); + std::string resolvedCCCID = context.resolveStringVar(tr.getCCCId(), ctxCCCID); + if (!resolvedCCCID.empty()) { foundContextVars = true; - usedContextVars->setStringVar(tr.getCCCId(), resolvedCCCID.c_str()); + usedContextVars->addStringVars(ctxCCCID); } return foundContextVars; From 0475c88bc9e12d0db5298d3eb7f766ad7ed3a2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Fri, 4 Nov 2022 09:21:20 -0400 Subject: [PATCH 4/8] Adding cccid to the context when there are no context variable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/transforms/FileTransform.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index a71e424e65..4fd4d5d475 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -284,8 +284,9 @@ bool CollectContextVariables(const Config &, // Check if the CCCID is using a context variable and add it to the context if that's the case. ContextRcPtr ctxCCCID = Context::Create(); - std::string resolvedCCCID = context.resolveStringVar(tr.getCCCId(), ctxCCCID); - if (!resolvedCCCID.empty()) + const char * cccid = tr.getCCCId(); + std::string resolvedCCCID = context.resolveStringVar(cccid, ctxCCCID); + if (0 != strcmp(resolvedCCCID.c_str(), cccid)) { foundContextVars = true; usedContextVars->addStringVars(ctxCCCID); From ea5c50f8a5df1c27c9032328a97d9d53f3b2737c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Mon, 7 Nov 2022 13:50:44 -0500 Subject: [PATCH 5/8] Adding a few unit tests to test that the processor is different when changing the FileTransform's CCCID. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- tests/cpu/Config_tests.cpp | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index b274fa3694..44df019b64 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -7833,6 +7833,67 @@ OCIO_ADD_TEST(Config, context_variables_typical_use_cases) cfg->getProcessor(ctx2, "cs1", "cs2").get()); } } + + + // Case 7 - Context variables in the FileTransform's CCCID. + { + static const std::string CONFIG = + "ocio_profile_version: 2\n" + "\n" + "environment:\n" + " FILE: cdl_test1.ccc\n" + " SHOT: cc0002\n" + " CCPREFIX: cc\n" + " CCNUM: 03\n" + "\n" + "search_path: " + OCIO::GetTestFilesDir() + "\n" + "\n" + "roles:\n" + " default: cs1\n" + "\n" + "displays:\n" + " disp1:\n" + " - ! {name: view1, colorspace: cs2}\n" + "\n" + "colorspaces:\n" + " - !\n" + " name: cs1\n" + "\n" + " - !\n" + " name: cs2\n" + " from_scene_reference: ! {src: $FILE, cccid: cc0001}\n"; + + std::istringstream iss; + iss.str(CONFIG); + + OCIO::ConfigRcPtr cfg; + OCIO_CHECK_NO_THROW(cfg = OCIO::Config::CreateFromStream(iss)->createEditableCopy()); + OCIO_CHECK_NO_THROW(cfg->validate()); + + OCIO::ConstTransformRcPtr ctf = cfg->getColorSpace("cs2")->getTransform( + OCIO::COLORSPACE_DIR_FROM_REFERENCE + ); + OCIO::TransformRcPtr tf = ctf->createEditableCopy(); + OCIO::FileTransformRcPtr fileTf = OCIO::DynamicPtrCast(tf); + OCIO_CHECK_ASSERT(fileTf); + + // String literal as cccid + OCIO::ConstProcessorRcPtr p1 = cfg->getProcessor(fileTf); + + // Context variable as cccid + fileTf->setCCCId("$SHOT"); + OCIO::ConstProcessorRcPtr p2 = cfg->getProcessor(fileTf); + + // Combinaisons of context variables and string literals. + fileTf->setCCCId("$CCPREFIX00$CCNUM"); + OCIO::ConstProcessorRcPtr p3 = cfg->getProcessor(fileTf); + + // All three processors should be different. + OCIO_CHECK_NE(p1.get(), p2.get()); + OCIO_CHECK_NE(p1.get(), p3.get()); + OCIO_CHECK_NE(p2.get(), p3.get()); + + } } OCIO_ADD_TEST(Config, virtual_display) From 77112fd065a1a792b78ec04679767b6b7c5b9131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 8 Nov 2022 13:27:05 -0500 Subject: [PATCH 6/8] Using setStringVar to set CCNUM context variable in unit test. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- tests/cpu/Config_tests.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index 44df019b64..a39670beea 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -7841,10 +7841,8 @@ OCIO_ADD_TEST(Config, context_variables_typical_use_cases) "ocio_profile_version: 2\n" "\n" "environment:\n" - " FILE: cdl_test1.ccc\n" " SHOT: cc0002\n" " CCPREFIX: cc\n" - " CCNUM: 03\n" "\n" "search_path: " + OCIO::GetTestFilesDir() + "\n" "\n" @@ -7861,7 +7859,7 @@ OCIO_ADD_TEST(Config, context_variables_typical_use_cases) "\n" " - !\n" " name: cs2\n" - " from_scene_reference: ! {src: $FILE, cccid: cc0001}\n"; + " from_scene_reference: ! {src: cdl_test1.ccc, cccid: $CCPREFIX00$CCNUM}\n"; std::istringstream iss; iss.str(CONFIG); @@ -7873,20 +7871,21 @@ OCIO_ADD_TEST(Config, context_variables_typical_use_cases) OCIO::ConstTransformRcPtr ctf = cfg->getColorSpace("cs2")->getTransform( OCIO::COLORSPACE_DIR_FROM_REFERENCE ); - OCIO::TransformRcPtr tf = ctf->createEditableCopy(); - OCIO::FileTransformRcPtr fileTf = OCIO::DynamicPtrCast(tf); - OCIO_CHECK_ASSERT(fileTf); + OCIO_REQUIRE_ASSERT(ctf); + + auto ctx = cfg->getCurrentContext()->createEditableCopy(); // String literal as cccid - OCIO::ConstProcessorRcPtr p1 = cfg->getProcessor(fileTf); + ctx->setStringVar("CCNUM", "01"); + OCIO::ConstProcessorRcPtr p1 = cfg->getProcessor(ctx, ctf, OCIO::TRANSFORM_DIR_FORWARD); // Context variable as cccid - fileTf->setCCCId("$SHOT"); - OCIO::ConstProcessorRcPtr p2 = cfg->getProcessor(fileTf); + ctx->setStringVar("CCNUM", "02"); + OCIO::ConstProcessorRcPtr p2 = cfg->getProcessor(ctx, ctf, OCIO::TRANSFORM_DIR_FORWARD); - // Combinaisons of context variables and string literals. - fileTf->setCCCId("$CCPREFIX00$CCNUM"); - OCIO::ConstProcessorRcPtr p3 = cfg->getProcessor(fileTf); + // Combination of context variables and string literals. + ctx->setStringVar("CCNUM", "03"); + OCIO::ConstProcessorRcPtr p3 = cfg->getProcessor(ctx, ctf, OCIO::TRANSFORM_DIR_FORWARD); // All three processors should be different. OCIO_CHECK_NE(p1.get(), p2.get()); From d65ca567700e0ee0c4dfd90d7760480929c0f953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 9 Nov 2022 10:47:12 -0500 Subject: [PATCH 7/8] Adding a test in FileTransform to test CollectContextVariables directly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- tests/cpu/Config_tests.cpp | 7 +-- tests/cpu/transforms/FileTransform_tests.cpp | 48 ++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index a39670beea..c2bfed235a 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -7841,7 +7841,6 @@ OCIO_ADD_TEST(Config, context_variables_typical_use_cases) "ocio_profile_version: 2\n" "\n" "environment:\n" - " SHOT: cc0002\n" " CCPREFIX: cc\n" "\n" "search_path: " + OCIO::GetTestFilesDir() + "\n" @@ -7873,17 +7872,14 @@ OCIO_ADD_TEST(Config, context_variables_typical_use_cases) ); OCIO_REQUIRE_ASSERT(ctf); - auto ctx = cfg->getCurrentContext()->createEditableCopy(); + OCIO::ContextRcPtr ctx = cfg->getCurrentContext()->createEditableCopy(); - // String literal as cccid ctx->setStringVar("CCNUM", "01"); OCIO::ConstProcessorRcPtr p1 = cfg->getProcessor(ctx, ctf, OCIO::TRANSFORM_DIR_FORWARD); - // Context variable as cccid ctx->setStringVar("CCNUM", "02"); OCIO::ConstProcessorRcPtr p2 = cfg->getProcessor(ctx, ctf, OCIO::TRANSFORM_DIR_FORWARD); - // Combination of context variables and string literals. ctx->setStringVar("CCNUM", "03"); OCIO::ConstProcessorRcPtr p3 = cfg->getProcessor(ctx, ctf, OCIO::TRANSFORM_DIR_FORWARD); @@ -7891,7 +7887,6 @@ OCIO_ADD_TEST(Config, context_variables_typical_use_cases) OCIO_CHECK_NE(p1.get(), p2.get()); OCIO_CHECK_NE(p1.get(), p3.get()); OCIO_CHECK_NE(p2.get(), p3.get()); - } } diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index 928adfa6fe..a3d480bae2 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -431,4 +431,52 @@ OCIO_ADD_TEST(FileTransform, context_variables) // A basic check to validate that context variables are correctly used. OCIO_CHECK_NO_THROW(cfg->getProcessor(ctx, file, OCIO::TRANSFORM_DIR_FORWARD)); + + + // Case 4 - The 'cccid' now contain a context variable + static const std::string CONFIG = + "ocio_profile_version: 2\n" + "\n" + "environment:\n" + " CCPREFIX: cc\n" + "\n" + "search_path: " + OCIO::GetTestFilesDir() + "\n" + "\n" + "roles:\n" + " default: cs1\n" + "\n" + "displays:\n" + " disp1:\n" + " - ! {name: view1, colorspace: cs2}\n" + "\n" + "colorspaces:\n" + " - !\n" + " name: cs1\n" + "\n" + " - !\n" + " name: cs2\n" + " from_scene_reference: ! {src: cdl_test1.ccc, cccid: $CCPREFIX00$CCNUM}\n"; + + std::istringstream iss; + iss.str(CONFIG); + + OCIO_CHECK_NO_THROW(cfg = OCIO::Config::CreateFromStream(iss)->createEditableCopy()); + OCIO_CHECK_NO_THROW(cfg->validate()); + + ctx = cfg->getCurrentContext()->createEditableCopy(); + OCIO_CHECK_NO_THROW(ctx->setStringVar("CCNUM", "01")); + + usedContextVars = OCIO::Context::Create(); // New & empty instance. + OCIO::ConstTransformRcPtr tr1 = cfg->getColorSpace("cs2")->getTransform( + OCIO::COLORSPACE_DIR_FROM_REFERENCE + ); + OCIO::ConstFileTransformRcPtr fTr1 = OCIO::DynamicPtrCast(tr1); + OCIO_CHECK_ASSERT(fTr1); + + OCIO_CHECK_ASSERT(CollectContextVariables(*cfg, *ctx, *fTr1, usedContextVars)); + OCIO_CHECK_EQUAL(2, usedContextVars->getNumStringVars()); + OCIO_CHECK_EQUAL(std::string("CCPREFIX"), usedContextVars->getStringVarNameByIndex(0)); + OCIO_CHECK_EQUAL(std::string("cc"), usedContextVars->getStringVarByIndex(0)); + OCIO_CHECK_EQUAL(std::string("CCNUM"), usedContextVars->getStringVarNameByIndex(1)); + OCIO_CHECK_EQUAL(std::string("01"), usedContextVars->getStringVarByIndex(1)); } From 215145be9d6bf6646f9935c07f5e7757b52a01e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 10 Nov 2022 09:37:34 -0500 Subject: [PATCH 8/8] Minor tweaks for the unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- tests/cpu/transforms/FileTransform_tests.cpp | 96 ++++++++++---------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index a3d480bae2..55315822cf 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -433,50 +433,54 @@ OCIO_ADD_TEST(FileTransform, context_variables) OCIO_CHECK_NO_THROW(cfg->getProcessor(ctx, file, OCIO::TRANSFORM_DIR_FORWARD)); - // Case 4 - The 'cccid' now contain a context variable - static const std::string CONFIG = - "ocio_profile_version: 2\n" - "\n" - "environment:\n" - " CCPREFIX: cc\n" - "\n" - "search_path: " + OCIO::GetTestFilesDir() + "\n" - "\n" - "roles:\n" - " default: cs1\n" - "\n" - "displays:\n" - " disp1:\n" - " - ! {name: view1, colorspace: cs2}\n" - "\n" - "colorspaces:\n" - " - !\n" - " name: cs1\n" - "\n" - " - !\n" - " name: cs2\n" - " from_scene_reference: ! {src: cdl_test1.ccc, cccid: $CCPREFIX00$CCNUM}\n"; - - std::istringstream iss; - iss.str(CONFIG); - - OCIO_CHECK_NO_THROW(cfg = OCIO::Config::CreateFromStream(iss)->createEditableCopy()); - OCIO_CHECK_NO_THROW(cfg->validate()); - - ctx = cfg->getCurrentContext()->createEditableCopy(); - OCIO_CHECK_NO_THROW(ctx->setStringVar("CCNUM", "01")); - - usedContextVars = OCIO::Context::Create(); // New & empty instance. - OCIO::ConstTransformRcPtr tr1 = cfg->getColorSpace("cs2")->getTransform( - OCIO::COLORSPACE_DIR_FROM_REFERENCE - ); - OCIO::ConstFileTransformRcPtr fTr1 = OCIO::DynamicPtrCast(tr1); - OCIO_CHECK_ASSERT(fTr1); - - OCIO_CHECK_ASSERT(CollectContextVariables(*cfg, *ctx, *fTr1, usedContextVars)); - OCIO_CHECK_EQUAL(2, usedContextVars->getNumStringVars()); - OCIO_CHECK_EQUAL(std::string("CCPREFIX"), usedContextVars->getStringVarNameByIndex(0)); - OCIO_CHECK_EQUAL(std::string("cc"), usedContextVars->getStringVarByIndex(0)); - OCIO_CHECK_EQUAL(std::string("CCNUM"), usedContextVars->getStringVarNameByIndex(1)); - OCIO_CHECK_EQUAL(std::string("01"), usedContextVars->getStringVarByIndex(1)); + { + // Case 4 - The 'cccid' now contains a context variable + static const std::string CONFIG = + "ocio_profile_version: 2\n" + "\n" + "environment:\n" + " CCPREFIX: cc\n" + " CCNUM: 02\n" + "\n" + "search_path: " + OCIO::GetTestFilesDir() + "\n" + "\n" + "roles:\n" + " default: cs1\n" + "\n" + "displays:\n" + " disp1:\n" + " - ! {name: view1, colorspace: cs2}\n" + "\n" + "colorspaces:\n" + " - !\n" + " name: cs1\n" + "\n" + " - !\n" + " name: cs2\n" + " from_scene_reference: ! {src: cdl_test1.ccc, cccid: $CCPREFIX00$CCNUM}\n"; + + std::istringstream iss; + iss.str(CONFIG); + + OCIO::ConstConfigRcPtr cfg; + OCIO_CHECK_NO_THROW(cfg = OCIO::Config::CreateFromStream(iss)); + OCIO_CHECK_NO_THROW(cfg->validate()); + + ctx = cfg->getCurrentContext()->createEditableCopy(); + OCIO_CHECK_NO_THROW(ctx->setStringVar("CCNUM", "01")); + + usedContextVars = OCIO::Context::Create(); // New & empty instance. + OCIO::ConstTransformRcPtr tr1 = cfg->getColorSpace("cs2")->getTransform( + OCIO::COLORSPACE_DIR_FROM_REFERENCE + ); + OCIO::ConstFileTransformRcPtr fTr1 = OCIO::DynamicPtrCast(tr1); + OCIO_CHECK_ASSERT(fTr1); + + OCIO_CHECK_ASSERT(CollectContextVariables(*cfg, *ctx, *fTr1, usedContextVars)); + OCIO_CHECK_EQUAL(2, usedContextVars->getNumStringVars()); + OCIO_CHECK_EQUAL(std::string("CCPREFIX"), usedContextVars->getStringVarNameByIndex(0)); + OCIO_CHECK_EQUAL(std::string("cc"), usedContextVars->getStringVarByIndex(0)); + OCIO_CHECK_EQUAL(std::string("CCNUM"), usedContextVars->getStringVarNameByIndex(1)); + OCIO_CHECK_EQUAL(std::string("01"), usedContextVars->getStringVarByIndex(1)); + } }