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  void dump() const;
172  UT_StringHolder toString() const;
173 
174  ColorSpaceMode myMode = CS_OCIO_SPACE;
175  float myGamma = 1.0f;
181  bool myOCIOForward = true;
182  bool myHoudiniAdjust = true;
183  };
184 
185  TIL_ImageSource();
186 
187  void bumpRefCount(int i);
188 
189  void invalidate() { myValidFlag = false; }
190  bool isValid() const { return myValidFlag; }
191 
192  virtual bool willProvideFetcher() const { return false; }
193 
194  // global stuff... (not source specific).
195  virtual fpreal getGlobalTime() =0;
196  virtual fpreal getSampleRate() =0;
197  virtual fpreal getStartTime() =0;
198  virtual fpreal getEndTime() =0;
199 
200  virtual UT_StringHolder getBottomLeftCaption() const { return ""; };
201  virtual UT_StringHolder getTopRightCaption() const { return ""; };
202 
203  // returns the image index (0 to length-1) or the frame (start to end)
204  // based on the current time.
205  int getImageIndexFromTime(fpreal t);
206  int getFrameFromTime(fpreal t);
207 
208  virtual bool doesImageExist(int /*frame*/,
209  bool /*adjust*/ = true)
210  { return true; }
211 
212  virtual int getActualFrame(int frame) { return frame; }
213  virtual void removeFrame(int /*frame*/) { }
214  virtual void addFrame(int /*frame*/) { }
215  virtual void removeSequence() {}
216  virtual bool canAddFrame() { return false; }
217 
218  virtual bool isNetwork() { return false; }
219 
220  // allows time mapping (mostly for disk files).
222  bool /*shift_only*/ = false,
223  const TIL_Sequence * /*ref*/ = 0)
224  { return t; }
225  virtual int getFrameShift(int fr,
226  bool /*shift_only*/ = false,
227  const TIL_Sequence * /*ref*/ =0)
228  { return fr; }
229 
230  // Allows you to remap a frame for information purposes (like the Houdini
231  // frame number when rendered to mplay).
232  virtual int getApparentFrame(int fr) { return fr; }
233 
234  // name of the source (cop2 name, disk file).
235  virtual const char *getName() = 0;
236  virtual void getFullName(UT_String &name) = 0;
237  virtual void getFrameName(int frame, UT_String &name);
238 
239  // ah, well.. whaddayathink
240  virtual bool equals(const TIL_ImageSource *) const = 0;
241 
242  // Called to open the source (return false on failure). if reset is set, all
243  // errors will be cleared.
244  virtual bool open(short & /*key*/,
245  int /*reset*/ = 0,
246  fpreal /*t*/ = TIL_GLOBAL_TIME)
247  { return false; }
248 
249  // called to close the source.
250  virtual void close(short /*key*/) { ; }
251 
252  // returns true if the res & data type are constant for the sequence.
253  virtual bool isConstantSequence() const { return false; }
254 
255  virtual bool isArbitrarilyZoomable() const { return true; }
256 
257  /// Return a completed TIL_Sequence structure with postprocessing, if any.
258  const TIL_Sequence *getSequence(fpreal t, const UT_Options &options,
259  bool skip_postprocessor = false)
260  {
261  if (myPostprocessor && myPostprocessor->isEnabled() &&
262  !skip_postprocessor)
263  return myPostprocessor->getSequence(t, options);
264  else
265  return getSourceSequence(t, options);
266  }
267 
268  /// Return a completed TIL_Sequence structure without postprocessing.
269  virtual const TIL_Sequence *getSourceSequence(
270  fpreal t,
271  const UT_Options &options) = 0;
272 
274  {
275  return UT_Options();
276  }
277 
278  const TIL_Sequence *getSequence(fpreal t, bool skip_postprocessor = false)
279  {
280  return getSequence(t, getDefaultOptions(), skip_postprocessor);
281  }
282 
283  // return an identifier that can be used to identify a single frame
284  // out of the source, unique across multiple sources.
285  virtual UT_TokenString *getID(fpreal t, int xres, int yres,
286  const TIL_Plane &plane,
287  int array_index,
288  const UT_Options& options) = 0;
289 
290  void getImageBounds(const TIL_Plane &plane,
291  int array_index,
292  fpreal t, int xres, int yres,
293  const UT_Options& options,
294  int &x1, int &y1,
295  int &x2, int &y2,
296  bool skip_postprocessor = false)
297  {
298  if (myPostprocessor && myPostprocessor->isEnabled() &&
299  !skip_postprocessor)
300  myPostprocessor->getImageBounds(
301  plane, array_index, t, xres, yres, options, x1, y1, x2, y2);
302  else
303  getSourceImageBounds(
304  plane, array_index, t, xres, yres, options, x1, y1, x2, y2);
305  }
306 
307  virtual void getSourceImageBounds(const TIL_Plane &plane,
308  int array_index, fpreal t,
309  int xres, int yres,
310  const UT_Options& options,
311  int &x1, int &y1,
312  int &x2, int &y2);
313 
314  // Returns a list of regions currently being cooked
315  virtual void getCookRegions(TIL_CookRegionList &region) = 0;
316 
317  /// Returns true iff there is currently a priority circle active.
318  /// If there is, centrex, centrey, and radius are set to those of the circle.
319  virtual bool getPriorityCircle(float &centrex, float &centrey, float &radius) const
320  {
321  return false;
322  }
323 
324  // return an int that uniquely identifies the source.
325  virtual int getID() const = 0;
326 
327  // fill the TIL_Raster with the appropriate image (ie, cook it).
328  // return 0 on failure.
330  fpreal t, int xres, int yres,
331  const TIL_Plane &plane,
332  int array_index,
333  int xstart, int ystart,
334  int xend, int yend, float gamma,
335  const UT_Options &options,
336  bool include_alpha = false,
337  bool is_interactive = false,
338  int fxres = 0, int fyres = 0,
339  bool skip_postprocessor = false)
340  {
341  if (myPostprocessor && myPostprocessor->isEnabled() &&
342  !skip_postprocessor)
343  return myPostprocessor->getImage(
344  image, t, xres, yres, plane, array_index, xstart, ystart, xend,
345  yend, gamma, options, include_alpha, is_interactive, fxres,
346  fyres);
347  else
348  return getSourceImage(
349  image, t, xres, yres, plane, array_index, xstart, ystart, xend,
350  yend, gamma, options, include_alpha, is_interactive, fxres,
351  fyres);
352  }
353 
354  virtual int getSourceImage(TIL_Raster *image,
355  fpreal t, int xres, int yres,
356  const TIL_Plane &plane,
357  int array_index,
358  int xstart, int ystart,
359  int xend, int yend, float gamma,
360  const UT_Options &,
361  bool include_alpha = false,
362  bool is_interactive = false,
363  int fxres = 0,
364  int fyres = 0) = 0;
365 
366  virtual void getInfo(UT_WorkBuffer &infotext);
367 
368  virtual void getComment(UT_String &comment, fpreal t);
369  virtual void setComment(const UT_String &comment, fpreal t);
370 
371  // There's duplicate information in the IMG_TileOptions class, we only use
372  // the Format and FormatOptions in the writing process.
373  virtual int writeImage(const char *filename,
374  const IMG_TileOptions *finfo,
375  const TIL_Sequence *,
376  int step,
377  const ColorSpace &cspace,
378  void (*info)(void*, const char*),
379  void *data,
380  bool suppress_summary_dialog,
381  bool overwrite);
382 
383  virtual int writeImage(const char *filename,
384  const IMG_TileOptions *finfo,
385  int xres, int yres,
386  const char *color,
387  const char *alpha,
388  int start, int end, int step,
389  const ColorSpace &cspace,
390  void (*info)(void*, const char*),
391  void *data,
392  bool suppress_summary_dialog,
393  bool overwrite);
394 
395  virtual void writeImageComplete(int successcount,
396  int failcount,
397  const UT_String &failedfiles);
398 
399  // normally, once you're done with an image, it will stay cached if there's
400  // room. The parm is the frame index. Return false to have it deallocated
401  // immediately.
402  virtual bool isCachingNeeded(int ) const { return true; }
403 
404  // only really needed for COPs.
405  virtual size_t getVersion() { return 1; }
406  virtual bool isFrameLocked(fpreal /*t*/) const { return false; }
407  virtual bool isAnythingLocked() const { return false; }
408  virtual bool isPlaneLocked(const TIL_Plane *,
409  fpreal /*t*/) const { return false; }
410  virtual const TIL_Plane *getPreviewPlane(int /*index*/) { return nullptr; }
411 
412  virtual void setMouseLocation(int mx, int my,
413  float radius = 64.0f);
414 
415  virtual void bumpVersion(bool ) { }
416  virtual bool isSlowOperation() const { return false; }
417 
418  virtual bool getColorCurves(const char *planename,
419  int array, fpreal t,
420  TIL_ColorCurves &curves,
421  UT_String &first,
422  bool allnodes, int comp=-1,
423  bool natural_range = true,
424  float start = 0.0f,
425  float end = 1.0f,
426  int evalpoints = 0);
427 
428  virtual bool allowUserSelection() const { return false; }
429 
430  virtual TIL_ImageSource *selectParentSource(int px, int py,
431  const char *planename,
432  int array_index);
433 
434  // Allow the source to have a callback invoked. The function should return
435  // true if a script is run
436  virtual bool hasPixelScript(int slot) const;
437  virtual bool runPixelScript(int px, int py, int slot);
438 
439  // Returns true if the image source is stereoscopic, ie, it can provide
440  // left / right images (as two separate planes).
441  virtual bool isStereoscopicSource(fpreal t) const;
442  virtual int getLeftPlaneIndex(fpreal t) const;
443  virtual const char *getLeftPlaneName(fpreal t) const;
444  virtual int getRightPlaneIndex(fpreal t) const;
445  virtual const char *getRightPlaneName(fpreal t) const;
446 
447  // NOTE: This level has nothing to destruct.
448  virtual int64 getMemoryUsage(bool inclusive) const = 0;
449 
450  // Return image metadata
451  virtual const IMG_Metadata *getMetadata(int frame) const = 0;
452  // Return metadata for a given plane
453  virtual const IMG_Metadata *getPlaneMetadata(int frame,
454  const UT_StringRef &planename) const;
455 
456  virtual fpreal getRenderTime(int frame) const
457  { return -1.0; }
458 
459  virtual int64 getPeakMemUsage(int frame) const
460  { return 0; }
461 
462  virtual OP_Node* getOp() const
463  { return 0; }
464 
466  { return false; }
467 
468  // Returns the style sheet json string at a given pixel.
469  // By default, there is none
470  virtual bool getStyleSheetJSON(int x, int y, UT_StringHolder& str)
471  { return false; }
472 
473  // Returns the style sheet object at a given pixel.
474  // By default there is none
475  virtual STY_StyleSheet* getStyleSheet(int x, int y)
476  { return NULL; }
477 
478  // Returns the material node at a given pixel
479  virtual OP_Node* getMaterialNode(int x, int y)
480  { return NULL; }
481 
482  // Indicates that an auto update is being performed
483  virtual void onAutoUpdate() {}
484 
485  /// Set the postprocessor, which will be checked and called when applicable,
486  /// providing an opportunity to override the behaviour of this image source.
487  /// The constructor for the postprocessor type T must accept a reference to
488  /// the owning TIL_ImageSource as the first argument.
489  /// @returns The newly created postprocessor.
490  /// @see TIL_ImageSourcePostprocessor
491  template <typename T, typename... Args>
492  T *setPostprocessor(Args &&...args)
493  {
495  std::is_convertible_v<T*, TIL_ImageSourcePostprocessor*>,
496  "T must inherit from the TIL_ImageSourcePostprocessor interface.");
497  myPostprocessor = UTmakeUnique<T>(*this, std::forward<Args>(args)...);
498  return static_cast<T*>(myPostprocessor.get());
499  }
500 
501  /// Get the current postprocessor.
502  /// @see setPostprocessor
505  { return myPostprocessor.get(); }
506 
509  { return myPostprocessor.get(); }
510 
511 protected:
512  virtual ~TIL_ImageSource();
514 private:
515  int myRefCount;
516  bool myValidFlag;
517 
519  myPostprocessor;
520 };
521 
522 // Convenience class for opening and closing a source.
524 {
525 public:
526  TIL_Access(TIL_ImageSource &source, int reset=0,
528  ~TIL_Access();
529 
530  UT_NON_COPYABLE(TIL_Access)
531 
532  bool isOpen() const { return myOpen; }
533 
534 private:
535  TIL_ImageSource &mySource;
536  short myAccessKey;
537  bool myOpen;
538 };
539 
540 #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.
virtual bool isArbitrarilyZoomable() const
*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:87
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:283
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)