View Single Post
Old 09-01-2020, 08:19 AM   #34
pazos
cosiņeiro
pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.
 
Posts: 1,406
Karma: 2451781
Join Date: Apr 2014
Device: BQ Cervantes 4
Quote:
Originally Posted by NiLuJe View Post
@pazos: The second hunk does make sense, but it's missing getting the width/height from buffer, too, because right now it uses the image buffer but with the framebuffer's dimensions .

(Which I realize may be the point, but then what happens if image buffer's dimension != framebuffer's dimension?)
It seems that I was lucky on my tests. A "cover" that doesn't match framebuffer dimension is attached.

And the proper code, as suggested, would be:

Code:
--- a/ffi/blitbuffer.lua
+++ b/ffi/blitbuffer.lua
@@ -1760,17 +1760,19 @@ write blitbuffer contents to a PNG file
 @param filename the name of the file to be created
 --]]
 local Png  -- lazy load ffi/png
-function BB_mt.__index:writePNG(filename, bgr)
+function BB_mt.__index:writePNG(filename, bgr, buffer)
     if not Png then Png = require("ffi/png") end
     local hook, mask, _ = debug.gethook()
     debug.sethook()
-    local w, h = self:getWidth(), self:getHeight()
+    local w = buffer and buffer:getWidth() or self:getWidth()
+    local h = buffer and buffer:getHeight() or self:getHeight()
     local cdata = C.malloc(w * h * 4)
     local mem = ffi.cast("char*", cdata)
     for y = 0, h-1 do
         local offset = 4 * w * y
         for x = 0, w-1 do
-            local c = self:getPixel(x, y):getColorRGB32()
+            local c = buffer and buffer:getPixel(x, y):getColorRGB32() or
+                self:getPixel(x, y):getColorRGB32()
             -- NOTE: Kobo's FB is BGR(A), we already trick MuPDF into doing it that way for us, so, keep faking it here!
             if bgr then
                 mem[offset] = c.b
Attached Thumbnails
Click image for larger version

Name:	test2.png
Views:	194
Size:	178.9 KB
ID:	181684  
pazos is offline   Reply With Quote