ImageWidget optimisations (#2394)

Avoid multiple renderings.
Don't cache big images (ie: screensaver images)
pull/2400/head
poire-z 8 years ago committed by Qingping Hou
parent 2c01f3add9
commit e1c3448d0e

@ -83,14 +83,18 @@ function ImageWidget:_loadfile()
-- hit cache -- hit cache
self._bb = cache.bb self._bb = cache.bb
else else
-- cache this image if self.height and self.height > 200 then -- don't cache big images
DEBUG("cache", hash) self._bb = Mupdf.renderImageFile(self.file, self.width, self.height)
cache = ImageCacheItem:new{ else
bb = Mupdf.renderImageFile(self.file, self.width, self.height), -- cache this image
} DEBUG("cache", hash)
cache.size = cache.bb.pitch * cache.bb.h * cache.bb:getBpp() / 8 cache = ImageCacheItem:new{
ImageCache:insert(hash, cache) bb = Mupdf.renderImageFile(self.file, self.width, self.height),
self._bb = cache.bb }
cache.size = cache.bb.pitch * cache.bb.h * cache.bb:getBpp() / 8
ImageCache:insert(hash, cache)
self._bb = cache.bb
end
end end
else else
error("Image file type not supported.") error("Image file type not supported.")
@ -98,6 +102,9 @@ function ImageWidget:_loadfile()
end end
function ImageWidget:_render() function ImageWidget:_render()
if self._bb then -- already rendered
return
end
if self.image then if self.image then
self:_loadimage() self:_loadimage()
elseif self.file then elseif self.file then

Loading…
Cancel
Save