Skip to content

Commit d7b41f6

Browse files
hodoulpfnordwareremiamichdolanlgritz
authored
Port from master to RB-2.0 - Adsk Contrib - Improve File Rules support for v1 (#1445)
* Adsk Contrib - Improve File Rules support for v1 configs (#1417) * Adsk Contrib - Improve file rules for v1 configs Signed-off-by: Patrick Hodoul <[email protected]> * Adsk Contrib - Emergency GPU build fix (#1391) Signed-off-by: Patrick Hodoul <[email protected]> * Adsk Contrib - Fix some bugs found by Maya and SonarCloud (#1403) * Adsk Contrib - Fix some bugs found by Maya and SonarCloud Signed-off-by: Patrick Hodoul <[email protected]> * Fix a Windows warning Signed-off-by: Patrick Hodoul <[email protected]> * After Effects and Photoshop plug-in updates (#1373) * Set Mac OS deployment target to 10.10 Signed-off-by: Brendan Bolles <[email protected]> * More 10.10 targets Signed-off-by: Brendan Bolles <[email protected]> * Ditch ADD_EXTRA_BUILTINS Signed-off-by: Brendan Bolles <[email protected]> * Getting strange callback when AE effect is pasted Signed-off-by: Brendan Bolles <[email protected]> * Use NDEBUG in AE project Signed-off-by: Brendan Bolles <[email protected]> * Disable radio buttons with no config Signed-off-by: Brendan Bolles <[email protected]> * Update version Signed-off-by: Brendan Bolles <[email protected]> * Move to AE 2021 SDK, set PF_OutFlag2_MUTABLE_RENDER_SEQUENCE_DATA_SLOWER Signed-off-by: Brendan Bolles <[email protected]> * Define OCIO_DEPRECATED in After Effects builds Signed-off-by: Brendan Bolles <[email protected]> * Verify change from color space menu Signed-off-by: Brendan Bolles <[email protected]> * Handle situation where color space has a '/' in it Signed-off-by: Brendan Bolles <[email protected]> * Windows family separator fix Signed-off-by: Brendan Bolles <[email protected]> * Invert everything Signed-off-by: Brendan Bolles <[email protected]> * Invert everything Windows Signed-off-by: Brendan Bolles <[email protected]> * Disable more controls Signed-off-by: Brendan Bolles <[email protected]> * Incorporate invert into LUT export Signed-off-by: Brendan Bolles <[email protected]> * Get rid of fullPaths stuff Signed-off-by: Brendan Bolles <[email protected]> * Fix changed config settings retention Signed-off-by: Brendan Bolles <[email protected]> Co-authored-by: Patrick Hodoul <[email protected]> Signed-off-by: Patrick Hodoul <[email protected]> * Add OpenColorIOConfig.cmake generation (#1397) * Initial OpenColorIO Config CMake implementation Signed-off-by: Rémi Achard <[email protected]> * Remove macro, improve documentation Signed-off-by: Rémi Achard <[email protected]> Co-authored-by: Patrick Hodoul <[email protected]> Signed-off-by: Patrick Hodoul <[email protected]> * Use CMake visibility flags (#1411) * Update install doc minimal version numbers Signed-off-by: Rémi Achard <[email protected]> * Use CMake visibility presets variables Signed-off-by: Rémi Achard <[email protected]> * Fix python package case Signed-off-by: Rémi Achard <[email protected]> * Allow advanced user to override symbol visibility Signed-off-by: Rémi Achard <[email protected]> Co-authored-by: Patrick Hodoul <[email protected]> Signed-off-by: Patrick Hodoul <[email protected]> * Fix Windows build Signed-off-by: Patrick Hodoul <[email protected]> * Update include/OpenColorIO/OpenColorIO.h Co-authored-by: Michael Dolan <[email protected]> Signed-off-by: Patrick Hodoul <[email protected]> * Update src/OpenColorIO/FileRules.cpp Co-authored-by: Michael Dolan <[email protected]> Signed-off-by: Patrick Hodoul <[email protected]> * Hide dependency symbol visibility (#1409) (#1416) When creating libOpenColorIO.so, we lacked the linker commands that hide symbol visibility from the dependent libraries, which is necessary to prevent OCIO from exporting the symbols from Expat and the other dependencies that OCIO needs to use internally but is not trying intentionally to expose via its API. Failing to do this can result in symbol clashes and all sorts of subtle errors if OCIO is used in an app that also uses and is linked against a potentially different version of Expat (or any of the other deps). Signed-off-by: Larry Gritz <[email protected]> Co-authored-by: Larry Gritz <[email protected]> Signed-off-by: Patrick Hodoul <[email protected]> * Adsk Contrib - Improve DX11 & Cg fragment shader language support (#1406) * Adsk Contrib - Improve DX11 support Signed-off-by: Patrick Hodoul <[email protected]> * Improve Cg support Signed-off-by: Patrick Hodoul <[email protected]> * Improve GPU comments Signed-off-by: Patrick Hodoul <[email protected]> * Fix unit test failures Signed-off-by: Patrick Hodoul <[email protected]> Co-authored-by: Brendan Bolles <[email protected]> Co-authored-by: Rémi Achard <[email protected]> Co-authored-by: Michael Dolan <[email protected]> Co-authored-by: Larry Gritz <[email protected]> Co-authored-by: doug-walker <[email protected]> * Add missing file change Signed-off-by: Patrick Hodoul <[email protected]> Co-authored-by: Brendan Bolles <[email protected]> Co-authored-by: Rémi Achard <[email protected]> Co-authored-by: Michael Dolan <[email protected]> Co-authored-by: Larry Gritz <[email protected]> Co-authored-by: doug-walker <[email protected]>
1 parent 9eb736b commit d7b41f6

File tree

9 files changed

+722
-236
lines changed

9 files changed

+722
-236
lines changed

docs/guides/authoring/overview.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,40 +300,40 @@ to use to control other types of tasks not listed below.
300300

301301
* ``color_picking`` - colors in a color-selection UI can be displayed
302302
in this space, while selecting colors in a different working space
303-
(e.g. ``scene_linear`` or ``texture_paint``)
303+
(e.g. ``scene_linear`` or ``texture_paint``).
304304

305305
* ``color_timing`` - color space used for applying color corrections,
306306
e.g. user-specified grade within an image viewer (if the application
307307
uses the ``DisplayTransform::setDisplayCC`` API method)
308308

309309
* ``compositing_log`` - a log color space used for certain processing
310310
operations (plate resizing, pulling keys, degrain, etc). Used by the
311-
OCIOLogConvert Nuke node
311+
OCIOLogConvert Nuke node.
312312

313313
* ``data`` - used when writing data outputs such as normals, depth
314314
data, and other "non color" data. The color space in this role should
315315
typically have ``data: true`` specified, so no color transforms are
316-
applied
316+
applied.
317317

318318
* ``default`` - when ``strictparsing: false``, this color space is used
319-
as a fallback. If not defined, the ``scene_linear`` role is used
319+
as a fallback.
320320

321321
* ``matte_paint`` - color space which matte-paintings are created in
322322
(for more information, :ref:`see the guide on baking ICC profiles
323323
for Photoshop <userguide-bakelut-photoshop>`, and
324-
:ref:`config-spivfx`)
324+
:ref:`config-spivfx`).
325325

326326
* ``reference`` - the color space against which the other color spaces
327-
are defined
327+
are defined.
328328

329329
.. note::
330330
The reference role has sometimes been misinterpreted as being the
331331
space in which "reference art" is stored in.
332332

333333
* ``scene_linear`` - the scene-referred linear-to-light color space,
334-
often the same as the reference space (see:ref:`faq-terminology`)
334+
often the same as the reference space (see:ref:`faq-terminology`).
335335

336336
* ``texture_paint`` - similar to ``matte_paint`` but for painting
337337
textures for 3D objects (see the description of texture painting in
338-
:ref:`SPI's pipeline <config-spipipeline-texture>`)
338+
:ref:`SPI's pipeline <config-spipipeline-texture>`).
339339

docs/guides/authoring/rules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ determine the colorspace ``lnf`` (it being the right-most substring
115115
containing a colorspace name)
116116

117117
However, if the colorspace cannot be determined and ``strictparsing:
118-
true``, it will produce an error.
118+
true``, it will return an empty string.
119119

120120
If the colorspace cannot be determined and ``strictparsing: false``,
121121
the default role will be used. This allows unhandled images to operate

include/OpenColorIO/OpenColorIO.h

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,8 @@ class OCIOEXPORT Config
994994
*/
995995
void setFileRules(ConstFileRulesRcPtr fileRules);
996996

997-
/// Get the color space of the first rule that matched filePath.
997+
/// Get the color space of the first rule that matched filePath. (For v1 configs, this is
998+
/// equivalent to calling parseColorSpaceFromString with strictparsing set to false.)
998999
const char * getColorSpaceFromFilepath(const char * filePath) const;
9991000

10001001
/**
@@ -1149,64 +1150,56 @@ class OCIOEXPORT Config
11491150
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const Config&);
11501151

11511152

1152-
1153-
// TODO: Move to .rst
1154-
// FileRules
1155-
// *********
1156-
// The File Rules are a set of filepath to color space mappings that are evaluated
1157-
// from first to last. The first rule to match is what determines which color space is
1158-
// returned. There are four types of rules available. Each rule type has a name key that may
1159-
// be used by applications to refer to that rule. Name values must be unique i.e. using a
1160-
// case insensitive comparison. The other keys depend on the rule type:
1161-
//
1162-
// - Basic Rule: This is the basic rule type that uses Unix glob style pattern matching and
1163-
// is thus very easy to use. It contains the keys:
1164-
//
1165-
// * name: Name of the rule
1166-
//
1167-
// * colorspace: Color space name to be returned.
1168-
//
1169-
// * pattern: Glob pattern to be used for the main part of the name/path.
1170-
//
1171-
// * extension: Glob pattern to be used for the file extension. Note that if glob tokens
1172-
// are not used, the extension will be used in a non-case-sensitive way by default.
1173-
//
1174-
// - Regex Rule: This is similar to the basic rule but allows additional capabilities for
1175-
// power-users. It contains the keys:
1176-
//
1177-
// * name: Name of the rule
1178-
//
1179-
// * colorspace: Color space name to be returned.
1180-
//
1181-
// * regex: Regular expression to be evaluated.
1182-
//
1183-
// - OCIO v1 style Rule: This rule allows the use of the OCIO v1 style, where the string
1184-
// is searched for color space names from the config. This rule may occur 0 or 1 times
1185-
// in the list. The position in the list prioritizes it with respect to the other rules.
1186-
// StrictParsing is not used. If no color space is found in the path, the rule will not
1187-
// match and the next rule will be considered.
1188-
// \see FileRules::insertPathSearchRule.
1189-
// It has the key:
1190-
//
1191-
// * name: Must be "ColorSpaceNamePathSearch".
1192-
//
1193-
// - Default Rule: The file_rules must always end with this rule. If no prior rules match,
1194-
// this rule specifies the color space applications will use.
1195-
// \see FileRules::setDefaultRuleColorSpace.
1196-
// It has the keys:
1197-
//
1198-
// * name: must be "Default".
1199-
//
1200-
// * colorspace : Color space name to be returned.
1201-
//
1202-
// Custom string keys and associated string values may be used to convey app or
1203-
// workflow-specific information, e.g. whether the color space should be left as is
1204-
// or converted into a working space.
1205-
//
1206-
// Getters and setters are using the rule position, they will throw if the position is not
1207-
// valid. If the rule at the specified position does not implement the requested property
1208-
// getter will return NULL and setter will throw.
1209-
//
1153+
/**
1154+
* \brief
1155+
* The File Rules are a set of filepath to color space mappings that are evaluated
1156+
* from first to last. The first rule to match is what determines which color space is
1157+
* returned. There are four types of rules available. Each rule type has a name key that may
1158+
* be used by applications to refer to that rule. Name values must be unique i.e. using a
1159+
* case insensitive comparison. The other keys depend on the rule type:
1160+
*
1161+
* * *Basic Rule*: This is the basic rule type that uses Unix glob style pattern matching and
1162+
* is thus very easy to use. It contains the keys:
1163+
* * name: Name of the rule
1164+
* * colorspace: Color space name to be returned.
1165+
* * pattern: Glob pattern to be used for the main part of the name/path.
1166+
* * extension: Glob pattern to be used for the file extension. Note that if glob tokens
1167+
* are not used, the extension will be used in a non-case-sensitive way by default.
1168+
*
1169+
* * *Regex Rule*: This is similar to the basic rule but allows additional capabilities for
1170+
* power-users. It contains the keys:
1171+
* * name: Name of the rule
1172+
* * colorspace: Color space name to be returned.
1173+
* * regex: Regular expression to be evaluated.
1174+
*
1175+
* * *OCIO v1 style Rule*: This rule allows the use of the OCIO v1 style, where the string
1176+
* is searched for color space names from the config. This rule may occur 0 or 1 times
1177+
* in the list. The position in the list prioritizes it with respect to the other rules.
1178+
* StrictParsing is not used. If no color space is found in the path, the rule will not
1179+
* match and the next rule will be considered.
1180+
* see \ref insertPathSearchRule.
1181+
* It has the key:
1182+
* * name: Must be "ColorSpaceNamePathSearch".
1183+
*
1184+
* * *Default Rule*: The file_rules must always end with this rule. If no prior rules match,
1185+
* this rule specifies the color space applications will use.
1186+
* see \ref setDefaultRuleColorSpace.
1187+
* It has the keys:
1188+
* * name: must be "Default".
1189+
* * colorspace : Color space name to be returned.
1190+
*
1191+
* Custom string keys and associated string values may be used to convey app or
1192+
* workflow-specific information, e.g. whether the color space should be left as is
1193+
* or converted into a working space.
1194+
*
1195+
* Getters and setters are using the rule position, they will throw if the position is not
1196+
* valid. If the rule at the specified position does not implement the requested property
1197+
* getter will return NULL and setter will throw.
1198+
*
1199+
* When loading a v1 config, a set of FileRules are created with ColorSpaceNamePathSearch followed
1200+
* by the Default rule pointing to the default role. This allows getColorSpaceFromFilepath to emulate
1201+
* OCIO v1 code that used parseColorSpaceFromString with strictparsing set to false.
1202+
*/
12101203

12111204
class OCIOEXPORT FileRules
12121205
{

src/OpenColorIO/Config.cpp

Lines changed: 17 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,6 @@ void GetColorSpaceReferences(std::set<std::string> & colorSpaceNames,
192192
}
193193
}
194194

195-
static constexpr char AddedDefault[]{ "added_default_rule_colorspace" };
196-
197-
void FindAvailableName(const ColorSpaceSetRcPtr & colorspaces, std::string & csname)
198-
{
199-
int i = 0;
200-
csname = AddedDefault;
201-
while (true)
202-
{
203-
if (!colorspaces->hasColorSpace(csname.c_str()))
204-
{
205-
break;
206-
}
207-
208-
csname = AddedDefault + std::to_string(i);
209-
++i;
210-
}
211-
}
212-
213195
// Views are stored in two vectors of objects, using pointers to temporarily group them.
214196
typedef std::vector<const View *> ViewPtrVec;
215197

@@ -591,56 +573,6 @@ class Config::Impl
591573

592574
static ConstConfigRcPtr Read(std::istream & istream, const char * filename);
593575

594-
// Upgrade from v1 to v2.
595-
void upgradeFromVersion1ToVersion2() noexcept
596-
{
597-
// V2 adds file_rules and these require a default rule. We try to initialize the default
598-
// rule using the default role. If the default role doesn't exist, we look for a Raw
599-
// ColorSpace with isdata true. If that is not found either, we add new ColorSpace
600-
// named "added_default_rule_colorspace".
601-
602-
m_majorVersion = 2;
603-
m_minorVersion = 0;
604-
605-
const char * rname = LookupRole(m_roles, ROLE_DEFAULT);
606-
if (!hasColorSpace(rname))
607-
{
608-
std::string defaultCS;
609-
bool addNewDefault = true;
610-
// The default role doesn't exist so look for a color space named "raw"
611-
// (not case-sensitive) with isdata true.
612-
const int csindex = getColorSpaceIndex("raw");
613-
if (-1 != csindex)
614-
{
615-
auto cs = m_allColorSpaces->getColorSpaceByIndex(csindex);
616-
if (cs->isData())
617-
{
618-
// "Raw" color space can be used for default.
619-
addNewDefault = false;
620-
defaultCS = cs->getName();
621-
}
622-
}
623-
624-
if (addNewDefault)
625-
{
626-
FindAvailableName(m_allColorSpaces, defaultCS);
627-
auto newCS = ColorSpace::Create();
628-
newCS->setName(defaultCS.c_str());
629-
newCS->setIsData(true);
630-
m_allColorSpaces->addColorSpace(newCS);
631-
// Put the added CS in the inactive list to avoid it showing up in user menus.
632-
if (!m_inactiveColorSpaceNamesConf.empty())
633-
{
634-
m_inactiveColorSpaceNamesConf += ",";
635-
}
636-
m_inactiveColorSpaceNamesConf += defaultCS;
637-
setInactiveColorSpaces(m_inactiveColorSpaceNamesConf.c_str());
638-
}
639-
640-
m_fileRules->setColorSpace(m_fileRules->getNumEntries() - 1, defaultCS.c_str());
641-
}
642-
}
643-
644576
// Validate view object that can be a config defined shared view or a display-defined view.
645577
void validateView(const std::string & display, const View & view, bool checkUseDisplayName) const
646578
{
@@ -1274,15 +1206,19 @@ void Config::upgradeToLatestVersion() noexcept
12741206
{
12751207
if (wasVersion == 1)
12761208
{
1277-
m_impl->upgradeFromVersion1ToVersion2();
1209+
UpdateFileRulesFromV1ToV2(*this, m_impl->m_fileRules);
1210+
1211+
// The instance version is now 2.0
1212+
m_impl->m_majorVersion = 2;
1213+
m_impl->m_minorVersion = 0;
12781214
}
1215+
12791216
static_assert(LastSupportedMajorVersion == 2, "Config: Handle newer versions");
12801217
setMajorVersion(LastSupportedMajorVersion);
12811218
setMinorVersion(LastSupportedMinorVersion[LastSupportedMajorVersion - 1]);
12821219
}
12831220
}
12841221

1285-
12861222
ConfigRcPtr Config::createEditableCopy() const
12871223
{
12881224
ConfigRcPtr config = Config::Create();
@@ -1762,26 +1698,17 @@ void Config::validate() const
17621698

17631699
///// FileRules
17641700

1765-
// All Config objects have a fileRules object, regardless of version. This object is
1766-
// initialized to have a defaultRule with the color space set to "default" (i.e., the default
1767-
// role). The fileRules->validate call will validate that all color spaces used in rules
1768-
// exist, or if they are roles that they point to a color space that exists. Because this would
1769-
// cause validate to improperly fail on v1 configs (since they are not required to actually
1770-
// contain file rules), we don't do this check on v1 configs when there is only one rule.
1771-
if (getMajorVersion() >= 2 || getImpl()->m_fileRules->getNumEntries() != 1)
1701+
try
17721702
{
1773-
try
1774-
{
1775-
getImpl()->m_fileRules->getImpl()->validate(*this);
1776-
}
1777-
catch (const Exception & e)
1778-
{
1779-
std::ostringstream os;
1780-
os << "Config failed validation. File rules failed with: ";
1781-
os << e.what();
1782-
getImpl()->m_validationtext = os.str();
1783-
throw Exception(getImpl()->m_validationtext.c_str());
1784-
}
1703+
getImpl()->m_fileRules->getImpl()->validate(*this);
1704+
}
1705+
catch (const Exception & e)
1706+
{
1707+
std::ostringstream os;
1708+
os << "Config failed validation. File rules failed with: ";
1709+
os << e.what();
1710+
getImpl()->m_validationtext = os.str();
1711+
throw Exception(getImpl()->m_validationtext.c_str());
17851712
}
17861713

17871714
///// Resolve all file Transforms using context variables.
@@ -4723,7 +4650,7 @@ void Config::Impl::checkVersionConsistency() const
47234650

47244651
// Check for the file rules.
47254652

4726-
if (m_majorVersion < 2 && m_fileRules->getNumEntries() > 1)
4653+
if (m_majorVersion < 2 && m_fileRules->getNumEntries() > 2)
47274654
{
47284655
throw Exception("Only version 2 (or higher) can have file rules.");
47294656
}

0 commit comments

Comments
 (0)