Skip to content

Commit

Permalink
BlitBuffer: tweak debug hook handling (koreader#1210)
Browse files Browse the repository at this point in the history
* Drop unused variable
* Avoid possibly maybe eventually shadowing a "mask" variable.
  • Loading branch information
NiLuJe committed Oct 6, 2020
1 parent f89af6f commit 1096538
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions ffi/blitbuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ end

function BB_mt.__index:blitDefault(dest, dest_x, dest_y, offs_x, offs_y, width, height, setter, set_param)
-- slow default variant:
local hook, mask, count = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()
local o_y = offs_y
for y = dest_y, dest_y+height-1 do
Expand All @@ -984,7 +984,7 @@ function BB_mt.__index:blitDefault(dest, dest_x, dest_y, offs_x, offs_y, width,
end
o_y = o_y + 1
end
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end
-- no optimized blitting by default:
BB_mt.__index.blitTo4 = BB_mt.__index.blitDefault
Expand Down Expand Up @@ -1259,7 +1259,7 @@ function BB_mt.__index:invertRect(x, y, w, h)
cblitbuffer.BB_invert_rect(ffi.cast("struct BlitBuffer *", self),
x, y, w, h)
else
local hook, mask, count = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()
-- Handle rotation...
x, y, w, h = self:getPhysicalRect(x, y, w, h)
Expand Down Expand Up @@ -1326,7 +1326,7 @@ function BB_mt.__index:invertRect(x, y, w, h)
end
end
end
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end
end

Expand Down Expand Up @@ -1359,7 +1359,7 @@ function BB_mt.__index:paintRect(x, y, w, h, value, setter)
cblitbuffer.BB_fill_rect(ffi.cast("struct BlitBuffer *", self),
x, y, w, h, value:getColor8().a)
else
local hook, mask, count = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()
-- We can only do fast filling when there's no complex processing involved (i.e., simple setPixel only)
-- NOTE: We cheat a bit when targeting non-grayscale BBs,
Expand Down Expand Up @@ -1399,7 +1399,7 @@ function BB_mt.__index:paintRect(x, y, w, h, value, setter)
end
end
end
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end
end

Expand All @@ -1411,14 +1411,14 @@ function BB4_mt.__index:paintRect(x, y, w, h, value, setter)
w, x = BB.checkBounds(w, x, 0, self:getWidth(), 0xFFFF)
h, y = BB.checkBounds(h, y, 0, self:getHeight(), 0xFFFF)
if w <= 0 or h <= 0 then return end
local hook, mask, count = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()
for tmp_y = y, y+h-1 do
for tmp_x = x, x+w-1 do
setter(self, tmp_x, tmp_y, value)
end
end
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

--[[
Expand Down Expand Up @@ -1739,7 +1739,7 @@ local Png -- lazy load ffi/png

function BB4_mt.__index:writePNG(filename)
if not Png then Png = require("ffi/png") end
local hook, mask, _ = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()

local w, h = self:getWidth(), self:getHeight()
Expand All @@ -1749,12 +1749,12 @@ function BB4_mt.__index:writePNG(filename)

Png.encodeToFile(filename, ffi.cast("const unsigned char*", bbdump.data), w, h, 1)
bbdump:free()
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

function BB8_mt.__index:writePNG(filename)
if not Png then Png = require("ffi/png") end
local hook, mask, _ = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()

local w, h = self:getWidth(), self:getHeight()
Expand All @@ -1766,12 +1766,12 @@ function BB8_mt.__index:writePNG(filename)

Png.encodeToFile(filename, ffi.cast("const unsigned char*", bbdump.data), w, h, 1)
bbdump:free()
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

function BB8A_mt.__index:writePNG(filename)
if not Png then Png = require("ffi/png") end
local hook, mask, _ = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()

local w, h = self:getWidth(), self:getHeight()
Expand All @@ -1781,12 +1781,12 @@ function BB8A_mt.__index:writePNG(filename)

Png.encodeToFile(filename, ffi.cast("const unsigned char*", bbdump.data), w, h, 2)
bbdump:free()
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

function BBRGB16_mt.__index:writePNG(filename)
if not Png then Png = require("ffi/png") end
local hook, mask, _ = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()

local w, h = self:getWidth(), self:getHeight()
Expand All @@ -1796,15 +1796,15 @@ function BBRGB16_mt.__index:writePNG(filename)

Png.encodeToFile(filename, ffi.cast("const unsigned char*", bbdump.data), w, h, 3)
bbdump:free()
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

function BBRGB24_mt.__index:writePNG(filename, bgr)
-- If input is BGR, devolve straight away to the crap fallback...
if bgr then return self:writePNGFromBGR(filename) end

if not Png then Png = require("ffi/png") end
local hook, mask, _ = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()

local w, h = self:getWidth(), self:getHeight()
Expand All @@ -1814,15 +1814,15 @@ function BBRGB24_mt.__index:writePNG(filename, bgr)

Png.encodeToFile(filename, ffi.cast("const unsigned char*", bbdump.data), w, h, 3)
bbdump:free()
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

function BBRGB32_mt.__index:writePNG(filename, bgr)
-- If input is BGR, devolve straight away to the crap fallback...
if bgr then return self:writePNGFromBGR(filename) end

if not Png then Png = require("ffi/png") end
local hook, mask, _ = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()

local w, h = self:getWidth(), self:getHeight()
Expand All @@ -1832,13 +1832,13 @@ function BBRGB32_mt.__index:writePNG(filename, bgr)

Png.encodeToFile(filename, ffi.cast("const unsigned char*", bbdump.data), w, h, 4)
bbdump:free()
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

-- Crap manual fallback when a have a BGR <-> RGB swap to handle...
function BB_mt.__index:writePNGFromBGR(filename)
if not Png then Png = require("ffi/png") end
local hook, mask, _ = debug.gethook()
local hook, hmask, _ = debug.gethook()
debug.sethook()
local w, h = self:getWidth(), self:getHeight()
local stride = w * 3
Expand All @@ -1857,7 +1857,7 @@ function BB_mt.__index:writePNGFromBGR(filename)
end
Png.encodeToFile(filename, mem, w, h, 3)
C.free(cdata)
debug.sethook(hook, mask)
debug.sethook(hook, hmask)
end

-- if no special case in BB???_mt exists, use function from BB_mt
Expand Down

0 comments on commit 1096538

Please sign in to comment.