Add white threshold for paged documents (#15412)

This commit is contained in:
kerivin authored and GitHub committed 2026-05-20 16:36:49 +02:00
1 parent 17b9a64aed
commit bd1dd7dfd4
3 files changed
+34 -3

No files matched your search

+12 -3
View File
@@ -100,6 +100,7 @@ function KoptInterface:setDefaultConfigurable(configurable)
configurable.page_margin = G_defaults:readSetting("DKOPTREADER_CONFIG_PAGE_MARGIN")
configurable.quality = G_defaults:readSetting("DKOPTREADER_CONFIG_RENDER_QUALITY")
configurable.contrast = G_defaults:readSetting("DKOPTREADER_CONFIG_CONTRAST")
configurable.white_threshold = G_defaults:readSetting("DKOPTREADER_CONFIG_WHITE_THRESHOLD")
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")
@@ -140,6 +141,10 @@ function KoptInterface:createContext(doc, pageno, bbox)
kc:setLanguage(lang)
kc:setTrim(doc.configurable.trim_page)
kc:setWrap(doc.configurable.text_wrap)
if doc.configurable.white_threshold ~= 255 then
kc:setWhiteThreshold(doc.configurable.white_threshold)
kc:setPaintWhiteThreshold(1)
end
kc:setIndent(doc.configurable.detect_indent)
kc:setColumns(doc.configurable.max_columns)
kc:setDeviceDim(canvas_size.w, canvas_size.h)
@@ -392,10 +397,14 @@ function KoptInterface:getCoverPageImage(doc)
end
end
function KoptInterface:is_optimizing_page(doc)
return doc.configurable.page_opt == 1 or doc.configurable.auto_straighten > 0 or doc.configurable.white_threshold ~= 255
end
function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, hinting)
if doc.configurable.text_wrap == 1 then
return self:renderReflowedPage(doc, pageno, rect, zoom, rotation, hinting)
elseif doc.configurable.page_opt == 1 or doc.configurable.auto_straighten > 0 then
elseif self:is_optimizing_page(doc) then
return self:renderOptimizedPage(doc, pageno, rect, zoom, rotation, hinting)
else
return Document.renderPage(doc, pageno, rect, zoom, rotation, gamma, hinting)
@@ -542,7 +551,7 @@ function KoptInterface:hintPage(doc, pageno, zoom, rotation, gamma)
if doc.configurable.text_wrap == 1 then
self:hintReflowedPage(doc, pageno, zoom, rotation, true)
elseif doc.configurable.page_opt == 1 or doc.configurable.auto_straighten > 0 then
elseif self:is_optimizing_page(doc) then
self:renderOptimizedPage(doc, pageno, nil, zoom, rotation, true)
else
Document.hintPage(doc, pageno, zoom, rotation, gamma)
@@ -582,7 +591,7 @@ function KoptInterface:drawPage(doc, target, x, y, rect, pageno, zoom, rotation,
local nightmode_invert = doc.configurable.nightmode_document == 1 and Screen.night_mode
if doc.configurable.text_wrap == 1 then
self:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation, nightmode_invert)
elseif doc.configurable.page_opt == 1 or doc.configurable.auto_straighten > 0 then
elseif self:is_optimizing_page(doc) then
self:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation, nightmode_invert)
elseif nightmode_invert then
Document.drawPageInverted(doc, target, x, y, rect, pageno, zoom, rotation, gamma)