From 894cb3190d3eaeb215b39b9e566d8aa0f2350a93 Mon Sep 17 00:00:00 2001 From: poire-z Date: Fri, 10 Nov 2023 20:36:57 +0100 Subject: [PATCH] Page browser: show nightmode thumbnails when in nightmode (#11091) Just prevent page thumbnails ImageWidgets to be nightmode inverted, unlike all other ones which are expected to be double inverted to get their original colors shown. The same thumbnail can be used and cached in both day and night modes, unless "nightmode_images" is enabled and have crengine itself invert images, making thumbnails different. --- frontend/apps/reader/modules/readerthumbnail.lua | 6 +++++- frontend/ui/widget/imagewidget.lua | 3 ++- frontend/ui/widget/pagebrowserwidget.lua | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerthumbnail.lua b/frontend/apps/reader/modules/readerthumbnail.lua index 0f7653c0f..14d422a54 100644 --- a/frontend/apps/reader/modules/readerthumbnail.lua +++ b/frontend/apps/reader/modules/readerthumbnail.lua @@ -250,6 +250,10 @@ end function ReaderThumbnail:getPageThumbnail(page, width, height, batch_id, when_generated_callback) self:setupCache() self.current_target_size_tag = string.format("w%d_h%d", width, height) + if self.ui.rolling and Screen.night_mode and self.ui.document.configurable.nightmode_images == 1 then + -- We'll get a different bb in this case: it needs its own cache hash + self.current_target_size_tag = self.current_target_size_tag .. "_nm" + end local hash = string.format("p%d-%s", page, self.current_target_size_tag) local tile = self.tile_cache and self.tile_cache:check(hash) if tile then @@ -431,7 +435,7 @@ function ReaderThumbnail:_getPageImage(page) self.ui.document:setGammaIndex(30) -- as downscaling will make text grayer end self.ui.document:setImageScaling(false) -- No need for smooth scaling as all will be downscaled - self.ui.document:setNightmodeImages(false) -- We don't invert page images even if nightmode set: keep images as-is + -- (We keep "nighmode_images" as it was set: we may get and cache a different bb whether nightmode is on or off) self.ui.view.state.page = page -- Be on requested page self.ui.document:gotoPage(page) -- Current xpointer needs to be updated for some of what follows self.ui.bookmark:onPageUpdate(page) -- Update dogear state for this page diff --git a/frontend/ui/widget/imagewidget.lua b/frontend/ui/widget/imagewidget.lua index d452c9df3..f3dda77a3 100644 --- a/frontend/ui/widget/imagewidget.lua +++ b/frontend/ui/widget/imagewidget.lua @@ -74,6 +74,7 @@ local ImageWidget = Widget:extend{ dim = nil, alpha = false, -- honors alpha values from the image is_icon = false, -- set to true by sub-class IconWidget + original_in_nightmode = true, -- defaults to display the original image colors in nightmode -- When rotation_angle is not 0, native image is rotated by this angle -- before scaling. @@ -578,7 +579,7 @@ function ImageWidget:paintTo(bb, x, y) --- but we currently don't, as we don't really trickle down --- a way to discriminate them from the B&W ones. --- Currently, this is *only* the KOReader icon in Help, AFAIK. - if Screen.night_mode and not self.is_icon then + if Screen.night_mode and self.original_in_nightmode and not self.is_icon then bb:invertRect(x, y, size.w, size.h) end end diff --git a/frontend/ui/widget/pagebrowserwidget.lua b/frontend/ui/widget/pagebrowserwidget.lua index 07123c1b8..0cdd835ef 100644 --- a/frontend/ui/widget/pagebrowserwidget.lua +++ b/frontend/ui/widget/pagebrowserwidget.lua @@ -749,6 +749,7 @@ function PageBrowserWidget:showTile(grid_idx, page, tile, do_refresh) ImageWidget:new{ image = tile.bb, image_disposable = false, + original_in_nightmode = false, -- we want our page thumbnail nightmode'd when in nighmtmode }, } item_container[1] = thumb_frame