mirror of
https://github.com/ciromattia/kcc
synced 2026-10-08 10:32:31 +00:00
Changed upscale algorithm to bicubic + little code cleanup
This commit is contained in:
@@ -34,6 +34,7 @@ except ImportError:
|
|||||||
from kcc import KCC_gui
|
from kcc import KCC_gui
|
||||||
from multiprocessing import freeze_support
|
from multiprocessing import freeze_support
|
||||||
if sys.platform.startswith('darwin'):
|
if sys.platform.startswith('darwin'):
|
||||||
|
# Workaround Finder-launched app PATH evaluation
|
||||||
os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']
|
os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']
|
||||||
from kcc import KCC_ui_osx as KCC_ui
|
from kcc import KCC_ui_osx as KCC_ui
|
||||||
elif sys.platform.startswith('linux'):
|
elif sys.platform.startswith('linux'):
|
||||||
@@ -47,6 +48,7 @@ else:
|
|||||||
from kcc import KCC_ui
|
from kcc import KCC_ui
|
||||||
|
|
||||||
|
|
||||||
|
# Implementing detection of already running KCC instance and forwarding argv to it
|
||||||
class QApplicationMessaging(QtGui.QApplication):
|
class QApplicationMessaging(QtGui.QApplication):
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
QtGui.QApplication.__init__(self, argv)
|
QtGui.QApplication.__init__(self, argv)
|
||||||
|
|||||||
+8
-3
@@ -158,6 +158,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
if GUI.ColorBox.isChecked():
|
if GUI.ColorBox.isChecked():
|
||||||
argv.append("--forcecolor")
|
argv.append("--forcecolor")
|
||||||
for i in range(GUI.JobList.count()):
|
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():
|
if GUI.JobList.item(i).icon().isNull():
|
||||||
currentJobs.append(unicode(GUI.JobList.item(i).text()))
|
currentJobs.append(unicode(GUI.JobList.item(i).text()))
|
||||||
GUI.JobList.clear()
|
GUI.JobList.clear()
|
||||||
@@ -255,6 +256,8 @@ class WorkerThread(QtCore.QThread):
|
|||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
shutil.move(mobiPath, mobiPath + '_toclean')
|
shutil.move(mobiPath, mobiPath + '_toclean')
|
||||||
try:
|
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']:
|
if profile in ['K345', 'KHD', 'KF', 'KFHD', 'KFHD8', 'KFHDX8', 'KFA']:
|
||||||
newKindle = True
|
newKindle = True
|
||||||
else:
|
else:
|
||||||
@@ -546,18 +549,20 @@ class Ui_KCC(object):
|
|||||||
def addMessage(self, message, icon=None, replace=False):
|
def addMessage(self, message, icon=None, replace=False):
|
||||||
if icon:
|
if icon:
|
||||||
icon = eval('self.icons.' + icon)
|
icon = eval('self.icons.' + icon)
|
||||||
item = QtGui.QListWidgetItem(icon, ' ' + self.stripTags(message))
|
item = QtGui.QListWidgetItem(icon, ' ' + self.stripTags(message))
|
||||||
else:
|
else:
|
||||||
item = QtGui.QListWidgetItem(' ' + self.stripTags(message))
|
item = QtGui.QListWidgetItem(' ' + self.stripTags(message))
|
||||||
if replace:
|
if replace:
|
||||||
GUI.JobList.takeItem(GUI.JobList.count()-1)
|
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 = QtGui.QLabel(message)
|
||||||
label.setStyleSheet('background-image:url('');background-color:rgba(255,0,0,0.5);')
|
label.setStyleSheet('background-image:url('');background-color:rgba(255,0,0,0.5);')
|
||||||
label.setOpenExternalLinks(True)
|
label.setOpenExternalLinks(True)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setPointSize(self.listFontSize)
|
font.setPointSize(self.listFontSize)
|
||||||
label.setFont(font)
|
label.setFont(font)
|
||||||
item.setTextColor(QtGui.QColor('transparent'))
|
|
||||||
GUI.JobList.addItem(item)
|
GUI.JobList.addItem(item)
|
||||||
GUI.JobList.setItemWidget(item, label)
|
GUI.JobList.setItemWidget(item, label)
|
||||||
GUI.JobList.scrollToBottom()
|
GUI.JobList.scrollToBottom()
|
||||||
|
|||||||
+8
-2
@@ -207,9 +207,11 @@ class ComicPage:
|
|||||||
palImg.putpalette(self.palette)
|
palImg.putpalette(self.palette)
|
||||||
self.image = self.image.convert('L')
|
self.image = self.image.convert('L')
|
||||||
self.image = self.image.convert('RGB')
|
self.image = self.image.convert('RGB')
|
||||||
|
# Quantize is deprecated but new function call it internally anyway...
|
||||||
self.image = self.image.quantize(palette=palImg)
|
self.image = self.image.quantize(palette=palImg)
|
||||||
|
|
||||||
def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0):
|
def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0):
|
||||||
|
# High-quality downscaling filter
|
||||||
method = Image.ANTIALIAS
|
method = Image.ANTIALIAS
|
||||||
if bordersColor:
|
if bordersColor:
|
||||||
fill = bordersColor
|
fill = bordersColor
|
||||||
@@ -224,6 +226,7 @@ class ComicPage:
|
|||||||
else:
|
else:
|
||||||
size = (self.panelviewsize[0], self.panelviewsize[1])
|
size = (self.panelviewsize[0], self.panelviewsize[1])
|
||||||
generateBorder = False
|
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 self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
|
||||||
if not upscale:
|
if not upscale:
|
||||||
borderw = (self.size[0] - self.image.size[0]) / 2
|
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)]
|
int(round(float(borderh)/float(self.image.size[1])*100, 2)*100*1.5)]
|
||||||
return self.image
|
return self.image
|
||||||
else:
|
else:
|
||||||
method = Image.BILINEAR
|
# Cubic spline interpolation in a 4x4 environment
|
||||||
if stretch: # If stretching call directly resize() without other considerations.
|
method = Image.BICUBIC
|
||||||
|
# If stretching is on - Resize without other considerations
|
||||||
|
if stretch:
|
||||||
self.image = self.image.resize(size, method)
|
self.image = self.image.resize(size, method)
|
||||||
if generateBorder:
|
if generateBorder:
|
||||||
if fill == 'white':
|
if fill == 'white':
|
||||||
@@ -258,6 +263,7 @@ class ComicPage:
|
|||||||
self.noHPV = True
|
self.noHPV = True
|
||||||
self.noVPV = True
|
self.noVPV = True
|
||||||
return self.image
|
return self.image
|
||||||
|
# Otherwise - Upscale/Downscale
|
||||||
ratioDev = float(self.size[0]) / float(self.size[1])
|
ratioDev = float(self.size[0]) / float(self.size[1])
|
||||||
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
|
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
|
||||||
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
|
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user