Skip to content

Commit e412d8a

Browse files
Adsk Contrib - Named color transforms (#1189)
* Named color transforms Signed-off-by: Bernard Lefebvre <[email protected]> * Allow NamedTransforms to be inactive using the same mechanism as color spaces. Signed-off-by: Bernard Lefebvre <[email protected]> * Wrong enum Signed-off-by: Bernard Lefebvre <[email protected]> * Fix issue introduced by merge from master (version checking for NamedTransform serialization in config) Signed-off-by: Bernard Lefebvre <[email protected]>
1 parent 73c1f75 commit e412d8a

39 files changed

+3341
-417
lines changed

include/OpenColorIO/OpenColorIO.h

Lines changed: 114 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,6 @@ class OCIOEXPORT Config
429429
const char * getColorSpaceNameByIndex(SearchReferenceSpaceType searchReferenceType,
430430
ColorSpaceVisibility visibility, int index) const;
431431

432-
/**
433-
* \brief Get the color space from all the color spaces
434-
* (i.e. active and inactive) and return null if the name is not found.
435-
*
436-
* \note
437-
* The fcn accepts either a color space OR role name.
438-
* (Color space names take precedence over roles.)
439-
*/
440-
ConstColorSpaceRcPtr getColorSpace(const char * name) const;
441-
442-
// The following three methods only work from the list of active color spaces.
443-
444432
/**
445433
* \brief Work on the active color spaces only.
446434
*
@@ -467,6 +455,16 @@ class OCIOEXPORT Config
467455
*/
468456
int getIndexForColorSpace(const char * name) const;
469457

458+
/**
459+
* \brief Get the color space from all the color spaces
460+
* (i.e. active and inactive) and return null if the name is not found.
461+
*
462+
* \note
463+
* The fcn accepts either a color space OR role name.
464+
* (Color space names take precedence over roles.)
465+
*/
466+
ConstColorSpaceRcPtr getColorSpace(const char * name) const;
467+
470468
/**
471469
* \brief Add a color space to the configuration.
472470
*
@@ -519,10 +517,12 @@ class OCIOEXPORT Config
519517
void setStrictParsingEnabled(bool enabled);
520518

521519
/**
522-
* \brief Set/get a list of inactive color space names.
520+
* \brief Set/get a list of inactive color space or named transform names.
523521
*
522+
* Notes:
523+
* * List can contain color space and/or named transform names.
524524
* * The inactive spaces are color spaces that should not appear in application menus.
525-
* * These color spaces will still work in :cpp:func:`Config::getProcessor` calls.
525+
* * These color spaces will still work in Config::getProcessor calls.
526526
* * The argument is a comma-delimited string. A null or empty string empties the list.
527527
* * The environment variable OCIO_INACTIVE_COLORSPACES may also be used to set the
528528
* inactive color space list.
@@ -905,6 +905,52 @@ class OCIOEXPORT Config
905905

906906
void clearViewTransforms();
907907

908+
/**
909+
* \defgroup Methods related to named transforms.
910+
* @{
911+
*/
912+
913+
/**
914+
* \brief Work on the named transforms selected by visibility.
915+
*/
916+
int getNumNamedTransforms(NamedTransformVisibility visibility) const noexcept;
917+
918+
/**
919+
* \brief Work on the named transforms selected by visibility (active or inactive).
920+
*
921+
* Return an empty string for invalid index.
922+
*/
923+
const char * getNamedTransformNameByIndex(NamedTransformVisibility visibility,
924+
int index) const noexcept;
925+
926+
/// Work on the active named transforms only.
927+
int getNumNamedTransforms() const noexcept;
928+
929+
/// Work on the active named transforms only and return an empty string for invalid index.
930+
const char * getNamedTransformNameByIndex(int index) const noexcept;
931+
932+
/// Get an index from the active named transforms only and return -1 if the name is not found.
933+
int getIndexForNamedTransform(const char * name) const noexcept;
934+
935+
/**
936+
* \brief Get the named transform from all the named transforms (i.e. active and inactive) and
937+
* return null if the name is not found.
938+
*/
939+
ConstNamedTransformRcPtr getNamedTransform(const char * name) const noexcept;
940+
941+
/**
942+
* \brief Add or replace named transform.
943+
*
944+
* \note
945+
* Throws if namedTransform is null, name is missing, or no transform is set.
946+
*/
947+
void addNamedTransform(const ConstNamedTransformRcPtr & namedTransform);
948+
949+
/// Clear all named transforms.
950+
void clearNamedTransforms();
951+
952+
/** @} */
953+
908954
//
909955
// File Rules
910956
//
@@ -1775,6 +1821,60 @@ class OCIOEXPORT Look
17751821
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const Look&);
17761822

17771823

1824+
/**
1825+
* \brief NamedTransform.
1826+
*
1827+
* A NamedTransform provides a way for config authors to include a set of color
1828+
* transforms that are independent of the color space being processed. For example a "utility
1829+
* curve" transform where there is no need to convert to or from a reference space.
1830+
*/
1831+
1832+
class OCIOEXPORT NamedTransform
1833+
{
1834+
public:
1835+
static NamedTransformRcPtr Create();
1836+
1837+
virtual NamedTransformRcPtr createEditableCopy() const = 0;
1838+
1839+
virtual const char * getName() const noexcept = 0;
1840+
virtual void setName(const char * name) noexcept = 0;
1841+
1842+
/// \see ColorSpace::getFamily
1843+
virtual const char * getFamily() const noexcept = 0;
1844+
/// \see ColorSpace::setFamily
1845+
virtual void setFamily(const char * family) noexcept = 0;
1846+
1847+
virtual const char * getDescription() const noexcept = 0;
1848+
virtual void setDescription(const char * description) noexcept = 0;
1849+
1850+
/// \see ColorSpace::hasCategory
1851+
virtual bool hasCategory(const char * category) const noexcept = 0;
1852+
/// \see ColorSpace::addCategory
1853+
virtual void addCategory(const char * category) noexcept = 0;
1854+
/// \see ColorSpace::removeCategory
1855+
virtual void removeCategory(const char * category) noexcept = 0;
1856+
/// \see ColorSpace::getNumCategories
1857+
virtual int getNumCategories() const noexcept = 0;
1858+
/// \see ColorSpace::getCategory
1859+
virtual const char * getCategory(int index) const noexcept = 0;
1860+
/// \see ColorSpace::clearCategories
1861+
virtual void clearCategories() noexcept = 0;
1862+
1863+
virtual ConstTransformRcPtr getTransform(TransformDirection dir) const = 0;
1864+
virtual void setTransform(const ConstTransformRcPtr & transform, TransformDirection dir) = 0;
1865+
1866+
NamedTransform(const NamedTransform &) = delete;
1867+
NamedTransform & operator= (const NamedTransform &) = delete;
1868+
// Do not use (needed only for pybind11).
1869+
virtual ~NamedTransform() = default;
1870+
1871+
protected:
1872+
NamedTransform() = default;
1873+
};
1874+
1875+
extern OCIOEXPORT std::ostream & operator<< (std::ostream &, const NamedTransform &);
1876+
1877+
17781878
//
17791879
// ViewTransform
17801880
//

include/OpenColorIO/OpenColorTypes.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class OCIOEXPORT Look;
5252
typedef OCIO_SHARED_PTR<const Look> ConstLookRcPtr;
5353
typedef OCIO_SHARED_PTR<Look> LookRcPtr;
5454

55+
class OCIOEXPORT NamedTransform;
56+
typedef OCIO_SHARED_PTR<const NamedTransform> ConstNamedTransformRcPtr;
57+
typedef OCIO_SHARED_PTR<NamedTransform> NamedTransformRcPtr;
58+
5559
class OCIOEXPORT ViewTransform;
5660
typedef OCIO_SHARED_PTR<const ViewTransform> ConstViewTransformRcPtr;
5761
typedef OCIO_SHARED_PTR<ViewTransform> ViewTransformRcPtr;
@@ -280,6 +284,13 @@ enum ColorSpaceVisibility
280284
COLORSPACE_ALL
281285
};
282286

287+
enum NamedTransformVisibility
288+
{
289+
NAMEDTRANSFORM_ACTIVE = 0,
290+
NAMEDTRANSFORM_INACTIVE,
291+
NAMEDTRANSFORM_ALL
292+
};
293+
283294
enum ViewType
284295
{
285296
VIEW_SHARED = 0,

src/OpenColorIO/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ set(SOURCES
5757
LookParse.cpp
5858
MathUtils.cpp
5959
md5/md5.cpp
60+
NamedTransform.cpp
6061
OCIOYaml.cpp
6162
Op.cpp
6263
OpOptimizers.cpp

0 commit comments

Comments
 (0)