Skip to content

Commit d8ff444

Browse files
committed
- replacing getAMFTransformIDs and getICCProfileName with more generic getInterchangeAttribute function. Same with the setters
- getInterchangeAttribute() and setInterchangeAttribute() functions currently knows and accepts "amf_transform_ids" and "icc_profile_name" keys. other keys will throw. - ColorSpace serializer will list all of the key/value pairs. - InteropID and interchangeAttributes are now allowed in earlier config versions down to 2.0 too. Config::checkVersionConsistency() will throw only for version smaller than 2.0. - YAML loader and saver now supports the "interchange" section. Any unknown keys under that section will be ignored upon load and will generate a warning but won't throw. - Generic str key/value loader/saver is extended for re usability (and fixed incorrect throw message). - since the amf keywords are separated by newline characters, the newline sanitizer that was used for the description is also generalized and applied to all of the current and possible future interchange fields. - ColorSpace_test.cpp file updated to test the current state and behavior of the API. - ComputeValues function in the CPUProcessor_tests.cpp was taking the linenumber as as template parameter. This was a very bad idea as that means each invocation of the function would create a separate copy of the function which was causing all sorts of issues in the debugger and failing to compile when the line numbers are not constants (happens in JIT debug sessions). Fixed by making the line number a normal parameter. - Python ColorSpace object no longer takes the amf of icc parameters in the constructor. User needs to set them explicitely later on. Signed-off-by: cuneyt.ozdas <cuneyt.ozdas@autodesk.com>
1 parent 49cd2e8 commit d8ff444

9 files changed

Lines changed: 587 additions & 520 deletions

File tree

include/OpenColorIO/OpenColorIO.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <fstream>
1414
#include <vector>
1515
#include <cstdint>
16+
#include <map>
1617

1718
#include "OpenColorABI.h"
1819
#include "OpenColorTypes.h"
@@ -1992,23 +1993,25 @@ class OCIOEXPORT ColorSpace
19921993
void setInteropID(const char * interopID);
19931994

19941995
/**
1995-
* Get/Set the AMF transform IDs for the color space.
1996-
*
1997-
* The AMF transform IDs are used to identify specific transforms in the ACES Metadata File.
1998-
* Multiple transform IDs can be specified in a newline-separated string.
1999-
*/
2000-
const char * getAMFTransformIDs() const noexcept;
2001-
void setAMFTransformIDs(const char * amfTransformIDs);
2002-
2003-
/**
2004-
* Get/Set the ICC profile name for the color space.
2005-
*
2006-
* The ICC profile name identifies the ICC color profile associated with this color space.
2007-
* This can be used to link OCIO color spaces with corresponding ICC profiles for
2008-
* applications that need to work with both color management systems.
1996+
* Get/Set the interchange attributes.
1997+
*
1998+
* Currently supported attribute names are "amf_transform_ids" and
1999+
* "icc_profile_name". Using any other name will throw. If the attribute is
2000+
* not defined, it'll return empty string. Similarly setting it to empty
2001+
* string will effectively delete the attribute.
2002+
*
2003+
* The AMF transform IDs are used to identify specific transforms in the
2004+
* ACES Metadata File. Multiple transform IDs can be specified in a
2005+
* newline-separated string.
2006+
*
2007+
* The ICC profile name identifies the ICC color profile associated with
2008+
* this color space. This can be used to link OCIO color spaces with
2009+
* corresponding ICC profiles for applications that need to work with both
2010+
* color management systems.
20092011
*/
2010-
const char * getICCProfileName() const noexcept;
2011-
void setICCProfileName(const char * iccProfileName);
2012+
const char *getInterchangeAttribute(const char *attrName) const;
2013+
void setInterchangeAttribute(const char* attrName, const char *value);
2014+
std::map<std::string, std::string> getInterchangeAttributes() const noexcept;
20122015

20132016
BitDepth getBitDepth() const noexcept;
20142017
void setBitDepth(BitDepth bitDepth);

src/OpenColorIO/ColorSpace.cpp

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cstring>
55
#include <sstream>
66
#include <vector>
7+
#include <map>
78

89
#include <OpenColorIO/OpenColorIO.h>
910

@@ -13,6 +14,13 @@
1314
#include "utils/StringUtils.h"
1415

1516

17+
namespace
18+
{
19+
const std::array<const std::string, 2> knownInterchangeNames = {
20+
"amf_transform_ids",
21+
"icc_profile_name" };
22+
}
23+
1624
namespace OCIO_NAMESPACE
1725
{
1826

@@ -25,9 +33,8 @@ class ColorSpace::Impl
2533
std::string m_description;
2634
std::string m_encoding;
2735
std::string m_interopID;
28-
std::string m_AMFTransformIDs;
29-
std::string m_ICCProfileName;
3036
StringUtils::StringVec m_aliases;
37+
std::map<std::string, std::string> m_interchangeAttribs;
3138

3239
BitDepth m_bitDepth{ BIT_DEPTH_UNKNOWN };
3340
bool m_isData{ false };
@@ -66,8 +73,7 @@ class ColorSpace::Impl
6673
m_description = rhs.m_description;
6774
m_encoding = rhs.m_encoding;
6875
m_interopID = rhs.m_interopID;
69-
m_AMFTransformIDs = rhs.m_AMFTransformIDs;
70-
m_ICCProfileName = rhs.m_ICCProfileName;
76+
m_interchangeAttribs= rhs.m_interchangeAttribs;
7177
m_bitDepth = rhs.m_bitDepth;
7278
m_isData = rhs.m_isData;
7379
m_referenceSpaceType = rhs.m_referenceSpaceType;
@@ -277,27 +283,60 @@ void ColorSpace::setInteropID(const char * interopID)
277283
getImpl()->m_interopID = id;
278284
}
279285

280-
const char * ColorSpace::getAMFTransformIDs() const noexcept
286+
const char * ColorSpace::getInterchangeAttribute(const char* attrName) const
281287
{
282-
return getImpl()->m_AMFTransformIDs.c_str();
283-
}
288+
std::string nameTrimmed = StringUtils::Trim(attrName);
289+
for (auto& key : knownInterchangeNames)
290+
{
291+
// do case-insensitive comparison.
292+
if (StringUtils::Compare(key, nameTrimmed))
293+
{
294+
auto it = m_impl->m_interchangeAttribs.find(key);
295+
if (it != m_impl->m_interchangeAttribs.end())
296+
{
297+
return it->second.c_str();
298+
}
299+
return "";
300+
}
301+
}
284302

285-
void ColorSpace::setAMFTransformIDs(const char * amfTransformIDs)
286-
{
287-
getImpl()->m_AMFTransformIDs = amfTransformIDs ? amfTransformIDs : "";
303+
std::ostringstream oss;
304+
oss << "Unknown attribute name '" << attrName << "'.";
305+
throw Exception(oss.str().c_str());
288306
}
289307

290-
const char * ColorSpace::getICCProfileName() const noexcept
308+
void ColorSpace::setInterchangeAttribute(const char* attrName, const char* value)
291309
{
292-
return getImpl()->m_ICCProfileName.c_str();
310+
std::string nameTrimmed = StringUtils::Trim(attrName);
311+
for (auto& key : knownInterchangeNames)
312+
{
313+
// Do case-insensitive comparison.
314+
if (StringUtils::Compare(key, nameTrimmed))
315+
{
316+
// use key instead of nameTrim for storing in correct capitalization.
317+
if (!value || !*value)
318+
{
319+
m_impl->m_interchangeAttribs.erase(key);
320+
}
321+
else
322+
{
323+
m_impl->m_interchangeAttribs[key] = value;
324+
}
325+
return;
326+
}
327+
}
328+
329+
std::ostringstream oss;
330+
oss << "Unknown attribute name '" << attrName << "'.";
331+
throw Exception(oss.str().c_str());
293332
}
294333

295-
void ColorSpace::setICCProfileName(const char * iccProfileName)
334+
std::map<std::string, std::string> ColorSpace::getInterchangeAttributes() const noexcept
296335
{
297-
getImpl()->m_ICCProfileName = iccProfileName ? iccProfileName : "";
336+
return m_impl->m_interchangeAttribs;
298337
}
299338

300-
BitDepth ColorSpace::getBitDepth() const noexcept
339+
BitDepth ColorSpace::ColorSpace::getBitDepth() const noexcept
301340
{
302341
return getImpl()->m_bitDepth;
303342
}
@@ -516,15 +555,10 @@ std::ostream & operator<< (std::ostream & os, const ColorSpace & cs)
516555
{
517556
os << ", description=" << str;
518557
}
519-
str = cs.getAMFTransformIDs();
520-
if (!str.empty())
521-
{
522-
os << ", amf_transform_ids=" << str;
523-
}
524-
str = cs.getICCProfileName();
525-
if (!str.empty())
558+
// TODO: Do we need to output the section name too?
559+
for (const auto& attr : cs.getInterchangeAttributes())
526560
{
527-
os << ", icc_profile_name=" << str;
561+
os << ", " << attr.first << "=" << attr.second;
528562
}
529563
if(cs.getTransform(COLORSPACE_DIR_TO_REFERENCE))
530564
{

src/OpenColorIO/Config.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5675,27 +5675,20 @@ void Config::Impl::checkVersionConsistency() const
56755675
}
56765676
}
56775677

5678-
if (hexVersion < 0x02050000) // Version 2.5
5678+
if (m_majorVersion < 2)
56795679
{
56805680
if (*cs->getInteropID())
56815681
{
56825682
std::ostringstream os;
56835683
os << "Config failed validation. The color space '" << cs->getName() << "' ";
5684-
os << "has non-empty InteropID and config version is less than 2.5.";
5685-
throw Exception(os.str().c_str());
5686-
}
5687-
if (*cs->getAMFTransformIDs())
5688-
{
5689-
std::ostringstream os;
5690-
os << "Config failed validation. The color space '" << cs->getName() << "' ";
5691-
os << "has non-empty AMFTransformIDs and config version is less than 2.5.";
5684+
os << "has non-empty InteropID and config version is less than 2.0.";
56925685
throw Exception(os.str().c_str());
56935686
}
5694-
if (*cs->getICCProfileName())
5687+
if (cs->getInterchangeAttributes().size()>0)
56955688
{
56965689
std::ostringstream os;
56975690
os << "Config failed validation. The color space '" << cs->getName() << "' ";
5698-
os << "has non-empty ICCProfileName and config version is less than 2.5.";
5691+
os << "has non-empty interchange attributes and config version is less than 2.0.";
56995692
throw Exception(os.str().c_str());
57005693
}
57015694
}

0 commit comments

Comments
 (0)