mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 01:36:27 +00:00
Changed upscale algorithm to bicubic + little code cleanup
This commit is contained in:
2
kcc.py
2
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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
10
kcc/image.py
10
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]
|
||||
|
||||
Reference in New Issue
Block a user