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 
25 
26 /// Abstract interface to OpenColorIO
27 namespace PXL_OCIO
28 {
29  /// @{
30  /// Private classes
31  class ColorSpace;
32  class Processor;
33  /// @}
34 
36  static constexpr BitDepth DefaultBitDepth = BitDepth::BIT_DEPTH_F32;
37 
39  {
40  bool isValid() const;
41  bool isNoOp() const;
42  bool is3D() const;
43  void clear() { myProcessor = nullptr; }
44  SYS_SAFE_BOOL operator bool() const { return isValid(); }
45 
46  Processor *myProcessor = nullptr;
47  int myLoadID = 0;
48  };
49 
50  /// The path and filename of the config file being used.
52 
53  /// Returns whether the user has set $OCIO, $OCIO_ACTIVE_DISPLAYS or
54  /// $OCIO_ACTIVE_VIEWS is set. If there's an error loading the
55  /// configuration, this method will return @c false.
56  PXL_API bool isOCIOEnvSet(bool check_for_active_vars=true);
57 
58  /// Returns the current color space name
59  PXL_API const char *getDefaultDisplay();
60 
61  /// Returns the current color space name
62  PXL_API const char *getDefaultView(const char *display = NULL);
63 
64  /// Return the list of views for a given display.
65  PXL_API bool getViewsForDisplay(const char *display,
66  UT_StringArray &view_names);
67 
68  /// Returns the list of active displays
70 
71  /// Returns the list of active views
73 
74  /// Returns a list of the supported color spaces
76 
77  /// Returns a list of looks (color transforms)
78  PXL_API void getLooks(UT_StringArray &looks);
79 
80  /// Returns a list of the supported roles
81  PXL_API void getRoles(UT_StringArray &names);
82 
83  /// Reload the configuration.
84  PXL_API void reload();
85 
86  PXL_API const char *getDefaultRole();
87  PXL_API const char *getReferenceRole();
88  PXL_API const char *getDataRole();
89  PXL_API const char *getSceneLinearRole();
90  PXL_API const char *getCompLogRole();
91  PXL_API const char *getColorPickingRole();
92 
93  // Return the name of the color space associated with the "scene_linear" role
95 
96  // find an sRGB color space in the given config file.
98  PXL_API UT_StringHolder getsRGBColorSpace(const char *display);
99 
100  /// @{
101  /// Test whether a color space is one of the well-known color spaces
102  PXL_API bool issRGB(const ColorSpace *s);
103  PXL_API bool isSceneLinear(const ColorSpace *s);
104  /// @}
105 
106  // find an rec709 color space in the given config file
108 
109  // find a linear rec709 color space in the given config file
111 
112  // Find a raw color space
114 
115  /// Return the colorspace defined by the view for a given display.
116  PXL_API const char *getColorSpaceForDisplayView(const char *display_name,
117  const char *view_name);
118 
119  /// Return the colorspace defined by the view for a given display.
120  PXL_API const char *getTransformNameForDisplayView(const char *display_name,
121  const char *view_name);
122 
123  /// Return the looks attached to the view for a given display.
124  PXL_API const char *getLooksForDisplayView(const char *display_name,
125  const char *view_name);
126 
127 
128  /// Guess at the colorspace using the rightmost colorspace found, or NULL
129  /// if none are found.
130  PXL_API const char *parseColorSpaceFromString(const char *string);
131 
133 
134  /// Convert a PXL_ColorSpace to roughly the OCIO equivalent
136  const UT_StringHolder &ocioname);
137 
138  /// @{
139  /// Get the best approximation for the PXL_ColorSpace from the OCIO color
140  /// space. The @c name will be filled out with the full name of the space.
141  /// The return value will be PXL_CS_OCIO, unless it's a well known space.
146  /// @}
147 
148 
149  /// Return a color space handle given a name. The name may be a color
150  /// space name or prefixed with "role:" to specify a color space role.
152 
153  /// Return the name of the color space
154  PXL_API const char *getName(const ColorSpace *space);
155  /// Return the description of the color space
156  PXL_API const char *getDescription(const ColorSpace *space);
157  /// Return the allocation variable meta data about the color space
158  PXL_API bool getAllocationVars(const ColorSpace* space,
159  bool &uniform,
160  fpreal &min,
161  fpreal &max,
162  fpreal &offset);
163  /// Set 'fp' to true if the color space is defined for FP, false for uint
164  PXL_API bool isFloatPointSpace(const ColorSpace* space,
165  bool &fp);
166 
167  /// Fill out metadata for color space in a UT_Options
168  /// Keys are the tokens in the config.ocio file:
169  /// - @c name
170  /// - @c family
171  /// - @c equalitygroup
172  /// - @c bitdepth
173  /// - @c description
174  /// - @c isdata
175  /// - @c allocation
176  /// - @c allocationvars
177  PXL_API bool getInfo(const ColorSpace *space, UT_Options &info);
178 
179  /// Get the viewing rule names
181  /// Lookup a viewing rule by the name
183 
184  /// @{
185  /// Lookup processors which can be used to transform colors efficiently.
186  /// @note: These processors become invalid on a reload.
188  const UT_StringHolder &dest,
189  const UT_StringHolder &looks,
190  bool forward_transform=true,
191  const BitDepth src_depth=DefaultBitDepth,
192  const BitDepth dst_depth=DefaultBitDepth);
194  const ColorSpace *dest,
195  const UT_StringHolder &looks,
196  bool forward_transform=true,
197  const BitDepth src_depth=DefaultBitDepth,
198  const BitDepth dst_depth=DefaultBitDepth);
200  const UT_StringHolder &display,
201  const UT_StringHolder &view,
202  bool forward_transform,
203  const BitDepth src_depth=DefaultBitDepth,
204  const BitDepth dst_depth=DefaultBitDepth);
206  const UT_StringHolder &view_transform,
207  bool forward_transform,
208  const BitDepth src_depth=DefaultBitDepth,
209  const BitDepth dst_depth=DefaultBitDepth);
210  /// @}
211 
212  /// Transform pixels by a processor
213  PXL_API bool transform(const PHandle &processor,
214  fpreal32 *data, const int npixels,
215  const int nchannels);
216  PXL_API bool transform(const PHandle &processor,
217  const void *src, void *dst, const int width,
218  const int height, const int src_channels,
219  const int dst_channels);
220 
221  // Process buffer in-place
222  PXL_API bool transform(const PHandle &processor,
223  void *data, int width, int height, int channels);
224 
225  /// @{
226  /// Is there a transform from src->dest with the applied looks.
227  inline bool isValidTransform(const PHandle &processor)
228  {
229  return processor.isValid();
230  }
231  /// @}
232 
233  /// @{
234  /// Valid transform, but does nothing. This is true if the src and dest
235  /// color spaces are equal, but also handles special cases like
236  /// transforming from "raw" spaces. So, this is more correct than an
237  /// operator==() or isEqual() method.
238  inline bool isNoOpTransform(const PHandle &processor)
239  {
240  return processor.isNoOp();
241  }
242  /// @}
243 
244  /// @{
245  /// Does the transform from src->dest with applied looks require a 3D LUT.
246  inline bool is3DTransform(const PHandle &processor)
247  {
248  return processor.is3D();
249  }
250  /// @}
251 
252  /// @{
253  /// Transform color data from one color space to another color space.
254  /// The color space names may either refer to a color space name, or it can
255  /// also be prefixed with "role:" and refer to a color space role. The
256  /// 'looks' is a comma separated list of color gradings (aka looks)
257  inline bool transform(const UT_StringHolder &src,
258  const UT_StringHolder &dest,
259  const UT_StringHolder &looks,
260  fpreal32 *data, int npixels, int nchannels,
261  bool forward_transform = true)
262  {
263  return transform(lookupProcessor(src, dest, looks, forward_transform),
264  data, npixels, nchannels);
265  }
266  inline bool transform(const ColorSpace *src,
267  const ColorSpace *dest,
268  const UT_StringHolder &looks,
269  fpreal32 *data, int npixels, int nchannels,
270  bool forward_transform = true)
271  {
272  return transform(lookupProcessor(src, dest, looks, forward_transform),
273  data, npixels, nchannels);
274  }
275  /// @}
276 
277  /// Transform from a colorspace to a display/view, including looks.
278  inline bool transformToView(const UT_StringHolder &src,
279  const UT_StringHolder &display,
280  const UT_StringHolder &view,
281  fpreal32 *data, int npixels, int nchannels,
282  bool forward_xform = true)
283  {
284  return transform(lookupViewProcessor(src, display, view, forward_xform),
285  data, npixels, nchannels);
286  }
287 
288  /// Transform with the given view transform, which must exist in the config
289  inline bool transform(const UT_StringHolder &view_transform,
290  fpreal32 *data, int npixels, int nchannels,
291  bool forward_transform = true)
292  {
293  return transform(lookupViewProcessor(view_transform, forward_transform),
294  data, npixels, nchannels);
295  }
296 
297  /// @{
298  /// When the OCIO config is reloaded, all processor and color space
299  /// pointers become invalid. You can register a callback (and remove it)
300  /// to be notified of reloads.
302  PXL_API void removeConfigChangeCB(int id);
303  /// @}
304 
305 } // end PXL_OCIO namespace
306 
307 #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:278
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
#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)
bool is3DTransform(const PHandle &processor)
Definition: PXL_OCIO.h:246
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:84
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:278
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 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 void getActiveDisplays(UT_StringArray &names)
Returns the list of active displays.
bool isNoOpTransform(const PHandle &processor)
Definition: PXL_OCIO.h:238
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:227