From c3b8d488132fc81a1682e2589b54b277158e9584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Fri, 11 Oct 2013 11:15:21 +0200 Subject: [PATCH] Changed upscale algorithm to bicubic + little code cleanup --- kcc.py | 2 ++ kcc/KCC_gui.py | 11 ++++++++--- kcc/image.py | 10 ++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/kcc.py b/kcc.py index 9b4916d..6d84ab7 100644 --- a/kcc.py +++ b/kcc.py @@ -34,6 +34,7 @@ except ImportError: from kcc import KCC_gui from multiprocessing import freeze_support if sys.platform.startswith('darwin'): + # Workaround Finder-launched app PATH evaluation os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH'] from kcc import KCC_ui_osx as KCC_ui elif sys.platform.startswith('linux'): @@ -47,6 +48,7 @@ else: from kcc import KCC_ui +# Implementing detection of already running KCC instance and forwarding argv to it class QApplicationMessaging(QtGui.QApplication): def __init__(self, argv): QtGui.QApplication.__init__(self, argv) diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py index ffdda89..4ea1caa 100644 --- a/kcc/KCC_gui.py +++ b/kcc/KCC_gui.py @@ -158,6 +158,7 @@ class WorkerThread(QtCore.QThread): if GUI.ColorBox.isChecked(): argv.append("--forcecolor") for i in range(GUI.JobList.count()): + # Make sure that we don't consider any system message as job to do if GUI.JobList.item(i).icon().isNull(): currentJobs.append(unicode(GUI.JobList.item(i).text())) GUI.JobList.clear() @@ -255,6 +256,8 @@ class WorkerThread(QtCore.QThread): mobiPath = item.replace('.epub', '.mobi') shutil.move(mobiPath, mobiPath + '_toclean') try: + # MOBI file produced by KindleGen is hybrid. KF8 + M7 + Source header + # KindleSplit is removing redundant data as we need only KF8 part for new Kindle models if profile in ['K345', 'KHD', 'KF', 'KFHD', 'KFHD8', 'KFHDX8', 'KFA']: newKindle = True else: @@ -546,18 +549,20 @@ class Ui_KCC(object): def addMessage(self, message, icon=None, replace=False): if icon: icon = eval('self.icons.' + icon) - item = QtGui.QListWidgetItem(icon, ' ' + self.stripTags(message)) + item = QtGui.QListWidgetItem(icon, ' ' + self.stripTags(message)) else: - item = QtGui.QListWidgetItem(' ' + self.stripTags(message)) + item = QtGui.QListWidgetItem(' ' + self.stripTags(message)) if replace: GUI.JobList.takeItem(GUI.JobList.count()-1) + # Due to lack of HTML support in QListWidgetItem we overlay text field with QLabel + # We still fill original text field with transparent content to trigger creation of horizontal scrollbar + item.setTextColor(QtGui.QColor('transparent')) label = QtGui.QLabel(message) label.setStyleSheet('background-image:url('');background-color:rgba(255,0,0,0.5);') label.setOpenExternalLinks(True) font = QtGui.QFont() font.setPointSize(self.listFontSize) label.setFont(font) - item.setTextColor(QtGui.QColor('transparent')) GUI.JobList.addItem(item) GUI.JobList.setItemWidget(item, label) GUI.JobList.scrollToBottom() diff --git a/kcc/image.py b/kcc/image.py index bc3c7fe..7401a78 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -207,9 +207,11 @@ class ComicPage: palImg.putpalette(self.palette) self.image = self.image.convert('L') self.image = self.image.convert('RGB') + # Quantize is deprecated but new function call it internally anyway... self.image = self.image.quantize(palette=palImg) def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0): + # High-quality downscaling filter method = Image.ANTIALIAS if bordersColor: fill = bordersColor @@ -224,6 +226,7 @@ class ComicPage: else: size = (self.panelviewsize[0], self.panelviewsize[1]) generateBorder = False + # If image is smaller than screen and upscale is off - Just expand it if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]: if not upscale: borderw = (self.size[0] - self.image.size[0]) / 2 @@ -238,8 +241,10 @@ class ComicPage: int(round(float(borderh)/float(self.image.size[1])*100, 2)*100*1.5)] return self.image else: - method = Image.BILINEAR - if stretch: # If stretching call directly resize() without other considerations. + # Cubic spline interpolation in a 4x4 environment + method = Image.BICUBIC + # If stretching is on - Resize without other considerations + if stretch: self.image = self.image.resize(size, method) if generateBorder: if fill == 'white': @@ -258,6 +263,7 @@ class ComicPage: self.noHPV = True self.noVPV = True return self.image + # Otherwise - Upscale/Downscale ratioDev = float(self.size[0]) / float(self.size[1]) if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev: diff = int(self.image.size[1] * ratioDev) - self.image.size[0]