Allow for toggling color rendering

New menu item in Screen submenu.
hasColorScreen enabled for SDL device.
pull/3286/head
poire-z 7 years ago committed by Frans de Jonge
parent f45188fb9d
commit 53f083f516

@ -219,6 +219,10 @@ function ReaderPaging:addToMainMenu(menu_items)
} }
end end
function ReaderPaging:onColorRenderingUpdate()
self.ui.document:updateColorRendering()
end
--[[ --[[
Set reading position on certain page Set reading position on certain page
Page position is a fractional number ranging from 0 to 1, indicating the read Page position is a fractional number ranging from 0 to 1, indicating the read

@ -530,6 +530,10 @@ function ReaderRolling:onChangeScreenMode(mode)
self:onUpdatePos() self:onUpdatePos()
end end
function ReaderRolling:onColorRenderingUpdate()
self.ui.document:updateColorRendering()
end
--[[ --[[
PosUpdate event is used to signal other widgets that pos has been changed. PosUpdate event is used to signal other widgets that pos has been changed.
--]] --]]

@ -24,6 +24,7 @@ local Device = {
isTouchDevice = no, isTouchDevice = no,
hasFrontlight = no, hasFrontlight = no,
needsTouchScreenProbe = no, needsTouchScreenProbe = no,
hasColorScreen = no,
-- use these only as a last resort. We should abstract the functionality -- use these only as a last resort. We should abstract the functionality
-- and have device dependent implementations in the corresponting -- and have device dependent implementations in the corresponting
@ -57,9 +58,10 @@ function Device:init()
error("screen/framebuffer must be implemented") error("screen/framebuffer must be implemented")
end end
self.screen.isColorScreen = self.hasColorScreen
self.screen.isColorEnabled = function() self.screen.isColorEnabled = function()
if G_reader_settings:has("color_rendering") then return G_reader_settings:isTrue("color_rendering") end if G_reader_settings:has("color_rendering") then return G_reader_settings:isTrue("color_rendering") end
return self.screen.color return self.screen.isColorScreen()
end end
local is_eink = G_reader_settings:readSetting("eink") local is_eink = G_reader_settings:readSetting("eink")

@ -14,6 +14,7 @@ local Device = Generic:new{
hasFrontlight = yes, hasFrontlight = yes,
isTouchDevice = yes, isTouchDevice = yes,
needsScreenRefreshAfterResume = no, needsScreenRefreshAfterResume = no,
hasColorScreen = yes,
} }
if os.getenv("DISABLE_TOUCH") == "1" then if os.getenv("DISABLE_TOUCH") == "1" then

@ -73,6 +73,7 @@ function CreDocument:engineInit()
end end
function CreDocument:init() function CreDocument:init()
self:updateColorRendering()
self:engineInit() self:engineInit()
self.configurable:loadDefaults(self.options) self.configurable:loadDefaults(self.options)
@ -137,6 +138,20 @@ end
function CreDocument:close() function CreDocument:close()
Document.close(self) Document.close(self)
if self.buffer then
self.buffer:free()
self.buffer = nil
end
end
function CreDocument:updateColorRendering()
Document.updateColorRendering(self) -- will set self.render_color
-- Delete current buffer, a new one will be created according
-- to self.render_color
if self.buffer then
self.buffer:free()
self.buffer = nil
end
end end
function CreDocument:getPageCount() function CreDocument:getPageCount()
@ -239,15 +254,15 @@ function CreDocument:drawCurrentView(target, x, y, rect, pos)
self.buffer:free() self.buffer:free()
self.buffer = nil self.buffer = nil
end end
local color = Screen:isColorEnabled()
if not self.buffer then if not self.buffer then
-- Note about color rendering:
-- If we use TYPE_BBRGB32 (and LVColorDrawBuf drawBuf(..., 32) in cre.cpp), -- If we use TYPE_BBRGB32 (and LVColorDrawBuf drawBuf(..., 32) in cre.cpp),
-- we get inverted Red and Blue in the blitbuffer (could be that -- we get inverted Red and Blue in the blitbuffer (could be that
-- crengine/src/lvdrawbuf.cpp treats our 32bits not as RGBA). -- crengine/src/lvdrawbuf.cpp treats our 32bits not as RGBA).
-- But it is all fine if we use TYPE_BBRGB16. -- But it is all fine if we use TYPE_BBRGB16.
self.buffer = Blitbuffer.new(rect.w, rect.h, color and Blitbuffer.TYPE_BBRGB16 or nil) self.buffer = Blitbuffer.new(rect.w, rect.h, self.render_color and Blitbuffer.TYPE_BBRGB16 or nil)
end end
self._document:drawCurrentPage(self.buffer, color) self._document:drawCurrentPage(self.buffer, self.render_color)
target:blitFrom(self.buffer, x, y, 0, 0, rect.w, rect.h) target:blitFrom(self.buffer, x, y, 0, 0, rect.w, rect.h)
end end
@ -307,7 +322,7 @@ function CreDocument:getLinkFromPosition(pos)
return self._document:getLinkFromPosition(pos.x, pos.y) return self._document:getLinkFromPosition(pos.x, pos.y)
end end
function Document:gotoPos(pos) function CreDocument:gotoPos(pos)
logger.dbg("CreDocument: goto position", pos) logger.dbg("CreDocument: goto position", pos)
self._document:gotoPos(pos) self._document:gotoPos(pos)
end end

@ -24,6 +24,7 @@ local function validDjvuFile(filename)
end end
function DjvuDocument:init() function DjvuDocument:init()
self:updateColorRendering()
local djvu = require("libs/libkoreader-djvu") local djvu = require("libs/libkoreader-djvu")
self.koptinterface = require("document/koptinterface") self.koptinterface = require("document/koptinterface")
self.configurable:loadDefaults(self.options) self.configurable:loadDefaults(self.options)

@ -72,6 +72,10 @@ function Document:_init()
author = "", author = "",
date = "" date = ""
} }
-- Should be updated by a call to Document.updateColorRendering(self)
-- in subclasses
self.render_color = false
end end
-- override this method to open a document -- override this method to open a document
@ -269,14 +273,30 @@ function Document:findText()
return nil return nil
end end
function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode) function Document:updateColorRendering()
if self.is_color_capable and Screen:isColorEnabled() then
self.render_color = true
else
self.render_color = false
end
end
function Document:preRenderPage()
return nil
end
function Document:postRenderPage()
return nil
end
function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode, color)
return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|" return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|"
..zoom.."|"..rotation.."|"..gamma.."|"..render_mode ..zoom.."|"..rotation.."|"..gamma.."|"..render_mode..(color and "|color" or "")
end end
function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode) function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
local hash_excerpt local hash_excerpt
local hash = self:getFullPageHash(pageno, zoom, rotation, gamma, render_mode) local hash = self:getFullPageHash(pageno, zoom, rotation, gamma, render_mode, self.render_color)
local tile = Cache:check(hash, TileCacheItem) local tile = Cache:check(hash, TileCacheItem)
if not tile then if not tile then
hash_excerpt = hash.."|"..tostring(rect) hash_excerpt = hash.."|"..tostring(rect)
@ -284,6 +304,8 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
end end
if tile then return tile end if tile then return tile end
self:preRenderPage()
local page_size = self:getPageDimensions(pageno, zoom, rotation) local page_size = self:getPageDimensions(pageno, zoom, rotation)
-- this will be the size we actually render -- this will be the size we actually render
local size = page_size local size = page_size
@ -303,16 +325,12 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
end end
-- prepare cache item with contained blitbuffer -- prepare cache item with contained blitbuffer
local bbtype = nil -- use Blitbuffer default greyscale type
if self.is_color_capable and Screen:isColorEnabled() then
bbtype = Blitbuffer.TYPE_BBRGB32
end
tile = TileCacheItem:new{ tile = TileCacheItem:new{
persistent = true, persistent = true,
size = size.w * size.h + 64, -- estimation size = size.w * size.h + 64, -- estimation
excerpt = size, excerpt = size,
pageno = pageno, pageno = pageno,
bb = Blitbuffer.new(size.w, size.h, bbtype) bb = Blitbuffer.new(size.w, size.h, self.render_color and Blitbuffer.TYPE_BBRGB32 or nil)
} }
-- create a draw context -- create a draw context
@ -339,6 +357,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
page:close() page:close()
Cache:insert(hash, tile) Cache:insert(hash, tile)
self:postRenderPage()
return tile return tile
end end

@ -3,9 +3,9 @@ local CacheItem = require("cacheitem")
local Document = require("document/document") local Document = require("document/document")
local DrawContext = require("ffi/drawcontext") local DrawContext = require("ffi/drawcontext")
local KoptOptions = require("ui/data/koptoptions") local KoptOptions = require("ui/data/koptoptions")
local Screen = require("device").screen
local logger = require("logger") local logger = require("logger")
local util = require("util") local util = require("util")
local pdf = nil
local PdfDocument = Document:new{ local PdfDocument = Document:new{
_document = false, _document = false,
@ -16,8 +16,13 @@ local PdfDocument = Document:new{
} }
function PdfDocument:init() function PdfDocument:init()
local pdf = require("ffi/mupdf") if not pdf then pdf = require("ffi/mupdf") end
pdf.color = Screen:isColorEnabled() -- mupdf.color has to stay false for kopt to work correctly
-- and be accurate (including its job about showing highlight
-- boxes). We will turn it on and off in PdfDocument:preRenderPage()
-- and :postRenderPage() when mupdf is called without kopt involved.
pdf.color = false
self:updateColorRendering()
self.koptinterface = require("document/koptinterface") self.koptinterface = require("document/koptinterface")
self.configurable:loadDefaults(self.options) self.configurable:loadDefaults(self.options)
local ok local ok
@ -39,6 +44,14 @@ function PdfDocument:init()
-- end -- end
end end
function PdfDocument:preRenderPage()
pdf.color = self.render_color
end
function PdfDocument:postRenderPage()
pdf.color = false
end
function PdfDocument:unlock(password) function PdfDocument:unlock(password)
if not self._document:authenticatePassword(password) then if not self._document:authenticatePassword(password) then
return false return false

@ -10,8 +10,10 @@ local PicDocument = Document:new{
} }
function PicDocument:init() function PicDocument:init()
self:updateColorRendering()
if not pic then pic = require("ffi/pic") end if not pic then pic = require("ffi/pic") end
pic.color = Screen:isColorEnabled() -- pic.color needs to be true before opening document to allow toggling color
pic.color = Screen.isColorScreen()
local ok local ok
ok, self._document = pcall(pic.openDocument, self.file) ok, self._document = pcall(pic.openDocument, self.file)
if not ok then if not ok then

@ -107,13 +107,19 @@ common_settings.screen = {
text = _("Screen"), text = _("Screen"),
sub_item_table = { sub_item_table = {
require("ui/elements/screen_dpi_menu_table"), require("ui/elements/screen_dpi_menu_table"),
require("ui/elements/refresh_menu_table"),
require("ui/elements/screen_eink_opt_menu_table"), require("ui/elements/screen_eink_opt_menu_table"),
require("ui/elements/menu_activate"),
require("ui/elements/screen_disable_double_tap_table"), require("ui/elements/screen_disable_double_tap_table"),
require("ui/elements/refresh_menu_table"),
require("ui/elements/flash_keyboard"), require("ui/elements/flash_keyboard"),
require("ui/elements/menu_activate"),
}, },
} }
if Screen.isColorScreen() then
table.insert(common_settings.screen.sub_item_table, 4, require("ui/elements/screen_color_menu_table"))
common_settings.screen.sub_item_table[4].separator = true
else
common_settings.screen.sub_item_table[3].separator = true
end
if Device:isAndroid() then if Device:isAndroid() then
table.insert(common_settings.screen.sub_item_table, require("ui/elements/screen_fullscreen_menu_table")) table.insert(common_settings.screen.sub_item_table, require("ui/elements/screen_fullscreen_menu_table"))
end end

@ -0,0 +1,14 @@
local Event = require("ui/event")
local Screen = require("device").screen
local UIManager = require("ui/uimanager")
local _ = require("gettext")
return {
text = _("Color rendering"),
enabled_func = Screen.isColorScreen,
checked_func = Screen.isColorEnabled,
callback = function()
G_reader_settings:flipNilOrTrue("color_rendering")
UIManager:broadcastEvent(Event:new("ColorRenderingUpdate"))
end
}
Loading…
Cancel
Save