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