diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index ee0d0f90e..1b88adeec 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -221,7 +221,7 @@ function ReaderView:paintTo(bb, x, y) self.dialog.dithered = nil -- For KOpt, let the user choose. if self.ui.document.info.has_pages then - -- Also enforce dithering in PicDocument + -- Also enforce HW dithering in PicDocument if self.ui.document.is_pic or self.document.configurable.hw_dithering == 1 then self.dialog.dithered = true end diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index a2c940303..03830d2d8 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -190,6 +190,7 @@ local settingsList = { kopt_contrast = {category="absolutenumber", paging=true}, kopt_page_opt = {category="configurable", paging=true}, kopt_hw_dithering = {category="configurable", paging=true, condition=Device:hasEinkScreen() and Device:canHWDither()}, + kopt_sw_dithering = {category="configurable", paging=true, condition=Device:hasEinkScreen() and Device.screen.fb_bpp == 8}, kopt_quality = {category="configurable", paging=true}, kopt_doc_language = {category="string", paging=true}, kopt_forced_ocr = {category="configurable", paging=true}, @@ -355,6 +356,7 @@ local dispatcher_menu_order = { "kopt_contrast", "kopt_page_opt", "kopt_hw_dithering", + "kopt_sw_dithering", "kopt_quality", "kopt_doc_language", diff --git a/frontend/document/canvascontext.lua b/frontend/document/canvascontext.lua index 6e2a88b58..0bdd14609 100644 --- a/frontend/document/canvascontext.lua +++ b/frontend/document/canvascontext.lua @@ -51,6 +51,10 @@ function CanvasContext:init(device) self.is_bgr = true Mupdf.bgr = true end + + self.hasEinkScreen = device.hasEinkScreen + self.canHWDither = device.canHWDither + self.fb_bpp = device.screen.fb_bpp end diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 6e4fa4d31..53e7330ad 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -495,11 +495,21 @@ Draw page content to blitbuffer. --]] function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma, render_mode) local tile = self:renderPage(pageno, rect, zoom, rotation, gamma, render_mode) - target:blitFrom(tile.bb, - x, y, - rect.x - tile.excerpt.x, - rect.y - tile.excerpt.y, - rect.w, rect.h) + -- Enable SW dithering if requested (only available in koptoptions) + -- Much Like ReaderView, also enforce SW dithering in PicDocument if the device can't do HW dithering... + if (self.is_pic and CanvasContext:hasEinkScreen() and not CanvasContext:canHWDither() and CanvasContext.fb_bpp == 8) or (self.configurable.sw_dithering and self.configurable.sw_dithering == 1) then + target:ditherblitFrom(tile.bb, + x, y, + rect.x - tile.excerpt.x, + rect.y - tile.excerpt.y, + rect.w, rect.h) + else + target:blitFrom(tile.bb, + x, y, + rect.x - tile.excerpt.x, + rect.y - tile.excerpt.y, + rect.w, rect.h) + end end function Document:getDrawnImagesStatistics() diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 74bac1b1c..33bbb0262 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -497,14 +497,25 @@ This can also be used to remove some gray background or to convert a grayscale o }, { name = "hw_dithering", - name_text = _("Dithering"), + name_text = _("HW Dithering"), toggle = {_("off"), _("on")}, values = {0, 1}, default_value = 0, advanced = true, show = Device:hasEinkScreen() and Device:canHWDither(), name_text_hold_callback = optionsutil.showValues, - help_text = _([[Enable Hardware dithering.]]), + help_text = _([[Enable hardware dithering.]]), + }, + { + name = "sw_dithering", + name_text = _("SW Dithering"), + toggle = {_("off"), _("on")}, + values = {0, 1}, + default_value = 0, + advanced = true, + show = Device:hasEinkScreen() and Device.screen.fb_bpp == 8, + name_text_hold_callback = optionsutil.showValues, + help_text = _([[Enable software dithering.]]), }, { name = "quality",