Quote:
Originally Posted by NiLuJe
@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