HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_ImageSource.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: TIL_ImageSource.h (TIL library, C++)
7  *
8  * COMMENTS:
9  * This is the base class for an image source (ie, COP for Houdini,
10  * or disk files for a standalone viewer).
11  */
12 
13 #ifndef TIL_IMAGESOURCE_H
14 #define TIL_IMAGESOURCE_H
15 
16 #include "TIL_API.h"
17 #include <SYS/SYS_Types.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_ValArray.h>
21 #include <UT/UT_Color.h>
22 #include <UT/UT_Options.h>
23 #include <PXL/PXL_Common.h>
24 #include <stdlib.h>
25 #include <limits>
26 
27 #define TIL_GLOBAL_TIME (std::numeric_limits<fpreal>::infinity())
28 
29 class UT_Options;
30 class UT_String;
31 class UT_StringHolder;
32 class UT_TokenString;
33 class UT_WorkBuffer;
34 class IMG_TileOptions;
35 class IMG_Metadata;
36 
37 class TIL_Plane;
38 class TIL_Raster;
39 class TIL_Sequence;
40 class TIL_ColorCurves;
41 class TIL_ImageSource;
42 
43 class STY_StyleSheet;
44 class OP_Node;
45 
47 {
48  int myID;
49 
50  int myX0, myX1;
51  int myY0, myY1;
52 
55 };
56 
58 
59 /// Interface that allows another class to override the behaviour of a
60 /// TIL_ImageSource. The purpose is to allow postprocessing effects such as
61 /// slap compositing to be applied to any TIL_ImageSource.
63 {
64 public:
65  /// The lifetime of the postprocessor must not exceed that of the reference
66  /// image source that postprocessing will be applied to.
68 
70 
71  virtual void getImageBounds(const TIL_Plane &plane,
72  int array_index,
73  fpreal t, int xres, int yres,
74  const UT_Options& options,
75  int &x1, int &y1,
76  int &x2, int &y2) = 0;
77 
78  virtual int getImage(TIL_Raster *image,
79  fpreal t, int xres, int yres,
80  const TIL_Plane &plane,
81  int array_index,
82  int xstart, int ystart,
83  int xend, int yend, float gamma,
84  const UT_Options &options,
85  bool include_alpha,
86  bool is_interactive,
87  int fxres, int fyres) = 0;
88 
89  virtual const TIL_Sequence *getSequence(fpreal t,
90  const UT_Options &options) = 0;
91 
92  /// If false, the postprocessor will be ignored.
93  virtual bool isEnabled() const = 0;
94 
95  /// The version is incremented whenever the postprocessor changes its
96  /// behaviour, to indicate that any cached results are outdated.
97  virtual int getVersion() const { return 0; }
98 
99 protected:
100  /// Get the source which this postprocessor is postprocessing.
101  TIL_ImageSource &getSource() { return mySource; }
102 
103 private:
104  TIL_ImageSource &mySource;
105 };
106 
108 {
109 public:
110  // Specify how color space transformation should be done
112  {
113  CS_HOUDINI, // Use Houdini and possibly override gamma/LUT
114  CS_OCIO_SPACE, // Use OCIO transform
115  CS_OCIO_DISPLAY_VIEW, // Bake OCIO display/view
116  };
118  {
119  ColorSpace();
120  void setAutomatic() { setAutomatic(1); }
121  void setAutomaticManual(bool convert_space,
122  float gamma,
123  const UT_StringHolder &lut)
124  {
125  if (convert_space)
126  setAutomatic(gamma, lut);
127  else
128  setManual(gamma, lut);
129  }
130  void setManual(float gamma,
131  const UT_StringHolder &lut=UT_StringHolder())
132  {
133  myMode = CS_HOUDINI;
134  myHoudiniAdjust = false;
135  myGamma = gamma;
136  myLUTFile = lut;
137  }
138  void setAutomatic(float gamma,
139  const UT_StringHolder &lut=UT_StringHolder())
140  {
141  myMode = CS_HOUDINI;
142  myHoudiniAdjust = true;
143  myGamma = gamma;
144  myLUTFile = lut;
145  }
147  {
148  myMode = CS_OCIO_SPACE;
149  myOCIODest.clear();
150  myOCIOLook.clear();
151  }
152  void setOCIO(const UT_StringHolder &dest,
153  const UT_StringHolder &look = UT_StringHolder())
154  {
155  myMode = CS_OCIO_SPACE;
156  myOCIODest = dest;
157  myOCIOLook = look;
158  }
159  void setOCIODisplayView(const UT_StringHolder &display,
160  const UT_StringHolder &view,
161  bool forward = true)
162  {
163  myMode = CS_OCIO_DISPLAY_VIEW;
164  myOCIODisplay = display;
165  myOCIOView = view;
166  myOCIOForward = forward;
167  }
168  bool ocioAutomatic() const { return myOCIODest.empty(); }
169  bool adjustColorSpace() const { return myHoudiniAdjust; }
170 
171  ColorSpaceMode myMode = CS_OCIO_SPACE;
172  float myGamma = 1.0f;
178  bool myOCIOForward = true;
179  bool myHoudiniAdjust = true;
180  };
181 
182  TIL_ImageSource();
183 
184  void bumpRefCount(int i);
185 
186  void invalidate() { myValidFlag = false; }
187  bool isValid() const { return myValidFlag; }
188 
189  virtual bool willProvideFetcher() const { return false; }
190 
191  // global stuff... (not source specific).
192  virtual fpreal getGlobalTime() =0;
193  virtual fpreal getSampleRate() =0;
194  virtual fpreal getStartTime() =0;
195  virtual fpreal getEndTime() =0;
196 
197  virtual UT_StringHolder getBottomLeftCaption() const { return ""; };
198  virtual UT_StringHolder getTopRightCaption() const { return ""; };
199 
200  // returns the image index (0 to length-1) or the frame (start to end)
201  // based on the current time.
202  int getImageIndexFromTime(fpreal t);
203  int getFrameFromTime(fpreal t);
204 
205  virtual bool doesImageExist(int /*frame*/,
206  bool /*adjust*/ = true)
207  { return true; }
208 
209  virtual int getActualFrame(int frame) { return frame; }
210  virtual void removeFrame(int /*frame*/) { }
211  virtual void addFrame(int /*frame*/) { }
212  virtual void removeSequence() {}
213  virtual bool canAddFrame() { return false; }
214 
215  virtual bool isNetwork() { return false; }
216 
217  // allows time mapping (mostly for disk files).
219  bool /*shift_only*/ = false,
220  const TIL_Sequence * /*ref*/ = 0)
221  { return t; }
222  virtual int getFrameShift(int fr,
223  bool /*shift_only*/ = false,
224  const TIL_Sequence * /*ref*/ =0)
225  { return fr; }
226 
227  // Allows you to remap a frame for information purposes (like the Houdini
228  // frame number when rendered to mplay).
229  virtual int getApparentFrame(int fr) { return fr; }
230 
231  // name of the source (cop2 name, disk file).
232  virtual const char *getName() = 0;
233  virtual void getFullName(UT_String &name) = 0;
234  virtual void getFrameName(int frame, UT_String &name);
235 
236  // ah, well.. whaddayathink
237  virtual bool equals(const TIL_ImageSource *) const = 0;
238 
239  // Called to open the source (return false on failure). if reset is set, all
240  // errors will be cleared.
241  virtual bool open(short & /*key*/,
242  int /*reset*/ = 0,
243  fpreal /*t*/ = TIL_GLOBAL_TIME)
244  { return false; }
245 
246  // called to close the source.
247  virtual void close(short /*key*/) { ; }
248 
249  // returns true if the res & data type are constant for the sequence.
250  virtual bool isConstantSequence() const { return false; }
251 
252  /// Return a completed TIL_Sequence structure with postprocessing, if any.
253  const TIL_Sequence *getSequence(fpreal t, const UT_Options &options,
254  bool skip_postprocessor = false)
255  {
256  if (myPostprocessor && myPostprocessor->isEnabled() &&
257  !skip_postprocessor)
258  return myPostprocessor->getSequence(t, options);
259  else
260  return getSourceSequence(t, options);
261  }
262 
263  /// Return a completed TIL_Sequence structure without postprocessing.
264  virtual const TIL_Sequence *getSourceSequence(
265  fpreal t,
266  const UT_Options &options) = 0;
267 
269  {
270  return UT_Options();
271  }
272 
273  const TIL_Sequence *getSequence(fpreal t, bool skip_postprocessor = false)
274  {
275  return getSequence(t, getDefaultOptions(), skip_postprocessor);
276  }
277 
278  // return an identifier that can be used to identify a single frame
279  // out of the source, unique across multiple sources.
280  virtual UT_TokenString *getID(fpreal t, int xres, int yres,
281  const TIL_Plane &plane,
282  int array_index,
283  const UT_Options& options) = 0;
284 
285  void getImageBounds(const TIL_Plane &plane,
286  int array_index,
287  fpreal t, int xres, int yres,
288  const UT_Options& options,
289  int &x1, int &y1,
290  int &x2, int &y2,
291  bool skip_postprocessor = false)
292  {
293  if (myPostprocessor && myPostprocessor->isEnabled() &&
294  !skip_postprocessor)
295  myPostprocessor->getImageBounds(
296  plane, array_index, t, xres, yres, options, x1, y1, x2, y2);
297  else
298  getSourceImageBounds(
299  plane, array_index, t, xres, yres, options, x1, y1, x2, y2);
300  }
301 
302  virtual void getSourceImageBounds(const TIL_Plane &plane,
303  int array_index, fpreal t,
304  int xres, int yres,
305  const UT_Options& options,
306  int &x1, int &y1,
307  int &x2, int &y2);
308 
309  // Returns a list of regions currently being cooked
310  virtual void getCookRegions(TIL_CookRegionList &region) = 0;
311 
312  /// Returns true iff there is currently a priority circle active.
313  /// If there is, centrex, centrey, and radius are set to those of the circle.
314  virtual bool getPriorityCircle(float &centrex, float &centrey, float &radius) const
315  {
316  return false;
317  }
318 
319  // return an int that uniquely identifies the source.
320  virtual int getID() const = 0;
321 
322  // fill the TIL_Raster with the appropriate image (ie, cook it).
323  // return 0 on failure.
325  fpreal t, int xres, int yres,
326  const TIL_Plane &plane,
327  int array_index,
328  int xstart, int ystart,
329  int xend, int yend, float gamma,
330  const UT_Options &options,
331  bool include_alpha = false,
332  bool is_interactive = false,
333  int fxres = 0, int fyres = 0,
334  bool skip_postprocessor = false)
335  {
336  if (myPostprocessor && myPostprocessor->isEnabled() &&
337  !skip_postprocessor)
338  return myPostprocessor->getImage(
339  image, t, xres, yres, plane, array_index, xstart, ystart, xend,
340  yend, gamma, options, include_alpha, is_interactive, fxres,
341  fyres);
342  else
343  return getSourceImage(
344  image, t, xres, yres, plane, array_index, xstart, ystart, xend,
345  yend, gamma, options, include_alpha, is_interactive, fxres,
346  fyres);
347  }
348 
349  virtual int getSourceImage(TIL_Raster *image,
350  fpreal t, int xres, int yres,
351  const TIL_Plane &plane,
352  int array_index,
353  int xstart, int ystart,
354  int xend, int yend, float gamma,
355  const UT_Options &,
356  bool include_alpha = false,
357  bool is_interactive = false,
358  int fxres = 0,
359  int fyres = 0) = 0;
360 
361  virtual void getInfo(UT_WorkBuffer &infotext);
362 
363  virtual void getComment(UT_String &comment, fpreal t);
364  virtual void setComment(const UT_String &comment, fpreal t);
365 
366  // There's duplicate information in the IMG_TileOptions class, we only use
367  // the Format and FormatOptions in the writing process.
368  virtual int writeImage(const char *filename,
369  const IMG_TileOptions *finfo,
370  const TIL_Sequence *,
371  int step,
372  const ColorSpace &cspace,
373  void (*info)(void*, const char*),
374  void *data,
375  bool suppress_summary_dialog,
376  bool overwrite);
377 
378  virtual int writeImage(const char *filename,
379  const IMG_TileOptions *finfo,
380  int xres, int yres,
381  const char *color,
382  const char *alpha,
383  int start, int end, int step,
384  const ColorSpace &cspace,
385  void (*info)(void*, const char*),
386  void *data,
387  bool suppress_summary_dialog,
388  bool overwrite);
389 
390  virtual void writeImageComplete(int successcount,
391  int failcount,
392  const UT_String &failedfiles);
393 
394  // normally, once you're done with an image, it will stay cached if there's
395  // room. The parm is the frame index. Return false to have it deallocated
396  // immediately.
397  virtual bool isCachingNeeded(int ) const { return true; }
398 
399  // only really needed for COPs.
400  virtual size_t getVersion() { return 1; }
401  virtual bool isFrameLocked(fpreal /*t*/) const { return false; }
402  virtual bool isAnythingLocked() const { return false; }
403  virtual bool isPlaneLocked(const TIL_Plane *,
404  fpreal /*t*/) const { return false; }
405  virtual const TIL_Plane *getPreviewPlane(int /*index*/) { return nullptr; }
406 
407  virtual void setMouseLocation(int mx, int my,
408  float radius = 64.0f);
409 
410  virtual void bumpVersion(bool ) { }
411  virtual bool isSlowOperation() const { return false; }
412 
413  virtual bool getColorCurves(const char *planename,
414  int array, fpreal t,
415  TIL_ColorCurves &curves,
416  UT_String &first,
417  bool allnodes, int comp=-1,
418  bool natural_range = true,
419  float start = 0.0f,
420  float end = 1.0f,
421  int evalpoints = 0);
422 
423  virtual bool allowUserSelection() const { return false; }
424 
425  virtual TIL_ImageSource *selectParentSource(int px, int py,
426  const char *planename,
427  int array_index);
428 
429  // Allow the source to have a callback invoked. The function should return
430  // true if a script is run
431  virtual bool hasPixelScript(int slot) const;
432  virtual bool runPixelScript(int px, int py, int slot);
433 
434  // Returns true if the image source is stereoscopic, ie, it can provide
435  // left / right images (as two separate planes).
436  virtual bool isStereoscopicSource(fpreal t) const;
437  virtual int getLeftPlaneIndex(fpreal t) const;
438  virtual const char *getLeftPlaneName(fpreal t) const;
439  virtual int getRightPlaneIndex(fpreal t) const;
440  virtual const char *getRightPlaneName(fpreal t) const;
441 
442  // NOTE: This level has nothing to destruct.
443  virtual int64 getMemoryUsage(bool inclusive) const = 0;
444 
445  // Return image metadata
446  virtual const IMG_Metadata *getMetadata(int frame) const = 0;
447  // Return metadata for a given plane
448  virtual const IMG_Metadata *getPlaneMetadata(int frame,
449  const UT_StringRef &planename) const;
450 
451  virtual fpreal getRenderTime(int frame) const
452  { return -1.0; }
453 
454  virtual int64 getPeakMemUsage(int frame) const
455  { return 0; }
456 
457  virtual OP_Node* getOp() const
458  { return 0; }
459 
461  { return false; }
462 
463  // Returns the style sheet json string at a given pixel.
464  // By default, there is none
465  virtual bool getStyleSheetJSON(int x, int y, UT_StringHolder& str)
466  { return false; }
467 
468  // Returns the style sheet object at a given pixel.
469  // By default there is none
470  virtual STY_StyleSheet* getStyleSheet(int x, int y)
471  { return NULL; }
472 
473  // Returns the material node at a given pixel
474  virtual OP_Node* getMaterialNode(int x, int y)
475  { return NULL; }
476 
477  // Indicates that an auto update is being performed
478  virtual void onAutoUpdate() {}
479 
480  /// Set the postprocessor, which will be checked and called when applicable,
481  /// providing an opportunity to override the behaviour of this image source.
482  /// The constructor for the postprocessor type T must accept a reference to
483  /// the owning TIL_ImageSource as the first argument.
484  /// @returns The newly created postprocessor.
485  /// @see TIL_ImageSourcePostprocessor
486  template <typename T, typename... Args>
487  T *setPostprocessor(Args &&...args)
488  {
490  std::is_convertible_v<T*, TIL_ImageSourcePostprocessor*>,
491  "T must inherit from the TIL_ImageSourcePostprocessor interface.");
492  myPostprocessor = UTmakeUnique<T>(*this, std::forward<Args>(args)...);
493  return static_cast<T*>(myPostprocessor.get());
494  }
495 
496  /// Get the current postprocessor.
497  /// @see setPostprocessor
500  { return myPostprocessor.get(); }
501 
504  { return myPostprocessor.get(); }
505 
506 protected:
507  virtual ~TIL_ImageSource();
509 private:
510  int myRefCount;
511  bool myValidFlag;
512 
514  myPostprocessor;
515 };
516 
517 // Convenience class for opening and closing a source.
519 {
520 public:
521  TIL_Access(TIL_ImageSource &source, int reset=0,
523  ~TIL_Access();
524 
525  UT_NON_COPYABLE(TIL_Access)
526 
527  bool isOpen() const { return myOpen; }
528 
529 private:
530  TIL_ImageSource &mySource;
531  short myAccessKey;
532  bool myOpen;
533 };
534 
535 #endif
virtual bool isConstantSequence() const
virtual STY_StyleSheet * getStyleSheet(int x, int y)
GLint first
Definition: glcorearb.h:405
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
GT_API const UT_StringHolder filename
virtual bool getPreferredViewingPlane(UT_WorkBuffer &buf) const
const TIL_Sequence * getSequence(fpreal t, const UT_Options &options, bool skip_postprocessor=false)
Return a completed TIL_Sequence structure with postprocessing, if any.
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
#define SYS_STATIC_ASSERT_MSG(expr, msg)
GLuint start
Definition: glcorearb.h:475
int getImage(TIL_Raster *image, fpreal t, int xres, int yres, const TIL_Plane &plane, int array_index, int xstart, int ystart, int xend, int yend, float gamma, const UT_Options &options, bool include_alpha=false, bool is_interactive=false, int fxres=0, int fyres=0, bool skip_postprocessor=false)
const TIL_Sequence * getSequence(fpreal t, bool skip_postprocessor=false)
virtual void removeSequence()
virtual int getApparentFrame(int fr)
TIL_ImageSource & getSource()
Get the source which this postprocessor is postprocessing.
virtual UT_StringHolder getTopRightCaption() const
virtual OP_Node * getOp() const
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
virtual fpreal getFrameTime(fpreal t, bool=false, const TIL_Sequence *=0)
virtual void addFrame(int)
OutGridT const XformOp bool bool
GLdouble GLdouble x2
Definition: glad.h:2349
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_Array< TIL_CookRegion > TIL_CookRegionList
virtual bool allowUserSelection() const
bool isValid() const
GLfloat f
Definition: glcorearb.h:1926
TIL_ImageSourcePostprocessor(TIL_ImageSource &source)
T * setPostprocessor(Args &&...args)
void setOCIO(const UT_StringHolder &dest, const UT_StringHolder &look=UT_StringHolder())
GLboolean reset
Definition: glad.h:5138
virtual const TIL_Plane * getPreviewPlane(int)
virtual bool getPriorityCircle(float &centrex, float &centrey, float &radius) const
virtual bool willProvideFetcher() const
#define TIL_GLOBAL_TIME
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
virtual fpreal getRenderTime(int frame) const
GLuint GLuint end
Definition: glcorearb.h:475
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GLdouble y1
Definition: glad.h:2349
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
virtual int getFrameShift(int fr, bool=false, const TIL_Sequence *=0)
virtual void close(short)
long long int64
Definition: SYS_Types.h:116
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
virtual void onAutoUpdate()
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual int getActualFrame(int frame)
virtual bool isPlaneLocked(const TIL_Plane *, fpreal) const
GLint GLenum GLint x
Definition: glcorearb.h:409
virtual bool isFrameLocked(fpreal) const
void setManual(float gamma, const UT_StringHolder &lut=UT_StringHolder())
GLdouble t
Definition: glad.h:2397
virtual bool isSlowOperation() const
IFDmantra py
Definition: HDK_Image.dox:266
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:1030
virtual OP_Node * getMaterialNode(int x, int y)
void setAutomatic(float gamma, const UT_StringHolder &lut=UT_StringHolder())
GLuint color
Definition: glcorearb.h:1261
fpreal64 fpreal
Definition: SYS_Types.h:278
virtual bool open(short &, int=0, fpreal=TIL_GLOBAL_TIME)
virtual UT_Options getDefaultOptions() const
virtual size_t getVersion()
virtual int64 getPeakMemUsage(int frame) const
**If you just want to fire and args
Definition: thread.h:618
virtual bool canAddFrame()
virtual void bumpVersion(bool)
Map of metadata items.
Definition: IMG_Metadata.h:217
const TIL_ImageSourcePostprocessor * getPostprocessor() const
class OCIOEXPORT ColorSpace
virtual bool isNetwork()
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
void setAutomaticManual(bool convert_space, float gamma, const UT_StringHolder &lut)
virtual bool isAnythingLocked() const
virtual int getVersion() const
virtual void removeFrame(int)
virtual UT_StringHolder getBottomLeftCaption() const
#define TIL_API
Definition: TIL_API.h:10
virtual bool getStyleSheetJSON(int x, int y, UT_StringHolder &str)
virtual bool isCachingNeeded(int) const
TIL_ImageSourcePostprocessor * getPostprocessor()
Definition: format.h:1821
void getImageBounds(const TIL_Plane &plane, int array_index, fpreal t, int xres, int yres, const UT_Options &options, int &x1, int &y1, int &x2, int &y2, bool skip_postprocessor=false)
void setOCIODisplayView(const UT_StringHolder &display, const UT_StringHolder &view, bool forward=true)
virtual bool doesImageExist(int, bool=true)