black_hex & white_hex added

This commit is contained in:
keringo
2025-06-25 21:11:20 +03:00
parent 633e5c8bd4
commit 0a523f9ecf
14 changed files with 116 additions and 39 deletions

View File

@@ -390,31 +390,33 @@ function Document:resetTileCacheValidity()
self.tile_cache_validity_ts = os.time()
end
function Document:getFullPageHash(pageno, zoom, rotation, gamma)
function Document:getFullPageHash(pageno, zoom, rotation, gamma, black_hex, white_hex)
return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|"
..zoom.."|"
..rotation.."|"..gamma.."|"..self.render_mode..(self.render_color and "|color" or "|bw")
..rotation.."|"..gamma.."|"..black_hex.."|"..white_hex
..self.render_mode..(self.render_color and "|color" or "|bw")
..(self.reflowable_font_size and "|"..self.reflowable_font_size or "")
end
function Document:getPagePartHash(pageno, zoom, rotation, gamma, rect)
function Document:getPagePartHash(pageno, zoom, rotation, gamma, black_hex, white_hex, rect)
return "renderpgpart|"..self.file.."|"..self.mod_time.."|"..pageno.."|"
..tostring(rect).."|"..zoom.."|"..tostring(rect.scaled_rect).."|"
..rotation.."|"..gamma.."|"..self.render_mode..(self.render_color and "|color" or "|bw")
..rotation.."|"..gamma.."|"..black_hex.."|"..white_hex
..self.render_mode..(self.render_color and "|color" or "|bw")
..(self.reflowable_font_size and "|"..self.reflowable_font_size or "")
end
function Document:renderPage(pageno, rect, zoom, rotation, gamma, hinting)
function Document:renderPage(pageno, rect, zoom, rotation, gamma, black_hex, white_hex, hinting)
-- If rect contains a nested scaled_rect object, our caller handled scaling itself (e.g., drawPagePart)
local is_prescaled = rect and rect.scaled_rect ~= nil or false
local hash, hash_excerpt, tile
if is_prescaled then
hash = self:getPagePartHash(pageno, zoom, rotation, gamma, rect)
hash = self:getPagePartHash(pageno, zoom, rotation, gamma, black_hex, white_hex, rect)
tile = DocCache:check(hash, TileCacheItem)
else
hash = self:getFullPageHash(pageno, zoom, rotation, gamma)
hash = self:getFullPageHash(pageno, zoom, rotation, gamma, black_hex, white_hex)
tile = DocCache:check(hash, TileCacheItem)
@@ -502,6 +504,9 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, hinting)
dc:setGamma(gamma)
end
dc:setBlackHex(black_hex)
dc:setWhiteHex(white_hex)
-- And finally, render the page in our BB
local page = self._document:openPage(pageno)
page:draw(dc, tile.bb, size.x, size.y, self.render_mode)
@@ -516,9 +521,9 @@ end
-- a hint for the cache engine to paint a full page to the cache
--- @todo this should trigger a background operation
function Document:hintPage(pageno, zoom, rotation, gamma)
function Document:hintPage(pageno, zoom, rotation, gamma, black_hex, white_hex)
logger.dbg("hinting page", pageno)
self:renderPage(pageno, nil, zoom, rotation, gamma, true)
self:renderPage(pageno, nil, zoom, rotation, gamma, black_hex, white_hex, true)
end
--[[
@@ -529,8 +534,8 @@ Draw page content to blitbuffer.
@target: target blitbuffer
@rect: visible_area inside document page
--]]
function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma)
local tile = self:renderPage(pageno, rect, zoom, rotation, gamma)
function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma, black_hex, white_hex)
local tile = self:renderPage(pageno, rect, zoom, rotation, gamma, black_hex, white_hex)
-- Enable SW dithering if requested (only available in koptoptions)
if self.sw_dithering then
target:ditherblitFrom(tile.bb,
@@ -570,7 +575,7 @@ function Document:drawPagePart(pageno, native_rect, rotation)
rect.scaled_rect = scaled_rect
-- Enable SMP via the hinting flag
local tile = self:renderPage(pageno, rect, zoom, rotation, 1.0, true)
local tile = self:renderPage(pageno, rect, zoom, rotation, 1.0, 0x000000, 0xFFFFFF, true)
return tile.bb, rotate
end