Isolate PDF SMask (#15401)

Closes #7992.
This commit is contained in:
kerivin authored and GitHub committed 2026-05-18 19:15:02 +02:00
1 parent 659a649732
commit cb46108e4c
6 files changed
+30 -12

No files matched your search

+7 -4
View File
@@ -392,15 +392,16 @@ end
function Document:getFullPageHash(pageno, zoom, rotation, gamma)
return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|"
..zoom.."|"
..rotation.."|"..gamma.."|"..self.render_mode..(self.render_color and "|color" or "|bw")
..zoom.."|"..rotation.."|"..gamma.."|"..self.configurable.background_cleanup.."|"
..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)
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")
..tostring(rect).."|"..zoom.."|"..tostring(rect.scaled_rect)
.."|"..rotation.."|"..gamma.."|"..self.configurable.background_cleanup.."|"
..self.render_mode..(self.render_color and "|color" or "|bw")
..(self.reflowable_font_size and "|"..self.reflowable_font_size or "")
end
@@ -502,6 +503,8 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, hinting)
dc:setGamma(gamma)
end
dc:setIsolateSMask(self.configurable.background_cleanup)
-- 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)
+6 -5
View File
@@ -103,6 +103,7 @@ function KoptInterface:setDefaultConfigurable(configurable)
configurable.defect_size = G_defaults:readSetting("DKOPTREADER_CONFIG_DEFECT_SIZE")
configurable.line_spacing = G_defaults:readSetting("DKOPTREADER_CONFIG_LINE_SPACING")
configurable.word_spacing = G_defaults:readSetting("DKOPTREADER_CONFIG_DEFAULT_WORD_SPACING")
configurable.background_cleanup = 0
end
function KoptInterface:waitForContext(kc)
@@ -385,7 +386,7 @@ function KoptInterface:getCoverPageImage(doc)
local native_size = Document.getNativePageDimensions(doc, 1)
local canvas_size = CanvasContext:getSize()
local zoom = math.min(canvas_size.w / native_size.w, canvas_size.h / native_size.h)
local tile = Document.renderPage(doc, 1, nil, zoom, 0, 1.0)
local tile = Document.renderPage(doc, 1, nil, zoom, 0, 1.0, false)
if tile then
return tile.bb:copy()
end
@@ -540,9 +541,9 @@ function KoptInterface:hintPage(doc, pageno, zoom, rotation, gamma)
DocCache:memoryPressureCheck()
if doc.configurable.text_wrap == 1 then
self:hintReflowedPage(doc, pageno, zoom, rotation, gamma, true)
self:hintReflowedPage(doc, pageno, zoom, rotation, true)
elseif doc.configurable.page_opt == 1 or doc.configurable.auto_straighten > 0 then
self:renderOptimizedPage(doc, pageno, nil, zoom, rotation, gamma, true)
self:renderOptimizedPage(doc, pageno, nil, zoom, rotation, true)
else
Document.hintPage(doc, pageno, zoom, rotation, gamma)
end
@@ -557,7 +558,7 @@ off by calling self:waitForContext(kctx)
Inherited from common document interface.
--]]
function KoptInterface:hintReflowedPage(doc, pageno, zoom, rotation, gamma, hinting)
function KoptInterface:hintReflowedPage(doc, pageno, zoom, rotation, hinting)
local bbox = doc:getPageBBox(pageno)
local hash_list = { "kctx" }
self:getContextHash(doc, pageno, bbox, hash_list)
@@ -596,7 +597,7 @@ Draw cached tile pixels into target blitbuffer.
Inherited from common document interface.
--]]
function KoptInterface:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation, nightmode_invert)
local tile = self:renderPage(doc, pageno, rect, zoom, rotation, 1.0)
local tile = self:renderPage(doc, pageno, rect, zoom, rotation, 1.0, false)
target:blitFrom(tile.bb,
x, y,
rect.x - tile.excerpt.x,
+14
View File
@@ -515,6 +515,20 @@ Some of the other settings are only available when reflow mode is enabled.]]),
name_text_hold_callback = optionsutil.showValues,
help_text = _([[Remove watermarks from the rendered document.
This can also be used to remove some gray background or to convert a grayscale or color document to black & white and get more contrast for easier reading.]]),
},
{
name = "background_cleanup",
name_text = _("Background Cleanup"),
toggle = {C_("Background Cleanup", "off"), C_("Background Cleanup", "on")},
values = {0, 1},
default_value = 0,
args = {0, 1},
show_func = function(configurable, document)
return document.is_pdf == true
end,
name_text_hold_callback = optionsutil.showValues,
help_text = _([[Render the essentials in black and white, ignoring extra data for better contrast and faster rendering.
Useful for Internet Archive PDF documents.]]),
},
{
name = "hw_dithering",
+1 -1
View File
@@ -28,7 +28,7 @@ describe("Cache module", function()
it("should deserialize blitbuffer", function()
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
doc:hintPage(pageno, 1, 0, 1.0, 0)
doc:hintPage(pageno, 1, 0, 1.0)
end
DocCache:clear()
end)
+1 -1
View File
@@ -60,7 +60,7 @@ describe("Koptinterface module", function()
it("should hint reflowed page in background", function()
doc.configurable.text_wrap = 1
Koptinterface:hintReflowedPage(doc, 1, 1.0, 0, 1.0, 0)
Koptinterface:hintReflowedPage(doc, 1, 1.0, 0, false)
-- and wait for reflowing to complete
local kc = Koptinterface:getCachedContext(doc, 1)
assert.truthy(kc)
+1 -1
View File
@@ -23,7 +23,7 @@ describe("PDF benchmark:", function()
end
for pageno = 1, math.min(9, doc.info.number_of_pages) do
local secs, usecs = util.gettime()
assert.truthy(doc:renderPage(pageno, nil, 1, 0, 1.0))
assert.truthy(doc:renderPage(pageno, nil, 1, 0, 1.0, false))
local nsecs, nusecs = util.gettime()
local dur = nsecs - secs + (nusecs - usecs) / 1000000
logDuration(logfile, pageno, dur)