From e0868826ad40d754bee6e89c28c53e9d45c85051 Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Sun, 19 Oct 2014 00:22:35 +0200 Subject: [PATCH 1/3] use new FFI based mupdf API This will use the new API where the Lua/C interface was used before and also drop usage of mupdfimg wrapper which is now implemented within the mupdf interface --- base | 2 +- frontend/document/credocument.lua | 4 +-- frontend/document/pdfdocument.lua | 40 ++---------------------------- frontend/ui/widget/imagewidget.lua | 6 ++--- 4 files changed, 8 insertions(+), 44 deletions(-) diff --git a/base b/base index a4191d336..bb2f598cf 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit a4191d33665e4a3c2a63b9d243913a12c9d7a890 +Subproject commit bb2f598cfa2aebf565ae5947293c9cfe06021183 diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 88ced31f7..d5a94db5a 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -3,7 +3,6 @@ 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") @@ -148,7 +147,8 @@ function CreDocument:getCoverPageImage() self:loadDocument() local data, size = self._document:getCoverPageImageData() 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) return image end diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index b6faca5e4..0b4c82011 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -5,56 +5,20 @@ local Document = require("document/document") local Configurable = require("configurable") local DrawContext = require("ffi/drawcontext") 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{ _document = false, - -- muPDF manages its own additional cache - mupdf_cache_size = 5 * 1024 * 1024, dc_null = DrawContext.new(), options = KoptOptions, koptinterface = nil, } function PdfDocument:init() - local pdf = require("libs/libkoreader-pdf") + local pdf = require("ffi/mupdf") self.koptinterface = require("document/koptinterface") self.configurable:loadDefaults(self.options) 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 error(self._document) -- will contain error message end diff --git a/frontend/ui/widget/imagewidget.lua b/frontend/ui/widget/imagewidget.lua index d4c4b31dc..ac2c90a11 100644 --- a/frontend/ui/widget/imagewidget.lua +++ b/frontend/ui/widget/imagewidget.lua @@ -1,6 +1,6 @@ local Widget = require("ui/widget/widget") local CacheItem = require("cacheitem") -local Image = require("ffi/mupdfimg") +local Mupdf = require("ffi/mupdf") local Geom = require("ui/geometry") local Cache = require("cache") local DEBUG = require("dbg") @@ -54,9 +54,9 @@ function ImageWidget:_loadfile() -- cache this image DEBUG("cache", hash) 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) self._bb = cache.bb end From ee6b5a7fe12aa9cc7f0887b2397fe95270a8aaac Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Mon, 20 Oct 2014 09:18:32 +0200 Subject: [PATCH 2/3] update to latest base --- base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base b/base index bb2f598cf..217e78683 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit bb2f598cfa2aebf565ae5947293c9cfe06021183 +Subproject commit 217e786836bcba654c53ecde6c1f2e9b7ac66840 From 2050c0aa6653cf8d8f77f71f5626303d3e544682 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 21 Oct 2014 17:19:21 +0800 Subject: [PATCH 3/3] fix renderImage invocation --- base | 2 +- frontend/document/credocument.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base b/base index 217e78683..1c0cf8963 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 217e786836bcba654c53ecde6c1f2e9b7ac66840 +Subproject commit 1c0cf8963b19068679b19ef52ebffd0ffafae627 diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index d5a94db5a..5d77ff10f 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -148,7 +148,7 @@ function CreDocument:getCoverPageImage() local data, size = self._document:getCoverPageImageData() if data and size then local Mupdf = require("ffi/mupdf") - local image = Mupdf:renderImage(data, size) + local image = Mupdf.renderImage(data, size) ffi.C.free(data) return image end