HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpenColorAppHelpers.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 // Copyright Contributors to the OpenColorIO Project.
3 
4 
5 #ifndef INCLUDED_OCIO_OPENCOLORAPPHELPERS_H
6 #define INCLUDED_OCIO_OPENCOLORAPPHELPERS_H
7 
8 #include "OpenColorTypes.h"
9 
10 #ifndef OCIO_NAMESPACE
11 #error This header cannot be used directly. Use <OpenColorIO/OpenColorIO.h> instead.
12 #endif
13 
14 
15 namespace OCIO_NAMESPACE
16 {
17 
18 /**
19  * Parameters controlling which color spaces appear in menus.
20  *
21  * The ColorSpaceMenuHelper class is intended to be used by applications to get the list of items
22  * to show in color space menus.
23  *
24  * The ColorSpaceMenuParameters class is used to configure the behavior as needed for any given
25  * menu. Here is the algorithm used to produce a list of "items" (or strings) that will appear in
26  * a menu:
27  *
28  * 1) Use setRole to identify a role that controls a given menu. If the config has this role,
29  * then only that color space is returned. The name is set to the color space name, the UIName
30  * is presented as "<role name> (<color space name>)". It may be useful for the application to
31  * then grey-out the menu or otherwise indicate to the user that the value for this menu is not
32  * user selectable since it was pre-determined by the config. If the config does not have that
33  * role, the algorithm continues to the remaining steps.
34  *
35  * 2) The IncludeColorSpaces, SearchReferenceSpaceType, and IncludeNamedTransforms parameters are
36  * used to identify a set of items from the config that are potential candidates for use in the
37  * menu, as follows:
38  * - IncludeColorSpaces: Set to true to include color spaces in the menu.
39  * - SearchReferenceSpaceType: Use this to control whether the menu should include all color
40  * spaces, only display color spaces, or only non-display color spaces.
41  * - IncludeNamedTransforms: Set to true to include named transforms in the menu.
42  *
43  * 3) The set of items from step 2 is then filtered in step 3 using the following parameters:
44  * - AppCategories: A list of strings specified by the application based on the purpose of
45  * the menu. For example, if the menu is used to select a color space for importing an
46  * image, the application might specify the 'file-io' category, whereas if it is to select
47  * a working color space, it might specify the 'working-space' category. Application
48  * developers should document what strings they are using for each menu so that config
49  * authors know what categories to use in their configs. Alternatively, an application
50  * could let advanced users customize the string to use for a given menu in the
51  * application.
52  * - Encodings: A list of strings used to further refine the items selected from the
53  * AppCategories. For example, an application might specify 'working-space' as the
54  * category and then specify 'scene-linear' as the encoding to only use items that have
55  * both of those properties (e.g., only select scene-linear working color spaces).
56  * - UserCategories: A list of strings specified by the end-user of the application. OCIO
57  * will check for these strings in an environment variable, or they may be passed in from
58  * the application.
59  * - TreatNoCategoryAsAny: By default, color spaces (or named transforms) that have no
60  * categories are handled as if they had any of the categories. Config authors that want to
61  * hide color spaces without categories should either put them in the inactiveColorSpaces
62  * list or add a category that will never be searched for (e.g., "invisible" or "hidden").
63  * App developers may set this option to false to hide items without any categories.
64  *
65  * Basically the intent is for the filtering to return the intersection of the app categories,
66  * encoding, and user categories. However, some fall-backs are in place to ensure that the
67  * filtering does not remove all menu items. Here is the detailed description:
68  *
69  * 3a) The items from step 2 are filtered to generate a list of appItems containing only the ones
70  * that contain at least one of the AppCategories strings in their "categories" property and
71  * one of the encodings in their "encoding" property. If this list is empty, an attempt is
72  * made to generate a non-empty appItems list by only filtering by AppCategories. If that is
73  * empty, an attempt is made to only filter by Encodings.
74  *
75  * 3b) The items from step 2 are filtered to generate a list of userItems containing only the ones
76  * that have at least one of the UserCategories strings in their "categories" property.
77  *
78  * 3c) If both appItems and userItems are non-empty, a list of resultItems will be generated as
79  * the intersection of those two lists.
80  *
81  * 3d) If the resultItems list is empty, the appList will be expanded by only filtering by
82  * AppCategories and not encodings. The resultItems will be formed again as the intersection
83  * of the appItems and userItems.
84  *
85  * 3e) If the resultItems is still empty, it will be set to just the appItems from step 3a.
86  *
87  * 3f) If the resultItems is still empty, it will be set to just the userItems.
88  *
89  * 3g) If the resultItems is still empty, the items are not filtered and all items from step 2 are
90  * returned. The rationale is that if step 2 has produced any items, it is not acceptable for
91  * step 3 to remove all of them. An application usually expects to have a non-zero number of
92  * items to display in the menu. However, if step 2 produces no items (e.g. the application
93  * requests only named transforms and the config has no named transform), then no items will
94  * be returned.
95  *
96  *
97  * 4) If IncludeRoles is true, the items from step 3 are extended by including an item for each
98  * role. The name is set to the role name, the UIName is presented as "<role name> (<color
99  * space name>)", and the family is set to "Roles".
100  *
101  * 5) If AddColorSpace has been used to add any additional items, these are appended to the final
102  * list.
103  */
105 {
106 public:
107  static ColorSpaceMenuParametersRcPtr Create(ConstConfigRcPtr config);
108  /// Config is required to be able to create a ColorSpaceMenuHelper.
109  virtual void setConfig(ConstConfigRcPtr config) noexcept = 0;
110  virtual ConstConfigRcPtr getConfig() const noexcept = 0;
111 
112  /// If role is a valid role, other parameters are ignored and menu will contain only that role.
113  virtual void setRole(const char * role) noexcept = 0;
114  virtual const char * getRole() const noexcept = 0;
115 
116 
117  /**
118  * Include all color spaces (or not) to ColorSpaceMenuHelper. Default is to include color
119  * spaces.
120  */
121  virtual void setIncludeColorSpaces(bool include) noexcept = 0;
122  virtual bool getIncludeColorSpaces() const noexcept = 0;
123 
124  /**
125  * Can be used to restrict the search using the ReferenceSpaceType of the color spaces.
126  * It has no effect on roles and named transforms.
127  */
128  virtual SearchReferenceSpaceType getSearchReferenceSpaceType() const noexcept = 0;
129  virtual void setSearchReferenceSpaceType(SearchReferenceSpaceType colorSpaceType) noexcept = 0;
130 
131  /**
132  * Include all named transforms (or not) to ColorSpaceMenuHelper. Default is not to include
133  * named transforms.
134  */
135  virtual void setIncludeNamedTransforms(bool include) noexcept = 0;
136  virtual bool getIncludeNamedTransforms() const noexcept = 0;
137 
138  /**
139  * When searching for color spaces using app or user categories, treat color spaces or
140  * named transforms that have no categories as if they had any of the categories.
141  * Default is true.
142  */
143  virtual void setTreatNoCategoryAsAny(bool value) noexcept = 0;
144  virtual bool getTreatNoCategoryAsAny() const noexcept = 0;
145 
146  /**
147  * App categories is a comma separated list of categories. If appCategories is not NULL and
148  * not empty, all color spaces that have one of the categories will be part of the menu.
149  */
150  virtual void setAppCategories(const char * appCategories) noexcept = 0;
151  virtual const char * getAppCategories() const noexcept = 0;
152 
153  /**
154  * Encodings is a comma separated list of encodings. When not empty, is retricting the search
155  * to color spaces that are using one of the encodings.
156  */
157  virtual void setEncodings(const char * encodings) noexcept = 0;
158  virtual const char * getEncodings() const noexcept = 0;
159 
160  /**
161  * User categories is a comma separated list of categories. If OCIO_USER_CATEGORIES_ENVVAR
162  * env. variable is defined and not empty, this parameter is ignored and the value of the
163  * env. variable is used for user categories.
164  */
165  virtual void setUserCategories(const char * userCategories) noexcept = 0;
166  virtual const char * getUserCategories() const noexcept = 0;
167 
168 
169  /**
170  * Include all roles (or not) to ColorSpaceMenuHelper. Default is not to include roles.
171  * Roles are added after color spaces with an single hierarchy level named "Roles".
172  */
173  virtual void setIncludeRoles(bool include) noexcept = 0;
174  virtual bool getIncludeRoles() const noexcept = 0;
175 
176  /**
177  * Add an additional color space (or named transform) to the menu.
178  *
179  * Note that an additional color space could be:
180  * * an inactive color space,
181  * * an active color space not having at least one of the selected categories,
182  * * a newly created color space.
183  * Will throw when creating the menu if color space is not part of the config. Nothing is done
184  * if it is already part of the menu.
185  * It's ok to call this multiple times with the same color space, it will only be added to the
186  * menu once. If a role name is passed in, the name in the menu will be the color space name
187  * the role points to.
188  */
189  virtual void addColorSpace(const char * name) noexcept = 0;
190 
191  virtual size_t getNumAddedColorSpaces() const noexcept = 0;
192  virtual const char * getAddedColorSpace(size_t index) const noexcept = 0;
193  virtual void clearAddedColorSpaces() noexcept = 0;
194 
195  /// Do not use (needed only for pybind11).
196  virtual ~ColorSpaceMenuParameters() = default;
197 };
198 
199 extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const ColorSpaceMenuParameters &);
200 
201 /**
202  * Helper class to create menus for the content of a config.
203  *
204  * Menu can list color spaces, roles, named transforms. Each entry has a name, a UI name, a
205  * description, and a family. Family can also be accessed as hierarchy levels; levels are created
206  * by splitting the family using the 'family separator'. Hierarchy levels are meant to be used as
207  * sub-menus.
208  *
209  * The UI name is what is intended to be put in application menus seen by the end-user. However,
210  * please note that the UI name is not guaranteed to remain stable between releases and so if
211  * applications need to save something it should be the 'name' rather than the 'UI name'.
212  * Currently, the only difference between the 'name' and 'UI name' is for roles.
213  *
214  * The overall ordering of items is: color spaces, named transforms, roles, and additional color
215  * spaces. The display color spaces will either come before or after the other color spaces based
216  * on where that block of spaces appears in the config. The order of items returned by the menu
217  * helper preserves the order of items in the config itself for each type of elements, thus
218  * preserving the intent of the config author. For example, if you call getName at idx
219  * and idx+1, the name returned at idx+1 will be from farther down in the config than the one at
220  * idx as long as both are of the same type. (An application may ask for only the items in one
221  * of those blocks if it wants to handle them separately.) If the application makes use of
222  * hierarchical menus, that will obviously impose a different order on what the user sees in the
223  * menu. Though even with hierarchical menus, applications should try to preserve config ordering
224  * (which is equivalent to index ordering) for items within the same sub-menu.
225  */
227 {
228 public:
230 
231  /// Access to the color spaces (or roles).
232  virtual size_t getNumColorSpaces() const noexcept = 0;
233  /**
234  * Get the color space (or role) name used in the config for this menu item. Will be empty
235  * if the index is out of range.
236  */
237  virtual const char * getName(size_t idx) const noexcept = 0;
238  /**
239  * Get the name to use in the menu UI. This might be different from the config name, for
240  * example in the case of roles. Will be empty if the index is out of range.
241  */
242  virtual const char * getUIName(size_t idx) const noexcept = 0;
243 
244  /**
245  * Get the index of the element of a given name. Return (size_t)-1 name if NULL or empty, or if
246  * no element with that name is found.
247  */
248  virtual size_t getIndexFromName(const char * name) const noexcept = 0;
249  virtual size_t getIndexFromUIName(const char * name) const noexcept = 0;
250 
251  virtual const char * getDescription(size_t idx) const noexcept = 0;
252  virtual const char * getFamily(size_t idx) const noexcept = 0;
253 
254  /**
255  * Hierarchy levels are created from the family string. It is split into levels using the
256  * 'family separator'.
257  */
258  virtual size_t getNumHierarchyLevels(size_t idx) const noexcept = 0;
259  virtual const char * getHierarchyLevel(size_t idx, size_t i) const noexcept = 0;
260 
261  /// Get the color space name from the UI name.
262  virtual const char * getNameFromUIName(const char * uiName) const noexcept = 0;
263  /// Get the color space UI name from the name.
264  virtual const char * getUINameFromName(const char * name) const noexcept = 0;
265 
266  ColorSpaceMenuHelper(const ColorSpaceMenuHelper &) = delete;
268 
269  /// Do not use (needed only for pybind11).
270  virtual ~ColorSpaceMenuHelper() = default;
271 
272 protected:
273  ColorSpaceMenuHelper() = default;
274 };
275 
276 extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const ColorSpaceMenuHelper &);
277 
278 namespace ColorSpaceHelpers
279 {
280 /**
281  * Add a new color space to the config instance. The output of the userTransform must be in the
282  * specified connectionColorSpace.
283  *
284  * Note: If the config does not already use categories, we do not add them since that would
285  * make a big change to how existing color spaces show up in menus.
286  */
287 extern OCIOEXPORT void AddColorSpace(ConfigRcPtr & config,
288  const char * name,
289  const char * transformFilePath,
290  const char * categories, // Could be null or empty.
291  const char * connectionColorSpaceName);
292 
293 } // ColorSpaceHelpers
294 
295 namespace DisplayViewHelpers
296 {
297 
298 /**
299  * Get the processor from the working color space to (display, view) pair (forward) or (display,
300  * view) pair to working (inverse). The working color space name could be a role name or a color
301  * space name. ChannelView can be empty. If not already present, each of these functions adds
302  * ExposureContrastTransforms to enable changing exposure, contrast, and gamma after the processor
303  * has been created using dynamic properties.
304  */
306  const ConstContextRcPtr & context,
307  const char * workingName,
308  const char * displayName,
309  const char * viewName,
310  const ConstMatrixTransformRcPtr & channelView,
312 
314  const char * workingName,
315  const char * displayName,
316  const char * viewName,
317  const ConstMatrixTransformRcPtr & channelView,
318  TransformDirection direction);
319 
320 /// Get an identity processor containing only the ExposureContrastTransforms.
322 
323 /**
324  * Add a new (display, view) pair and the new color space to a configuration instance.
325  * The input to the userTransform must be in the specified connectionColorSpace.
326  */
327 extern OCIOEXPORT void AddDisplayView(ConfigRcPtr & config,
328  const char * displayName,
329  const char * viewName,
330  const char * lookDefinition, // Could be empty or null
331  const char * colorSpaceName, // Could be empty or null
332  const char * colorSpaceFamily, // Could be empty or null
333  const char * colorSpaceDescription, // Could be empty or null
334  const char * categories, // Could be empty or null
335  const char * transformFilePath,
336  const char * connectionColorSpaceName);
337 
338 /**
339  * Remove a (display, view) pair including the associated color space (only if not used).
340  * Note that the view is always removed but the display is only removed if empty.
341  */
342 extern OCIOEXPORT void RemoveDisplayView(ConfigRcPtr & config,
343  const char * displayName,
344  const char * viewName);
345 
346 } // DisplayViewHelpers
347 
348 
349 /**
350  * Whereas the DisplayViewTransform simply applies a specific view from an OCIO display, the
351  * LegacyViewingPipeline provides an example of a complete viewing pipeline of the sort that could
352  * be used to implement a viewport in a typical application. It therefore adds, around the
353  * DisplayViewTransform, various optional color correction steps and RGBA channel view swizzling.
354  * The direction of the DisplayViewTranform is used as the direction of the pipeline.
355  * Note: The LegacyViewingPipeline class provides the same functionality as the OCIO v1
356  * DisplayTransform.
357  *
358  * Legacy viewing pipeline:
359  * * Start in display transform input color space.
360  * * If linearCC is provided:
361  * * Go to scene_linear colorspace.
362  * * Apply linearCC transform.
363  * * If colorTimingCC is provided:
364  * * Go to color_timing colorspace.
365  * * Apply colorTimingCC transform.
366  * * Apply looks (from display transform or from looks override).
367  * * Go to first look color space.
368  * * Apply first look transform.
369  * * Iterate for all looks.
370  * * Apply channelView transform.
371  * * Apply display transform (without looks).
372  * * Apply displayCC.
373  * Note that looks are applied even if the display transform involves data color spaces.
374  */
376 {
377 public:
378  static LegacyViewingPipelineRcPtr Create();
379 
380  virtual ConstDisplayViewTransformRcPtr getDisplayViewTransform() const noexcept = 0;
381  virtual void setDisplayViewTransform(const ConstDisplayViewTransformRcPtr & dt) noexcept = 0;
382 
383  virtual ConstTransformRcPtr getLinearCC() const noexcept = 0;
384  virtual void setLinearCC(const ConstTransformRcPtr & cc) noexcept = 0;
385 
386  virtual ConstTransformRcPtr getColorTimingCC() const noexcept = 0;
387  virtual void setColorTimingCC(const ConstTransformRcPtr & cc) noexcept = 0;
388 
389  virtual ConstTransformRcPtr getChannelView() const noexcept = 0;
390  virtual void setChannelView(const ConstTransformRcPtr & transform) noexcept = 0;
391 
392  virtual ConstTransformRcPtr getDisplayCC() const noexcept = 0;
393  virtual void setDisplayCC(const ConstTransformRcPtr & cc) noexcept = 0;
394 
395  /**
396  * Specify whether the lookOverride should be used, or not. This is a separate flag, as
397  * it's often useful to override "looks" to an empty string.
398  */
399  virtual void setLooksOverrideEnabled(bool enable) = 0;
400  virtual bool getLooksOverrideEnabled() const = 0;
401 
402  /**
403  * A user can optionally override the looks that are, by default, used with the expected
404  * display / view combination. A common use case for this functionality is in an image
405  * viewing app, where per-shot looks are supported. If for some reason a per-shot look is
406  * not defined for the current Context, the Config::getProcessor fcn will not succeed by
407  * default. Thus, with this mechanism the viewing app could override to looks = "", and
408  * this will allow image display to continue (though hopefully) the interface would reflect
409  * this fallback option.
410  *
411  * Looks is a potentially comma (or colon) delimited list of lookNames, where +/- prefixes
412  * are optionally allowed to denote forward/inverse look specification (and forward is
413  * assumed in the absence of either).
414  */
415  virtual void setLooksOverride(const char * looks) = 0;
416  virtual const char * getLooksOverride() const = 0;
417 
418  virtual ConstProcessorRcPtr getProcessor(const ConstConfigRcPtr & config,
419  const ConstContextRcPtr & context) const = 0;
420 
421  virtual ConstProcessorRcPtr getProcessor(const ConstConfigRcPtr & config) const = 0;
422 
425 
426  /// Do not use (needed only for pybind11).
427  virtual ~LegacyViewingPipeline() = default;
428 
429 protected:
430  LegacyViewingPipeline() = default;
431 };
432 
433 extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const LegacyViewingPipeline &);
434 
435 /**
436  * The MixingSlider and MixingColorSpaceManager classes are to help applications implement correct
437  * color pickers. The term "color mixing" is used here to describe what is done in a typical
438  * application "color picker" user interface.
439  *
440  * A user may want to mix colors in different color spaces. The two most common mixing space
441  * options are a scene-linear working space or the display space.
442  *
443  * Since scene-linear color spaces are not perceptually uniform, it is necessary to compensate UI
444  * widgets such as sliders. For example, it is nice if mid-gray falls near the center of mixing
445  * controls rather than way over near the black end. This may be done by using a mapping from
446  * linear into an approximately perceptually uniform space.
447  *
448  * Also note that a color picking/mixing UI may want to present a given color space in several
449  * different encodings. The most common two encodings for color mixing are RGB and HSV.
450  *
451  * Note that these helpers anticipate that a user may want to mix colors using values that extend
452  * outside the typical [0,1] domain.
453  */
455 {
456 public:
457  /// Set the minimum edge of a UI slider for conversion to mixing space.
458  virtual void setSliderMinEdge(float sliderMixingMinEdge) noexcept = 0;
459 
460  /// Minimum edge of a UI slider for conversion to mixing space.
461  virtual float getSliderMinEdge() const noexcept = 0;
462 
463  /// Set the maximum edge of a UI slider for conversion to mixing space.
464  virtual void setSliderMaxEdge(float sliderMixingMaxEdge) noexcept = 0;
465 
466  /// Maximum edge of a UI slider for conversion to mixing space.
467  virtual float getSliderMaxEdge() const noexcept = 0;
468 
469  /// Convert from units in distance along the slider to mixing space units.
470  virtual float sliderToMixing(float sliderUnits) const noexcept = 0;
471 
472  /// Convert from mixing space units to distance along the slider.
473  virtual float mixingToSlider(float mixingUnits) const noexcept = 0;
474 
475  MixingSlider(const MixingSlider &) = delete;
476  MixingSlider & operator=(const MixingSlider &) = delete;
477 
478  /// Do not use (needed only for pybind11).
479  virtual ~MixingSlider() = default;
480 
481 protected:
482  MixingSlider() = default;
483 };
484 
485 extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const MixingSlider &);
486 
487 /**
488  * Used to mix (or pick/choose) colors.
489  */
491 {
492 public:
493 
494  static MixingColorSpaceManagerRcPtr Create(ConstConfigRcPtr & config);
495 
496  /// Access to the mixing spaces.
497  virtual size_t getNumMixingSpaces() const noexcept = 0;
498  virtual const char * getMixingSpaceUIName(size_t idx) const = 0;
499  virtual size_t getSelectedMixingSpaceIdx() const noexcept = 0;
500  virtual void setSelectedMixingSpaceIdx(size_t idx) = 0;
501  virtual void setSelectedMixingSpace(const char * mixingSpace) = 0;
502 
503  virtual bool isPerceptuallyUniform() const noexcept = 0;
504 
505  /// Access to the mixing encodings.
506  virtual size_t getNumMixingEncodings() const noexcept = 0;
507  virtual const char * getMixingEncodingName(size_t idx) const = 0;
508  virtual size_t getSelectedMixingEncodingIdx() const noexcept = 0;
509  virtual void setSelectedMixingEncodingIdx(size_t idx) = 0;
510  virtual void setSelectedMixingEncoding(const char * mixingEncoding) = 0;
511 
512  /// Refresh the instance (i.e. needed following a configuration change for example).
513  virtual void refresh(ConstConfigRcPtr config) = 0;
514 
515  virtual ConstProcessorRcPtr getProcessor(const char * workingName,
516  const char * displayName,
517  const char * viewName,
518  TransformDirection direction) const = 0;
519 
520  virtual MixingSlider & getSlider() noexcept = 0;
521  virtual MixingSlider & getSlider(float sliderMixingMinEdge,
522  float sliderMixingMaxEdge) noexcept = 0;
523 
526 
527  /// Do not use (needed only for pybind11).
528  virtual ~MixingColorSpaceManager() = default;
529 
530 protected:
531  MixingColorSpaceManager() = default;
532 };
533 
534 extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const MixingColorSpaceManager &);
535 
536 /**
537  * The ConfigMergingParameters class holds the options that control how a merge is done.
538  *
539  * In terms of OCIOM file, it represent one of the merges in an OCIOM file.
540  *
541  */
543 {
544 public:
545 
547  {
548  /// Combine elements of the base and input configs, with the input taking priority.
549  STRATEGY_PREFER_INPUT = 0,
550  /// Combine elements of the base and input configs, with the base taking priority.
552  /// Use only the input elements for that section of the config.
554  /// Use only the base elements for that section of the config.
556  /// The elements in the input config are removed from the base config. (If the names
557  /// match, the item is removed, even if the content is not identical.)
559  /// Strategy has not been set yet.
560  STRATEGY_UNSPECIFIED
561  };
562 
563  static ConfigMergingParametersRcPtr Create();
564 
565  ConfigMergingParametersRcPtr createEditableCopy() const;
566 
567  /// Set the file name of the base config. This is used along with the search path of
568  /// the ConfigMerger object.
569  void setBaseConfigName(const char * baseConfig);
570  const char * getBaseConfigName() const;
571 
572  /// Set the file name of the input config. This is used along with the search path of
573  /// the ConfigMerger object.
574  void setInputConfigName(const char * inputConfig);
575  const char * getInputConfigName() const;
576 
577  /// Set a name to use for this merger. This may be used as the input or base config name
578  /// in subsequent mergers.
579  void setOutputName(const char * outputName);
580  const char * getOutputName() const;
581 
582  // Options
583 
584  /// Set the default strategy. This will be used if the strategy for a given config section
585  /// is not set, and will be used for basic attributes such as the config description.
586  /// Default = STRATEGY_PREFER_INPUT.
587  void setDefaultStrategy(const ConfigMergingParameters::MergeStrategies strategy);
588  ConfigMergingParameters::MergeStrategies getDefaultStrategy() const;
589 
590  /// Set a prefix to add to the family of input config items. (It must use '/' as the
591  /// separator and will be replaced by the actual family separator of the config.)
592  void setInputFamilyPrefix(const char * prefix);
593  const char * getInputFamilyPrefix() const;
594 
595  /// Set a prefix to add to the family of base config items. (It must use '/' as the
596  /// separator and will be replaced by the actual family separator of the config.)
597  void setBaseFamilyPrefix(const char * prefix);
598  const char * getBaseFamilyPrefix() const;
599 
600  /// If true, items from the input config will be higher in the file than those of the
601  /// base config. Default = true.
602  void setInputFirst(bool enabled);
603  bool isInputFirst() const;
604 
605  /// If true, throw an exception rather than log a warning when a conflict is detected.
606  /// Default = false.
607  void setErrorOnConflict(bool enabled);
608  bool isErrorOnConflict() const;
609 
610  /// If true, a color space from the input config is compared against those of the base
611  /// config. If it is mathematically equivalent, it is not added. Instead, its name and
612  /// aliases are added to the original color space. Default = true.
613  void setAvoidDuplicates(bool enabled);
614  bool isAvoidDuplicates() const;
615 
616  /// If true, the reference spaces of the base and input config are compared and color
617  /// spaces from the input config will be adjusted to use the reference space of the base.
618  /// If the interchange roles are not set, heuristics will be used to try and determine
619  /// the reference space. Default = true.
620  void setAdjustInputReferenceSpace(bool enabled);
621  bool isAdjustInputReferenceSpace() const;
622 
623  // Overrides
624 
625  /// Override the name of the merged config.
626  void setName(const char * mergedConfigName);
627  const char * getName() const;
628 
629  /// Override the description of the merged config.
630  void setDescription(const char * mergedConfigDesc);
631  const char * getDescription() const;
632 
633  /// Override a context variable in the merged config.
634  void addEnvironmentVar(const char * name, const char * defaultValue);
635  /// Get the number of context variable overrides.
636  int getNumEnvironmentVars() const;
637  const char * getEnvironmentVar(int index) const;
638  const char * getEnvironmentVarValue(int index) const;
639 
640  /// Override the search_path of the merged config.
641  void setSearchPath(const char * path);
642  void addSearchPath(const char * path);
643  const char * getSearchPath() const;
644 
645  /// Override the active_displays of the merged config.
646  void setActiveDisplays(const char * displays);
647  const char * getActiveDisplays() const;
648 
649  /// Override the active_views of the merged config.
650  void setActiveViews(const char * views);
651  const char * getActiveViews() const;
652 
653  /// Override the inactive_colorspaces of the merged config.
654  void setInactiveColorSpaces(const char * colorspaces);
655  const char * getInactiveColorSpaces() const;
656 
657  // Config section strategies
658 
659  /// Set the merge strategy for the roles section.
660  void setRoles(MergeStrategies strategy);
661  MergeStrategies getRoles() const;
662 
663  /// Set the merge strategy for the file_rules section.
664  void setFileRules(MergeStrategies strategy);
665  MergeStrategies getFileRules() const;
666 
667  /// Set the merge strategy for the displays/views section.
668  /// This includes shared_views, displays, viewing_rules,
669  /// virtual_display, active_display, and active_views.
670  void setDisplayViews(MergeStrategies strategy);
671  MergeStrategies getDisplayViews() const;
672 
673  /// Set the merge strategy for the view_transforms section.
674  /// This includes the view_transforms and default_view_transform.
675  void setViewTransforms(MergeStrategies strategy);
676  MergeStrategies getViewTransforms() const;
677 
678  /// Set the merge strategy for the looks section.
679  void setLooks(MergeStrategies strategy);
680  MergeStrategies getLooks() const;
681 
682  /// Set the merge strategy for the color spaces section.
683  /// This includes colorspaces, display_colorspaces, environment, search_path,
684  /// family_separator, and inactive_colorspaces.
685  void setColorspaces(MergeStrategies strategy);
686  MergeStrategies getColorspaces() const;
687 
688  /// Set the merge strategy for the named_transforms section.
689  void setNamedTransforms(MergeStrategies strategy);
690  MergeStrategies getNamedTransforms() const;
691 
694 
695  /// Do not use (needed only for pybind11).
697 
698 private:
700 
701  static void deleter(ConfigMergingParameters * c);
702 
703  class Impl;
704  Impl * m_impl;
705  Impl * getImpl() { return m_impl; }
706  const Impl * getImpl() const { return m_impl; }
707 };
708 
709 extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const ConfigMergingParameters &);
710 
711 /**
712  * The ConfigMerger class is the controller for the merging process.
713  *
714  * It may be read from or serialized to an OCIOM file.
715  *
716  * It is controlling the search_path to find the base and input config, and the merge parameters.
717  *
718  * It contains an instance of ConfigMergingParameters for each merge present under the "merge"
719  * section.
720  *
721  * For example, consider the following OCIOM file contents:
722  *
723  * ociom_version: 1.0
724  * search_path:
725  * - /usr/local/configs
726  * - .
727  * merge:
728  * Merge_ADD_THIS:
729  * [...]
730  * Merge_ADD_THAT:
731  * [...]
732  *
733  * For this OCIOM, there would be two instances of ConfigMergingParameters.
734  * One for the merge with output name "Merge_ADD_THIS" and one for "Merge_ADD_THAT".
735  *
736  * Where the [...] sections have the following structure:
737  *
738  * Merge_ADD_THIS:
739  * base: base.ocio
740  * input: input.ocio
741  * options:
742  * input_family_prefix: ""
743  * base_family_prefix: ""
744  * input_first: true
745  * error_on_conflict: false
746  * default_strategy: PreferInput
747  * avoid_duplicates: true
748  * adjust_input_reference_space: true
749  * overrides:
750  * name: ""
751  * description: ""
752  * search_path: ""
753  * environment: {}
754  * active_displays: []
755  * active_views: []
756  * inactive_colorspaces: []
757  * params:
758  * roles:
759  * strategy: PreferBase
760  * file_rules:
761  * strategy: PreferInput
762  * display-views:
763  * strategy: InputOnly
764  * view_transforms:
765  * strategy: InputOnly
766  * looks:
767  * strategy: BaseOnly
768  * colorspaces:
769  * strategy: PreferInput
770  * named_transform:
771  * strategy: Remove
772  *
773  * The indentation is significant and must be as shown. Default items may be omitted.
774  *
775  */
777 {
778 public:
779  static ConfigMergerRcPtr Create();
780 
781  // Create by parsing an OCIOM file.
782  static ConstConfigMergerRcPtr CreateFromFile(const char * filepath);
783 
784  ConfigMergerRcPtr createEditableCopy() const;
785 
786  /// These search paths are used to locate the input and base config.
787  /// Set the entire search path. The ':' character is used to separate paths.
788  void setSearchPath(const char * path);
789  /// Add a single path to the search paths.
790  void addSearchPath(const char * path);
791  /// Get the number of search paths.
792  int getNumSearchPaths() const;
793  const char * getSearchPath(int index) const;
794 
795  /**
796  * \brief Set the home directory used to resolve relative search paths.
797  *
798  * The working directory defaults to the location of the OCIOM file. It is used to convert
799  * any relative paths to absolute. If no search paths have been set, the working directory
800  * will be used as the fallback search path.
801  */
802  void setWorkingDir(const char * dirname);
803  const char * getWorkingDir() const;
804 
805  /// Get the parameters for one of the merges. Returns null if index is out of range.
806  ConfigMergingParametersRcPtr getParams(int index) const;
807  int getNumConfigMergingParameters() const;
808  void addParams(ConfigMergingParametersRcPtr params);
809 
810  /**
811  * \brief Execute the merge(s) based on the merger object.
812  *
813  * Execute the merge(s) based on the merger object that was previously populated by using
814  * ConfigMerger::CreateFromFile or created from scratch by using ConfigMerger::Create() and
815  * programmatically configuring it.
816  *
817  * \return a merger object (call getMergedConfig to obtain the result)
818  */
819  ConstConfigMergerRcPtr mergeConfigs() const;
820 
821  /// Get the final merged config.
822  ConstConfigRcPtr getMergedConfig() const;
823  /// Get one of the merged configs (if there are a series of merges). Returns null
824  /// if index is out of range.
825  ConstConfigRcPtr getMergedConfig(int index) const;
826  int getNumMergedConfigs() const;
827 
828  /// Serialize to the OCIOM file format.
829  void serialize(std::ostream& os) const;
830 
831  /// Set the version of the OCIOM file format.
832  void setVersion(unsigned int major, unsigned int minor);
833  unsigned int getMajorVersion() const;
834  unsigned int getMinorVersion() const;
835 
836  ConfigMerger(const ConfigMerger &) = delete;
837  ConfigMerger & operator=(const ConfigMerger &) = delete;
838 
839  /// Do not use (needed only for pybind11).
840  ~ConfigMerger();
841 
842 private:
843  ConfigMerger();
844 
845  static void deleter(ConfigMerger * c);
846 
847  class Impl;
848  Impl * m_impl;
849  Impl * getImpl() { return m_impl; }
850  const Impl * getImpl() const { return m_impl; }
851 };
852 
853 extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const ConfigMerger &);
854 
855 namespace ConfigMergingHelpers
856 {
857 
858 /**
859  * \brief Merge the input into the base config, using the supplied merge parameters.
860  *
861  * \param params ConfigMergingParameters controlling the merger.
862  * \param params The base config.
863  * \param params The input config to merge.
864  * \return The merged config object.
865  */
867  const ConstConfigRcPtr & baseConfig,
868  const ConstConfigRcPtr & inputConfig);
869 
870 /**
871  * \brief Merge a single color space into the base config, using the supplied merge parameters.
872  *
873  * Note that the AdjustInputReferenceSpace merge parameter will be ignored and set to false.
874  * To use automatic reference space conversion, add the color space to an input config that
875  * has the necessary interchange role set.
876  *
877  * \param params ConfigMergingParameters controlling the merger.
878  * \param params The base config.
879  * \param params The input color space to merge.
880  * \return The merged config object.
881  */
883  const ConstConfigRcPtr & baseConfig,
884  const ConstColorSpaceRcPtr & colorspace);
885 
886 } // ConfigMergingHelpers
887 
888 } // namespace OCIO_NAMESPACE
889 
890 #endif // INCLUDED_OCIO_OPENCOLORAPPHELPERS_H
OCIOEXPORT void AddDisplayView(ConfigRcPtr &config, const char *displayName, const char *viewName, const char *lookDefinition, const char *colorSpaceName, const char *colorSpaceFamily, const char *colorSpaceDescription, const char *categories, const char *transformFilePath, const char *connectionColorSpaceName)
PXL_API const char * getDescription(const ColorSpace *space)
Return the description of the color space.
OCIOEXPORT void RemoveDisplayView(ConfigRcPtr &config, const char *displayName, const char *viewName)
PXL_API void getActiveViews(UT_StringArray &names)
Returns the list of active views.
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
OCIO_SHARED_PTR< ColorSpaceMenuParameters > ColorSpaceMenuParametersRcPtr
OCIO_SHARED_PTR< const Transform > ConstTransformRcPtr
#define OCIO_NAMESPACE
Definition: OpenColorABI.h:8
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glcorearb.h:2539
OCIO_SHARED_PTR< const ConfigMerger > ConstConfigMergerRcPtr
GLenum const GLfloat * params
Definition: glcorearb.h:105
OCIO_SHARED_PTR< LegacyViewingPipeline > LegacyViewingPipelineRcPtr
OCIOEXPORT ConstProcessorRcPtr GetProcessor(const ConstConfigRcPtr &config, const ConstContextRcPtr &context, const char *workingName, const char *displayName, const char *viewName, const ConstMatrixTransformRcPtr &channelView, TransformDirection direction)
OCIO_SHARED_PTR< const ColorSpaceMenuParameters > ConstColorSpaceMenuParametersRcPtr
PXL_API void getRoles(UT_StringArray &names)
Returns a list of the supported roles.
OCIO_SHARED_PTR< const Context > ConstContextRcPtr
OCIOEXPORT ConstProcessorRcPtr GetIdentityProcessor(const ConstConfigRcPtr &config)
Get an identity processor containing only the ExposureContrastTransforms.
Use only the input elements for that section of the config.
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
OCIO_SHARED_PTR< MixingColorSpaceManager > MixingColorSpaceManagerRcPtr
Combine elements of the base and input configs, with the base taking priority.
OPENVDB_API void setVersion(std::ios_base &, const VersionId &libraryVersion, uint32_t fileVersion)
Associate specific file format and library version numbers with the given stream. ...
OCIOEXPORT void AddColorSpace(ConfigRcPtr &config, const char *name, const char *transformFilePath, const char *categories, const char *connectionColorSpaceName)
#define OCIOEXPORT
Definition: OpenColorABI.h:67
OCIO_SHARED_PTR< const Processor > ConstProcessorRcPtr
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_API const UT_StringHolder transform
OCIO_SHARED_PTR< const DisplayViewTransform > ConstDisplayViewTransformRcPtr
OCIO_SHARED_PTR< ColorSpaceMenuHelper > ColorSpaceMenuHelperRcPtr
OCIO_SHARED_PTR< const Config > ConstConfigRcPtr
OCIO_SHARED_PTR< const MatrixTransform > ConstMatrixTransformRcPtr
OCIOEXPORT ConfigRcPtr MergeConfigs(const ConfigMergingParametersRcPtr &params, const ConstConfigRcPtr &baseConfig, const ConstConfigRcPtr &inputConfig)
Merge the input into the base config, using the supplied merge parameters.
OCIO_SHARED_PTR< Config > ConfigRcPtr
LeafData & operator=(const LeafData &)=delete
GLuint index
Definition: glcorearb.h:786
OCIO_SHARED_PTR< ConfigMerger > ConfigMergerRcPtr
OCIOEXPORT std::ostream & operator<<(std::ostream &, const ColorSpaceMenuParameters &)
Use only the base elements for that section of the config.
PXL_API void getLooks(UT_StringArray &looks)
Returns a list of looks (color transforms)
PXL_API void getActiveDisplays(UT_StringArray &names)
Returns the list of active displays.
OCIO_SHARED_PTR< ConfigMergingParameters > ConfigMergingParametersRcPtr
OCIO_SHARED_PTR< const ColorSpace > ConstColorSpaceRcPtr
OCIOEXPORT ConfigRcPtr MergeColorSpace(const ConfigMergingParametersRcPtr &params, const ConstConfigRcPtr &baseConfig, const ConstColorSpaceRcPtr &colorspace)
Merge a single color space into the base config, using the supplied merge parameters.