HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PXL_OCIO.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: PXL_OCIO.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __PXL_OCIO__
12 #define __PXL_OCIO__
13 
14 #include "PXL_API.h"
15 #include "PXL_Common.h"
16 #include <SYS/SYS_Types.h>
17 #include <UT/UT_Functor.h>
18 
19 class UT_StringHolder;
20 class UT_StringRef;
21 class UT_StringArray;
22 class UT_Options;
23 
24 /// Abstract interface to OpenColorIO
25 namespace PXL_OCIO
26 {
27  /// @{
28  /// Private classes
29  class ColorSpace;
30  class Processor;
31  /// @}
32 
33  /// Mirrors the OCIO enum so that we don't have to expose the
34  /// OCIO_NAMESPACE and we can avoid namespace collisions.
35  enum class BitDepth
36  {
43  PXL_BIT_DEPTH_UINT32, // Like OCIO, historical reasons, but not supported
46  };
47 
48  static constexpr BitDepth DefaultBitDepth = BitDepth::PXL_BIT_DEPTH_F32;
49 
51  {
52  bool isValid() const;
53  bool isNoOp() const;
54  bool is3D() const;
55  void clear() { myProcessor = nullptr; }
56  explicit operator bool() const { return isValid(); }
57 
58  Processor *myProcessor = nullptr;
59  int myLoadID = 0;
60  };
61 
62  /// The path and filename of the config file being used.
64 
65  /// Returns whether the user has set $OCIO, $OCIO_ACTIVE_DISPLAYS or
66  /// $OCIO_ACTIVE_VIEWS is set. If there's an error loading the
67  /// configuration, this method will return @c false.
68  PXL_API bool isOCIOEnvSet(bool check_for_active_vars=true);
69 
70  /// Returns the current color space name
71  PXL_API const char *getDefaultDisplay();
72 
73  /// Returns the current color space name
74  PXL_API const char *getDefaultView(const char *display = NULL);
75 
76  /// Return the list of views for a given display.
77  PXL_API bool getViewsForDisplay(const char *display,
78  UT_StringArray &view_names);
79 
80  /// Returns the list of active displays
82 
83  /// Returns the list of active views
85 
86  /// Returns a list of the supported color spaces
88 
89  /// Returns a list of looks (color transforms)
90  PXL_API void getLooks(UT_StringArray &looks);
91 
92  /// Returns a list of the supported roles
93  PXL_API void getRoles(UT_StringArray &names);
94 
95  /// Reload the configuration.
96  PXL_API void reload();
97 
98  PXL_API const char *getDefaultRole();
99  PXL_API const char *getReferenceRole();
100  PXL_API const char *getDataRole();
101  PXL_API const char *getSceneLinearRole();
102  PXL_API const char *getCompLogRole();
103  PXL_API const char *getColorPickingRole();
104 
105  // Return the name of the color space associated with the "scene_linear" role
107 
108  // find an sRGB color space in the given config file.
110  PXL_API UT_StringHolder getsRGBColorSpace(const char *display);
111 
112  /// @{
113  /// Test whether a color space is one of the well-known color spaces
114  PXL_API bool issRGB(const ColorSpace *s);
115  PXL_API bool isRec709(const ColorSpace *s);
116  PXL_API bool isLinearRec709(const ColorSpace *s);
117  PXL_API bool isSceneLinear(const ColorSpace *s);
118  PXL_API bool isRaw(const ColorSpace *s);
119  /// @}
120 
121  // find an rec709 color space in the given config file
123 
124  // find a linear rec709 color space in the given config file
126 
127  // Find a raw color space
129 
130  /// Return the colorspace defined by the view for a given display.
131  PXL_API const char *getColorSpaceForDisplayView(const char *display_name,
132  const char *view_name);
133 
134  /// Return the colorspace defined by the view for a given display.
135  PXL_API const char *getTransformNameForDisplayView(const char *display_name,
136  const char *view_name);
137 
138  /// Return the looks attached to the view for a given display.
139  PXL_API const char *getLooksForDisplayView(const char *display_name,
140  const char *view_name);
141 
142 
143  /// Guess at the colorspace using the rightmost colorspace found, or NULL
144  /// if none are found.
145  PXL_API const char *parseColorSpaceFromString(const char *string);
146 
148 
149  /// Convert a PXL_ColorSpace to roughly the OCIO equivalent
151  const UT_StringHolder &ocioname);
152 
153  /// @{
154  /// Get the best approximation for the PXL_ColorSpace from the OCIO color
155  /// space. The @c name will be filled out with the full name of the space.
156  /// The return value will be PXL_CS_OCIO, unless it's a well known space.
161  /// @}
162 
163 
164  /// Return a color space handle given a name. The name may be a color
165  /// space name or prefixed with "role:" to specify a color space role.
167 
168  /// Return the name of the color space
169  PXL_API const char *getName(const ColorSpace *space);
170  /// Return the description of the color space
171  PXL_API const char *getDescription(const ColorSpace *space);
172  /// Return the Nanocolor name for the color space. If it's not possible to
173  /// determine the Nanocolor space name, this will return an empty string.
174  PXL_API const UT_StringHolder &getNanocolorName(const ColorSpace *space);
175  /// Return the OpenUSD color space token:
176  /// See: https://openusd.org/release/user_guides/color_user_guide.html
177  PXL_API const UT_StringHolder &getOpenUSDName(const ColorSpace *space);
178  /// Return the "best" alias for the color space (either Nanocolor or OpenUSD)
179  PXL_API const UT_StringHolder &getBestAlias(const ColorSpace *space);
180 
181  /// Return the allocation variable meta data about the color space
182  PXL_API bool getAllocationVars(const ColorSpace* space,
183  bool &uniform,
184  fpreal &min,
185  fpreal &max,
186  fpreal &offset);
187  /// Set 'fp' to true if the color space is defined for FP, false for uint
188  PXL_API bool isFloatPointSpace(const ColorSpace* space,
189  bool &fp);
190  /// Return a list of the aliases for a color space
191  PXL_API void getAliases(const ColorSpace *space,
192  UT_StringArray &aliases);
193 
194  /// Fill out metadata for color space in a UT_Options
195  /// Keys are the tokens in the config.ocio file:
196  /// - @c name
197  /// - @c family
198  /// - @c equalitygroup
199  /// - @c bitdepth
200  /// - @c description
201  /// - @c isdata
202  /// - @c allocation
203  /// - @c allocationvars
204  PXL_API bool getInfo(const ColorSpace *space, UT_Options &info);
205 
206  /// Get the viewing rule names
208  /// Lookup a viewing rule by the name
210 
211  /// @{
212  /// Lookup processors which can be used to transform colors efficiently.
213  /// @note: These processors become invalid on a reload.
215  const UT_StringHolder &dest,
216  const UT_StringHolder &looks,
217  bool forward_transform=true,
218  const BitDepth src_depth=DefaultBitDepth,
219  const BitDepth dst_depth=DefaultBitDepth);
221  const ColorSpace *dest,
222  const UT_StringHolder &looks,
223  bool forward_transform=true,
224  const BitDepth src_depth=DefaultBitDepth,
225  const BitDepth dst_depth=DefaultBitDepth);
227  const UT_StringHolder &display,
228  const UT_StringHolder &view,
229  bool forward_transform,
230  const BitDepth src_depth=DefaultBitDepth,
231  const BitDepth dst_depth=DefaultBitDepth);
233  const UT_StringHolder &view_transform,
234  bool forward_transform,
235  const BitDepth src_depth=DefaultBitDepth,
236  const BitDepth dst_depth=DefaultBitDepth);
237  /// @}
238 
239  /// Transform pixels by a processor
240  PXL_API bool transform(const PHandle &processor,
241  fpreal32 *data, const int npixels,
242  const int nchannels);
243  PXL_API bool transform(const PHandle &processor,
244  const void *src, void *dst, const int width,
245  const int height, const int src_channels,
246  const int dst_channels);
247 
248  // Process buffer in-place
249  PXL_API bool transform(const PHandle &processor,
250  void *data, int width, int height, int channels);
251 
252  /// @{
253  /// Is there a transform from src->dest with the applied looks.
254  inline bool isValidTransform(const PHandle &processor)
255  {
256  return processor.isValid();
257  }
258  /// @}
259 
260  /// @{
261  /// Valid transform, but does nothing. This is true if the src and dest
262  /// color spaces are equal, but also handles special cases like
263  /// transforming from "raw" spaces. So, this is more correct than an
264  /// operator==() or isEqual() method.
265  inline bool isNoOpTransform(const PHandle &processor)
266  {
267  return processor.isNoOp();
268  }
269  /// @}
270 
271  /// @{
272  /// Does the transform from src->dest with applied looks require a 3D LUT.
273  inline bool is3DTransform(const PHandle &processor)
274  {
275  return processor.is3D();
276  }
277  /// @}
278 
279  /// @{
280  /// Transform color data from one color space to another color space.
281  /// The color space names may either refer to a color space name, or it can
282  /// also be prefixed with "role:" and refer to a color space role. The
283  /// 'looks' is a comma separated list of color gradings (aka looks)
284  inline bool transform(const UT_StringHolder &src,
285  const UT_StringHolder &dest,
286  const UT_StringHolder &looks,
287  fpreal32 *data, int npixels, int nchannels,
288  bool forward_transform = true)
289  {
290  return transform(lookupProcessor(src, dest, looks, forward_transform),
291  data, npixels, nchannels);
292  }
293  inline bool transform(const ColorSpace *src,
294  const ColorSpace *dest,
295  const UT_StringHolder &looks,
296  fpreal32 *data, int npixels, int nchannels,
297  bool forward_transform = true)
298  {
299  return transform(lookupProcessor(src, dest, looks, forward_transform),
300  data, npixels, nchannels);
301  }
302  /// @}
303 
304  /// Transform from a colorspace to a display/view, including looks.
305  inline bool transformToView(const UT_StringHolder &src,
306  const UT_StringHolder &display,
307  const UT_StringHolder &view,
308  fpreal32 *data, int npixels, int nchannels,
309  bool forward_xform = true)
310  {
311  return transform(lookupViewProcessor(src, display, view, forward_xform),
312  data, npixels, nchannels);
313  }
314 
315  /// Transform with the given view transform, which must exist in the config
316  inline bool transform(const UT_StringHolder &view_transform,
317  fpreal32 *data, int npixels, int nchannels,
318  bool forward_transform = true)
319  {
320  return transform(lookupViewProcessor(view_transform, forward_transform),
321  data, npixels, nchannels);
322  }
323 
324  /// @{
325  /// When the OCIO config is reloaded, all processor and color space
326  /// pointers become invalid. You can register a callback (and remove it)
327  /// to be notified of reloads.
329  PXL_API void removeConfigChangeCB(int id);
330  /// @}
331 
332 } // end PXL_OCIO namespace
333 
334 #endif
PXL_API bool isSceneLinear(const ColorSpace *s)
PXL_API void reload()
Reload the configuration.
PXL_API const char * getDescription(const ColorSpace *space)
Return the description of the color space.
PXL_API UT_StringHolder parseColorSpaceFromHolder(const UT_StringHolder &s)
PXL_API void getColorSpaces(UT_StringArray &names)
Returns a list of the supported color spaces.
PXL_API const char * getCompLogRole()
PXL_API void getActiveViews(UT_StringArray &names)
Returns the list of active views.
PXL_API bool isLinearRec709(const ColorSpace *s)
bool transformToView(const UT_StringHolder &src, const UT_StringHolder &display, const UT_StringHolder &view, fpreal32 *data, int npixels, int nchannels, bool forward_xform=true)
Transform from a colorspace to a display/view, including looks.
Definition: PXL_OCIO.h:305
PXL_API PHandle lookupProcessor(const UT_StringHolder &src, const UT_StringHolder &dest, const UT_StringHolder &looks, bool forward_transform=true, const BitDepth src_depth=DefaultBitDepth, const BitDepth dst_depth=DefaultBitDepth)
GLdouble s
Definition: glad.h:3009
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
PXL_API const char * getDefaultView(const char *display=NULL)
Returns the current color space name.
float fpreal32
Definition: SYS_Types.h:200
PXL_API bool getViewsForDisplay(const char *display, UT_StringArray &view_names)
Return the list of views for a given display.
PXL_API const char * getDataRole()
#define PXL_API
Definition: PXL_API.h:10
OutGridT const XformOp bool bool
bool is3D() const
PXL_API const char * getTransformNameForDisplayView(const char *display_name, const char *view_name)
Return the colorspace defined by the view for a given display.
PXL_API const UT_StringHolder & getSceneLinearColorSpace()
PXL_API void getRoles(UT_StringArray &names)
Returns a list of the supported roles.
PXL_API PHandle lookupViewProcessor(const UT_StringHolder &src, const UT_StringHolder &display, const UT_StringHolder &view, bool forward_transform, const BitDepth src_depth=DefaultBitDepth, const BitDepth dst_depth=DefaultBitDepth)
PXL_API const UT_StringHolder & getRawColorSpace()
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
GLintptr offset
Definition: glcorearb.h:665
PXL_API const UT_StringHolder & getNanocolorName(const ColorSpace *space)
PXL_API const UT_StringHolder & getOpenUSDName(const ColorSpace *space)
PXL_API bool isRaw(const ColorSpace *s)
PXL_API bool isFloatPointSpace(const ColorSpace *space, bool &fp)
Set 'fp' to true if the color space is defined for FP, false for uint.
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
PXL_API const UT_StringHolder & pxlImageColorSpace(PXL_ColorSpace cs, const UT_StringHolder &ocioname)
Convert a PXL_ColorSpace to roughly the OCIO equivalent.
PXL_API const char * getSceneLinearRole()
PXL_API const char * getReferenceRole()
PXL_API bool getAllocationVars(const ColorSpace *space, bool &uniform, fpreal &min, fpreal &max, fpreal &offset)
Return the allocation variable meta data about the color space.
PXL_API const ColorSpace * lookupSpace(const UT_StringHolder &name)
PXL_API void getAliases(const ColorSpace *space, UT_StringArray &aliases)
Return a list of the aliases for a color space.
bool is3DTransform(const PHandle &processor)
Definition: PXL_OCIO.h:273
GLuint const GLchar * name
Definition: glcorearb.h:786
PXL_API const UT_StringHolder & getsRGBColorSpace()
bool isNoOp() const
PXL_API const char * getDefaultDisplay()
Returns the current color space name.
PXL_API const char * parseColorSpaceFromString(const char *string)
PXL_API const UT_StringHolder & getLinearRec709ColorSpace()
GLenum GLenum dst
Definition: glcorearb.h:1793
typename valxform::SharedOpTransformer< InIterT, OutTreeT, const XformOp > Processor
A map of string to various well defined value types.
Definition: UT_Options.h:87
PXL_API bool isOCIOEnvSet(bool check_for_active_vars=true)
PXL_API const UT_StringRef & configFilePath()
The path and filename of the config file being used.
fpreal64 fpreal
Definition: SYS_Types.h:283
PXL_ColorSpace
Definition: PXL_Common.h:72
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
PXL_API bool isRec709(const ColorSpace *s)
PXL_API bool transform(const PHandle &processor, fpreal32 *data, const int npixels, const int nchannels)
Transform pixels by a processor.
bool isValid() const
PXL_API bool getInfo(const ColorSpace *space, UT_Options &info)
PXL_API bool issRGB(const ColorSpace *s)
PXL_API void viewingRuleNames(UT_StringArray &names)
Get the viewing rule names.
GLint GLsizei width
Definition: glcorearb.h:103
PXL_API int addConfigChangeCB(UT_Functor< void > callback)
PXL_API const char * getColorSpaceForDisplayView(const char *display_name, const char *view_name)
Return the colorspace defined by the view for a given display.
PXL_API const char * getColorPickingRole()
class OCIOEXPORT ColorSpace
PXL_API void getLooks(UT_StringArray &looks)
Returns a list of looks (color transforms)
PXL_API const UT_Options & viewingRule(const UT_StringRef &name)
Lookup a viewing rule by the name.
PXL_API const UT_StringHolder & getBestAlias(const ColorSpace *space)
Return the "best" alias for the color space (either Nanocolor or OpenUSD)
PXL_API void getActiveDisplays(UT_StringArray &names)
Returns the list of active displays.
bool isNoOpTransform(const PHandle &processor)
Definition: PXL_OCIO.h:265
PXL_API void removeConfigChangeCB(int id)
PXL_API const char * getDefaultRole()
Definition: format.h:1821
PXL_API const UT_StringHolder & getRec709ColorSpace()
PXL_API const char * getLooksForDisplayView(const char *display_name, const char *view_name)
Return the looks attached to the view for a given display.
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
GLenum src
Definition: glcorearb.h:1793
bool isValidTransform(const PHandle &processor)
Definition: PXL_OCIO.h:254