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 
36 class TIL_Plane;
37 class TIL_Raster;
38 class TIL_Sequence;
39 class TIL_ColorCurves;
40 
41 class STY_StyleSheet;
42 class OP_Node;
43 
45 {
46  int myID;
47 
48  int myX0, myX1;
49  int myY0, myY1;
50 
53 };
54 
56 
58 {
59 public:
60  // Specify how color space transformation should be done
62  {
63  CS_HOUDINI, // Use Houdini and possibly override gamma/LUT
64  CS_OCIO_SPACE, // Use OCIO transform
65  CS_OCIO_DISPLAY_VIEW, // Bake OCIO display/view
66  };
68  {
69  ColorSpace();
70  void setAutomatic() { setAutomatic(1); }
71  void setAutomaticManual(bool convert_space,
72  float gamma,
73  const UT_StringHolder &lut)
74  {
75  if (convert_space)
76  setAutomatic(gamma, lut);
77  else
78  setManual(gamma, lut);
79  }
80  void setManual(float gamma,
81  const UT_StringHolder &lut=UT_StringHolder())
82  {
83  myMode = CS_HOUDINI;
84  myHoudiniAdjust = false;
85  myGamma = gamma;
86  myLUTFile = lut;
87  }
88  void setAutomatic(float gamma,
89  const UT_StringHolder &lut=UT_StringHolder())
90  {
91  myMode = CS_HOUDINI;
92  myHoudiniAdjust = true;
93  myGamma = gamma;
94  myLUTFile = lut;
95  }
97  {
98  myMode = CS_OCIO_SPACE;
99  myOCIODest.clear();
100  myOCIOLook.clear();
101  }
102  void setOCIO(const UT_StringHolder &dest,
103  const UT_StringHolder &look = UT_StringHolder())
104  {
105  myMode = CS_OCIO_SPACE;
106  myOCIODest = dest;
107  myOCIOLook = look;
108  }
109  void setOCIODisplayView(const UT_StringHolder &display,
110  const UT_StringHolder &view,
111  bool forward = true)
112  {
113  myMode = CS_OCIO_DISPLAY_VIEW;
114  myOCIODisplay = display;
115  myOCIOView = view;
116  myOCIOForward = forward;
117  }
118  bool ocioAutomatic() const { return myOCIODest.empty(); }
119  bool adjustColorSpace() const { return myHoudiniAdjust; }
120 
121  ColorSpaceMode myMode = CS_OCIO_SPACE;
122  float myGamma = 1.0f;
128  bool myOCIOForward = true;
129  bool myHoudiniAdjust = true;
130  };
131 
132  TIL_ImageSource();
133 
134  void bumpRefCount(int i);
135 
136  void invalidate() { myValidFlag = false; }
137  bool isValid() const { return myValidFlag; }
138 
139  // global stuff... (not source specific).
140  virtual fpreal getGlobalTime() =0;
141  virtual fpreal getSampleRate() =0;
142  virtual fpreal getStartTime() =0;
143  virtual fpreal getEndTime() =0;
144 
145  virtual UT_StringHolder getBottomLeftCaption() const { return ""; };
146  virtual UT_StringHolder getTopRightCaption() const { return ""; };
147 
148  // returns the image index (0 to length-1) or the frame (start to end)
149  // based on the current time.
150  int getImageIndexFromTime(fpreal t);
151  int getFrameFromTime(fpreal t);
152 
153  virtual int doesImageExist(int /*frame*/,
154  bool /*adjust*/ = true)
155  { return 1; }
156 
157  virtual int getActualFrame(int frame) { return frame; }
158  virtual void removeFrame(int /*frame*/) { }
159  virtual void addFrame(int /*frame*/) { }
160  virtual void removeSequence() {}
161  virtual bool canAddFrame() { return false; }
162 
163  virtual bool isNetwork() { return false; }
164 
165  // allows time mapping (mostly for disk files).
167  bool /*shift_only*/ = false,
168  const TIL_Sequence * /*ref*/ = 0)
169  { return t; }
170  virtual int getFrameShift(int fr,
171  bool /*shift_only*/ = false,
172  const TIL_Sequence * /*ref*/ =0)
173  { return fr; }
174 
175  // Allows you to remap a frame for information purposes (like the Houdini
176  // frame number when rendered to mplay).
177  virtual int getApparentFrame(int fr) { return fr; }
178 
179  // name of the source (cop2 name, disk file).
180  virtual const char *getName() = 0;
181  virtual void getFullName(UT_String &name) = 0;
182  virtual void getFrameName(int frame, UT_String &name);
183 
184  // ah, well.. whaddayathink
185  virtual int equals(const TIL_ImageSource *) = 0;
186 
187  // Called to open the source (return 0 on failure). if reset is set, all
188  // errors will be cleared.
189  virtual int open(short & /*key*/,
190  int /*reset*/ = 0,
191  fpreal /*t*/ = TIL_GLOBAL_TIME)
192  { return 0; }
193 
194  // called to close the source.
195  virtual void close(short /*key*/) { ; }
196 
197  // returns true if the res & data type are constant for the sequence.
198  virtual bool isConstantSequence() const { return false; }
199 
200  // return a completed TIL_Sequence structure.
201  virtual const TIL_Sequence *getSequence(fpreal t, const UT_Options &options) = 0;
202 
204  {
205  return UT_Options();
206  }
207 
209  {
210  return getSequence(t, getDefaultOptions());
211  }
212 
213  // return an identifier that can be used to identify a single frame
214  // out of the source, unique across multiple sources.
215  virtual UT_TokenString *getID(fpreal t, int xres, int yres,
216  const TIL_Plane &plane,
217  int array_index,
218  const UT_Options& options) = 0;
219 
220  virtual void getImageBounds(const TIL_Plane &plane,
221  int array_index,
222  fpreal t, int xres, int yres,
223  const UT_Options& options,
224  int &x1, int &y1,
225  int &x2, int &y2);
226 
227  // Returns a list of regions currently being cooked
228  virtual void getCookRegions(TIL_CookRegionList &region) = 0;
229 
230  /// Returns true iff there is currently a priority circle active.
231  /// If there is, centrex, centrey, and radius are set to those of the circle.
232  virtual bool getPriorityCircle(float &centrex, float &centrey, float &radius) const
233  {
234  return false;
235  }
236 
237  // return an int that uniquely identifies the source.
238  virtual int getID() const = 0;
239 
240  // fill the TIL_Raster with the appropriate image (ie, cook it).
241  // return 0 on failure.
242  virtual int getImage(TIL_Raster *image,
243  fpreal t, int xres, int yres,
244  const TIL_Plane &plane,
245  int array_index,
246  int xstart, int ystart,
247  int xend, int yend, float gamma,
248  const UT_Options &,
249  bool include_alpha = false,
250  bool is_interactive = false,
251  int fxres = 0, int fyres = 0) = 0;
252 
253  virtual void getInfo(UT_WorkBuffer &infotext);
254 
255  virtual void getComment(UT_String &comment, fpreal t);
256  virtual void setComment(const UT_String &comment, fpreal t);
257 
258  // There's duplicate information in the IMG_TileOptions class, we only use
259  // the Format and FormatOptions in the writing process.
260  virtual int writeImage(const char *filename,
261  const IMG_TileOptions *finfo,
262  const TIL_Sequence *,
263  int step,
264  const ColorSpace &cspace,
265  void (*info)(void*, const char*),
266  void *data,
267  bool suppress_summary_dialog,
268  bool overwrite);
269 
270  virtual int writeImage(const char *filename,
271  const IMG_TileOptions *finfo,
272  int xres, int yres,
273  const char *color,
274  const char *alpha,
275  int start, int end, int step,
276  const ColorSpace &cspace,
277  void (*info)(void*, const char*),
278  void *data,
279  bool suppress_summary_dialog,
280  bool overwrite);
281 
282  virtual void writeImageComplete(int successcount,
283  int failcount,
284  const UT_String &failedfiles);
285 
286  // normally, once you're done with an image, it will stay cached if there's
287  // room. The parm is the frame index. Return false to have it deallocated
288  // immediately.
289  virtual bool isCachingNeeded(int ) const { return true; }
290 
291  // only really needed for COPs.
292  virtual size_t getVersion() { return 1; }
293  virtual int isFrameLocked(fpreal /*t*/) { return 0; }
294  virtual int isAnythingLocked() { return 0; }
295  virtual int isPlaneLocked(const TIL_Plane *,
296  fpreal /*t*/) { return 0; }
297  virtual const TIL_Plane *getPreviewPlane(int /*index*/) { return 0; }
298 
299  virtual void setMouseLocation(int mx, int my,
300  float radius = 64.0f);
301 
302  virtual void bumpVersion(bool ) { }
303  virtual bool isSlowOperation() const { return false; }
304 
305  virtual bool getColorCurves(const char *planename,
306  int array, fpreal t,
307  TIL_ColorCurves &curves,
308  UT_String &first,
309  bool allnodes, int comp=-1,
310  bool natural_range = true,
311  float start = 0.0f,
312  float end = 1.0f,
313  int evalpoints = 0);
314 
315  virtual bool allowUserSelection() const { return false; }
316 
317  virtual TIL_ImageSource *selectParentSource(int px, int py,
318  const char *planename,
319  int array_index);
320 
321  // Allow the source to have a callback invoked. The function should return
322  // true if a script is run
323  virtual bool hasPixelScript(int slot) const;
324  virtual bool runPixelScript(int px, int py, int slot);
325 
326  // Returns true if the image source is stereoscopic, ie, it can provide
327  // left / right images (as two separate planes).
328  virtual bool isStereoscopicSource(fpreal t) const;
329  virtual int getLeftPlaneIndex(fpreal t) const;
330  virtual const char *getLeftPlaneName(fpreal t) const;
331  virtual int getRightPlaneIndex(fpreal t) const;
332  virtual const char *getRightPlaneName(fpreal t) const;
333 
334  // NOTE: This level has nothing to destruct.
335  virtual int64 getMemoryUsage(bool inclusive) const = 0;
336 
337  virtual fpreal getRenderTime(int frame) const
338  { return -1.0; }
339 
340  virtual int64 getPeakMemUsage(int frame) const
341  { return 0; }
342 
343  virtual OP_Node* getOp() const
344  { return 0; }
345 
347  { return false; }
348 
349  // Returns the style sheet json string at a given pixel.
350  // By default, there is none
351  virtual bool getStyleSheetJSON(int x, int y, UT_StringHolder& str)
352  { return false; }
353 
354  // Returns the style sheet object at a given pixel.
355  // By default there is none
356  virtual STY_StyleSheet* getStyleSheet(int x, int y)
357  { return NULL; }
358 
359  // Returns the material node at a given pixel
360  virtual OP_Node* getMaterialNode(int x, int y)
361  { return NULL; }
362 
363  // Indicates that an auto update is being performed
364  virtual void onAutoUpdate() {}
365 
366 protected:
367  virtual ~TIL_ImageSource();
369 private:
370  int myRefCount;
371  bool myValidFlag;
372 };
373 
374 
375 // Convenience class for opening and closing a source.
377 {
378 public:
379  TIL_Access(TIL_ImageSource &source, int reset=0,
381  ~TIL_Access();
382 
383  UT_NON_COPYABLE(TIL_Access)
384 
385  bool isOpen() const { return myOpen; }
386 
387 private:
388  TIL_ImageSource &mySource;
389  short myAccessKey;
390  bool myOpen;
391 };
392 
393 #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
*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:623
GLuint start
Definition: glcorearb.h:475
virtual int isAnythingLocked()
virtual void removeSequence()
virtual int getApparentFrame(int fr)
virtual UT_StringHolder getTopRightCaption() const
virtual int isPlaneLocked(const TIL_Plane *, fpreal)
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)
GLdouble GLdouble x2
Definition: glad.h:2349
const TIL_Sequence * getSequence(fpreal t)
UT_Array< TIL_CookRegion > TIL_CookRegionList
virtual bool allowUserSelection() const
bool isValid() const
GLfloat f
Definition: glcorearb.h:1926
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
#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
virtual int doesImageExist(int, bool=true)
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()
virtual int isFrameLocked(fpreal)
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual int getActualFrame(int frame)
GLint GLenum GLint x
Definition: glcorearb.h:409
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:277
virtual UT_Options getDefaultOptions() const
virtual size_t getVersion()
virtual int64 getPeakMemUsage(int frame) const
virtual bool canAddFrame()
virtual void bumpVersion(bool)
Definition: core.h:982
class OCIOEXPORT ColorSpace
virtual bool isNetwork()
virtual int open(short &, int=0, fpreal=TIL_GLOBAL_TIME)
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
void setAutomaticManual(bool convert_space, float gamma, const UT_StringHolder &lut)
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
Definition: format.h:895
void setOCIODisplayView(const UT_StringHolder &display, const UT_StringHolder &view, bool forward=true)