mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
black_hex & white_hex added
This commit is contained in:
@@ -136,16 +136,16 @@ function DjvuDocument:findAllText(pattern, case_insensitive, nb_context_words, m
|
||||
return self.koptinterface:findAllText(self, pattern, case_insensitive, nb_context_words, max_hits)
|
||||
end
|
||||
|
||||
function DjvuDocument:renderPage(pageno, rect, zoom, rotation, gamma, hinting)
|
||||
return self.koptinterface:renderPage(self, pageno, rect, zoom, rotation, gamma, hinting)
|
||||
function DjvuDocument:renderPage(pageno, rect, zoom, rotation, gamma, black_hex, white_hex, hinting)
|
||||
return self.koptinterface:renderPage(self, pageno, rect, zoom, rotation, gamma, black_hex, white_hex, hinting)
|
||||
end
|
||||
|
||||
function DjvuDocument:hintPage(pageno, zoom, rotation, gamma)
|
||||
return self.koptinterface:hintPage(self, pageno, zoom, rotation, gamma)
|
||||
function DjvuDocument:hintPage(pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
return self.koptinterface:hintPage(self, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
end
|
||||
|
||||
function DjvuDocument:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
return self.koptinterface:drawPage(self, target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
function DjvuDocument:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
return self.koptinterface:drawPage(self, target, x, y, rect, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
end
|
||||
|
||||
function DjvuDocument:register(registry)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -99,6 +99,8 @@ 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.black_hex = G_defaults:readSetting("DKOPTREADER_CONFIG_BLACK_HEX")
|
||||
configurable.white_hex = G_defaults:readSetting("DKOPTREADER_CONFIG_WHITE_HEX")
|
||||
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")
|
||||
@@ -150,6 +152,8 @@ function KoptInterface:createContext(doc, pageno, bbox)
|
||||
kc:setQuality(doc.configurable.quality)
|
||||
-- k2pdfopt (for reflowing) and mupdf use different algorithms to apply gamma when rendering
|
||||
kc:setContrast(1 / doc.configurable.contrast)
|
||||
kc:setForegroundHex(doc.configurable.black_hex)
|
||||
kc:setBackgroundHex(doc.configurable.white_hex)
|
||||
kc:setDefectSize(doc.configurable.defect_size)
|
||||
kc:setLineSpacing(doc.configurable.line_spacing)
|
||||
kc:setWordSpacing(doc.configurable.word_spacing)
|
||||
@@ -384,19 +388,19 @@ 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, 0x000000, 0xFFFFFF)
|
||||
if tile then
|
||||
return tile.bb:copy()
|
||||
end
|
||||
end
|
||||
|
||||
function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, hinting)
|
||||
function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, black_hex, white_hex, 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
|
||||
return self:renderOptimizedPage(doc, pageno, rect, zoom, rotation, hinting)
|
||||
else
|
||||
return Document.renderPage(doc, pageno, rect, zoom, rotation, gamma, hinting)
|
||||
return Document.renderPage(doc, pageno, rect, zoom, rotation, gamma, black_hex, white_hex, hinting)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -491,16 +495,16 @@ function KoptInterface:renderOptimizedPage(doc, pageno, rect, zoom, rotation, hi
|
||||
end
|
||||
end
|
||||
|
||||
function KoptInterface:hintPage(doc, pageno, zoom, rotation, gamma)
|
||||
function KoptInterface:hintPage(doc, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
--- @note: Crappy safeguard around memory issues like in #7627: if we're eating too much RAM, drop half the cache...
|
||||
DocCache:memoryPressureCheck()
|
||||
|
||||
if doc.configurable.text_wrap == 1 then
|
||||
self:hintReflowedPage(doc, pageno, zoom, rotation, gamma, true)
|
||||
self:hintReflowedPage(doc, pageno, zoom, rotation, gamma, black_hex, white_hex, 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, gamma, black_hex, white_hex, true)
|
||||
else
|
||||
Document.hintPage(doc, pageno, zoom, rotation, gamma)
|
||||
Document.hintPage(doc, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -344,16 +344,16 @@ function PdfDocument:findAllText(pattern, case_insensitive, nb_context_words, ma
|
||||
return self.koptinterface:findAllText(self, pattern, case_insensitive, nb_context_words, max_hits)
|
||||
end
|
||||
|
||||
function PdfDocument:renderPage(pageno, rect, zoom, rotation, gamma, hinting)
|
||||
return self.koptinterface:renderPage(self, pageno, rect, zoom, rotation, gamma, hinting)
|
||||
function PdfDocument:renderPage(pageno, rect, zoom, rotation, gamma, black_hex, white_hex, hinting)
|
||||
return self.koptinterface:renderPage(self, pageno, rect, zoom, rotation, gamma, black_hex, white_hex, hinting)
|
||||
end
|
||||
|
||||
function PdfDocument:hintPage(pageno, zoom, rotation, gamma)
|
||||
return self.koptinterface:hintPage(self, pageno, zoom, rotation, gamma)
|
||||
function PdfDocument:hintPage(pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
return self.koptinterface:hintPage(self, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
end
|
||||
|
||||
function PdfDocument:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
return self.koptinterface:drawPage(self, target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
function PdfDocument:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
return self.koptinterface:drawPage(self, target, x, y, rect, pageno, zoom, rotation, gamma, black_hex, white_hex)
|
||||
end
|
||||
|
||||
function PdfDocument:register(registry)
|
||||
|
||||
Reference in New Issue
Block a user