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  /// @{
201  /// Is there a transform from src->dest with the applied looks.
202  inline bool isValidTransform(const ColorSpace *src,
203  const ColorSpace *dest,
204  const UT_StringHolder &looks,
205  bool forward_transform = true)
206  {
207  return lookupProcessor(src, dest, looks, forward_transform).isValid();
208  }
209  static inline bool isValidTransform(const UT_StringHolder &src,
210  const UT_StringHolder &dest,
211  const UT_StringHolder &looks,
212  bool forward_transform = true)
213  {
214  return isValidTransform(lookupSpace(src), lookupSpace(dest), looks,
215  forward_transform);
216  }
218  bool forward)
219  {
220  return lookupViewProcessor(transform, forward).isValid();
221  }
222  /// @}
223 
224  /// @{
225  /// Valid transform, but does nothing. This is true if the src and dest
226  /// color spaces are equal, but also handles special cases like
227  /// transforming from "raw" spaces. So, this is more correct than an
228  /// operator==() or isEqual() method.
229  inline bool isNoOpTransform(const ColorSpace *src,
230  const ColorSpace *dest,
231  const UT_StringHolder &looks,
232  bool forward_transform = true)
233  {
234  return lookupProcessor(src, dest, looks, forward_transform).isNoOp();
235  }
236  static inline bool isNoOpTransform(const UT_StringHolder &src,
237  const UT_StringHolder &dest,
238  const UT_StringHolder &looks,
239  bool forward_transform = true)
240  {
241  return isNoOpTransform(lookupSpace(src), lookupSpace(dest), looks,
242  forward_transform);
243  }
244  /// @}
245 
246  /// @{
247  /// Does the transform from src->dest with applied looks require a 3D LUT.
248  inline bool is3DTransform(const ColorSpace *src,
249  const ColorSpace *dest,
250  const UT_StringHolder &looks,
251  bool forward_transform = true)
252  {
253  return lookupProcessor(src, dest, looks, forward_transform).is3D();
254  }
255  static inline bool is3DTransform(const UT_StringHolder &src,
256  const UT_StringHolder &dest,
257  const UT_StringHolder &looks,
258  bool forward_transform = true)
259  {
260  return is3DTransform(lookupSpace(src), lookupSpace(dest), looks,
261  forward_transform);
262  }
263  /// @}
264 
265  inline bool is3DTransform(const UT_StringHolder &view_transform)
266  {
267  return lookupViewProcessor(view_transform, true).is3D();
268  }
269 
270  /// @{
271  /// Transform color data from one color space to another color space.
272  /// The color space names may either refer to a color space name, or it can
273  /// also be prefixed with "role:" and refer to a color space role. The
274  /// 'looks' is a comma separated list of color gradings (aka looks)
275  inline bool transform(const UT_StringHolder &src,
276  const UT_StringHolder &dest,
277  const UT_StringHolder &looks,
278  fpreal32 *data, int npixels, int nchannels,
279  bool forward_transform = true)
280  {
281  return transform(lookupProcessor(src, dest, looks, forward_transform),
282  data, npixels, nchannels);
283  }
284  inline bool transform(const ColorSpace *src,
285  const ColorSpace *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  /// @}
294 
295  /// Transform from a colorspace to a display/view, including looks.
296  inline bool transformToView(const UT_StringHolder &src,
297  const UT_StringHolder &display,
298  const UT_StringHolder &view,
299  fpreal32 *data, int npixels, int nchannels,
300  bool forward_xform = true)
301  {
302  return transform(lookupViewProcessor(src, display, view, forward_xform),
303  data, npixels, nchannels);
304  }
305 
306  /// Transform with the given view transform, which must exist in the config
307  inline bool transform(const UT_StringHolder &view_transform,
308  fpreal32 *data, int npixels, int nchannels,
309  bool forward_transform = true)
310  {
311  return transform(lookupViewProcessor(view_transform, forward_transform),
312  data, npixels, nchannels);
313  }
314 
315  /// @{
316  /// When the OCIO config is reloaded, all processor and color space
317  /// pointers become invalid. You can register a callback (and remove it)
318  /// to be notified of reloads.
320  PXL_API void removeConfigChangeCB(int id);
321  /// @}
322 
323 } // end PXL_OCIO namespace
324 
325 #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:296
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:248
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()
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()
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:229
PXL_API bool issRGB(const ColorSpace *s)
PXL_API void viewingRuleNames(UT_StringArray &names)
Get the viewing rule names.
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:202
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