resolve github inconsistencies

pull/825/head
WS64 10 years ago
parent 26413adab5
commit 1a71b3e503

@ -1,6 +1,26 @@
local Widget = require("ui/widget/widget")
local CacheItem = require("cacheitem")
local Image = require("ffi/mupdfimg")
local Geom = require("ui/geometry")
local Cache = require("cache")
local DEBUG = require("dbg")
local ImageCache = Cache:new{
max_memsize = 2*1024*1024, -- 2M of image cache
current_memsize = 0,
cache = {},
-- this will hold the LRU order of the cache
cache_order = {}
}
local ImageCacheItem = CacheItem:new{}
function ImageCacheItem:onFree()
if self.bb.free then
DEBUG("free image blitbuffer", self.bb)
self.bb:free()
end
end
--[[
ImageWidget shows an image from a file
@ -20,9 +40,23 @@ function ImageWidget:_render()
local itype = string.lower(string.match(self.file, ".+%.([^.]+)") or "")
if itype == "png" or itype == "jpg" or itype == "jpeg"
or itype == "tiff" then
self._bb = Image:fromFile(self.file, self.width, self.height)
local hash = "image|"..self.file.."|"..(self.width or "").."|"..(self.height or "")
local cache = ImageCache:check(hash)
if cache then
-- hit cache
self._bb = cache.bb
else
-- cache this image
DEBUG("cache", hash)
local cache = ImageCacheItem:new{
bb = Image:fromFile(self.file, self.width, self.height),
}
cache.size = cache.bb.pitch * cache.bb.h
ImageCache:insert(hash, cache)
self._bb = cache.bb
end
else
error(self.file .. ": Image file type not supported.")
error("Image file type not supported.")
end
local w, h = self._bb:getWidth(), self._bb:getHeight()
if (self.width and self.width ~= w) or (self.height and self.height ~= h) then
@ -31,27 +65,24 @@ function ImageWidget:_render()
end
function ImageWidget:getSize()
if not self._bb then
self:_render()
end
self:_render()
return Geom:new{ w = self._bb:getWidth(), h = self._bb:getHeight() }
end
function ImageWidget:rotate(degree)
if not self._bb then
self:_render()
end
self:_render()
self._bb:rotate(degree)
end
function ImageWidget:paintTo(bb, x, y)
if self.hide then return end
-- self:_reader is called in getSize method
local size = self:getSize()
self.dimen = Geom:new{
x = x, y = y,
w = size.w,
h = size.h
}
if self.hide then return end
bb:blitFrom(self._bb, x, y, 0, 0, size.w, size.h)
if self.invert then
bb:invertRect(x, y, size.w, size.h)
@ -61,11 +92,4 @@ function ImageWidget:paintTo(bb, x, y)
end
end
function ImageWidget:free()
if self._bb then
self._bb:free()
self._bb = nil
end
end
return ImageWidget

Loading…
Cancel
Save