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 <UT/UT_Functor.h>
16 #include <SYS/SYS_Types.h>
17 
18 class UT_StringHolder;
19 class UT_StringRef;
20 class UT_StringArray;
21 class UT_Options;
22 
23 /// Abstract interface to OpenColorIO
25 {
26 public:
27  /// Private class
28  class ColorSpace;
29 
30  /// The path and filename of the config file being used.
31  static const UT_StringRef &configFilePath();
32 
33  /// Returns whether the user has set $OCIO, $OCIO_ACTIVE_DISPLAYS or
34  /// $OCIO_ACTIVE_VIEWS is set. If there's an error loading the
35  /// configuration, this method will return @c false.
36  static bool isOCIOEnvSet(bool check_for_active_vars=true);
37 
38  /// Returns the current color space name
39  static const char *getDefaultDisplay();
40 
41  /// Returns the current color space name
42  static const char *getDefaultView(const char *display = NULL);
43 
44  /// Return the list of views for a given display.
45  static bool getViewsForDisplay(const char *display,
46  UT_StringArray &view_names);
47 
48  /// Returns the list of active displays
49  static void getActiveDisplays(UT_StringArray &names);
50 
51  /// Returns the list of active views
52  static void getActiveViews(UT_StringArray &names);
53 
54  /// Returns a list of the supported color spaces
55  static void getColorSpaces(UT_StringArray &names);
56 
57  /// Returns a list of looks (color transforms)
58  static void getLooks(UT_StringArray &looks);
59 
60  /// Returns a list of the supported roles
61  static void getRoles(UT_StringArray &names);
62 
63  /// Reload the configuration.
64  static void reload();
65 
66  static const char *getDefaultRole();
67  static const char *getReferenceRole();
68  static const char *getDataRole();
69  static const char *getSceneLinearRole();
70  static const char *getCompLogRole();
71  static const char *getColorPickingRole();
72 
73  // find an sRGB color space in the given config file
74  static const char *getsRGBColorSpace(const char *display = nullptr);
75 
76  /// Return the colorspace defined by the view for a given display.
77  static const char *getColorSpaceForDisplayView(const char *display_name,
78  const char *view_name);
79 
80  /// Return the colorspace defined by the view for a given display.
81  static const char *getTransformNameForDisplayView(const char *display_name,
82  const char *view_name);
83 
84  /// Return the looks attached to the view for a given display.
85  static const char *getLooksForDisplayView(const char *display_name,
86  const char *view_name);
87 
88 
89  /// Guess at the colorspace using the rightmost colorspace found, or NULL
90  /// if none are found.
91  static const char *parseColorSpaceFromString(const char *string);
92 
93  static UT_StringHolder parseColorSpaceFromHolder(const UT_StringHolder &s);
94 
95  /// Return a color space handle given a name. The name may be a color
96  /// space name or prefixed with "role:" to specify a color space role.
97  static const ColorSpace *lookupSpace(const UT_StringHolder &name);
98 
99  /// Return the name of the color space
100  static const char *getName(const ColorSpace *space);
101  /// Return the description of the color space
102  static const char *getDescription(const ColorSpace *space);
103  /// Return the allocation variable meta data about the color space
104  static bool getAllocationVars(const ColorSpace* space,
105  bool &uniform,
106  fpreal &min,
107  fpreal &max,
108  fpreal &offset);
109  /// Set 'fp' to true if the color space is defined for FP, false for uint
110  static bool isFloatPointSpace(const ColorSpace* space,
111  bool &fp);
112 
113  /// Fill out metadata for color space in a UT_Options
114  /// Keys are the tokens in the config.ocio file:
115  /// - @c name
116  /// - @c family
117  /// - @c equalitygroup
118  /// - @c bitdepth
119  /// - @c description
120  /// - @c isdata
121  /// - @c allocation
122  /// - @c allocationvars
123  static bool getInfo(const ColorSpace *space, UT_Options &info);
124 
125  /// Is there a transform from src->dest with the applied looks.
126  static bool isValidTransform(const UT_StringHolder &src,
127  const UT_StringHolder &dest,
128  const UT_StringHolder &looks,
129  bool forward_transform = true);
130  static bool isValidTransform(const UT_StringHolder &transform,
131  bool forward);
132 
133  /// Valid transform, but does nothing.
134  static bool isNoOpTransform(const UT_StringHolder &src,
135  const UT_StringHolder &dest,
136  const UT_StringHolder &looks,
137  bool forward_transform = true);
138 
139  /// Does the transform from src->dest with applied looks require a 3D LUT.
140  static bool is3DTransform(const UT_StringHolder &src,
141  const UT_StringHolder &dest,
142  const UT_StringHolder &looks,
143  bool forward_transform = true);
144 
145  static bool is3DTransform(const UT_StringHolder &view_transform);
146  static bool isSceneReferenceTransform(const UT_StringHolder &view_transform);
147 
148  /// @{
149  /// Transform color data from one color space to another color space.
150  /// The color space names may either refer to a color space name, or it can
151  /// also be prefixed with "role:" and refer to a color space role. The
152  /// 'looks' is a comma separated list of color gradings (aka looks)
153  static bool transform(const UT_StringHolder &src,
154  const UT_StringHolder &dest,
155  const UT_StringHolder &looks,
156  fpreal32 *data, int npixels, int nchannels,
157  bool forward_transform = true);
158  static bool transform(const ColorSpace *src,
159  const ColorSpace *dest,
160  const UT_StringHolder &looks,
161  fpreal32 *data, int npixels, int nchannels,
162  bool forward_transform = true);
163  /// @}
164 
165  /// Transform color data using the specified view transform (OCIO v2.0)
166  /// Always use this method when transforming from a colordpace to a view.
167  static bool transformView(const UT_StringHolder &src_cs,
168  const UT_StringHolder &display,
169  const UT_StringHolder &view,
170  fpreal32 *data,
171  int npixels,
172  int nchannels,
173  bool forward);
174 
175  /// Transform from a colorspace to a display/view, including looks.
176  static bool transformToView(const UT_StringHolder &src,
177  const UT_StringHolder &display,
178  const UT_StringHolder &view,
179  fpreal32 *data, int npixels, int nchannels,
180  bool forward_transform = true);
181 
182  /// Transform with the given view transform, which must exist in the config
183  static bool transform(const UT_StringHolder &view_transform,
184  fpreal32 *data, int npixels, int nchannels,
185  bool forward_transform = true);
186 
187 
188  static int addConfigChangeCB(UT_Functor<void> callback);
189  static void removeConfigChangeCB(int id);
190 
191  /// @{
192  /// If there are lots of of small data that need to be transformed into
193  /// same color space (especially across multiple threads), use the
194  /// following function to obtain an opaque pointer to OCIO processor and
195  /// pass it to transform() for better performance.
196  /// NOTE that the opaque pointer will become invalid upon reload().
197  class Processor;
198  class CPUProcessor;
199  struct PHandle
200  {
201  bool isValid() const { return myProc != nullptr; }
202  SYS_SAFE_BOOL operator bool() const { return isValid(); }
203  void clear()
204  {
205  myProc = nullptr;
206  myCPU = nullptr;
207  }
208  const Processor *myProc = nullptr;
209  const CPUProcessor *myCPU = nullptr;
210  };
211  static PHandle transformCache(const UT_StringHolder &src,
212  const UT_StringHolder &dest,
213  const UT_StringHolder &looks,
214  bool forward_transform = true);
215  static bool transform(const PHandle &processor,
216  fpreal32 *data, int npixels, int nchannels);
217 
218  /// @}
219 
220 private:
221 };
222 
223 #endif
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLuint const GLchar * name
Definition: glcorearb.h:786
GLenum src
Definition: glcorearb.h:1793
float fpreal32
Definition: SYS_Types.h:200
#define PXL_API
Definition: PXL_API.h:10
GLuint GLenum GLenum transform
Definition: glew.h:15055
class OCIOEXPORT CPUProcessor
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
GLuint const GLuint * names
Definition: glew.h:2695
A map of string to various well defined value types.
Definition: UT_Options.h:84
cl_int getInfo(Func f, cl_uint name, T *param)
Definition: cl.hpp:1028
class OCIOEXPORT Processor
fpreal64 fpreal
Definition: SYS_Types.h:277
Abstract interface to OpenColorIO.
Definition: PXL_OCIO.h:24
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool isValid() const
Definition: PXL_OCIO.h:201
Definition: core.h:982
GLintptr offset
Definition: glcorearb.h:665
class OCIOEXPORT ColorSpace
GLdouble s
Definition: glew.h:1395
Definition: format.h:895