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  mySkipPostprocessor(false),
51  myUTOptions()
52  {}
53 
54  void setCrop(float u1, float v1, float u2, float v2)
55  { myU1 = u1; myV1 = v1; myU2 = u2; myV2 = v2; }
56 
57  void setResolution(exint resx, exint resy)
58  { myOverrideRes = true; myOverX = resx; myOverY = resy; }
59 
60  float myZoom;
61  float myIZoom;
62  float myU1, myV1;
63  float myU2, myV2;
64 
65  /// Set to true if retrieving a raster at a different resolution
66  /// and scaling it to return is okay.
67  bool myScaled;
68 
77 
79 };
80 
82 {
83 public:
85  ~TIL_ImageCache() override;
86 
87  void setCacheLimit(bool enable);
88  void setCacheSize(unsigned size_in_kb);
89 
90  int64 getCurrentSize() const { return mySize; }
91  int64 getMaxSize() const { return myMaxSize; }
92 
93  void recalculateSize();
94 
95  static int64 getSystemMaxSize();
96 
97  void addToCache(TIL_Image *image);
98  void returnToCache(TIL_Image *&image);
99  void returnToCache(const TIL_Raster *r);
100  bool isRasterInCache(const TIL_Raster *r) const;
101 
102  void removeSourceFromCache(TIL_ImageSource *source);
103  void removeFrameFromCache(TIL_ImageSource *source, int fr);
104 
105  // the tokenstring, frame index and node path should be filled in.
106  // returns 1 and fills in the raster if found (0 otherwise).
107  TIL_Image * getImageFromCache(TIL_ImageState *match,
108  bool usedscaled = false,
110  bool bump = true);
111 
112  // Do not set force_all to true unless calling in a UT_Exit callback.
113  void clearImageCache(bool force_all = false);
114 
115  int getImage(TIL_Image *&image,
117  const char *plane,
118  exint planeindex,
119  float t,
120  void *look,
121  bool updateflag,
122  const TIL_GetImageOptions &opts =
124 
125  static void setUpdateCallback(void (*callback)(void *,
126  TIL_Raster *,
127  int,int,
128  float,float));
129 
130  void dumpCache(std::ostream &os);
131 
132  int64 utReduceCacheSizeBy(int64 amount) override;
133 protected:
134  // the UT_Cache interface
135  const char *utGetCacheName() const override
136  { return "Composite View Cache";}
137  int64 utGetCurrentSize() const override
138  { return getCurrentSize(); }
139  bool utHasMaxSize() const override
140  { return true; }
141  int64 utGetMaxSize() const override
142  { return getMaxSize()*1024; }
143  void utSetMaxSize(int64 size) override;
144 
145 private:
146  int fetchImage(TIL_Image *&image,
148  float t,
149  void *look,
150  bool updateflag,
151  bool scaled,
152  bool include_alpha,
153  bool interactive,
154  exint fxres,
155  exint fyres,
156  bool onlyifcached,
157  bool use_software_emul,
158  bool halffloatsupport,
159  bool skip_postprocessor,
160  const UT_Options &);
161 
162  void removeReference(TIL_Image *&image);
163  bool removeImage(TIL_Image *image);
164 
165  void pruneCache();
166 
167  void pruneAnyObsoleteImages();
168  void unlinkImage(TIL_Image *image);
169 
170  void lockCache() const;
171  void unlockCache() const;
172 
173  TIL_Image *myHead;
174  TIL_Image *myTail;
175  int64 mySize;
176  int64 myMaxSize;
177  exint myNumImages;
178  exint myNumObsolete;
179  unsigned myCacheLimit : 1,
180  my8BitEmulOnly :1;
181  mutable TIL_FastLock myLock;
182 };
183 
185 
186 #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:64
TIL_DataFormat myDataFormat
#define TILE_MAX_DATA_FORMAT
Definition: TIL_Defines.h:70
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:51
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
state
Definition: core.h:2289
TIL_AlphaOption myAlpha