mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
@@ -3,11 +3,13 @@ local Document = require("document/document")
|
||||
local Configurable = require("configurable")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local Image = require("ffi/mupdfimg")
|
||||
local Geom = require("ui/geometry")
|
||||
local Device = require("ui/device")
|
||||
local Screen = require("ui/screen")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local ffi = require("ffi")
|
||||
|
||||
local CreDocument = Document:new{
|
||||
-- this is defined in kpvcrlib/crengine/crengine/include/lvdocview.h
|
||||
@@ -130,6 +132,16 @@ function CreDocument:getPageCount()
|
||||
return self._document:getPages()
|
||||
end
|
||||
|
||||
function CreDocument:getCoverPageImage()
|
||||
self._document:loadDocument(self.file)
|
||||
local data, size = self._document:getCoverPageImageData()
|
||||
if data and size then
|
||||
local image = Image:fromData(data, size)
|
||||
ffi.C.free(data)
|
||||
return image
|
||||
end
|
||||
end
|
||||
|
||||
function CreDocument:getWordFromPosition(pos)
|
||||
local word_box = self._document:getWordFromPosition(pos.x, pos.y)
|
||||
DEBUG("CreDocument: get word box", word_box)
|
||||
|
||||
@@ -8,9 +8,9 @@ local _ = require("gettext")
|
||||
|
||||
local OTAManager = {
|
||||
ota_servers = {
|
||||
"http://vislab.bjmu.edu.cn/apps/koreader/ota/",
|
||||
"http://koreader.ak-team.com/",
|
||||
"http://hal9k.ifsc.usp.br/koreader/",
|
||||
"http://vislab.bjmu.edu.cn:80/apps/koreader/ota/",
|
||||
"http://koreader.ak-team.com:80/",
|
||||
"http://hal9k.ifsc.usp.br:80/koreader/",
|
||||
},
|
||||
ota_channels = {
|
||||
"nightly",
|
||||
|
||||
@@ -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,7 +40,21 @@ 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("Image file type not supported.")
|
||||
end
|
||||
@@ -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
|
||||
|
||||
Submodule koreader-base updated: 1075c61f74...77654ebd37
@@ -54,6 +54,12 @@ describe("EPUB document module", function()
|
||||
doc = DocumentRegistry:openDocument(sample_epub)
|
||||
assert.truthy(doc)
|
||||
end)
|
||||
it("should get cover image", function()
|
||||
local image = doc:getCoverPageImage()
|
||||
assert.truthy(image)
|
||||
assert.are.same(image:getWidth(), 442)
|
||||
assert.are.same(image:getHeight(), 616)
|
||||
end)
|
||||
it("should close document", function()
|
||||
doc:close()
|
||||
end)
|
||||
|
||||
BIN
test/leaves.epub
BIN
test/leaves.epub
Binary file not shown.
Reference in New Issue
Block a user