From 043dc13a24d3e1afa9f77aa71c231d9e793dd467 Mon Sep 17 00:00:00 2001 From: WS64 Date: Thu, 21 Aug 2014 22:22:49 +0200 Subject: [PATCH 01/12] Add "last book" screensaver for Kobo Epub only. If someone knows how to get an jpg/png from a pdf on linux (e.g. convert by imangemagick? But i am not a linux specialist and have no idea how to get that one into koreader) I can add something for linux too. cbz/cbr should be possible too, but I have not looked into it yet. Do I see it right that the Kindle screensavers are handled by Kindle itself? But on Kindle you also profit, you can see picture thumbnails now in the search results (long tap on found book) --- frontend/ui/uimanager.lua | 127 +++++++++++++++++++++++++++++++++++--- 1 file changed, 119 insertions(+), 8 deletions(-) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 0a4f5306c..97c65c9b4 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -59,6 +59,109 @@ local UIManager = { suspend_msg = nil } +function UIManager:getPicture(file) + + local contentopf + local contentpath + local epub_folder = "temp/epub" + + local function check_extension(cover) + if cover then + local itype = string.lower(string.match(cover, ".+%.([^.]+)") or "") + if not (itype == "png" or itype == "jpg" or itype == "jpeg" or itype == "tiff") then + cover = nil + end + end + return cover + end + + local function getValue(zipfile,which_line,to_find,excludecheck) + local f = io.open(zipfile,"r") + local i + + if f then + local line = f:read() + while line and not i do + i = line:lower():find(which_line:lower()) -- found something + if i then + f.close() + line = line:match(to_find .. "\"([^\"]+)\".*") + if not excludecheck then line = check_extension(line) end + if line then + return line + else + i = nil + end + end + if not i then line = f:read() end + end + f.close() + end + end + + local function guess(extension) + local cover = contentpath .. "Images/cover." .. extension + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then + cover = nil + end + return cover + end + + local function try_content_opf(which_line,to_find,addimage) + local cover = getValue(epub_folder .. "/" .. contentopf,which_line,to_find) + local imageadd + if cover then + if addimage then + imageadd = "Images/" + else + imageadd = "" + end + cover = contentpath .. imageadd .. cover + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then cover = nil end + end + return check_extension(cover) + end + + local cover + if file then + pcall(lfs.mkdir("temp")) + pcall(os.execute("rm -rf " .. epub_folder)) + pcall(lfs.mkdir(epub_folder)) + pcall(os.execute("unzip \"" .. file .. "\" cover.jpeg -oq -d " .. epub_folder)) + if io.open(epub_folder .. "/cover.jpeg","r") then -- picture in main folder + cover = epub_folder .. "/cover.jpeg" -- found one + else + pcall(os.execute("unzip \"" .. file .. "\" \"META-INF/container.xml\" -oq -d " .. epub_folder)) -- read container.xml + contentopf = getValue(epub_folder .. "/META-INF/container.xml","^%s* Date: Thu, 21 Aug 2014 22:24:59 +0200 Subject: [PATCH 02/12] Show filename on error in crash.log --- frontend/ui/widget/imagewidget.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/ui/widget/imagewidget.lua b/frontend/ui/widget/imagewidget.lua index 37e302229..cddd0d1cd 100644 --- a/frontend/ui/widget/imagewidget.lua +++ b/frontend/ui/widget/imagewidget.lua @@ -18,10 +18,11 @@ local ImageWidget = Widget:new{ function ImageWidget:_render() local itype = string.lower(string.match(self.file, ".+%.([^.]+)") or "") - if itype == "jpeg" or itype == "jpg" then - self._bb = Image:fromJPEG(self.file) - elseif itype == "png" then - self._bb = Image:fromPNG(self.file) + if itype == "png" or itype == "jpg" or itype == "jpeg" + or itype == "tiff" then + self._bb = Image:fromFile(self.file, self.width, self.height) + else + error(self.file .. ": 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 From 7e1b70211115a6f1be99d81d412530645c929942 Mon Sep 17 00:00:00 2001 From: WS64 Date: Thu, 21 Aug 2014 22:30:01 +0200 Subject: [PATCH 03/12] Allow to take an image from paretn instead of info-i.png --- frontend/ui/widget/infomessage.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/ui/widget/infomessage.lua b/frontend/ui/widget/infomessage.lua index 939e800c3..dc962e690 100644 --- a/frontend/ui/widget/infomessage.lua +++ b/frontend/ui/widget/infomessage.lua @@ -26,6 +26,10 @@ local InfoMessage = InputContainer:new{ } function InfoMessage:init() + if not self.image then + self.image_width = nil + self.image_height = nil + end if Device:hasKeys() then self.key_events = { AnyKeyPressed = { { Input.group.Any }, @@ -53,7 +57,9 @@ function InfoMessage:init() HorizontalGroup:new{ align = "center", ImageWidget:new{ - file = "resources/info-i.png" + file = self.image or "resources/info-i.png", + width = self.image_width, + height = self.image_height }, HorizontalSpan:new{ width = 10 }, TextBoxWidget:new{ From 23db9ddcb098eb8fcd1dd99f5731bf8c6f57fd53 Mon Sep 17 00:00:00 2001 From: WS64 Date: Thu, 21 Aug 2014 22:31:47 +0200 Subject: [PATCH 04/12] Parameter to turn "last-book-screensaver" off --- defaults.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/defaults.lua b/defaults.lua index 9c7913baf..635f5830e 100644 --- a/defaults.lua +++ b/defaults.lua @@ -166,8 +166,9 @@ SEARCH_PATH = true -- Light parameter for Kobo KOBO_LIGHT_OFF_ON_SUSPEND = false -KOBO_LIGHT_ON_START = -1 -- -1 or 0-100. -1 leaves light as it is, other sets light on start/wake up -KOBO_SCREEN_SAVER = "" -- image or directory with pictures or "-" +KOBO_LIGHT_ON_START = -1 -- -1 or 0-100. -1 leaves light as it is, other sets light on start/wake up +KOBO_SCREEN_SAVER = "" -- image or directory with pictures or "-" +KOBO_SCREEN_SAVER_LAST_BOOK = true -- get screensaver from last book if possible -- #################################################################### -- following features are not supported right now From db7c97211cee644b7d5e57afa02860e0db2ecab8 Mon Sep 17 00:00:00 2001 From: WS64 Date: Thu, 21 Aug 2014 22:34:00 +0200 Subject: [PATCH 05/12] Add images to info screen --- frontend/apps/filemanager/filemanagersearch.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 082620644..1573301f7 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -8,6 +8,7 @@ local Menu = require("ui/widget/menu") local Screen = require("ui/screen") local _ = require("gettext") local Font = require("ui/font") +local ImageWidget = require("ui/widget/imagewidget") local calibre = "metadata.calibre" local koreaderfile = "temp/metadata.koreader" @@ -541,7 +542,8 @@ function Search:onMenuHold(item) end item.notchecked = false end - UIManager:show(InfoMessage:new{text = item.info}) + UIManager:show(InfoMessage:new{text = item.info,image = UIManager:getPicture(item.path), image_width=240,image_height = 400}) + end end From f5f3e61782c85d3a45a4df63213b8e075990bdc8 Mon Sep 17 00:00:00 2001 From: WS64 Date: Fri, 22 Aug 2014 09:05:00 +0200 Subject: [PATCH 06/12] Removed screensaver functions to new lua file --- frontend/ui/uitoolbox.lua | 125 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 frontend/ui/uitoolbox.lua diff --git a/frontend/ui/uitoolbox.lua b/frontend/ui/uitoolbox.lua new file mode 100644 index 000000000..11fb0320c --- /dev/null +++ b/frontend/ui/uitoolbox.lua @@ -0,0 +1,125 @@ +local InputContainer = require("ui/widget/container/inputcontainer") + +local UIToolbox = InputContainer:new{ +} + +function UIToolbox:getPicture(file) + + local contentopf + local contentpath + local epub_folder = "temp/epub" + + local function check_extension(cover) + if cover then + local itype = string.lower(string.match(cover, ".+%.([^.]+)") or "") + if not (itype == "png" or itype == "jpg" or itype == "jpeg" or itype == "tiff") then + cover = nil + end + end + return cover + end + + local function getValue(zipfile,which_line,to_find,excludecheck) + local f = io.open(zipfile,"r") + local i + + if f then + local line = f:read() + while line and not i do + i = line:lower():find(which_line:lower()) -- found something + if i then + f.close() + line = line:match(to_find .. "\"([^\"]+)\".*") + if not excludecheck then line = check_extension(line) end + if line then + return line + else + i = nil + end + end + if not i then line = f:read() end + end + f.close() + end + end + + local function guess(extension) + local cover = contentpath .. "Images/cover." .. extension + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then + cover = nil + end + return cover + end + + local function try_content_opf(which_line,to_find,addimage) + local cover = getValue(epub_folder .. "/" .. contentopf,which_line,to_find) + local imageadd + if cover then + if addimage then + imageadd = "Images/" + else + imageadd = "" + end + cover = contentpath .. imageadd .. cover + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then cover = nil end + end + return check_extension(cover) + end + + local cover + if file then + pcall(lfs.mkdir("temp")) + pcall(os.execute("rm -rf " .. epub_folder)) + pcall(lfs.mkdir(epub_folder)) + pcall(os.execute("unzip \"" .. file .. "\" cover.jpeg -oq -d " .. epub_folder)) + if io.open(epub_folder .. "/cover.jpeg","r") then -- picture in main folder + cover = epub_folder .. "/cover.jpeg" -- found one + else + pcall(os.execute("unzip \"" .. file .. "\" \"META-INF/container.xml\" -oq -d " .. epub_folder)) -- read container.xml + contentopf = getValue(epub_folder .. "/META-INF/container.xml","^%s* Date: Fri, 22 Aug 2014 09:05:30 +0200 Subject: [PATCH 07/12] Removed screensaver functions to new lua file --- frontend/ui/uimanager.lua | 125 +------------------------------------- 1 file changed, 3 insertions(+), 122 deletions(-) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 97c65c9b4..a18fc8c44 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -6,6 +6,7 @@ local DEBUG = require("dbg") local _ = require("gettext") local util = require("ffi/util") local ImageWidget = require("ui/widget/imagewidget") +local UIToolbox = require("ui/uitoolbox") -- initialize output module, this must be initialized before Input Screen:init() @@ -59,125 +60,6 @@ local UIManager = { suspend_msg = nil } -function UIManager:getPicture(file) - - local contentopf - local contentpath - local epub_folder = "temp/epub" - - local function check_extension(cover) - if cover then - local itype = string.lower(string.match(cover, ".+%.([^.]+)") or "") - if not (itype == "png" or itype == "jpg" or itype == "jpeg" or itype == "tiff") then - cover = nil - end - end - return cover - end - - local function getValue(zipfile,which_line,to_find,excludecheck) - local f = io.open(zipfile,"r") - local i - - if f then - local line = f:read() - while line and not i do - i = line:lower():find(which_line:lower()) -- found something - if i then - f.close() - line = line:match(to_find .. "\"([^\"]+)\".*") - if not excludecheck then line = check_extension(line) end - if line then - return line - else - i = nil - end - end - if not i then line = f:read() end - end - f.close() - end - end - - local function guess(extension) - local cover = contentpath .. "Images/cover." .. extension - pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) - cover = epub_folder .. "/" .. cover - if not io.open(cover,"r") then - cover = nil - end - return cover - end - - local function try_content_opf(which_line,to_find,addimage) - local cover = getValue(epub_folder .. "/" .. contentopf,which_line,to_find) - local imageadd - if cover then - if addimage then - imageadd = "Images/" - else - imageadd = "" - end - cover = contentpath .. imageadd .. cover - pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) - cover = epub_folder .. "/" .. cover - if not io.open(cover,"r") then cover = nil end - end - return check_extension(cover) - end - - local cover - if file then - pcall(lfs.mkdir("temp")) - pcall(os.execute("rm -rf " .. epub_folder)) - pcall(lfs.mkdir(epub_folder)) - pcall(os.execute("unzip \"" .. file .. "\" cover.jpeg -oq -d " .. epub_folder)) - if io.open(epub_folder .. "/cover.jpeg","r") then -- picture in main folder - cover = epub_folder .. "/cover.jpeg" -- found one - else - pcall(os.execute("unzip \"" .. file .. "\" \"META-INF/container.xml\" -oq -d " .. epub_folder)) -- read container.xml - contentopf = getValue(epub_folder .. "/META-INF/container.xml","^%s* Date: Fri, 22 Aug 2014 09:05:59 +0200 Subject: [PATCH 08/12] Removed screensaver functions to new lua file --- frontend/apps/filemanager/filemanagersearch.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 1573301f7..473aa9fc6 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -8,7 +8,8 @@ local Menu = require("ui/widget/menu") local Screen = require("ui/screen") local _ = require("gettext") local Font = require("ui/font") -local ImageWidget = require("ui/widget/imagewidget") +--local ImageWidget = require("ui/widget/imagewidget") +local UIToolbox = require("ui/uitoolbox") local calibre = "metadata.calibre" local koreaderfile = "temp/metadata.koreader" @@ -542,7 +543,7 @@ function Search:onMenuHold(item) end item.notchecked = false end - UIManager:show(InfoMessage:new{text = item.info,image = UIManager:getPicture(item.path), image_width=240,image_height = 400}) + UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width=240,image_height = 400}) end end From 9661616edb3622e6cfd7a399ac4ce54209e8ac57 Mon Sep 17 00:00:00 2001 From: WS64 Date: Fri, 22 Aug 2014 09:07:56 +0200 Subject: [PATCH 09/12] Removed screensaver functions to new lua file --- frontend/apps/filemanager/filemanagersearch.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 473aa9fc6..1a9d1d736 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -8,7 +8,6 @@ local Menu = require("ui/widget/menu") local Screen = require("ui/screen") local _ = require("gettext") local Font = require("ui/font") ---local ImageWidget = require("ui/widget/imagewidget") local UIToolbox = require("ui/uitoolbox") local calibre = "metadata.calibre" From 03c2782844d5983c7fac40644ad16d61277304ee Mon Sep 17 00:00:00 2001 From: WS64 Date: Fri, 22 Aug 2014 18:30:20 +0200 Subject: [PATCH 10/12] Don't show "0: text" in series view but just "text" --- frontend/apps/filemanager/filemanagersearch.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 1a9d1d736..8565a5c21 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -685,7 +685,11 @@ function Search:browse(option,run,chosen) local book = libpath .. self.data[i][self.path] local text if option == "series" then - text = string.format("%6.1f",self.data[i][self.series_index]):gsub(".0$","") .. ": " .. self.data[i][self.title] .. " (" .. self.data[i][self.authors] .. ")" + if self.data[i][self.series_index] == "0.0" then + text = self.data[i][self.title] .. " (" .. self.data[i][self.authors] .. ")" + else + text = string.format("%6.1f",self.data[i][self.series_index]:gsub(".0$","")) .. ": " .. self.data[i][self.title] .. " (" .. self.data[i][self.authors] .. ")" + end else text = self.data[i][self.authors] .. ": " .. self.data[i][self.title] end From 26413adab50bf0b09cb624a7d724627554e88e89 Mon Sep 17 00:00:00 2001 From: WS64 Date: Sat, 23 Aug 2014 08:50:51 +0200 Subject: [PATCH 11/12] resolve github inconsistencies --- frontend/ui/uimanager.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index a18fc8c44..0bbec23f2 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -351,7 +351,7 @@ function UIManager:run() -- stop when we have no window to show if #self._window_stack == 0 then - DEBUG("no dialog left to show") + DEBUG("no dialog left to show, would loop endlessly") self:quit() return nil end @@ -529,3 +529,4 @@ end UIManager:init() return UIManager + From 1a71b3e5035a8919138a896ed8da00eec2ff2628 Mon Sep 17 00:00:00 2001 From: WS64 Date: Sat, 23 Aug 2014 09:01:58 +0200 Subject: [PATCH 12/12] resolve github inconsistencies --- frontend/ui/widget/imagewidget.lua | 56 +++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/frontend/ui/widget/imagewidget.lua b/frontend/ui/widget/imagewidget.lua index cddd0d1cd..fb10c3f6e 100644 --- a/frontend/ui/widget/imagewidget.lua +++ b/frontend/ui/widget/imagewidget.lua @@ -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