Skip to content

Commit

Permalink
Adsk Contrib - Enhance default view access (AcademySoftwareFoundation…
Browse files Browse the repository at this point in the history
…#1422)

Signed-off-by: Patrick Hodoul <Patrick.Hodoul@autodesk.com>

Co-authored-by: doug-walker <43830961+doug-walker@users.noreply.github.com>
  • Loading branch information
hodoulp and doug-walker committed Jul 6, 2021
1 parent e63ce1c commit c835f31
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/OpenColorIO/OpenColorIO.h
Expand Up @@ -607,6 +607,9 @@ class OCIOEXPORT Config
const char * getDisplay(int index) const;

const char * getDefaultView(const char * display) const;
// Get the default view for a given color space using the viewing rules.
// This is the preferred call to use if the color space being viewed is known.
const char * getDefaultView(const char * display, const char * colorspaceName) const;

/**
* Return the number of views attached to the display including the number of
Expand Down
5 changes: 5 additions & 0 deletions src/OpenColorIO/Config.cpp
Expand Up @@ -2972,6 +2972,11 @@ const char * Config::getDefaultView(const char * display) const
return getView(display, 0);
}

const char * Config::getDefaultView(const char * display, const char * colorspaceName) const
{
return getView(display, colorspaceName, 0);
}

int Config::getNumViews(const char * display) const
{
if (!display || !*display) return 0;
Expand Down
8 changes: 7 additions & 1 deletion src/bindings/python/PyConfig.cpp
Expand Up @@ -342,7 +342,13 @@ void bindPyConfig(py::module & m)
{
return DisplayIterator(self);
})
.def("getDefaultView", &Config::getDefaultView, "display"_a,
.def("getDefaultView",
(const char * (Config::*)(const char *) const)
&Config::getDefaultView, "display"_a,
DOC(Config, getDefaultView))
.def("getDefaultView",
(const char * (Config::*)(const char *, const char *) const)
&Config::getDefaultView, "display"_a, "colorSpacename"_a,
DOC(Config, getDefaultView))
.def("getViews", [](ConfigRcPtr & self, const std::string & display)
{
Expand Down
6 changes: 6 additions & 0 deletions tests/cpu/ViewingRules_tests.cpp
Expand Up @@ -508,4 +508,10 @@ active_views: []
OCIO_CHECK_EQUAL(view, "SView_a");
OCIO_CHECK_NO_THROW(view = configav->getView("sRGB", "c3", 4));
OCIO_CHECK_EQUAL(view, "View_b");

// Test the default methods.

OCIO_CHECK_EQUAL(std::string("sRGB"), std::string(configav->getDefaultDisplay()));
OCIO_CHECK_EQUAL(std::string(configav->getView("sRGB", "c3", 0)),
std::string(configav->getDefaultView("sRGB", "c3")));
}

0 comments on commit c835f31

Please sign in to comment.