From 819efb55aa65447b06c18927517cf9b67861ebbc Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Wed, 26 Sep 2012 14:08:33 +0100 Subject: [PATCH 1/3] Tidy up Screen:fb2bmp() function 1. Remove unused assert() around io.open of the input device. The failure to open input device is already guarded by the "if inputf" code. 2. Remove unneeded assert() around io.open of the output device. This is unneeded because we should not crash the whole application just because we cannot write screen dump (e.g. because filesystem is full, etc) --- rather we should exit gracefully. --- screen.lua | 64 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/screen.lua b/screen.lua index 2282861c6..9f34322cd 100644 --- a/screen.lua +++ b/screen.lua @@ -146,41 +146,43 @@ a vertical flip that makes it a bit slower, namely, NB: needs free memory of G_width*G_height/2 bytes to manupulate the fb-content! ]] function Screen:fb2bmp(fin, fout, vflip, pack) -- atm, for 4bpp framebuffers only - local inputf = assert(io.open(fin,"rb")) + local inputf = io.open(fin,"rb") if inputf then - local outputf, size = assert(io.open(fout,"wb")) - -- writing bmp-header - outputf:write(string.char(0x42,0x4D,0xF6,0xA9,3,0,0,0,0,0,0x76,0,0,0,40,0), - self:LE(G_width), self:LE(G_height), -- width & height: 4 chars each - string.char(0,0,1,0,4,0,0,0,0,0), - self:LE(G_height*G_width/2), -- raw bytes in image - string.char(0x87,0x19,0,0,0x87,0x19,0,0), -- 6536 pixel/m = 166 dpi for both x&y resolutions - string.char(16,0,0,0,0,0,0,0)) -- 16 colors - local line, i = G_width/2, 15 - -- add palette to bmp-header - while i>=0 do - outputf:write(string.char(i*16+i):rep(3), string.char(0)) - i=i-1 - end - if vflip then -- flip image vertically to make it bmp-compliant - -- read the fb-content line-by-line & fill the content-table in the inversed order - local content = {} - for i=1, G_height do - table.insert(content, 1, inputf:read(line)) + local outputf, size = io.open(fout,"wb") + if outputf then + -- writing bmp-header + outputf:write(string.char(0x42,0x4D,0xF6,0xA9,3,0,0,0,0,0,0x76,0,0,0,40,0), + self:LE(G_width), self:LE(G_height), -- width & height: 4 chars each + string.char(0,0,1,0,4,0,0,0,0,0), + self:LE(G_height*G_width/2), -- raw bytes in image + string.char(0x87,0x19,0,0,0x87,0x19,0,0), -- 6536 pixel/m = 166 dpi for both x&y resolutions + string.char(16,0,0,0,0,0,0,0)) -- 16 colors + local line, i = G_width/2, 15 + -- add palette to bmp-header + while i>=0 do + outputf:write(string.char(i*16+i):rep(3), string.char(0)) + i=i-1 end - -- write the v-flipped bmp-data - for i=1, G_height do - outputf:write(content[i]) + if vflip then -- flip image vertically to make it bmp-compliant + -- read the fb-content line-by-line & fill the content-table in the inversed order + local content = {} + for i=1, G_height do + table.insert(content, 1, inputf:read(line)) + end + -- write the v-flipped bmp-data + for i=1, G_height do + outputf:write(content[i]) + end + else -- without v-flip, it takes only 0.02s @ 600x800, 4bpp + outputf:write(inputf:read("*all")) end - else -- without v-flip, it takes only 0.02s @ 600x800, 4bpp - outputf:write(inputf:read("*all")) - end + outputf:close() + -- here one may use either standard archivers (bzip2, gzip) + -- or standalone converters (bmp2png, bmp2gif) + if pack then os.execute(pack..fout) end + end -- if output f inputf:close() - outputf:close() - -- here one may use either standard archivers (bzip2, gzip) - -- or standalone converters (bmp2png, bmp2gif) - if pack then os.execute(pack..fout) end - end + end -- if inputf end --[[ This function saves the fb-content (both 4bpp and 8bpp) as 8bpp PGM and pack it. From 0987c2826edc89298c5824871829355bb8a7ca8c Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Wed, 26 Sep 2012 15:58:51 +0100 Subject: [PATCH 2/3] Don't crash on pressing Del in History After deleting all the entries from History we should guard against pressing Del to try to delete a non-existent entry. --- filehistory.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/filehistory.lua b/filehistory.lua index cf2e5b6db..ca71b3837 100644 --- a/filehistory.lua +++ b/filehistory.lua @@ -220,6 +220,7 @@ function FileHistory:addAllCommands() "delete history entry", function(self) file_entry = self.result[self.perpage*(self.page-1)+self.current] + if not file_entry then return end local file_to_del = file_entry.dir .. "/" .. file_entry.name os.remove(DocToHistory(file_to_del)) -- to avoid showing just deleted file From 5d82ffe984a4d3105a5315bc3ccb0dbe47c9021d Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Wed, 26 Sep 2012 16:05:07 +0100 Subject: [PATCH 3/3] Redraw current page if necessary on pressing Back For PDF and DjVu files (but not for crereader) the command handler for "Back" key can call addJump() in order to avoid losing the top of the jump history on return. This (addJump()) can cause the TOC to be retrieved and the message "Retrieving TOC..." to be displayed. If this happens then we need to redraw the current page after displaying our own "Already first jump!" message. --- unireader.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unireader.lua b/unireader.lua index ed8393e16..933772603 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2261,7 +2261,13 @@ function UniReader:addAllCommands() "go backward in jump history", function(unireader) local prev_jump_no = 0 + local need_refresh = false if unireader.jump_history.cur > #unireader.jump_history then + -- addJump() will cause a "Retrieving TOC..." msg, so we'll + -- need to redraw the page after our own + -- ifo msg "Already first jump!" below + if not self.toc then need_refresh = true end + -- if cur points to head, put current page in history unireader:addJump(self.pageno) prev_jump_no = unireader.jump_history.cur - 2 @@ -2274,6 +2280,9 @@ function UniReader:addAllCommands() unireader:goto(unireader.jump_history[prev_jump_no].page, true) else showInfoMsgWithDelay("Already first jump!", 2000, 1) + if need_refresh then + unireader:redrawCurrentPage() + end end end) self.commands:add(KEY_BACK,MOD_SHIFT,"Back",