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 
34  {
35  bool isValid() const;
36  bool isNoOp() const;
37  bool is3D() const;
38  void clear() { myProcessor = nullptr; }
39  SYS_SAFE_BOOL operator bool() const { return isValid(); }
40 
41  Processor *myProcessor = nullptr;
42  int myLoadID = 0;
43  };
44 
45  /// The path and filename of the config file being used.
47 
48  /// Returns whether the user has set $OCIO, $OCIO_ACTIVE_DISPLAYS or
49  /// $OCIO_ACTIVE_VIEWS is set. If there's an error loading the
50  /// configuration, this method will return @c false.
51  PXL_API bool isOCIOEnvSet(bool check_for_active_vars=true);
52 
53  /// Returns the current color space name
54  PXL_API const char *getDefaultDisplay();
55 
56  /// Returns the current color space name
57  PXL_API const char *getDefaultView(const char *display = NULL);
58 
59  /// Return the list of views for a given display.
60  PXL_API bool getViewsForDisplay(const char *display,
61  UT_StringArray &view_names);
62 
63  /// Returns the list of active displays
65 
66  /// Returns the list of active views
68 
69  /// Returns a list of the supported color spaces
71 
72  /// Returns a list of looks (color transforms)
73  PXL_API void getLooks(UT_StringArray &looks);
74 
75  /// Returns a list of the supported roles
76  PXL_API void getRoles(UT_StringArray &names);
77 
78  /// Reload the configuration.
79  PXL_API void reload();
80 
81  PXL_API const char *getDefaultRole();
82  PXL_API const char *getReferenceRole();
83  PXL_API const char *getDataRole();
84  PXL_API const char *getSceneLinearRole();
85  PXL_API const char *getCompLogRole();
86  PXL_API const char *getColorPickingRole();
87 
88  // find an sRGB color space in the given config file.
90  PXL_API UT_StringHolder getsRGBColorSpace(const char *display);
91 
92  /// @{
93  /// Test whether a color space is one of the well-known color spaces
94  PXL_API bool issRGB(const ColorSpace *s);
95  PXL_API bool isSceneLinear(const ColorSpace *s);
96  /// @}
97 
98  // find an rec709 color space in the given config file
100 
101  // find a linear rec709 color space in the given config file
103 
104  // Find a raw color space
106 
107  /// Return the colorspace defined by the view for a given display.
108  PXL_API const char *getColorSpaceForDisplayView(const char *display_name,
109  const char *view_name);
110 
111  /// Return the colorspace defined by the view for a given display.
112  PXL_API const char *getTransformNameForDisplayView(const char *display_name,
113  const char *view_name);
114 
115  /// Return the looks attached to the view for a given display.
116  PXL_API const char *getLooksForDisplayView(const char *display_name,
117  const char *view_name);
118 
119 
120  /// Guess at the colorspace using the rightmost colorspace found, or NULL
121  /// if none are found.
122  PXL_API const char *parseColorSpaceFromString(const char *string);
123 
125 
126  /// Convert a PXL_ColorSpace to roughly the OCIO equivalent
128  const UT_StringHolder &ocioname);
129 
130  /// @{
131  /// Get the best approximation for the PXL_ColorSpace from the OCIO color
132  /// space. The @c name will be filled out with the full name of the space.
133  /// The return value will be PXL_CS_OCIO, unless it's a well known space.
138  /// @}
139 
140 
141  /// Return a color space handle given a name. The name may be a color
142  /// space name or prefixed with "role:" to specify a color space role.
144 
145  /// Return the name of the color space
146  PXL_API const char *getName(const ColorSpace *space);
147  /// Return the description of the color space
148  PXL_API const char *getDescription(const ColorSpace *space);
149  /// Return the allocation variable meta data about the color space
151  bool &uniform,
152  fpreal &min,
153  fpreal &max,
154  fpreal &offset);
155  /// Set 'fp' to true if the color space is defined for FP, false for uint
157  bool &fp);
158 
159  /// Fill out metadata for color space in a UT_Options
160  /// Keys are the tokens in the config.ocio file:
161  /// - @c name
162  /// - @c family
163  /// - @c equalitygroup
164  /// - @c bitdepth
165  /// - @c description
166  /// - @c isdata
167  /// - @c allocation
168  /// - @c allocationvars
169  PXL_API bool getInfo(const ColorSpace *space, UT_Options &info);
170 
171  /// Get the viewing rule names
173  /// Lookup a viewing rule by the name
175 
176  /// @{
177  /// Lookup processors which can be used to transform colors efficiently.
178  /// @note: These processors become invalid on a reload.
180  const UT_StringHolder &dest,
181  const UT_StringHolder &looks,
182  bool forward_transform=true);
184  const ColorSpace *dest,
185  const UT_StringHolder &looks,
186  bool forward_transform=true);
188  const UT_StringHolder &display,
189  const UT_StringHolder &view,
190  bool forward_transform);
192  const UT_StringHolder &view_transform,
193  bool forward_transform);
194  /// @}
195 
196  /// Transform pixels by a processor
197  PXL_API bool transform(const PHandle &processor,
198  fpreal32 *data, int npixels, int nchannels);
199 
200  PXL_API bool transform(const PHandle &processor, void *src, void *dst,
201  int width, int height, int nchannels);
202 
203  PXL_API bool transform(const PHandle &processor, fpreal32 *src,
204  int width, int height, int nchannels);
205 
206  /// @{
207  /// Is there a transform from src->dest with the applied looks.
208  inline bool isValidTransform(const ColorSpace *src,
209  const ColorSpace *dest,
210  const UT_StringHolder &looks,
211  bool forward_transform = true)
212  {
213  return lookupProcessor(src, dest, looks, forward_transform).isValid();
214  }
215  static inline bool isValidTransform(const UT_StringHolder &src,
216  const UT_StringHolder &dest,
217  const UT_StringHolder &looks,
218  bool forward_transform = true)
219  {
220  return isValidTransform(lookupSpace(src), lookupSpace(dest), looks,
221  forward_transform);
222  }
224  bool forward)
225  {
226  return lookupViewProcessor(transform, forward).isValid();
227  }
228  /// @}
229 
230  /// @{
231  /// Valid transform, but does nothing. This is true if the src and dest
232  /// color spaces are equal, but also handles special cases like
233  /// transforming from "raw" spaces. So, this is more correct than an
234  /// operator==() or isEqual() method.
235  inline bool isNoOpTransform(const ColorSpace *src,
236  const ColorSpace *dest,
237  const UT_StringHolder &looks,
238  bool forward_transform = true)
239  {
240  return lookupProcessor(src, dest, looks, forward_transform).isNoOp();
241  }
242  static inline bool isNoOpTransform(const UT_StringHolder &src,
243  const UT_StringHolder &dest,
244  const UT_StringHolder &looks,
245  bool forward_transform = true)
246  {
247  return isNoOpTransform(lookupSpace(src), lookupSpace(dest), looks,
248  forward_transform);
249  }
250  /// @}
251 
252  /// @{
253  /// Does the transform from src->dest with applied looks require a 3D LUT.
254  inline bool is3DTransform(const ColorSpace *src,
255  const ColorSpace *dest,
256  const UT_StringHolder &looks,
257  bool forward_transform = true)
258  {
259  return lookupProcessor(src, dest, looks, forward_transform).is3D();
260  }
261  static inline bool is3DTransform(const UT_StringHolder &src,
262  const UT_StringHolder &dest,
263  const UT_StringHolder &looks,
264  bool forward_transform = true)
265  {
266  return is3DTransform(lookupSpace(src), lookupSpace(dest), looks,
267  forward_transform);
268  }
269  /// @}
270 
271  inline bool is3DTransform(const UT_StringHolder &view_transform)
272  {
273  return lookupViewProcessor(view_transform, true).is3D();
274  }
275 
276  /// @{
277  /// Transform color data from one color space to another color space.
278  /// The color space names may either refer to a color space name, or it can
279  /// also be prefixed with "role:" and refer to a color space role. The
280  /// 'looks' is a comma separated list of color gradings (aka looks)
281  inline bool transform(const UT_StringHolder &src,
282  const UT_StringHolder &dest,
283  const UT_StringHolder &looks,
284  fpreal32 *data, int npixels, int nchannels,
285  bool forward_transform = true)
286  {
287  return transform(lookupProcessor(src, dest, looks, forward_transform),
288  data, npixels, nchannels);
289  }
290  inline bool transform(const ColorSpace *src,
291  const ColorSpace *dest,
292  const UT_StringHolder &looks,
293  fpreal32 *data, int npixels, int nchannels,
294  bool forward_transform = true)
295  {
296  return transform(lookupProcessor(src, dest, looks, forward_transform),
297  data, npixels, nchannels);
298  }
299 
300  inline bool transform(const UT_StringHolder &src,
301  const UT_StringHolder &dest,
302  const UT_StringHolder &looks,
303  void *src_data, void *dst_data, int width, int height,
304  int nchannels, bool forward_transform = true)
305  {
306  return transform(lookupProcessor(src, dest, looks, forward_transform),
307  src_data, dst_data, width, height, nchannels);
308  }
309 
310  inline bool transform(const UT_StringHolder &src,
311  const UT_StringHolder &dest,
312  const UT_StringHolder &looks,
313  fpreal32 *src_data, int width, int height,
314  int nchannels, bool forward_transform = true)
315  {
316  return transform(lookupProcessor(src, dest, looks, forward_transform),
317  src_data, width, height, nchannels);
318  }
319 
320  /// @}
321 
322  /// Transform from a colorspace to a display/view, including looks.
323  inline bool transformToView(const UT_StringHolder &src,
324  const UT_StringHolder &display,
325  const UT_StringHolder &view,
326  fpreal32 *data, int npixels, int nchannels,
327  bool forward_xform = true)
328  {
329  return transform(lookupViewProcessor(src, display, view, forward_xform),
330  data, npixels, nchannels);
331  }
332 
333  /// Transform with the given view transform, which must exist in the config
334  inline bool transform(const UT_StringHolder &view_transform,
335  fpreal32 *data, int npixels, int nchannels,
336  bool forward_transform = true)
337  {
338  return transform(lookupViewProcessor(view_transform, forward_transform),
339  data, npixels, nchannels);
340  }
341 
342  /// @{
343  /// When the OCIO config is reloaded, all processor and color space
344  /// pointers become invalid. You can register a callback (and remove it)
345  /// to be notified of reloads.
347  PXL_API void removeConfigChangeCB(int id);
348  /// @}
349 
350 } // end PXL_OCIO namespace
351 
352 #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.
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:323
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
bool is3DTransform(const ColorSpace *src, const ColorSpace *dest, const UT_StringHolder &looks, bool forward_transform=true)
Definition: PXL_OCIO.h:254
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 void getRoles(UT_StringArray &names)
Returns a list of the supported roles.
PXL_API bool transform(const PHandle &processor, fpreal32 *data, int npixels, int nchannels)
Transform pixels by a processor.
PXL_API const UT_StringHolder & getRawColorSpace()
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
GLintptr offset
Definition: glcorearb.h:665
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
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)
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
A map of string to various well defined value types.
Definition: UT_Options.h:84
PXL_API bool isOCIOEnvSet(bool check_for_active_vars=true)
class OCIOEXPORT Processor
PXL_API const UT_StringRef & configFilePath()
The path and filename of the config file being used.
fpreal64 fpreal
Definition: SYS_Types.h:277
PXL_ColorSpace
Definition: PXL_Common.h:72
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool isValid() const
PXL_API bool getInfo(const ColorSpace *space, UT_Options &info)
bool isNoOpTransform(const ColorSpace *src, const ColorSpace *dest, const UT_StringHolder &looks, bool forward_transform=true)
Definition: PXL_OCIO.h:235
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)
Definition: core.h:982
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 void getActiveDisplays(UT_StringArray &names)
Returns the list of active displays.
PXL_API PHandle lookupProcessor(const UT_StringHolder &src, const UT_StringHolder &dest, const UT_StringHolder &looks, bool forward_transform=true)
PXL_API void removeConfigChangeCB(int id)
PXL_API const char * getDefaultRole()
PXL_API PHandle lookupViewProcessor(const UT_StringHolder &src, const UT_StringHolder &display, const UT_StringHolder &view, bool forward_transform)
bool isValidTransform(const ColorSpace *src, const ColorSpace *dest, const UT_StringHolder &looks, bool forward_transform=true)
Definition: PXL_OCIO.h:208
Definition: format.h:895
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.
GLenum src
Definition: glcorearb.h:1793