HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
59  /// Set to true if retrieving a raster at a different resolution
60  /// and scaling it to return is okay.
61  bool myScaled;
62 
70 };
71 
73 {
74 public:
76  ~TIL_ImageCache();
77 
78  void setCacheLimit(bool enable);
79  void setCacheSize(unsigned size_in_kb);
80 
81  int64 getCurrentSize() const { return mySize; }
82  int64 getMaxSize() const { return myMaxSize; }
83 
84  static int64 getSystemMaxSize();
85 
86  void addToCache(TIL_Image *image);
87  void returnToCache(TIL_Image *&image);
88  void returnToCache(const TIL_Raster *r);
89 
90  void removeSourceFromCache(TIL_ImageSource *source);
91  void removeFrameFromCache(TIL_ImageSource *source, int fr);
92 
93  // the tokenstring, frame index and node path should be filled in.
94  // returns 1 and fills in the raster if found (0 otherwise).
95  TIL_Image * getImageFromCache(TIL_ImageState *match,
96  bool usedscaled = false,
98  bool bump = true);
99 
100  // Do not set force_all to true unless calling in a UT_Exit callback.
101  void clearImageCache(bool force_all = false);
102 
103  int getImage(TIL_Image *&image,
105  const char *plane,
106  exint planeindex,
107  float t,
108  void *look,
109  bool updateflag,
110  const TIL_GetImageOptions &opts =
112 
113  static void setUpdateCallback(void (*callback)(void *,
114  TIL_Raster *,
115  int,int,
116  float,float));
117 
118  void dumpCache(std::ostream &os);
119 
120  virtual int64 utReduceCacheSizeBy(int64 amount);
121 protected:
122  // the UT_Cache interface
123  virtual const char *utGetCacheName() const { return "COP Flipbook Cache";}
124  virtual int64 utGetCurrentSize() const { return getCurrentSize(); }
125  virtual bool utHasMaxSize() const { return true; }
126  virtual int64 utGetMaxSize() const { return getMaxSize()*1024; }
127  virtual void utSetMaxSize(int64 size);
128 
129 private:
130  int fetchImage(TIL_Image *&image,
131  TIL_ImageState *state,
132  float t,
133  void *look,
134  bool updateflag,
135  bool scaled,
136  bool include_alpha,
137  bool interactive,
138  exint fxres,
139  exint fyres,
140  bool onlyifcached,
141  bool use_software_emul,
142  bool halffloatsupport);
143 
144  void removeReference(TIL_Image *&image);
145  bool removeImage(TIL_Image *image);
146 
147  void pruneCache();
148 
149  void pruneAnyObsoleteImages();
150  void unlinkImage(TIL_Image *image);
151 
152  void lockCache(bool lock = true);
153 
154  TIL_Image *myHead;
155  TIL_Image *myTail;
156  int64 mySize;
157  int64 myMaxSize;
158  exint myNumImages;
159  exint myNumObsolete;
160  unsigned myCacheLimit : 1,
161  my8BitEmulOnly :1;
162  TIL_FastLock myLock;
163 };
164 
166 
167 #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:107
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:116
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