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 Nanocolor name for the color space. If it's not possible to
158  /// determine the Nanocolor space name, this will return an empty string.
159  PXL_API const UT_StringHolder &getNanocolorName(const ColorSpace *space);
160  /// Return the allocation variable meta data about the color space
161  PXL_API bool getAllocationVars(const ColorSpace* space,
162  bool &uniform,
163  fpreal &min,
164  fpreal &max,
165  fpreal &offset);
166  /// Set 'fp' to true if the color space is defined for FP, false for uint
167  PXL_API bool isFloatPointSpace(const ColorSpace* space,
168  bool &fp);
169 
170  /// Fill out metadata for color space in a UT_Options
171  /// Keys are the tokens in the config.ocio file:
172  /// - @c name
173  /// - @c family
174  /// - @c equalitygroup
175  /// - @c bitdepth
176  /// - @c description
177  /// - @c isdata
178  /// - @c allocation
179  /// - @c allocationvars
180  PXL_API bool getInfo(const ColorSpace *space, UT_Options &info);
181 
182  /// Get the viewing rule names
184  /// Lookup a viewing rule by the name
186 
187  /// @{
188  /// Lookup processors which can be used to transform colors efficiently.
189  /// @note: These processors become invalid on a reload.
191  const UT_StringHolder &dest,
192  const UT_StringHolder &looks,
193  bool forward_transform=true,
194  const BitDepth src_depth=DefaultBitDepth,
195  const BitDepth dst_depth=DefaultBitDepth);
197  const ColorSpace *dest,
198  const UT_StringHolder &looks,
199  bool forward_transform=true,
200  const BitDepth src_depth=DefaultBitDepth,
201  const BitDepth dst_depth=DefaultBitDepth);
203  const UT_StringHolder &display,
204  const UT_StringHolder &view,
205  bool forward_transform,
206  const BitDepth src_depth=DefaultBitDepth,
207  const BitDepth dst_depth=DefaultBitDepth);
209  const UT_StringHolder &view_transform,
210  bool forward_transform,
211  const BitDepth src_depth=DefaultBitDepth,
212  const BitDepth dst_depth=DefaultBitDepth);
213  /// @}
214 
215  /// Transform pixels by a processor
216  PXL_API bool transform(const PHandle &processor,
217  fpreal32 *data, const int npixels,
218  const int nchannels);
219  PXL_API bool transform(const PHandle &processor,
220  const void *src, void *dst, const int width,
221  const int height, const int src_channels,
222  const int dst_channels);
223 
224  // Process buffer in-place
225  PXL_API bool transform(const PHandle &processor,
226  void *data, int width, int height, int channels);
227 
228  /// @{
229  /// Is there a transform from src->dest with the applied looks.
230  inline bool isValidTransform(const PHandle &processor)
231  {
232  return processor.isValid();
233  }
234  /// @}
235 
236  /// @{
237  /// Valid transform, but does nothing. This is true if the src and dest
238  /// color spaces are equal, but also handles special cases like
239  /// transforming from "raw" spaces. So, this is more correct than an
240  /// operator==() or isEqual() method.
241  inline bool isNoOpTransform(const PHandle &processor)
242  {
243  return processor.isNoOp();
244  }
245  /// @}
246 
247  /// @{
248  /// Does the transform from src->dest with applied looks require a 3D LUT.
249  inline bool is3DTransform(const PHandle &processor)
250  {
251  return processor.is3D();
252  }
253  /// @}
254 
255  /// @{
256  /// Transform color data from one color space to another color space.
257  /// The color space names may either refer to a color space name, or it can
258  /// also be prefixed with "role:" and refer to a color space role. The
259  /// 'looks' is a comma separated list of color gradings (aka looks)
260  inline bool transform(const UT_StringHolder &src,
261  const UT_StringHolder &dest,
262  const UT_StringHolder &looks,
263  fpreal32 *data, int npixels, int nchannels,
264  bool forward_transform = true)
265  {
266  return transform(lookupProcessor(src, dest, looks, forward_transform),
267  data, npixels, nchannels);
268  }
269  inline bool transform(const ColorSpace *src,
270  const ColorSpace *dest,
271  const UT_StringHolder &looks,
272  fpreal32 *data, int npixels, int nchannels,
273  bool forward_transform = true)
274  {
275  return transform(lookupProcessor(src, dest, looks, forward_transform),
276  data, npixels, nchannels);
277  }
278  /// @}
279 
280  /// Transform from a colorspace to a display/view, including looks.
281  inline bool transformToView(const UT_StringHolder &src,
282  const UT_StringHolder &display,
283  const UT_StringHolder &view,
284  fpreal32 *data, int npixels, int nchannels,
285  bool forward_xform = true)
286  {
287  return transform(lookupViewProcessor(src, display, view, forward_xform),
288  data, npixels, nchannels);
289  }
290 
291  /// Transform with the given view transform, which must exist in the config
292  inline bool transform(const UT_StringHolder &view_transform,
293  fpreal32 *data, int npixels, int nchannels,
294  bool forward_transform = true)
295  {
296  return transform(lookupViewProcessor(view_transform, forward_transform),
297  data, npixels, nchannels);
298  }
299 
300  /// @{
301  /// When the OCIO config is reloaded, all processor and color space
302  /// pointers become invalid. You can register a callback (and remove it)
303  /// to be notified of reloads.
305  PXL_API void removeConfigChangeCB(int id);
306  /// @}
307 
308 } // end PXL_OCIO namespace
309 
310 #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:281
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)
#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:249
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: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:241
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:230