HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TIL_ImageCache.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_ImageCache.h (IMGUI library, C++)
7  *
8  * COMMENTS:
9  * Manages a cache of TIL_Raster images for viewing.
10  */
11 #ifndef TIL_IMAGE_CACHE_H
12 #define TIL_IMAGE_CACHE_H
13 
14 #include "TIL_API.h"
15 #include <iosfwd>
16 #include <UT/UT_Cache.h>
17 #include <UT/UT_FilterType.h>
18 
19 #include "TIL_Defines.h"
20 
21 class TIL_Image;
22 class TIL_ImageState;
23 class TIL_Look;
24 class TIL_ImageSource;
25 class TIL_Raster;
26 
31 };
32 
34 {
36  myZoom(1), myIZoom(1),
37  myU1(0), myV1(0), myU2(1), myV2(1),
38  myScaled(false),
40  myOnlyIfCached(false),
41  myOverrideRes(false),
42  myOverX(-1), myOverY(-1),
44  myHalfFloatSupport(true),
45  myUseAspectRatio(true)
46  {}
47 
48  void setCrop(float u1, float v1, float u2, float v2)
49  { myU1 = u1; myV1 = v1; myU2 = u2; myV2 = v2; }
50 
51  void setResolution(exint resx, exint resy)
52  { myOverrideRes = true; myOverX = resx; myOverY = resy; }
53 
54  float myZoom;
55  float myIZoom;
56  float myU1, myV1;
57  float myU2, myV2;
58  bool myScaled;
66 };
67 
69 {
70 public:
72  ~TIL_ImageCache();
73 
74  void setCacheLimit(bool enable);
75  void setCacheSize(unsigned size_in_kb);
76 
77  int64 getCurrentSize() const { return mySize; }
78  int64 getMaxSize() const { return myMaxSize; }
79 
80  static int64 getSystemMaxSize();
81 
82  void addToCache(TIL_Image *image);
83  void returnToCache(TIL_Image *&image);
84  void returnToCache(const TIL_Raster *r);
85 
86  void removeSourceFromCache(TIL_ImageSource *source);
87  void removeFrameFromCache(TIL_ImageSource *source, int fr);
88 
89  // the tokenstring, frame index and node path should be filled in.
90  // returns 1 and fills in the raster if found (0 otherwise).
91  TIL_Image * getImageFromCache(TIL_ImageState *match,
92  bool usedscaled = false,
94  bool bump = true);
95 
96  // Do not set force_all to true unless calling in a UT_Exit callback.
97  void clearImageCache(bool force_all = false);
98 
99  int getImage(TIL_Image *&image,
101  const char *plane,
102  exint planeindex,
103  float t,
104  void *look,
105  bool updateflag,
106  const TIL_GetImageOptions &opts =
108 
109  static void setUpdateCallback(void (*callback)(void *,
110  TIL_Raster *,
111  int,int,
112  float,float));
113 
114  void dumpCache(std::ostream &os);
115 
116  virtual int64 utReduceCacheSizeBy(int64 amount);
117 protected:
118  // the UT_Cache interface
119  virtual const char *utGetCacheName() const { return "COP Flipbook Cache";}
120  virtual int64 utGetCurrentSize() const { return getCurrentSize(); }
121  virtual bool utHasMaxSize() const { return true; }
122  virtual int64 utGetMaxSize() const { return getMaxSize()*1024; }
123  virtual void utSetMaxSize(int64 size);
124 
125 private:
126  int fetchImage(TIL_Image *&image,
127  TIL_ImageState *state,
128  float t,
129  void *look,
130  bool updateflag,
131  bool scaled,
132  bool include_alpha,
133  bool interactive,
134  exint fxres,
135  exint fyres,
136  bool onlyifcached,
137  bool use_software_emul,
138  bool halffloatsupport);
139 
140  void removeReference(TIL_Image *&image);
141  bool removeImage(TIL_Image *image);
142 
143  void pruneCache();
144 
145  void pruneAnyObsoleteImages();
146  void unlinkImage(TIL_Image *image);
147 
148  void lockCache(bool lock = true);
149 
150  TIL_Image *myHead;
151  TIL_Image *myTail;
152  int64 mySize;
153  int64 myMaxSize;
154  exint myNumImages;
155  exint myNumObsolete;
156  unsigned myCacheLimit : 1,
157  my8BitEmulOnly :1;
158  TIL_FastLock myLock;
159 };
160 
162 
163 #endif
void setResolution(exint resx, exint resy)
int64 getMaxSize() const
void setCrop(float u1, float v1, float u2, float v2)
virtual int64 utGetMaxSize() const
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
virtual bool utHasMaxSize() const
optional - override if the cache has a well defined maximum size
UT_FilterType
Definition: UT_FilterType.h:16
GLsizeiptr size
Definition: glcorearb.h:663
png_bytepp image
Definition: png.h:1849
virtual const char * utGetCacheName() const
required - return the english name for this cache.
long long int64
Definition: SYS_Types.h:100
virtual int64 utReduceCacheSizeBy(int64 amount)=0
GLfloat f
Definition: glcorearb.h:1925
#define TIL_DataFormat
Definition: TIL_Defines.h:64
TIL_DataFormat myDataFormat
#define TILE_MAX_DATA_FORMAT
Definition: TIL_Defines.h:70
TIL_API TIL_ImageCache * TILgetCache()
int64 exint
Definition: SYS_Types.h:109
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
Common base class for various caches.
Definition: UT_Cache.h:21
virtual int64 utGetCurrentSize() const
required - return the current cache size, in bytes
TIL_AlphaOption
virtual void utSetMaxSize(int64)
Definition: UT_Cache.h:45
GLfloat GLfloat v1
Definition: glcorearb.h:816
GLboolean r
Definition: glcorearb.h:1221
#define TIL_API
Definition: TIL_API.h:10
int64 getCurrentSize() const
TIL_AlphaOption myAlpha