Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/OpenColorIO/OpenColorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,13 @@ extern OCIOEXPORT const char * METADATA_NAME;
*/
extern OCIOEXPORT const char * METADATA_ID;

/**
* An ID when stored as an XML element rather than as an attribute. This is the
* preferred mechanism in the SMPTE ST 2036-1 version of the CLF format. If
* present, it is only available from the top-level FormatMetadata.
*/
extern OCIOEXPORT const char * METADATA_ID_ELEMENT;

/*!rst::
Caches
******
Expand Down
24 changes: 24 additions & 0 deletions src/OpenColorIO/HashUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright Contributors to the OpenColorIO Project.

#include <sstream>
#include <iomanip>

#include <OpenColorIO/OpenColorIO.h>

Expand All @@ -25,4 +26,27 @@ std::string CacheIDHash(const char * array, std::size_t size)
return oss.str();
}

std::string CacheIDHashUUID(const char * array, std::size_t size)
{
XXH128_hash_t hash = XXH3_128bits(array, size);

// Make sure that we have full, zero-padded 32 chars.
std::stringstream oss;
oss << std::hex << std::setfill('0');
oss << std::setw(16) << hash.high64;
oss << std::setw(16) << hash.low64;

// Format into 8-4-4-4-12 form.
std::string hex = oss.str();
std::string uuid =
hex.substr(0, 8) + "-" +
hex.substr(8, 4) + "-" +
hex.substr(12, 4) + "-" +
hex.substr(16, 4) + "-" +
hex.substr(20, 12);

return uuid;
}


} // namespace OCIO_NAMESPACE
4 changes: 4 additions & 0 deletions src/OpenColorIO/HashUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace OCIO_NAMESPACE

std::string CacheIDHash(const char * array, std::size_t size);

// Generates 128 bit UUID in the form of 8-4-4-4-12 using the hash of the passed
// string.
std::string CacheIDHashUUID(const char * array, std::size_t size);

} // namespace OCIO_NAMESPACE

#endif
12 changes: 3 additions & 9 deletions src/OpenColorIO/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,9 @@ const char * Processor::Impl::getCacheID() const

if(!m_cacheID.empty()) return m_cacheID.c_str();

if(m_ops.empty())
{
m_cacheID = "<NOOP>";
}
else
{
const std::string fullstr = m_ops.getCacheID();
m_cacheID = CacheIDHash(fullstr.c_str(), fullstr.size());
}
// Note: empty ops vector will also create a UUID.
const std::string fullstr = m_ops.getCacheID();
m_cacheID = CacheIDHashUUID(fullstr.c_str(), fullstr.size());

return m_cacheID.c_str();
}
Expand Down
Loading