Skip to content

Commit 5a9d520

Browse files
Merge branch 'AcademySoftwareFoundation:main' into bugfix/1868
2 parents 907bc53 + 6c15d45 commit 5a9d520

File tree

6 files changed

+892
-7
lines changed

6 files changed

+892
-7
lines changed

include/OpenColorIO/OpenColorIO.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,20 @@ class OCIOEXPORT Config
852852
* \ref Config::validate will throw if the config does not contain
853853
* the matching display color space.
854854
*/
855+
856+
/// Check if a view within a given display is referencing one of the config's shared views.
857+
bool viewIsShared(const char * dispName, const char * viewName) const;
858+
855859
/// Will throw if view or colorSpaceName are null or empty.
856860
void addSharedView(const char * view, const char * viewTransformName,
857861
const char * colorSpaceName, const char * looks,
858862
const char * ruleName, const char * description);
859863
/// Remove a shared view. Will throw if the view does not exist.
860864
void removeSharedView(const char * view);
861865

866+
/// Clear all shared views. This will throw if any displays are still using the shared views.
867+
void clearSharedViews();
868+
862869
const char * getDefaultDisplay() const;
863870
int getNumDisplays() const;
864871
/// Will return "" if the index is invalid.
@@ -883,6 +890,23 @@ class OCIOEXPORT Config
883890
int getNumViews(const char * display, const char * colorspaceName) const;
884891
const char * getView(const char * display, const char * colorspaceName, int index) const;
885892

893+
/**
894+
* \brief Compare views in a pair of configs.
895+
*
896+
* Will return false if either of the views does not exist. This will return true even
897+
* if the view is display-defined in one config and a reference to a shared view in the
898+
* other config (both within the same display), as long as the contents match. The
899+
* description text (if any) is ignored, since it is not a functional difference.
900+
*
901+
* Note that the comparison is only on the strings contained in the view definition,
902+
* the function does not attempt to compare that the color spaces or view transforms
903+
* being referenced are identical (only that they have the same name).
904+
*/
905+
static bool ViewsAreEqual(const ConstConfigRcPtr & first,
906+
const ConstConfigRcPtr & second,
907+
const char * dispName,
908+
const char * viewName);
909+
886910
/**
887911
* Returns the view_transform attribute of the (display, view) pair. View can
888912
* be a shared view of the display. If display is null or empty, config shared views are used.
@@ -900,6 +924,17 @@ class OCIOEXPORT Config
900924
/// Returns the description attribute of a (display, view) pair.
901925
const char * getDisplayViewDescription(const char * display, const char * view) const noexcept;
902926

927+
/**
928+
* \brief Determine if a display and view exist.
929+
*
930+
* This returns false if either the display or view doesn't exist. It works regardless
931+
* of whether the display or view are active, and it works regardless of whether the
932+
* view is display-defined or if the display has this as a shared view. It will only
933+
* check config-level shared views if dispName is null. It will not check config level
934+
* shared views if dispName is not null.
935+
*/
936+
bool displayHasView(const char * dispName, const char * viewName) const;
937+
903938
/**
904939
* For the (display, view) pair, specify which color space and look to use.
905940
* If a look is not desired, then just pass a null or empty string.
@@ -963,6 +998,18 @@ class OCIOEXPORT Config
963998
*
964999
*/
9651000

1001+
/**
1002+
* \brief Determine if a virtual view exists.
1003+
*
1004+
* This returns false if the virtual view doesn't exist. It works regardless of
1005+
* whether the virtual view is active, and it works regardless of whether the virtual
1006+
* view is display-defined or if the display has this as a shared virtual view.
1007+
*/
1008+
bool hasVirtualView(const char * viewName) const;
1009+
1010+
/// Check if a given virtual view is referencing one of the config's shared views.
1011+
bool virtualViewIsShared(const char * viewName) const;
1012+
9661013
void addVirtualDisplayView(const char * view,
9671014
const char * viewTransformName,
9681015
const char * colorSpaceName,
@@ -977,6 +1024,23 @@ class OCIOEXPORT Config
9771024
/// Get the view name at a specific index.
9781025
const char * getVirtualDisplayView(ViewType type, int index) const noexcept;
9791026

1027+
/**
1028+
* \brief Compare virtual views in a pair of configs.
1029+
*
1030+
* Will return false if either of the virtual views does not exist. This will return true
1031+
* even if the virtual view is display-defined in one config and a reference to a shared
1032+
* virtual view in the other config, as long as the contents match.
1033+
*
1034+
* The description text (if any) is ignored, since it is not a functional difference.
1035+
*
1036+
* Note that the comparison is only on the strings contained in the view definition,
1037+
* the function does not attempt to compare that the color spaces or view transforms
1038+
* being referenced are identical (only that they have the same name).
1039+
*/
1040+
static bool VirtualViewsAreEqual(const ConstConfigRcPtr & first,
1041+
const ConstConfigRcPtr & second,
1042+
const char * viewName);
1043+
9801044
const char * getVirtualDisplayViewTransformName(const char * view) const noexcept;
9811045
const char * getVirtualDisplayViewColorSpaceName(const char * view) const noexcept;
9821046
const char * getVirtualDisplayViewLooks(const char * view) const noexcept;

src/OpenColorIO/Config.cpp

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,6 +3305,22 @@ void Config::setViewingRules(ConstViewingRulesRcPtr viewingRules)
33053305
getImpl()->resetCacheIDs();
33063306
}
33073307

3308+
bool Config::viewIsShared(const char * dispName, const char * viewName) const
3309+
{
3310+
if (!viewName || !*viewName) return false;
3311+
3312+
for (int v = 0; v < getNumViews(VIEW_SHARED, dispName); v++)
3313+
{
3314+
const char * sharedViewName = getView(VIEW_SHARED, dispName, v);
3315+
if (sharedViewName && *sharedViewName && Platform::Strcasecmp(sharedViewName, viewName) == 0)
3316+
{
3317+
return true;
3318+
}
3319+
}
3320+
3321+
return false;
3322+
}
3323+
33083324
void Config::addSharedView(const char * view, const char * viewTransform,
33093325
const char * colorSpace, const char * looks,
33103326
const char * rule, const char * description)
@@ -3358,6 +3374,19 @@ void Config::removeSharedView(const char * view)
33583374
}
33593375
}
33603376

3377+
void Config::clearSharedViews()
3378+
{
3379+
int numViews = getNumViews(VIEW_SHARED, nullptr);
3380+
for (int v = numViews - 1; v >= 0; v--)
3381+
{
3382+
const char * sharedViewName = getView(VIEW_SHARED, nullptr, v);
3383+
if (sharedViewName && *sharedViewName)
3384+
{
3385+
removeSharedView(sharedViewName);
3386+
}
3387+
}
3388+
}
3389+
33613390
const char * Config::getDefaultDisplay() const
33623391
{
33633392
return getDisplay(0);
@@ -3487,6 +3516,43 @@ const char * Config::getView(const char * display, const char * colorspace, int
34873516
return "";
34883517
}
34893518

3519+
3520+
bool Config::ViewsAreEqual(const ConstConfigRcPtr & first,
3521+
const ConstConfigRcPtr & second,
3522+
const char * dispName, // may be empty or nullptr for shared views
3523+
const char * viewName)
3524+
{
3525+
// It's ok to call this even for displays/views that don't exist, it will simply return false.
3526+
3527+
// Note that this will return true even if the view is display-defined in one config and a reference
3528+
// to a shared view in the other config (both within the same display), as long as the contents match.
3529+
3530+
// These calls return null if either the display or view doesn't exist (regardless if it's active).
3531+
const char * cs1 = first->getDisplayViewColorSpaceName(dispName, viewName);
3532+
const char * cs2 = second->getDisplayViewColorSpaceName(dispName, viewName);
3533+
3534+
// If the color space is not null, the display and view exist.
3535+
if (cs1 && *cs1 && cs2 && *cs2)
3536+
{
3537+
// Both configs have a display and view by this name, now check the contents.
3538+
if (Platform::Strcasecmp(cs1, cs2) == 0)
3539+
{
3540+
// Note the remaining strings may be empty in a valid view.
3541+
// Intentionally not checking the description since it is not a functional difference.
3542+
if ( (Platform::Strcasecmp(first->getDisplayViewLooks(dispName, viewName),
3543+
second->getDisplayViewLooks(dispName, viewName)) == 0) &&
3544+
(Platform::Strcasecmp(first->getDisplayViewTransformName(dispName, viewName),
3545+
second->getDisplayViewTransformName(dispName, viewName)) == 0) &&
3546+
(Platform::Strcasecmp(first->getDisplayViewRule(dispName, viewName),
3547+
second->getDisplayViewRule(dispName, viewName)) == 0) )
3548+
{
3549+
return true;
3550+
}
3551+
}
3552+
}
3553+
return false;
3554+
}
3555+
34903556
const char * Config::getDisplayViewTransformName(const char * display, const char * view) const
34913557
{
34923558
const View * viewPtr = getImpl()->getView(display, view);
@@ -3525,6 +3591,21 @@ const char * Config::getDisplayViewDescription(const char * display, const char
35253591
return viewPtr ? viewPtr->m_description.c_str() : "";
35263592
}
35273593

3594+
bool Config::displayHasView(const char * dispName, const char * viewName) const
3595+
{
3596+
// This returns null if either the display or view doesn't exist.
3597+
// It works regardless of whether the display or view are active,
3598+
// and it works regardless of whether the view is display-defined
3599+
// or if the display has this as a shared view.
3600+
//
3601+
// It will only check config level shared views if dispName is null.
3602+
// It will not check config level shared views if dispName is not null.
3603+
const char * cs = getDisplayViewColorSpaceName(dispName, viewName);
3604+
3605+
// All views must have a color space, so if it's not empty, the view exists.
3606+
return (cs && *cs);
3607+
}
3608+
35283609
void Config::addDisplaySharedView(const char * display, const char * sharedView)
35293610
{
35303611
if (!display || !*display)
@@ -3695,6 +3776,30 @@ void Config::clearDisplays()
36953776
getImpl()->resetCacheIDs();
36963777
}
36973778

3779+
bool Config::hasVirtualView(const char * viewName) const
3780+
{
3781+
const char * cs = getVirtualDisplayViewColorSpaceName(viewName);
3782+
3783+
// All views must have a color space, so if it's not empty, the view exists.
3784+
return (cs && *cs);
3785+
}
3786+
3787+
bool Config::virtualViewIsShared(const char * viewName) const
3788+
{
3789+
if (!viewName || !*viewName) return false;
3790+
3791+
for (int v = 0; v < getVirtualDisplayNumViews(VIEW_SHARED); v++)
3792+
{
3793+
const char * sharedViewName = getVirtualDisplayView(VIEW_SHARED, v);
3794+
if (sharedViewName && *sharedViewName && Platform::Strcasecmp(sharedViewName, viewName) == 0)
3795+
{
3796+
return true;
3797+
}
3798+
}
3799+
3800+
return false;
3801+
}
3802+
36983803
void Config::addVirtualDisplayView(const char * view,
36993804
const char * viewTransform,
37003805
const char * colorSpace,
@@ -3795,10 +3900,44 @@ const char * Config::getVirtualDisplayView(ViewType type, int index) const noexc
37953900
return "";
37963901
}
37973902

3903+
bool Config::VirtualViewsAreEqual(const ConstConfigRcPtr & first,
3904+
const ConstConfigRcPtr & second,
3905+
const char * viewName)
3906+
{
3907+
const char * cs1 = first->getVirtualDisplayViewColorSpaceName(viewName);
3908+
const char * cs2 = second->getVirtualDisplayViewColorSpaceName(viewName);
3909+
3910+
// If the color space is not null, the display and view exist.
3911+
if (cs1 && *cs1 && cs2 && *cs2)
3912+
{
3913+
if (Platform::Strcasecmp(cs1, cs2) == 0)
3914+
{
3915+
// Note the remaining strings may be empty in a valid view.
3916+
// Intentionally not checking the description since it is not a functional difference.
3917+
if ( (Platform::Strcasecmp(first->getVirtualDisplayViewLooks(viewName),
3918+
second->getVirtualDisplayViewLooks(viewName)) == 0) &&
3919+
(Platform::Strcasecmp(first->getVirtualDisplayViewTransformName(viewName),
3920+
second->getVirtualDisplayViewTransformName(viewName)) == 0) &&
3921+
(Platform::Strcasecmp(first->getVirtualDisplayViewRule(viewName),
3922+
second->getVirtualDisplayViewRule(viewName)) == 0) )
3923+
{
3924+
return true;
3925+
}
3926+
}
3927+
}
3928+
return false;
3929+
}
3930+
37983931
const char * Config::getVirtualDisplayViewTransformName(const char * view) const noexcept
37993932
{
38003933
if (!view) return "";
38013934

3935+
// Get the view transform name for the case where a virtual view is shared.
3936+
if (virtualViewIsShared(view))
3937+
{
3938+
return getDisplayViewTransformName(nullptr, view);
3939+
}
3940+
38023941
ViewVec::const_iterator iter = FindView(getImpl()->m_virtualDisplay.m_views, view);
38033942
if (iter != getImpl()->m_virtualDisplay.m_views.end())
38043943
{
@@ -3812,6 +3951,12 @@ const char * Config::getVirtualDisplayViewColorSpaceName(const char * view) cons
38123951
{
38133952
if (!view) return "";
38143953

3954+
// Get the colorspace name for the case where a virtual view is shared.
3955+
if (virtualViewIsShared(view))
3956+
{
3957+
return getDisplayViewColorSpaceName(nullptr, view);
3958+
}
3959+
38153960
ViewVec::const_iterator iter = FindView(getImpl()->m_virtualDisplay.m_views, view);
38163961
if (iter != getImpl()->m_virtualDisplay.m_views.end())
38173962
{
@@ -3825,6 +3970,12 @@ const char * Config::getVirtualDisplayViewLooks(const char * view) const noexcep
38253970
{
38263971
if (!view) return "";
38273972

3973+
// Get the view looks for the case where a virtual view is shared
3974+
if (virtualViewIsShared(view))
3975+
{
3976+
return getDisplayViewLooks(nullptr, view);
3977+
}
3978+
38283979
ViewVec::const_iterator iter = FindView(getImpl()->m_virtualDisplay.m_views, view);
38293980
if (iter != getImpl()->m_virtualDisplay.m_views.end())
38303981
{
@@ -3838,6 +3989,12 @@ const char * Config::getVirtualDisplayViewRule(const char * view) const noexcept
38383989
{
38393990
if (!view) return "";
38403991

3992+
// Get the view rule for the case where a virtual view is shared
3993+
if (virtualViewIsShared(view))
3994+
{
3995+
return getDisplayViewRule(nullptr, view);
3996+
}
3997+
38413998
ViewVec::const_iterator iter = FindView(getImpl()->m_virtualDisplay.m_views, view);
38423999
if (iter != getImpl()->m_virtualDisplay.m_views.end())
38434000
{
@@ -3851,6 +4008,12 @@ const char * Config::getVirtualDisplayViewDescription(const char * view) const n
38514008
{
38524009
if (!view) return "";
38534010

4011+
// Get the view description for the case where a virtual view is shared
4012+
if (virtualViewIsShared(view))
4013+
{
4014+
return getDisplayViewDescription(nullptr, view);
4015+
}
4016+
38544017
ViewVec::const_iterator iter = FindView(getImpl()->m_virtualDisplay.m_views, view);
38554018
if (iter != getImpl()->m_virtualDisplay.m_views.end())
38564019
{

0 commit comments

Comments
 (0)