From 8216d732f2cf6d465014cca60afc9db186f19aff Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Mon, 16 Sep 2013 10:11:48 +0200 Subject: [PATCH] Improve quality of images manipulated by calibre. In particular improve images dropped or pasted into edit metadata. Note: Qt's default compression quality is 75, which is very low. Perhaps calibre's default doesn't need to be as high as 90, but it should be higher than 75. Perhaps this is a good place for a tweak. (reverted from commit ae1255461f82656d83a78a5555f0810620449eba) --- src/calibre/gui2/__init__.py | 4 ++-- src/calibre/gui2/widgets.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 5b8d2142a4..6116024938 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -738,14 +738,14 @@ def choose_images(window, name, title, select_only_single_file=True, return fd.get_files() return None -def pixmap_to_data(pixmap, format='JPEG'): +def pixmap_to_data(pixmap, format='JPEG', quality=90): ''' Return the QPixmap pixmap as a string saved in the specified format. ''' ba = QByteArray() buf = QBuffer(ba) buf.open(QBuffer.WriteOnly) - pixmap.save(buf, format) + pixmap.save(buf, format, quality=quality) return bytes(ba.data()) class ResizableDialog(QDialog): diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 43963d81fd..71cc7b6169 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -236,7 +236,7 @@ class ImageDropMixin(object): # {{{ def handle_image_drop(self, pmap): self.set_pixmap(pmap) - self.cover_changed.emit(pixmap_to_data(pmap)) + self.cover_changed.emit(pixmap_to_data(pmap, quality=100)) def dragMoveEvent(self, event): event.acceptProposedAction() @@ -268,7 +268,7 @@ class ImageDropMixin(object): # {{{ if not pmap.isNull(): self.set_pixmap(pmap) self.cover_changed.emit( - pixmap_to_data(pmap)) + pixmap_to_data(pmap, quality=100)) # }}} class ImageView(QWidget, ImageDropMixin): # {{{