Skip to content

Commit

Permalink
Adsk Contrib - Fix a CDL file load bug for ColorDecisionList case (Ac…
Browse files Browse the repository at this point in the history
…ademySoftwareFoundation#1022)

Signed-off-by: Patrick Hodoul <[email protected]>
  • Loading branch information
hodoulp authored and scoopxyz committed Jul 12, 2020
1 parent d205543 commit 7d8cbe7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/OpenColorIO/transforms/CDLTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void ClearCDLTransformFileCache()

CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cccid_)
{
if (!src || (strlen(src) == 0))
if (!src || !*src)
{
std::ostringstream os;
os << "Error loading CDL xml. ";
Expand All @@ -217,7 +217,7 @@ CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cc
AutoMutex lock(g_cacheMutex);

// Use g_cacheSrcIsCC as a proxy for if we have loaded this source
// file already (in which case it must be in cache, or an error)
// file already (in which case it must be in cache, or an error).

StringBoolMap::iterator srcIsCCiter = g_cacheSrcIsCC.find(src);
if (srcIsCCiter != g_cacheSrcIsCC.end())
Expand Down Expand Up @@ -252,7 +252,7 @@ CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cc
throw Exception (os.str().c_str());
}

// Try to read all ccs from the file, into cache
// Try to read all ccs from the file, into cache.
std::ifstream istream(src);
if (istream.fail())
{
Expand All @@ -268,18 +268,18 @@ CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cc

if (parser.isCC())
{
// Load a single ColorCorrection into the cache
// Load a single ColorCorrection into the cache.
CDLTransformRcPtr cdl = CDLTransform::Create();
parser.getCDLTransform(cdl);

cccid = "";
g_cacheSrcIsCC[src] = true;
g_cache[GetCDLLocalCacheKey(src, cccid)] = cdl;
}
else if (parser.isCCC())
else
{
// Load all CCs from the ColorCorrectionCollection
// into the cache
// Load all CCs from the ColorCorrectionCollection or from the ColorDecisionList
// into the cache.
CDLTransformMap transformMap;
CDLTransformVec transformVec;
FormatMetadataImpl metadata;
Expand Down
19 changes: 19 additions & 0 deletions tests/cpu/transforms/CDLTransform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "transforms/CDLTransform.cpp"

#include "testutils/UnitTest.h"
#include "UnitTestLogUtils.h"
#include "UnitTestUtils.h"

#include "Platform.h"
Expand Down Expand Up @@ -165,6 +166,24 @@ OCIO_ADD_TEST(CDLTransform, create_from_ccc_file)
}
}

OCIO_ADD_TEST(CDLTransform, create_from_cdl_file)
{
// As warning messages are expected, please mute them.
OCIO::MuteLogging mute;

// Note: Detailed test is already done, this unit test only validates that
// this CDL file (i.e. containing a ColorDecisionList) correctly loads
// using a CDLTransform.

const std::string filePath(std::string(OCIO::getTestFilesDir()) + "/cdl_test1.cdl");

OCIO::CDLTransformRcPtr transform;

OCIO_CHECK_NO_THROW(transform = OCIO::CDLTransform::CreateFromFile(filePath.c_str(), "cc0003"));
OCIO_CHECK_EQUAL(std::string("cc0003"), std::string(transform->getID()));
OCIO_CHECK_EQUAL(transform->getStyle(), OCIO::CDL_NO_CLAMP);
}

OCIO_ADD_TEST(CDLTransform, create_from_ccc_file_failure)
{
const std::string filePath(std::string(OCIO::getTestFilesDir()) + "/cdl_test1.ccc");
Expand Down

0 comments on commit 7d8cbe7

Please sign in to comment.