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 
17 #include <UT/UT_Cache.h>
18 #include <UT/UT_FilterType.h>
19 #include <UT/UT_Options.h>
20 
21 #include "TIL_Defines.h"
22 
23 class UT_Options;
24 
25 class TIL_Image;
26 class TIL_ImageState;
27 class TIL_Look;
28 class TIL_ImageSource;
29 class TIL_Raster;
30 
35 };
36 
38 {
40  myZoom(1), myIZoom(1),
41  myU1(0), myV1(0), myU2(1), myV2(1),
42  myScaled(false),
44  myOnlyIfCached(false),
45  myOverrideRes(false),
46  myOverX(-1), myOverY(-1),
48  myHalfFloatSupport(true),
49  myUseAspectRatio(true),
50  myUTOptions()
51  {}
52 
53  void setCrop(float u1, float v1, float u2, float v2)
54  { myU1 = u1; myV1 = v1; myU2 = u2; myV2 = v2; }
55 
56  void setResolution(exint resx, exint resy)
57  { myOverrideRes = true; myOverX = resx; myOverY = resy; }
58 
59  float myZoom;
60  float myIZoom;
61  float myU1, myV1;
62  float myU2, myV2;
63 
64  /// Set to true if retrieving a raster at a different resolution
65  /// and scaling it to return is okay.
66  bool myScaled;
67 
75 
77 };
78 
80 {
81 public:
83  ~TIL_ImageCache() override;
84 
85  void setCacheLimit(bool enable);
86  void setCacheSize(unsigned size_in_kb);
87 
88  int64 getCurrentSize() const { return mySize; }
89  int64 getMaxSize() const { return myMaxSize; }
90 
91  static int64 getSystemMaxSize();
92 
93  void addToCache(TIL_Image *image);
94  void returnToCache(TIL_Image *&image);
95  void returnToCache(const TIL_Raster *r);
96  bool isRasterInCache(const TIL_Raster *r) const;
97 
98  void removeSourceFromCache(TIL_ImageSource *source);
99  void removeFrameFromCache(TIL_ImageSource *source, int fr);
100 
101  // the tokenstring, frame index and node path should be filled in.
102  // returns 1 and fills in the raster if found (0 otherwise).
103  TIL_Image * getImageFromCache(TIL_ImageState *match,
104  bool usedscaled = false,
106  bool bump = true);
107 
108  // Do not set force_all to true unless calling in a UT_Exit callback.
109  void clearImageCache(bool force_all = false);
110 
111  int getImage(TIL_Image *&image,
113  const char *plane,
114  exint planeindex,
115  float t,
116  void *look,
117  bool updateflag,
118  const TIL_GetImageOptions &opts =
120 
121  static void setUpdateCallback(void (*callback)(void *,
122  TIL_Raster *,
123  int,int,
124  float,float));
125 
126  void dumpCache(std::ostream &os);
127 
128  int64 utReduceCacheSizeBy(int64 amount) override;
129 protected:
130  // the UT_Cache interface
131  const char *utGetCacheName() const override
132  { return "COP Flipbook Cache";}
133  int64 utGetCurrentSize() const override
134  { return getCurrentSize(); }
135  bool utHasMaxSize() const override
136  { return true; }
137  int64 utGetMaxSize() const override
138  { return getMaxSize()*1024; }
139  void utSetMaxSize(int64 size) override;
140 
141 private:
142  int fetchImage(TIL_Image *&image,
143  TIL_ImageState *state,
144  float t,
145  void *look,
146  bool updateflag,
147  bool scaled,
148  bool include_alpha,
149  bool interactive,
150  exint fxres,
151  exint fyres,
152  bool onlyifcached,
153  bool use_software_emul,
154  bool halffloatsupport,
155  const UT_Options &);
156 
157  void removeReference(TIL_Image *&image);
158  bool removeImage(TIL_Image *image);
159 
160  void pruneCache();
161 
162  void pruneAnyObsoleteImages();
163  void unlinkImage(TIL_Image *image);
164 
165  void lockCache() const;
166  void unlockCache() const;
167 
168  TIL_Image *myHead;
169  TIL_Image *myTail;
170  int64 mySize;
171  int64 myMaxSize;
172  exint myNumImages;
173  exint myNumObsolete;
174  unsigned myCacheLimit : 1,
175  my8BitEmulOnly :1;
176  mutable TIL_FastLock myLock;
177 };
178 
180 
181 #endif
UT_Options myUTOptions
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
A map of string to various well defined value types.
Definition: UT_Options.h:84
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