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() override;
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  int64 utReduceCacheSizeBy(int64 amount) override;
121 protected:
122  // the UT_Cache interface
123  const char *utGetCacheName() const override
124  { return "COP Flipbook Cache";}
125  int64 utGetCurrentSize() const override
126  { return getCurrentSize(); }
127  bool utHasMaxSize() const override
128  { return true; }
129  int64 utGetMaxSize() const override
130  { return getMaxSize()*1024; }
131  void utSetMaxSize(int64 size) override;
132 
133 private:
134  int fetchImage(TIL_Image *&image,
135  TIL_ImageState *state,
136  float t,
137  void *look,
138  bool updateflag,
139  bool scaled,
140  bool include_alpha,
141  bool interactive,
142  exint fxres,
143  exint fyres,
144  bool onlyifcached,
145  bool use_software_emul,
146  bool halffloatsupport);
147 
148  void removeReference(TIL_Image *&image);
149  bool removeImage(TIL_Image *image);
150 
151  void pruneCache();
152 
153  void pruneAnyObsoleteImages();
154  void unlinkImage(TIL_Image *image);
155 
156  void lockCache(bool lock = true);
157 
158  TIL_Image *myHead;
159  TIL_Image *myTail;
160  int64 mySize;
161  int64 myMaxSize;
162  exint myNumImages;
163  exint myNumObsolete;
164  unsigned myCacheLimit : 1,
165  my8BitEmulOnly :1;
166  TIL_FastLock myLock;
167 };
168 
170 
171 #endif
void setResolution(exint resx, exint resy)
int64 getMaxSize() const
int64 utGetCurrentSize() const override
required - return the current cache size, in bytes
int64 exint
Definition: SYS_Types.h:125
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
void setCrop(float u1, float v1, float u2, float v2)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
int64 utGetMaxSize() const override
UT_FilterType
Definition: UT_FilterType.h:16
GLdouble u1
Definition: glad.h:2676
virtual int64 utReduceCacheSizeBy(int64 amount)=0
GLfloat f
Definition: glcorearb.h:1926
#define TIL_DataFormat
Definition: TIL_Defines.h:65
TIL_DataFormat myDataFormat
#define TILE_MAX_DATA_FORMAT
Definition: TIL_Defines.h:71
TIL_API TIL_ImageCache * TILgetCache()
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
long long int64
Definition: SYS_Types.h:116
GLdouble GLdouble u2
Definition: glad.h:2676
Common base class for various caches.
Definition: UT_Cache.h:21
GLdouble t
Definition: glad.h:2397
bool utHasMaxSize() const override
optional - override if the cache has a well defined maximum size
TIL_AlphaOption
GLsizeiptr size
Definition: glcorearb.h:664
virtual void utSetMaxSize(int64)
Definition: UT_Cache.h:48
GLfloat GLfloat v1
Definition: glcorearb.h:817
const char * utGetCacheName() const override
required - return the english name for this cache.
GLboolean r
Definition: glcorearb.h:1222
#define TIL_API
Definition: TIL_API.h:10
int64 getCurrentSize() const
TIL_AlphaOption myAlpha