00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TIL_IMAGE_CACHE_H
00020 #define TIL_IMAGE_CACHE_H
00021
00022 #include "TIL_API.h"
00023 #include <iostream.h>
00024 #include <UT/UT_Cache.h>
00025 #include <UT/UT_FilterType.h>
00026
00027 #include "TIL_Defines.h"
00028
00029 class TIL_Image;
00030 class TIL_ImageState;
00031 class TIL_SoftwareEmulState;
00032 class TIL_Look;
00033 class TIL_ImageSource;
00034 class TIL_Raster;
00035
00036 enum TIL_AlphaOption {
00037 TIL_NO_ALPHA,
00038 TIL_USE_ALPHA,
00039 TIL_SOLID_ALPHA
00040 };
00041
00042
00043 class TIL_API TIL_ImageCache : public UT_Cache
00044 {
00045 public:
00046 TIL_ImageCache();
00047 ~TIL_ImageCache();
00048
00049 void setCacheLimit(bool enable);
00050 void setCacheSize(unsigned size_in_kb);
00051
00052 int64 getCurrentSize() const { return mySize; }
00053 int64 getMaxSize() const { return myMaxSize; }
00054
00055 static int64 getSystemMaxSize();
00056
00057 void addToCache(TIL_Image *image);
00058 void returnToCache(TIL_Image *&image);
00059 void returnToCache(const TIL_Raster *r);
00060
00061 void removeSourceFromCache(TIL_ImageSource *source);
00062 void removeFrameFromCache(TIL_ImageSource *source, int fr);
00063
00064
00065
00066 TIL_Image * getImageFromCache(TIL_ImageState *match,
00067 bool usedscaled = false,
00068 UT_FilterType f = UT_FILTER_BOX,
00069 bool bump = true);
00070
00071
00072 void clearImageCache(bool force_all = false);
00073
00074 int getImage(TIL_Image *&image,
00075 TIL_ImageSource *source,
00076 const char *plane,
00077 int planeindex,
00078 float t,
00079 void *look,
00080 bool updateflag,
00081 float zoom = 1.0F, float izoom = 1.0f,
00082 float u1 =0.0F, float v1=0.0F,
00083 float u2 =1.0F, float v2=1.0F,
00084 bool scaled = false,
00085 TIL_AlphaOption alpha = TIL_NO_ALPHA,
00086 bool onlyifcached = false,
00087 bool override_res = false,
00088 int overx = -1, int overy = -1,
00089 TIL_DataFormat data = TILE_MAX_DATA_FORMAT,
00090 bool apply_software_emul = true,
00091 bool halffloatsupport = true,
00092 bool useaspectratio = true);
00093
00094 static void setUpdateCallback(void (*callback)(void *,
00095 TIL_Raster *,
00096 int,int,
00097 float,float));
00098
00099 void dumpCache(ostream &os);
00100
00101 void setEmulation(bool hardaccel,
00102 float black,
00103 float white,
00104 float scale,
00105 float shift,
00106 int component,
00107 bool hardlut,
00108 const char *lut,
00109 float gamma,
00110 bool fastaspect,
00111 float aspect,
00112 bool use8bit);
00113
00114 virtual int64 utReduceCacheSizeBy(int64 amount);
00115 protected:
00116
00117 virtual const char *utGetCacheName() const { return "COP Flipbook Cache"; }
00118 virtual int64 utGetCurrentSize() { return getCurrentSize(); }
00119 virtual bool utHasMaxSize() const { return true; }
00120 virtual int64 utGetMaxSize() { return getMaxSize()*1024; }
00121 virtual void utSetMaxSize(int64 size);
00122
00123 private:
00124 int fetchImage(TIL_Image *&image,
00125 TIL_ImageState *state,
00126 float t,
00127 void *look,
00128 bool updateflag,
00129 bool scaled,
00130 bool include_alpha,
00131 bool interactive,
00132 int fxres,
00133 int fyres,
00134 bool onlyifcached,
00135 bool use_software_emul,
00136 bool halffloatsupport);
00137
00138 void applySoftwareEmulation(TIL_Image *&image);
00139 void removeAllOldEmulations();
00140 void removeObsoleteEmulation(TIL_Image *image);
00141
00142 void removeReference(TIL_Image *&image);
00143 bool removeImage(TIL_Image *image);
00144
00145 void pruneCache();
00146
00147 void pruneAnyObsoleteImages();
00148 void unlinkImage(TIL_Image *image);
00149
00150 void lockCache(bool lock = true);
00151
00152 TIL_Image *myHead;
00153 TIL_Image *myTail;
00154 int64 mySize;
00155 int64 myMaxSize;
00156 int myNumImages;
00157 int myNumObsolete;
00158 TIL_SoftwareEmulState *myEmulation;
00159 unsigned myCacheLimit : 1,
00160 my8BitEmulOnly :1,
00161 myKeepOriginal :1;
00162 TIL_FastLock myLock;
00163 };
00164
00165 TIL_API TIL_ImageCache *TILgetCache();
00166
00167 #endif