From 36631868f513ca5b2fc8231a340c1222ff55adc9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 26 Sep 2021 21:49:01 +0530 Subject: [PATCH] PDF Output: Fix a regression that broke conversion of comics that contain 1-bit images --- src/calibre/ebooks/pdf/render/serialize.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/pdf/render/serialize.py b/src/calibre/ebooks/pdf/render/serialize.py index 7fe0d9a25f..6b0524c6cb 100644 --- a/src/calibre/ebooks/pdf/render/serialize.py +++ b/src/calibre/ebooks/pdf/render/serialize.py @@ -301,6 +301,7 @@ class PDFStream(object): i = QImage(1, 1, QImage.Format.Format_ARGB32) i.fill(qRgba(0, 0, 0, 255)) self.alpha_bit = i.constBits().asstring(4).find(b'\xff') + self.bw_image_color_table = frozenset((QColor(Qt.GlobalColor.black).rgba(), QColor(Qt.GlobalColor.white).rgba())) @property def page_tree(self): @@ -426,9 +427,7 @@ class PDFStream(object): fmt = img.format() image = QImage(img) - if (image.depth() == 1 and img.colorTable().size() == 2 and - img.colorTable().at(0) == QColor(Qt.GlobalColor.black).rgba() and - img.colorTable().at(1) == QColor(Qt.GlobalColor.white).rgba()): + if image.depth() == 1 and frozenset(img.colorTable()) == self.bw_image_color_table: if fmt == QImage.Format.Format_MonoLSB: image = image.convertToFormat(QImage.Format.Format_Mono) fmt = QImage.Format.Format_Mono