From f1efd5fee52330a2079425fbf2faeb4fe814f23c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Dec 2025 19:59:04 +0530 Subject: [PATCH] Use device pixel ration when generating thumbnails for high res rendering --- src/calibre/gui2/library/bookshelf_view.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/library/bookshelf_view.py b/src/calibre/gui2/library/bookshelf_view.py index 94bbfa78f9..15b3a74c03 100644 --- a/src/calibre/gui2/library/bookshelf_view.py +++ b/src/calibre/gui2/library/bookshelf_view.py @@ -892,11 +892,11 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): self.expanded_cover.updated.connect(self.update_viewport) self.layout_constraints = LayoutConstraints() - self.layout_constraints = lc = self.layout_constraints._replace(width=self._get_available_width()) + self.layout_constraints = self.layout_constraints._replace(width=self._get_available_width()) self.cover_cache = CoverThumbnailCache( name='bookshelf-thumbnail-cache', ram_limit=800, max_size=gprefs['bookshelf_disk_cache_size'], thumbnailer=ThumbnailerWithDominantColor(), - thumbnail_size=(lc.max_spine_width, lc.spine_height), parent=self, version=2, + thumbnail_size=self.thumbnail_size(), parent=self, version=2, ) self.cover_cache.rendered.connect(self.update_viewport, type=Qt.ConnectionType.QueuedConnection) @@ -913,6 +913,12 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): self.template_title_is_empty = True self.template_statue_is_empty = True + def thumbnail_size(self) -> tuple[int, int]: + lc = self.layout_constraints + dpr = self.devicePixelRatioF() + sz = QSizeF(lc.max_spine_width * dpr, lc.spine_height * dpr).toSize() + return sz.width(), sz.height() + # Templates rendering methods def init_template(self, db): @@ -1365,7 +1371,10 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): # Draw with opacity painter.save() painter.setOpacity(0.3) # 30% opacity + dpr = thumbnail.devicePixelRatioF() + thumbnail.setDevicePixelRatio(self.devicePixelRatioF()) painter.drawPixmap(rect, thumbnail) + thumbnail.setDevicePixelRatio(dpr) painter.restore() # Cover integration methods