diff --git a/uppsrc/CtrlCore/ImageWin32.cpp b/uppsrc/CtrlCore/ImageWin32.cpp index 20ad00f82..601f63d43 100644 --- a/uppsrc/CtrlCore/ImageWin32.cpp +++ b/uppsrc/CtrlCore/ImageWin32.cpp @@ -339,6 +339,12 @@ void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << img.GetSize()); ImageSysDataMaker m; static LRUCache cache; + static int Rsz; + Rsz += img.GetLength(); + if(Rsz > 200 * 200) { // we do not want to do this for each small image painted... + Rsz = 0; + cache.Remove([](const ImageSysData& object) { return object.img.GetRefCount() == 1; }); + } LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount()); Size sz = Ctrl::GetPrimaryScreenArea().GetSize(); m.img = IsPrinter() && GetDeviceCaps(GetHandle(), NUMCOLORS) == 2 ? Dither(img, 360) : img; // If printer does not support color, dither diff --git a/uppsrc/Draw/Image.h b/uppsrc/Draw/Image.h index a18f57edf..b4150bd3a 100644 --- a/uppsrc/Draw/Image.h +++ b/uppsrc/Draw/Image.h @@ -253,6 +253,10 @@ public: char info[24]; }; explicit Image(const Init& init); + + // required by system image cache managemenent + + int GetRefCount() const { return data->refcount; } }; Image Premultiply(const Image& img);