Skip to content

Commit 9221ffa

Browse files
Adsk Contrib - Adding support for ocio://cg-config-latest and ocio://studio-config-latest (#1773)
* Added ResolveConfigPath function Signed-off-by: Cédrik Fuoco <[email protected]> * Added support for ocio://cg-config-latest and ocio://studio-config-latest Added unit tests that covers the new names. CreateFromBuiltinConfig now supports the URI interface directly as well. Previously, it was supporting only the built-in config name (not a URI). The config name was parsed out of the URI before passing it to CreateFromBuiltConfig by CreateFromFile. Signed-off-by: Cédrik Fuoco <[email protected]> * Documentations and typos Tweaking unit tests Other minor changes Signed-off-by: Cédrik Fuoco <[email protected]> * documentations Signed-off-by: Cédrik Fuoco <[email protected]> * Using OCIO_BUILTIN_URI_PREFIX where we can in the code (not in tests) Adding missing type in PyTypes.cpp Change name of constexpr to follow the others in OCIO (all in capital) Moved them to the cpp file since they can be useful in tests Comments Signed-off-by: Cédrik Fuoco <[email protected]> * documentation Signed-off-by: Cédrik Fuoco <[email protected]> * Fixing error : ISO C++ forbids converting a string constant to 'char*' that was brought up with Clang under Linux and macos. Signed-off-by: Cédrik Fuoco <[email protected]> * Remove deprecation for getDefaultBuiltinConfigName. Will wait for 2.3 release. Signed-off-by: Cédrik Fuoco <[email protected]> * Fixing issue with the rebase Signed-off-by: Cédrik Fuoco <[email protected]> --------- Signed-off-by: Cédrik Fuoco <[email protected]> Signed-off-by: Cédrik Fuoco <[email protected]> Signed-off-by: Doug Walker <[email protected]> Co-authored-by: Doug Walker <[email protected]>
1 parent 9cc2486 commit 9221ffa

File tree

15 files changed

+605
-529
lines changed

15 files changed

+605
-529
lines changed

include/OpenColorIO/OpenColorIO.h

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ extern OCIOEXPORT ConstConfigRcPtr GetCurrentConfig();
206206
/// Set the current configuration. This will then store a copy of the specified config.
207207
extern OCIOEXPORT void SetCurrentConfig(const ConstConfigRcPtr & config);
208208

209+
/**
210+
* \brief Make a config path forward-compatible by replacing special built-in config names
211+
* with the current name.
212+
*
213+
* Application developers should call this function on any config path they intend to persist
214+
* (e.g., to include in a file saved from a DCC).
215+
*
216+
* As the built-in config collection evolves, special names such as "ocio://default" and
217+
* "ocio://studio-config-latest" will point to newer versions of those configs. Therefore, it is
218+
* recommended that application developers not save those strings and instead save the string that
219+
* refers to the current version of that config. That way, it's guaranteed that there will be no
220+
* change of behavior in the future. For example, as of OCIO 2.2, "ocio://default" should be saved
221+
* as "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1".
222+
*
223+
* Note that there is no validation done on the path. That is left to the application since
224+
* typically the application will load the config before attempting to save its path
225+
* and therefore catch, for example, a badly formed URI such as "ocio:default".
226+
*
227+
* \return Resolved path if possible. Otherwise, the original path is returned unmodified.
228+
*/
229+
extern OCIOEXPORT const char * ResolveConfigPath(const char * originalPath) noexcept;
230+
209231
/**
210232
* \brief Extract an OCIO Config archive.
211233
*
@@ -298,13 +320,11 @@ class OCIOEXPORT Config
298320
/**
299321
* \brief Create a configuration using a specific config file.
300322
*
301-
* Also supports the following OCIO URI format for Built-in configs:
302-
* "ocio://default" - Default Built-in config.
303-
* "ocio://<CONFIG NAME>" - A specific Built-in config. For the list of available
304-
* <CONFIG NAME> strings, see \ref Config::CreateFromBuiltinConfig.
305-
*
306-
* Also supports archived configs (.ocioz files).
323+
* Supports the OCIO URI format for Built-in configs.
324+
* See \ref Config::CreateFromBuiltinConfig.
307325
*
326+
* Supports archived configs (.ocioz files).
327+
*
308328
* \throw Exception If the file may not be read or does not parse.
309329
* \return The Config object.
310330
*/
@@ -342,7 +362,13 @@ class OCIOEXPORT Config
342362
/**
343363
* \brief Create a configuration using an OCIO built-in config.
344364
*
345-
* \param configName Built-in config name.
365+
* \param configName Built-in config name (with or without the "ocio://" URI prefix).
366+
*
367+
* Also supports the following OCIO URI format for Built-in configs:
368+
* "ocio://default" - Default Built-in config.
369+
* "ocio://cg-config-latest" - Latest Built-in CG config.
370+
* "ocio://studio-config-latest" - Latest Built-in Studio config.
371+
* "ocio://<CONFIG NAME>" - A specific Built-in config.
346372
*
347373
* The available configNames are:
348374
*
@@ -3680,22 +3706,8 @@ class OCIOEXPORT BuiltinConfigRegistry
36803706
*/
36813707
virtual bool isBuiltinConfigRecommended(size_t configIndex) const = 0;
36823708

3683-
/**
3684-
* @brief Get the default recommended built-in config.
3685-
*
3686-
* Get the name of the built-in config that is currently recommended as the default config
3687-
* to use for applications looking for basic color management.
3688-
*
3689-
* As the built-in config collection evolves, the default config name will change in future
3690-
* releases.
3691-
*
3692-
* For backwards compatibility, the name provided here will always work as an argument
3693-
* to other methods so that any previous default config may be recovered.
3694-
*
3695-
* Throws if the name is not found.
3696-
*
3697-
* @return Default's built-in config name.
3698-
*/
3709+
// Return the full forward-compatible name of the default built-in config.
3710+
// Please use ResolveConfigPath(\"ocio://default\"). This method will be deprecated in OCIO 2.3.
36993711
virtual const char * getDefaultBuiltinConfigName() const = 0;
37003712
protected:
37013713
BuiltinConfigRegistry() = default;

include/OpenColorIO/OpenColorTypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,10 @@ extern OCIOEXPORT const char * OCIO_CONFIG_DEFAULT_NAME;
945945
extern OCIOEXPORT const char * OCIO_CONFIG_DEFAULT_FILE_EXT;
946946
extern OCIOEXPORT const char * OCIO_CONFIG_ARCHIVE_FILE_EXT;
947947

948+
// Built-in config feature
949+
// URI Prefix
950+
extern OCIOEXPORT const char * OCIO_BUILTIN_URI_PREFIX;
951+
948952
} // namespace OCIO_NAMESPACE
949953

950954
#endif

src/OpenColorIO/Config.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const char * OCIO_CONFIG_ARCHIVE_FILE_EXT = ".ocioz";
5959
// has the same name as the display the shared view is used by.
6060
const char * OCIO_VIEW_USE_DISPLAY_NAME = "<USE_DISPLAY_NAME>";
6161

62+
const char * OCIO_BUILTIN_URI_PREFIX = "ocio://";
63+
6264
namespace
6365
{
6466

@@ -1160,13 +1162,7 @@ ConstConfigRcPtr Config::CreateFromFile(const char * filename)
11601162
const std::string uri = filename;
11611163
if (std::regex_search(uri, match, uriPattern))
11621164
{
1163-
if (Platform::Strcasecmp(match.str(1).c_str(), "default") == 0)
1164-
{
1165-
// Processing ocio://default
1166-
const BuiltinConfigRegistry & reg = BuiltinConfigRegistry::Get();
1167-
return CreateFromBuiltinConfig(reg.getDefaultBuiltinConfigName());
1168-
}
1169-
return CreateFromBuiltinConfig(match.str(1).c_str());
1165+
return CreateFromBuiltinConfig(uri.c_str());
11701166
}
11711167

11721168
std::ifstream ifstream = Platform::CreateInputFileStream(
@@ -1234,11 +1230,31 @@ ConstConfigRcPtr Config::CreateFromConfigIOProxy(ConfigIOProxyRcPtr ciop)
12341230

12351231
ConstConfigRcPtr Config::CreateFromBuiltinConfig(const char * configName)
12361232
{
1233+
std::string builtinConfigName = configName;
1234+
1235+
// Normalize the input to the URI format.
1236+
if (!StringUtils::StartsWith(builtinConfigName, OCIO_BUILTIN_URI_PREFIX))
1237+
{
1238+
builtinConfigName = std::string(OCIO_BUILTIN_URI_PREFIX) + builtinConfigName;
1239+
}
1240+
1241+
// Resolve the URI if needed.
1242+
const std::string uri = ResolveConfigPath(builtinConfigName.c_str());
1243+
1244+
// Check if the config path starts with ocio://
1245+
static const std::regex uriPattern(R"(ocio:\/\/([^\s]+))");
1246+
std::smatch match;
1247+
if (std::regex_search(uri, match, uriPattern))
1248+
{
1249+
// Store config path without the "ocio://" prefix, if present.
1250+
builtinConfigName = match.str(1).c_str();
1251+
}
1252+
12371253
ConstConfigRcPtr builtinConfig;
12381254
const BuiltinConfigRegistry & reg = BuiltinConfigRegistry::Get();
12391255

12401256
// getBuiltinConfigByName will throw if config name not found.
1241-
const char * builtinConfigStr = reg.getBuiltinConfigByName(configName);
1257+
const char * builtinConfigStr = reg.getBuiltinConfigByName(builtinConfigName.c_str());
12421258
std::istringstream iss;
12431259
iss.str(builtinConfigStr);
12441260
builtinConfig = Config::CreateFromStream(iss);

src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.cpp

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <memory>
55
#include <algorithm>
66
#include <sstream>
7+
#include <regex>
78

89
// OpenColorIO must be first - order is important.
910
#include <OpenColorIO/OpenColorIO.h>
@@ -15,11 +16,51 @@
1516
#include "builtinconfigs/CGConfig.h"
1617
#include "builtinconfigs/StudioConfig.h"
1718

18-
#define OUT_OF_RANGE_EXCEPTION_TEXT "Config index is out of range."
19+
static constexpr char OUT_OF_RANGE_EXCEPTION_TEXT[] = "Config index is out of range.";
20+
21+
// TODO: Remove once getDefaultBuiltinConfigName is removed.
22+
static constexpr char DEFAULT_BUILTIN_CONFIG[] = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1";
23+
24+
// These are used for ResolveConfigPath function and we need to return a variable that still exists
25+
// once the function finishes since we are returning a const char *.
26+
static constexpr char DEFAULT_BUILTIN_CONFIG_URI[] = "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1";
27+
static constexpr char LATEST_CG_BUILTIN_CONFIG_URI[] = "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1";
28+
static constexpr char LATEST_STUDIO_BUILTIN_CONFIG_URI[] = "ocio://studio-config-v1.0.0_aces-v1.3_ocio-v2.1";
29+
30+
static constexpr char BUILTIN_DEFAULT_NAME[] = "default";
31+
static constexpr char BUILTIN_LATEST_CG_NAME[] = "cg-config-latest";
32+
static constexpr char BUILTIN_LATEST_STUDIO_NAME[] = "studio-config-latest";
1933

2034
namespace OCIO_NAMESPACE
2135
{
2236

37+
// Note that this function does not require initializing the built-in config registry.
38+
const char * ResolveConfigPath(const char * originalPath) noexcept
39+
{
40+
static const std::regex uriPattern(R"(ocio:\/\/([^\s]+))");
41+
std::smatch match;
42+
const std::string uri = originalPath;
43+
// Check if original path starts with "ocio://".
44+
if (std::regex_search(uri, match, uriPattern))
45+
{
46+
if (Platform::Strcasecmp(match.str(1).c_str(), BUILTIN_DEFAULT_NAME) == 0)
47+
{
48+
return DEFAULT_BUILTIN_CONFIG_URI;
49+
}
50+
else if (Platform::Strcasecmp(match.str(1).c_str(), BUILTIN_LATEST_CG_NAME) == 0)
51+
{
52+
return LATEST_CG_BUILTIN_CONFIG_URI;
53+
}
54+
else if (Platform::Strcasecmp(match.str(1).c_str(), BUILTIN_LATEST_STUDIO_NAME) == 0)
55+
{
56+
return LATEST_STUDIO_BUILTIN_CONFIG_URI;
57+
}
58+
}
59+
60+
// Return originalPath if no special path was used.
61+
return originalPath;
62+
}
63+
2364
const BuiltinConfigRegistry & BuiltinConfigRegistry::Get() noexcept
2465
{
2566
// Meyer's Singleton pattern.
@@ -46,8 +87,6 @@ void BuiltinConfigRegistryImpl::init() noexcept
4687

4788
CGCONFIG::Register(*this);
4889
STUDIOCONFIG::Register(*this);
49-
50-
this->setDefaultBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1");
5190
}
5291
}
5392

@@ -131,28 +170,7 @@ bool BuiltinConfigRegistryImpl::isBuiltinConfigRecommended(size_t configIndex) c
131170

132171
const char * BuiltinConfigRegistryImpl::getDefaultBuiltinConfigName() const
133172
{
134-
if (m_defaultBuiltinConfigName.empty())
135-
{
136-
// Make sure that at least one default built-ins config is present.
137-
throw Exception("Internal error - The default built-in config name has not been set yet.");
138-
}
139-
140-
return m_defaultBuiltinConfigName.c_str();
141-
}
142-
143-
void BuiltinConfigRegistryImpl::setDefaultBuiltinConfig(const char * configName)
144-
{
145-
// Search for config name.
146-
for (auto & builtin : m_builtinConfigs)
147-
{
148-
if (Platform::Strcasecmp(configName, builtin.m_name.c_str()) == 0)
149-
{
150-
m_defaultBuiltinConfigName = configName;
151-
return;
152-
}
153-
}
154-
155-
throw Exception("Internal error - Config name does not exist.");
173+
return DEFAULT_BUILTIN_CONFIG;
156174
}
157175

158176
} // namespace OCIO_NAMESPACE

src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,9 @@ using BuiltinConfigs = std::vector<BuiltinConfigData>;
9494
bool isBuiltinConfigRecommended(size_t configIndex) const override;
9595

9696
/// Get the default recommended built-in config.
97-
/// Throws for illegal index.
9897
const char * getDefaultBuiltinConfigName() const override;
99-
100-
/// Set the default built-in config.
101-
void setDefaultBuiltinConfig(const char * configName);
10298
private:
10399
BuiltinConfigs m_builtinConfigs;
104-
std::string m_defaultBuiltinConfigName;
105100
};
106101

107102
} // namespace OCIO_NAMESPACE

src/OpenColorIO/builtinconfigs/CG.cpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
// It is included in the following places:
88
// - CGConfig.cpp for the Built-in config feature.
9-
// - BuiltinConfigRegistry_tests.cpp for the unit tests
9+
// - BuiltinConfig_tests.cpp for the unit tests
1010

1111
constexpr char CG_CONFIG_V100_ACES_V13_OCIO_V21[] = { @cg-config-v1.0.0_aces-v1.3_ocio-v2.1@ };

src/OpenColorIO/builtinconfigs/CGConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ namespace CGCONFIG
1717
{
1818
void Register(BuiltinConfigRegistryImpl & registry) noexcept
1919
{
20+
// If a new built-in config is added, do not forget to update the latestCGBuiltinConfigURI
21+
// variable (in BuiltinConfigRegistry.h).
22+
2023
registry.addBuiltin(
2124
"cg-config-v1.0.0_aces-v1.3_ocio-v2.1",
2225
"Academy Color Encoding System - CG Config [COLORSPACES v1.0.0] [ACES v1.3] [OCIO v2.1]",

src/OpenColorIO/builtinconfigs/StudioConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ namespace STUDIOCONFIG
1717
{
1818
void Register(BuiltinConfigRegistryImpl & registry) noexcept
1919
{
20+
// If a new built-in config is added, do not forget to update the latestStudioBuiltinConfigURI
21+
// variable (in BuiltinConfigRegistry.h).
22+
2023
registry.addBuiltin(
2124
"studio-config-v1.0.0_aces-v1.3_ocio-v2.1",
2225
"Academy Color Encoding System - Studio Config [COLORSPACES v1.0.0] [ACES v1.3] [OCIO v2.1]",

src/bindings/python/PyConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,9 @@ void bindPyConfig(py::module & m)
13071307

13081308
m.def("ExtractOCIOZArchive", &ExtractOCIOZArchive,
13091309
DOC(PyOpenColorIO, ExtractOCIOZArchive));
1310+
1311+
m.def("ResolveConfigPath", &ResolveConfigPath,
1312+
DOC(PyOpenColorIO, ResolveConfigPath));
13101313
}
13111314

13121315
} // namespace OCIO_NAMESPACE

src/bindings/python/PyTypes.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,12 @@ void bindPyTypes(py::module & m)
880880
m.attr("OCIO_DISABLE_ALL_CACHES") = OCIO_DISABLE_ALL_CACHES;
881881
m.attr("OCIO_DISABLE_PROCESSOR_CACHES") = OCIO_DISABLE_PROCESSOR_CACHES;
882882
m.attr("OCIO_DISABLE_CACHE_FALLBACK") = OCIO_DISABLE_CACHE_FALLBACK;
883+
884+
m.attr("OCIO_CONFIG_DEFAULT_NAME") = OCIO_CONFIG_DEFAULT_NAME;
885+
m.attr("OCIO_CONFIG_DEFAULT_FILE_EXT") = OCIO_CONFIG_DEFAULT_FILE_EXT;
886+
m.attr("OCIO_CONFIG_ARCHIVE_FILE_EXT") = OCIO_CONFIG_ARCHIVE_FILE_EXT;
887+
888+
m.attr("OCIO_BUILTIN_URI_PREFIX") = OCIO_BUILTIN_URI_PREFIX;
883889
}
884890

885891
} // namespace OCIO_NAMESPACE

0 commit comments

Comments
 (0)