From f996a69568004784be7c1a328f4c6f8645fd60f2 Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Sun, 1 Jul 2012 20:49:55 +0300 Subject: [PATCH 01/10] add BMP and PGM methods. Use BMP in screenshot method Update master Conflicts: screen.lua --- screen.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/screen.lua b/screen.lua index 46a951d1f..d16ba7001 100644 --- a/screen.lua +++ b/screen.lua @@ -109,7 +109,64 @@ end function Screen:screenshot() lfs.mkdir("./screenshots") - local d = os.date("%Y%m%d%H%M%S") - showInfoMsgWithDelay("making screenshot... ", 1000, 1) - os.execute("dd ".."if=/dev/fb0 ".."of=/mnt/us/kindlepdfviewer/screenshots/" .. d .. ".raw") + local start = os.clock() + --showInfoMsgWithDelay("making screenshot... ", 2500, 1) + self:BMP(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", "bzip2 ") + showInfoMsgWithDelay(string.format("BMP-shot ready in %.2f(s)", os.clock()-start), 1000, 1) +end + +function Screen:BMP(fn, pack) -- ~1.6-1.8(s), @ Kindle3, 600x800, remains 4bpp + local inputf = assert(io.open("/dev/fb0","rb")) + if inputf then + local outputf = assert(io.open(fn,"wb")) + -- writing header + outputf:write("BM", string.char(246), string.char(169), string.char(3), string.rep(string.char(0),5), + string.char(118), string.rep(string.char(0),3), string.char(40), string.char(0), + string.rep(string.char(0),2), string.char(G_width%256), string.char((G_width-G_width%256)/256), -- width + string.rep(string.char(0),2), string.char(G_height%256), string.char((G_height-G_height%256)/256), -- height + string.rep(string.char(0),2), string.char(1), string.char(0), string.char(4), string.rep(string.char(0),5), + string.char(128), string.char(169), string.char(3), string.char(0), + string.char(135), string.char(25), string.rep(string.char(0),2), string.char(135), string.char(25), + string.rep(string.char(0), 2), string.char(16), string.rep(string.char(0),7)) + local block, i = G_width/2, 15 + -- add palette to header + while i>=0 do + outputf:write(string.rep(string.char(i*16+i),3), string.char(0)) + i=i-1 + end + -- now read fb0-content & invert the line order (i.e. make a vertical flip) + local content = "" + for i=1, G_height do + content = inputf:read(block)..content + end + -- write v-flipped bmp-data to the output file + outputf:write(content) + inputf:close() + outputf:close() + if pack then os.execute(pack..fn) end + end +end + +function Screen:PGM(fn, pack) -- ~2.5(s) @ Kindle3, 600x800 slow because of 4bpp to 8bpp conversion + local inputf = assert(io.open("/dev/fb0","rb")) + if inputf then + local outputf = assert(io.open(fn,"wb")) + outputf:write("P5\n\# Created by kindlepdfviewer\n"..G_width.." "..G_height.."\n255\n") + local bpp8, block, i, j, line = {}, G_width/2 + -- create convertion table: char > 2 chars + for j=0, 255 do + i = j%16 + bpp8[#bpp8+1] = string.char(255-j+i)..string.char(255-i*16) + end + -- now read, convert & write the fb0-content by blocks + for i=1, G_height do + line = inputf:read(block) + for j=1, block do + outputf:write(bpp8[1+string.byte(line,j)]) + end + end + inputf:close() + outputf:close() + if pack then os.execute(pack..fn) end + end end From e580a7c27877ebd88f052b33c4454feded1f4db5 Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Mon, 2 Jul 2012 09:35:26 +0300 Subject: [PATCH 02/10] Update master: fixes for BMP method --- screen.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/screen.lua b/screen.lua index d16ba7001..9dee59284 100644 --- a/screen.lua +++ b/screen.lua @@ -109,17 +109,17 @@ end function Screen:screenshot() lfs.mkdir("./screenshots") - local start = os.clock() - --showInfoMsgWithDelay("making screenshot... ", 2500, 1) + --local start = os.clock() + showInfoMsgWithDelay("making screenshot... ", 1000, 1) self:BMP(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", "bzip2 ") - showInfoMsgWithDelay(string.format("BMP-shot ready in %.2f(s)", os.clock()-start), 1000, 1) + --showInfoMsgWithDelay(string.format("Screenshot is ready in %.2f(s) ", os.clock()-start), 1000, 1) end -function Screen:BMP(fn, pack) -- ~1.6-1.8(s), @ Kindle3, 600x800, remains 4bpp +function Screen:BMP(fn, pack) -- ~0.1-0.2(s) @ Kindle3 (600x800) BMP remains 4bpp local inputf = assert(io.open("/dev/fb0","rb")) if inputf then local outputf = assert(io.open(fn,"wb")) - -- writing header + -- writing the bmp-header outputf:write("BM", string.char(246), string.char(169), string.char(3), string.rep(string.char(0),5), string.char(118), string.rep(string.char(0),3), string.char(40), string.char(0), string.rep(string.char(0),2), string.char(G_width%256), string.char((G_width-G_width%256)/256), -- width @@ -134,13 +134,15 @@ function Screen:BMP(fn, pack) -- ~1.6-1.8(s), @ Kindle3, 600x800, remains 4bpp outputf:write(string.rep(string.char(i*16+i),3), string.char(0)) i=i-1 end - -- now read fb0-content & invert the line order (i.e. make a vertical flip) - local content = "" + -- now read fb0-content & fill the table in the reversed line order (i.e. make a vertical flip) + local content = {} for i=1, G_height do - content = inputf:read(block)..content + table.insert(content, 1, inputf:read(block)) end -- write v-flipped bmp-data to the output file - outputf:write(content) + for i=1, G_height do + outputf:write(content[i]) + end inputf:close() outputf:close() if pack then os.execute(pack..fn) end From 13ac163c5198f166713add5b109255c265bae7ba Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Wed, 4 Jul 2012 20:35:01 +0300 Subject: [PATCH 03/10] save screenshots to bmp (or pgm) --- screen.lua | 84 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/screen.lua b/screen.lua index 9dee59284..69978bc88 100644 --- a/screen.lua +++ b/screen.lua @@ -107,39 +107,56 @@ function Screen:restoreFromBB(bb) end end + function Screen:screenshot() lfs.mkdir("./screenshots") --local start = os.clock() showInfoMsgWithDelay("making screenshot... ", 1000, 1) - self:BMP(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", "bzip2 ") + self:BMP(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", "bzip2 ") -- fastest for 4bpp devices + --self:PGM(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".pgm", "bzip2 ",8) -- fastest for 8bpp devices --showInfoMsgWithDelay(string.format("Screenshot is ready in %.2f(s) ", os.clock()-start), 1000, 1) end -function Screen:BMP(fn, pack) -- ~0.1-0.2(s) @ Kindle3 (600x800) BMP remains 4bpp +-- NuPogodi (02.07.2012): added the functions to save the fb-content in common graphic files - bmp & pgm. +-- todo: to look for the arm-compiled bmp2png converter & to use it instead of the current bzip2-packer. + +function Screen:LE(i) -- returns value in the little-endian binary sequence (4chars) + local j=i%256 -- lowest byte + return string.char(0,0,j,(i-j)/256) +end + +--[[ This function saves the 4bpp framebuffer as 4bpp BMP and, if necessary, packes the output by command os.execute(pack..fn). +Since framebuffer enumerates the lines from top to bottom and the bmp-file does it in the inversed order, the process includes +a vertical flip that makes it a bit slower - ~0.15(s) @ Kindle3 & Kindle2. +NB: needs free memory of G_width*G_height/2 bytes to manupulate the fb-content! ]] + +function Screen:BMP(fn, pack) -- for 4bpp framebuffers only local inputf = assert(io.open("/dev/fb0","rb")) if inputf then - local outputf = assert(io.open(fn,"wb")) - -- writing the bmp-header - outputf:write("BM", string.char(246), string.char(169), string.char(3), string.rep(string.char(0),5), - string.char(118), string.rep(string.char(0),3), string.char(40), string.char(0), - string.rep(string.char(0),2), string.char(G_width%256), string.char((G_width-G_width%256)/256), -- width - string.rep(string.char(0),2), string.char(G_height%256), string.char((G_height-G_height%256)/256), -- height - string.rep(string.char(0),2), string.char(1), string.char(0), string.char(4), string.rep(string.char(0),5), - string.char(128), string.char(169), string.char(3), string.char(0), - string.char(135), string.char(25), string.rep(string.char(0),2), string.char(135), string.char(25), - string.rep(string.char(0), 2), string.char(16), string.rep(string.char(0),7)) - local block, i = G_width/2, 15 - -- add palette to header + local outputf, size = assert(io.open(fn,"wb")) + if math.max(G_width,G_height)>1000 then -- KDX(G) + size=string.char(0x0F,0x1B,3,0) -- 0x00,0x72,0x06,0x00 > raw bytes in image 825*1200/2 = 0x000F1B30 @ KDX(G) + else -- 600x800 + size=string.char(0x80,0xA9,3,0) -- 0x80,0xA9,0x03,0x00 > raw bytes in image 600*800/2 = 0x0003A980 @ K2&3 + end + -- 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), size, + string.char(0x87,0x19,0,0,0x87,0x19,0,0), -- 0x87,0x19,0x00,0x00 = 6536 pix/m = 166 dpi - resolution_x, res_y + 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.rep(string.char(i*16+i),3), string.char(0)) + outputf:write(string.char(i*16+i):rep(3), string.char(0)) i=i-1 end - -- now read fb0-content & fill the table in the reversed line order (i.e. make a vertical flip) + -- 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(block)) + table.insert(content, 1, inputf:read(line)) end - -- write v-flipped bmp-data to the output file + -- write the v-flipped bmp-data for i=1, G_height do outputf:write(content[i]) end @@ -149,22 +166,29 @@ function Screen:BMP(fn, pack) -- ~0.1-0.2(s) @ Kindle3 (600x800) BMP remains 4bp end end -function Screen:PGM(fn, pack) -- ~2.5(s) @ Kindle3, 600x800 slow because of 4bpp to 8bpp conversion +--[[ This function saves the fb-content (both 4bpp and 8bpp) as 8bpp PGM and pack it. It's relatively slow for 4bpp devices +(~2.5s on Kindle3, 600x800, 4bpp), but should be extremely fast (<0.1s) when no 4bbp to 8bpp is needed. ]] + +function Screen:PGM(fn, pack, bpp) local inputf = assert(io.open("/dev/fb0","rb")) if inputf then local outputf = assert(io.open(fn,"wb")) outputf:write("P5\n\# Created by kindlepdfviewer\n"..G_width.." "..G_height.."\n255\n") - local bpp8, block, i, j, line = {}, G_width/2 - -- create convertion table: char > 2 chars - for j=0, 255 do - i = j%16 - bpp8[#bpp8+1] = string.char(255-j+i)..string.char(255-i*16) - end - -- now read, convert & write the fb0-content by blocks - for i=1, G_height do - line = inputf:read(block) - for j=1, block do - outputf:write(bpp8[1+string.byte(line,j)]) + if bpp == 8 then -- needs free memory of G_width*G_height bytes! + outputf:write(inputf:read("*all")) + else -- convert 4bpp to 8bpp; needs free memory to store a block = G_width/2 bytes (could be changed) + local bpp8, block, i, j, line = {}, G_width/2 + -- to accelerate a process, let us first create the convertion table: char (0..255) > 2 chars + for j=0, 255 do + i = j%16 + bpp8[#bpp8+1] = string.char(255-j+i)..string.char(255-i*16) + end + -- now read, convert & write the fb0-content by blocks + for i=1, G_height do + line = inputf:read(block) + for j=1, block do + outputf:write(bpp8[1+string.byte(line,j)]) + end end end inputf:close() From ead3355a2b5308f679e3a7f1484a2d761dd70811 Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Wed, 4 Jul 2012 20:40:14 +0300 Subject: [PATCH 04/10] Update master --- screen.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screen.lua b/screen.lua index 69978bc88..67c1734dd 100644 --- a/screen.lua +++ b/screen.lua @@ -135,7 +135,7 @@ function Screen:BMP(fn, pack) -- for 4bpp framebuffers only if inputf then local outputf, size = assert(io.open(fn,"wb")) if math.max(G_width,G_height)>1000 then -- KDX(G) - size=string.char(0x0F,0x1B,3,0) -- 0x00,0x72,0x06,0x00 > raw bytes in image 825*1200/2 = 0x000F1B30 @ KDX(G) + size=string.char(0x98,0x8D,7,0) -- 0x00,0x72,0x06,0x00 > raw bytes in image 825*1200/2 = 0x00078D98 @ KDX(G) else -- 600x800 size=string.char(0x80,0xA9,3,0) -- 0x80,0xA9,0x03,0x00 > raw bytes in image 600*800/2 = 0x0003A980 @ K2&3 end From 2e975fa18df5f36d52c91c26f3bba7707b630f51 Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Wed, 4 Jul 2012 20:47:29 +0300 Subject: [PATCH 05/10] Update master --- screen.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/screen.lua b/screen.lua index 67c1734dd..0538223a9 100644 --- a/screen.lua +++ b/screen.lua @@ -110,11 +110,11 @@ end function Screen:screenshot() lfs.mkdir("./screenshots") - --local start = os.clock() - showInfoMsgWithDelay("making screenshot... ", 1000, 1) + local start = os.clock() + --showInfoMsgWithDelay("making screenshot... ", 1000, 1) self:BMP(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", "bzip2 ") -- fastest for 4bpp devices --self:PGM(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".pgm", "bzip2 ",8) -- fastest for 8bpp devices - --showInfoMsgWithDelay(string.format("Screenshot is ready in %.2f(s) ", os.clock()-start), 1000, 1) + showInfoMsgWithDelay(string.format("Screenshot is ready in %.2f(s) ", os.clock()-start), 1000, 1) end -- NuPogodi (02.07.2012): added the functions to save the fb-content in common graphic files - bmp & pgm. From 17585c2bf430a4b559eb9e8b1b8516a393232f76 Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Wed, 4 Jul 2012 20:50:19 +0300 Subject: [PATCH 06/10] Update master for comment on image size --- screen.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screen.lua b/screen.lua index 0538223a9..fc93e4957 100644 --- a/screen.lua +++ b/screen.lua @@ -135,9 +135,9 @@ function Screen:BMP(fn, pack) -- for 4bpp framebuffers only if inputf then local outputf, size = assert(io.open(fn,"wb")) if math.max(G_width,G_height)>1000 then -- KDX(G) - size=string.char(0x98,0x8D,7,0) -- 0x00,0x72,0x06,0x00 > raw bytes in image 825*1200/2 = 0x00078D98 @ KDX(G) + size=string.char(0x98,0x8D,7,0) -- raw bytes in image 825*1200/2 = 0x00078D98 @ KDX(G) else -- 600x800 - size=string.char(0x80,0xA9,3,0) -- 0x80,0xA9,0x03,0x00 > raw bytes in image 600*800/2 = 0x0003A980 @ K2&3 + size=string.char(0x80,0xA9,3,0) -- raw bytes in image 600*800/2 = 0x0003A980 @ K2&3 end -- writing bmp-header outputf:write(string.char(0x42,0x4D,0xF6,0xA9,3,0,0,0,0,0,0x76,0,0,0,40,0), From 333537dfd6fbb428eee6b142096efb7fa838a7d6 Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Thu, 5 Jul 2012 15:31:44 +0300 Subject: [PATCH 07/10] to save screenshots as bmp (4bpp, 166dpi > fast) or pgm (8bpp, slow) --- screen.lua | 68 +++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/screen.lua b/screen.lua index fc93e4957..71535b57f 100644 --- a/screen.lua +++ b/screen.lua @@ -107,43 +107,38 @@ function Screen:restoreFromBB(bb) end end +-- NuPogodi (02.07.2012): functions to save the fb-content as common graphic files - bmp & pgm. +-- ToDo: png, gif ? -function Screen:screenshot() - lfs.mkdir("./screenshots") - local start = os.clock() - --showInfoMsgWithDelay("making screenshot... ", 1000, 1) - self:BMP(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", "bzip2 ") -- fastest for 4bpp devices - --self:PGM(lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".pgm", "bzip2 ",8) -- fastest for 8bpp devices - showInfoMsgWithDelay(string.format("Screenshot is ready in %.2f(s) ", os.clock()-start), 1000, 1) -end - --- NuPogodi (02.07.2012): added the functions to save the fb-content in common graphic files - bmp & pgm. --- todo: to look for the arm-compiled bmp2png converter & to use it instead of the current bzip2-packer. - -function Screen:LE(i) -- returns value in the little-endian binary sequence (4chars) - local j=i%256 -- lowest byte - return string.char(0,0,j,(i-j)/256) +function Screen:LE(x) -- converts positive upto 32bit-number to a little-endian for bmp-header + local s, n = "", 4 + if x<0x10000 then + s = string.char(0,0) + n = 2 + end + x = math.floor(x) + for i = 1,n do + s = s..string.char(x%256) + x = math.floor(x/256) + end + return s end --[[ This function saves the 4bpp framebuffer as 4bpp BMP and, if necessary, packes the output by command os.execute(pack..fn). Since framebuffer enumerates the lines from top to bottom and the bmp-file does it in the inversed order, the process includes -a vertical flip that makes it a bit slower - ~0.15(s) @ Kindle3 & Kindle2. +a vertical flip that makes it a bit slower - ~0.16(s) @ Kindle3 & Kindle2. NB: needs free memory of G_width*G_height/2 bytes to manupulate the fb-content! ]] -function Screen:BMP(fn, pack) -- for 4bpp framebuffers only - local inputf = assert(io.open("/dev/fb0","rb")) +function Screen:fb2bmp(fin, fout, pack) -- atm, for 4bpp framebuffers only + local inputf = assert(io.open(fin,"rb")) if inputf then - local outputf, size = assert(io.open(fn,"wb")) - if math.max(G_width,G_height)>1000 then -- KDX(G) - size=string.char(0x98,0x8D,7,0) -- raw bytes in image 825*1200/2 = 0x00078D98 @ KDX(G) - else -- 600x800 - size=string.char(0x80,0xA9,3,0) -- raw bytes in image 600*800/2 = 0x0003A980 @ K2&3 - end + 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), size, - string.char(0x87,0x19,0,0,0x87,0x19,0,0), -- 0x87,0x19,0x00,0x00 = 6536 pix/m = 166 dpi - resolution_x, res_y + string.char(0,0,1,0,4,0,0,0,0,0), + self:LE(G_width*G_height/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 @@ -162,28 +157,28 @@ function Screen:BMP(fn, pack) -- for 4bpp framebuffers only end inputf:close() outputf:close() - if pack then os.execute(pack..fn) end + if pack then os.execute(pack..fout) end end end --[[ This function saves the fb-content (both 4bpp and 8bpp) as 8bpp PGM and pack it. It's relatively slow for 4bpp devices -(~2.5s on Kindle3, 600x800, 4bpp), but should be extremely fast (<0.1s) when no 4bbp to 8bpp is needed. ]] +(~2.5s on Kindle3, 600x800, 4bpp), but should be extremely fast (<0.1s) when no color conversion (4bpp>8bpp) is needed. ]] -function Screen:PGM(fn, pack, bpp) - local inputf = assert(io.open("/dev/fb0","rb")) +function Screen:fb2pgm(fin, fout, pack, bpp) + local inputf = assert(io.open(fin,"rb")) if inputf then - local outputf = assert(io.open(fn,"wb")) + local outputf = assert(io.open(fout,"wb")) outputf:write("P5\n\# Created by kindlepdfviewer\n"..G_width.." "..G_height.."\n255\n") - if bpp == 8 then -- needs free memory of G_width*G_height bytes! + if bpp == 8 then -- then needs free memory of G_width*G_height bytes, but extremely fast! outputf:write(inputf:read("*all")) - else -- convert 4bpp to 8bpp; needs free memory to store a block = G_width/2 bytes (could be changed) + else -- convert 4bpp to 8bpp; needs free memory just to store a block = G_width/2 bytes local bpp8, block, i, j, line = {}, G_width/2 -- to accelerate a process, let us first create the convertion table: char (0..255) > 2 chars for j=0, 255 do i = j%16 - bpp8[#bpp8+1] = string.char(255-j+i)..string.char(255-i*16) + bpp8[#bpp8+1] = string.char(255-j+i, 255-i*16) end - -- now read, convert & write the fb0-content by blocks + -- now read, convert & write the fb-content by blocks for i=1, G_height do line = inputf:read(block) for j=1, block do @@ -193,6 +188,7 @@ function Screen:PGM(fn, pack, bpp) end inputf:close() outputf:close() - if pack then os.execute(pack..fn) end + if pack then os.execute(pack..fout) end end end + From c06605e86c196c6f58d205aba40972f4275becdd Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Fri, 6 Jul 2012 22:16:31 +0300 Subject: [PATCH 08/10] Update master --- screen.lua | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/screen.lua b/screen.lua index 71535b57f..f93cbf13a 100644 --- a/screen.lua +++ b/screen.lua @@ -107,7 +107,17 @@ function Screen:restoreFromBB(bb) end end --- NuPogodi (02.07.2012): functions to save the fb-content as common graphic files - bmp & pgm. + +function Screen:screenshot() + lfs.mkdir("./screenshots") + local start = os.clock() + --showInfoMsgWithDelay("making screenshot... ", 1000, 1) + self:fb2bmp("/dev/fb0", lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", true, "bzip2 ") + --self:fb2pgm("/dev/fb0", lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".pgm", "bzip2 ", 4) + showInfoMsgWithDelay(string.format("Screenshot is ready in %.2f(s) ", os.clock()-start), 1000, 1) +end + +-- NuPogodi (02.07.2012): added the functions to save the fb-content in common graphic files - bmp & pgm. -- ToDo: png, gif ? function Screen:LE(x) -- converts positive upto 32bit-number to a little-endian for bmp-header @@ -126,10 +136,12 @@ end --[[ This function saves the 4bpp framebuffer as 4bpp BMP and, if necessary, packes the output by command os.execute(pack..fn). Since framebuffer enumerates the lines from top to bottom and the bmp-file does it in the inversed order, the process includes -a vertical flip that makes it a bit slower - ~0.16(s) @ Kindle3 & Kindle2. +a vertical flip that makes it a bit slower, namely, + ~0.16(s) @ Kindle3 & Kindle2 (600x800) ~0.02s @ without v-flip + ~0.36(s) @ Kindle DX (824x1200) NB: needs free memory of G_width*G_height/2 bytes to manupulate the fb-content! ]] -function Screen:fb2bmp(fin, fout, pack) -- atm, for 4bpp framebuffers only +function Screen:fb2bmp(fin, fout, vflip, pack) -- atm, for 4bpp framebuffers only local inputf = assert(io.open(fin,"rb")) if inputf then local outputf, size = assert(io.open(fout,"wb")) @@ -137,7 +149,7 @@ function Screen:fb2bmp(fin, fout, pack) -- atm, for 4bpp framebuffers only 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_width*G_height/2), -- raw bytes in image + 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 @@ -146,23 +158,32 @@ function Screen:fb2bmp(fin, fout, pack) -- atm, for 4bpp framebuffers only outputf:write(string.char(i*16+i):rep(3), string.char(0)) i=i-1 end - -- 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]) + 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 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 ---[[ This function saves the fb-content (both 4bpp and 8bpp) as 8bpp PGM and pack it. It's relatively slow for 4bpp devices -(~2.5s on Kindle3, 600x800, 4bpp), but should be extremely fast (<0.1s) when no color conversion (4bpp>8bpp) is needed. ]] +--[[ This function saves the fb-content (both 4bpp and 8bpp) as 8bpp PGM and pack it. +It's relatively slow for 4bpp devices such as + ~2.5s @ K2 and K3 > 600x800, 4bpp + ~5.0s @ KDX > 824x1200, +but should be very fast (<<0.1s) when no color conversion (4bpp>8bpp) is needed. ]] function Screen:fb2pgm(fin, fout, pack, bpp) local inputf = assert(io.open(fin,"rb")) From 7a3de8b6b7904fd71d2b47f642e6d57a73eda67e Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 26 Aug 2012 00:21:48 +0800 Subject: [PATCH 09/10] move battery info file to /tmp --- filechooser.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/filechooser.lua b/filechooser.lua index 1b6b28fe2..9f3de8780 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -50,7 +50,7 @@ function getProperTitleLength(txt,font_face,max_width) end function BatteryLevel() - local fn, battery = "./data/temporary", "?" + local fn, battery = "/tmp/kindle-battery-info", "?" -- NuPogodi, 18.05.12: This command seems to work even without Amazon Kindle framework os.execute("(gasgauge-info ".."-s) ".."> "..fn) if io.open(fn,"r") then @@ -200,7 +200,6 @@ function FileChooser:choose(ypos, height) if i <= #self.dirs then DrawFileItem(self.dirs[i],self.margin_H,ypos+self.title_H+self.spacing*c,"folder") elseif i <= self.items then - print("-----", self.files[i-#self.dirs]) local file_type = string.lower(string.match(self.files[i-#self.dirs], ".+%.([^.]+)") or "") DrawFileItem(self.files[i-#self.dirs],self.margin_H,ypos+self.title_H+self.spacing*c,file_type) end From 5be38246f556d1ae98b0b08ace84ff06ce726f58 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 26 Aug 2012 03:19:59 +0800 Subject: [PATCH 10/10] fix comment in screen.lua set default to no pack on bmp image --- screen.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/screen.lua b/screen.lua index f93cbf13a..621d84926 100644 --- a/screen.lua +++ b/screen.lua @@ -112,7 +112,8 @@ function Screen:screenshot() lfs.mkdir("./screenshots") local start = os.clock() --showInfoMsgWithDelay("making screenshot... ", 1000, 1) - self:fb2bmp("/dev/fb0", lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", true, "bzip2 ") + self:fb2bmp("/dev/fb0", lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", true, nil) + --self:fb2bmp("/dev/fb0", lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".bmp", true, "bzip2 ") --self:fb2pgm("/dev/fb0", lfs.currentdir().."/screenshots/"..os.date("%Y%m%d%H%M%S")..".pgm", "bzip2 ", 4) showInfoMsgWithDelay(string.format("Screenshot is ready in %.2f(s) ", os.clock()-start), 1000, 1) end @@ -189,7 +190,7 @@ function Screen:fb2pgm(fin, fout, pack, bpp) local inputf = assert(io.open(fin,"rb")) if inputf then local outputf = assert(io.open(fout,"wb")) - outputf:write("P5\n\# Created by kindlepdfviewer\n"..G_width.." "..G_height.."\n255\n") + outputf:write("P5\n# Created by kindlepdfviewer\n"..G_width.." "..G_height.."\n255\n") if bpp == 8 then -- then needs free memory of G_width*G_height bytes, but extremely fast! outputf:write(inputf:read("*all")) else -- convert 4bpp to 8bpp; needs free memory just to store a block = G_width/2 bytes