2
0
mirror of https://github.com/koreader/koreader synced 2024-11-04 12:00:25 +00:00

Merge pull request #1014 from hwhw/master

use new FFI based mupdf API
This commit is contained in:
Huang Xin 2014-10-21 18:13:21 +08:00
commit 3c1d2c69df
4 changed files with 8 additions and 44 deletions

2
base

@ -1 +1 @@
Subproject commit a4191d33665e4a3c2a63b9d243913a12c9d7a890 Subproject commit 1c0cf8963b19068679b19ef52ebffd0ffafae627

View File

@ -3,7 +3,6 @@ local Document = require("document/document")
local Configurable = require("configurable") local Configurable = require("configurable")
local Blitbuffer = require("ffi/blitbuffer") local Blitbuffer = require("ffi/blitbuffer")
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
local Image = require("ffi/mupdfimg")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Device = require("ui/device") local Device = require("ui/device")
local Screen = require("ui/screen") local Screen = require("ui/screen")
@ -148,7 +147,8 @@ function CreDocument:getCoverPageImage()
self:loadDocument() self:loadDocument()
local data, size = self._document:getCoverPageImageData() local data, size = self._document:getCoverPageImageData()
if data and size then if data and size then
local image = Image:fromData(data, size) local Mupdf = require("ffi/mupdf")
local image = Mupdf.renderImage(data, size)
ffi.C.free(data) ffi.C.free(data)
return image return image
end end

View File

@ -5,56 +5,20 @@ local Document = require("document/document")
local Configurable = require("configurable") local Configurable = require("configurable")
local DrawContext = require("ffi/drawcontext") local DrawContext = require("ffi/drawcontext")
local DEBUG = require("dbg") local DEBUG = require("dbg")
local ffi = require("ffi")
ffi.cdef[[
typedef struct fz_point_s fz_point;
struct fz_point_s {
float x, y;
};
typedef enum {
FZ_ANNOT_TEXT,
FZ_ANNOT_LINK,
FZ_ANNOT_FREETEXT,
FZ_ANNOT_LINE,
FZ_ANNOT_SQUARE,
FZ_ANNOT_CIRCLE,
FZ_ANNOT_POLYGON,
FZ_ANNOT_POLYLINE,
FZ_ANNOT_HIGHLIGHT,
FZ_ANNOT_UNDERLINE,
FZ_ANNOT_SQUIGGLY,
FZ_ANNOT_STRIKEOUT,
FZ_ANNOT_STAMP,
FZ_ANNOT_CARET,
FZ_ANNOT_INK,
FZ_ANNOT_POPUP,
FZ_ANNOT_FILEATTACHMENT,
FZ_ANNOT_SOUND,
FZ_ANNOT_MOVIE,
FZ_ANNOT_WIDGET,
FZ_ANNOT_SCREEN,
FZ_ANNOT_PRINTERMARK,
FZ_ANNOT_TRAPNET,
FZ_ANNOT_WATERMARK,
FZ_ANNOT_3D
} fz_annot_type;
]]
local PdfDocument = Document:new{ local PdfDocument = Document:new{
_document = false, _document = false,
-- muPDF manages its own additional cache
mupdf_cache_size = 5 * 1024 * 1024,
dc_null = DrawContext.new(), dc_null = DrawContext.new(),
options = KoptOptions, options = KoptOptions,
koptinterface = nil, koptinterface = nil,
} }
function PdfDocument:init() function PdfDocument:init()
local pdf = require("libs/libkoreader-pdf") local pdf = require("ffi/mupdf")
self.koptinterface = require("document/koptinterface") self.koptinterface = require("document/koptinterface")
self.configurable:loadDefaults(self.options) self.configurable:loadDefaults(self.options)
local ok local ok
ok, self._document = pcall(pdf.openDocument, self.file, self.mupdf_cache_size) ok, self._document = pcall(pdf.openDocument, self.file)
if not ok then if not ok then
error(self._document) -- will contain error message error(self._document) -- will contain error message
end end

View File

@ -1,6 +1,6 @@
local Widget = require("ui/widget/widget") local Widget = require("ui/widget/widget")
local CacheItem = require("cacheitem") local CacheItem = require("cacheitem")
local Image = require("ffi/mupdfimg") local Mupdf = require("ffi/mupdf")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Cache = require("cache") local Cache = require("cache")
local DEBUG = require("dbg") local DEBUG = require("dbg")
@ -54,9 +54,9 @@ function ImageWidget:_loadfile()
-- cache this image -- cache this image
DEBUG("cache", hash) DEBUG("cache", hash)
local cache = ImageCacheItem:new{ local cache = ImageCacheItem:new{
bb = Image:fromFile(self.file, self.width, self.height), bb = Mupdf.renderImageFile(self.file, self.width, self.height),
} }
cache.size = cache.bb.pitch * cache.bb.h cache.size = cache.bb.pitch * cache.bb.h * cache.bb:getBpp() / 8
ImageCache:insert(hash, cache) ImageCache:insert(hash, cache)
self._bb = cache.bb self._bb = cache.bb
end end