mirror of
https://github.com/ciromattia/kcc
synced 2026-10-05 17:12:32 +00:00
Code cleanup
This commit is contained in:
@@ -138,13 +138,12 @@ The app relies and includes the following scripts/binaries:
|
|||||||
## SAMPLE FILES CREATED BY KCC
|
## SAMPLE FILES CREATED BY KCC
|
||||||
* [Kindle Paperwhite](http://kcc.vulturis.eu/Samples/Ubunchu!-KPW.mobi)
|
* [Kindle Paperwhite](http://kcc.vulturis.eu/Samples/Ubunchu!-KPW.mobi)
|
||||||
* [Kindle](http://kcc.vulturis.eu/Samples/Ubunchu!-K345.mobi)
|
* [Kindle](http://kcc.vulturis.eu/Samples/Ubunchu!-K345.mobi)
|
||||||
|
* [Kindle DX](http://kcc.vulturis.eu/Samples/Ubunchu!-KDX.mobi)
|
||||||
* [Kindle Fire](http://kcc.vulturis.eu/Samples/Ubunchu!-KF.mobi)
|
* [Kindle Fire](http://kcc.vulturis.eu/Samples/Ubunchu!-KF.mobi)
|
||||||
* [Kindle Fire HD](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHD.mobi)
|
* [Kindle Fire HD](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHD.mobi)
|
||||||
* [Kindle Fire HD 8.9"](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHD8.mobi)
|
* [Kindle Fire HD 8.9"](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHD8.mobi)
|
||||||
* [Kindle Fire HDX](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHDX.mobi)
|
* [Kindle Fire HDX](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHDX.mobi)
|
||||||
* [Kindle Fire HDX 8.9"](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHDX8.mobi)
|
* [Kindle Fire HDX 8.9"](http://kcc.vulturis.eu/Samples/Ubunchu!-KFHDX8.mobi)
|
||||||
* [Kindle DX](http://kcc.vulturis.eu/Samples/Ubunchu!-KDX.mobi)
|
|
||||||
* [Kindle DXG](http://kcc.vulturis.eu/Samples/Ubunchu!-KDXG.mobi)
|
|
||||||
|
|
||||||
## CHANGELOG
|
## CHANGELOG
|
||||||
####1.00
|
####1.00
|
||||||
|
|||||||
@@ -99,6 +99,10 @@ class WorkerThread(QtCore.QThread):
|
|||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QtCore.QThread.__init__(self)
|
QtCore.QThread.__init__(self)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.conversionAlive = False
|
||||||
|
self.errors = False
|
||||||
|
self.kindlegenErrorCode = 0
|
||||||
|
self.kindlegenError = None
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.wait()
|
self.wait()
|
||||||
@@ -610,6 +614,7 @@ class Ui_KCC(object):
|
|||||||
self.versionCheck = VersionThread(self)
|
self.versionCheck = VersionThread(self)
|
||||||
self.conversionAlive = False
|
self.conversionAlive = False
|
||||||
self.needClean = True
|
self.needClean = True
|
||||||
|
self.GammaValue = 1.0
|
||||||
|
|
||||||
self.addMessage('<b>Welcome!</b>', 'info')
|
self.addMessage('<b>Welcome!</b>', 'info')
|
||||||
self.addMessage('<b>Remember:</b> All options have additional informations in tooltips.', 'info')
|
self.addMessage('<b>Remember:</b> All options have additional informations in tooltips.', 'info')
|
||||||
|
|||||||
+39
-40
@@ -287,23 +287,22 @@ def getImageFileName(imgfile):
|
|||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
def applyImgOptimization(img, options, overrideQuality=5):
|
def applyImgOptimization(img, opt, overrideQuality=5):
|
||||||
img.getImageFill(options.webtoon)
|
img.getImageFill(opt.webtoon)
|
||||||
if not options.webtoon:
|
if not opt.webtoon:
|
||||||
img.cropWhiteSpace(10.0)
|
img.cropWhiteSpace(10.0)
|
||||||
if options.cutpagenumbers and not options.webtoon:
|
if opt.cutpagenumbers and not opt.webtoon:
|
||||||
img.cutPageNumber()
|
img.cutPageNumber()
|
||||||
img.optimizeImage(options.gamma)
|
img.optimizeImage(opt.gamma)
|
||||||
if overrideQuality != 5:
|
if overrideQuality != 5:
|
||||||
img.resizeImage(options.upscale, options.stretch, options.bordersColor, overrideQuality)
|
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, overrideQuality)
|
||||||
else:
|
else:
|
||||||
img.resizeImage(options.upscale, options.stretch, options.bordersColor, options.quality)
|
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, opt.quality)
|
||||||
if options.forcepng and not options.forcecolor:
|
if opt.forcepng and not opt.forcecolor:
|
||||||
img.quantizeImage()
|
img.quantizeImage()
|
||||||
|
|
||||||
|
|
||||||
def dirImgProcess(path):
|
def dirImgProcess(path):
|
||||||
global options
|
|
||||||
work = []
|
work = []
|
||||||
pagenumber = 0
|
pagenumber = 0
|
||||||
pagenumbermodifier = 0
|
pagenumbermodifier = 0
|
||||||
@@ -349,9 +348,9 @@ def dirImgProcess(path):
|
|||||||
raise UserWarning("Source directory is empty.")
|
raise UserWarning("Source directory is empty.")
|
||||||
|
|
||||||
|
|
||||||
def fileImgProcess_init(queue, options):
|
def fileImgProcess_init(queue, opt):
|
||||||
fileImgProcess.queue = queue
|
fileImgProcess.queue = queue
|
||||||
fileImgProcess.options = options
|
fileImgProcess.options = opt
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
@@ -359,54 +358,53 @@ def fileImgProcess(work):
|
|||||||
afile = work[0]
|
afile = work[0]
|
||||||
dirpath = work[1]
|
dirpath = work[1]
|
||||||
pagenumber = work[2]
|
pagenumber = work[2]
|
||||||
options = fileImgProcess.options
|
opt = fileImgProcess.options
|
||||||
output = None
|
output = None
|
||||||
if options.verbose:
|
if opt.verbose:
|
||||||
print "Optimizing " + afile + " for " + options.profile
|
print "Optimizing " + afile + " for " + opt.profile
|
||||||
else:
|
else:
|
||||||
print ".",
|
print ".",
|
||||||
fileImgProcess.queue.put(".")
|
fileImgProcess.queue.put(".")
|
||||||
img = image.ComicPage(os.path.join(dirpath, afile), options.profileData)
|
img = image.ComicPage(os.path.join(dirpath, afile), opt.profileData)
|
||||||
if options.quality == 2:
|
if opt.quality == 2:
|
||||||
wipe = False
|
wipe = False
|
||||||
else:
|
else:
|
||||||
wipe = True
|
wipe = True
|
||||||
if options.nosplitrotate:
|
if opt.nosplitrotate:
|
||||||
split = None
|
split = None
|
||||||
else:
|
else:
|
||||||
split = img.splitPage(dirpath, options.righttoleft, options.rotate)
|
split = img.splitPage(dirpath, opt.righttoleft, opt.rotate)
|
||||||
if split is not None:
|
if split is not None:
|
||||||
if options.verbose:
|
if opt.verbose:
|
||||||
print "Splitted " + afile
|
print "Splitted " + afile
|
||||||
output = pagenumber
|
output = pagenumber
|
||||||
img0 = image.ComicPage(split[0], options.profileData)
|
img0 = image.ComicPage(split[0], opt.profileData)
|
||||||
applyImgOptimization(img0, options)
|
applyImgOptimization(img0, opt)
|
||||||
img0.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe)
|
img0.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
||||||
img1 = image.ComicPage(split[1], options.profileData)
|
img1 = image.ComicPage(split[1], opt.profileData)
|
||||||
applyImgOptimization(img1, options)
|
applyImgOptimization(img1, opt)
|
||||||
img1.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe)
|
img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
||||||
if options.quality == 2:
|
if opt.quality == 2:
|
||||||
img3 = image.ComicPage(split[0], options.profileData)
|
img3 = image.ComicPage(split[0], opt.profileData)
|
||||||
applyImgOptimization(img3, options, 0)
|
applyImgOptimization(img3, opt, 0)
|
||||||
img3.saveToDir(dirpath, options.forcepng, options.forcecolor, True)
|
img3.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
img4 = image.ComicPage(split[1], options.profileData)
|
img4 = image.ComicPage(split[1], opt.profileData)
|
||||||
applyImgOptimization(img4, options, 0)
|
applyImgOptimization(img4, opt, 0)
|
||||||
img4.saveToDir(dirpath, options.forcepng, options.forcecolor, True)
|
img4.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
else:
|
else:
|
||||||
applyImgOptimization(img, options)
|
applyImgOptimization(img, opt)
|
||||||
img.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe)
|
img.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
||||||
if options.quality == 2:
|
if opt.quality == 2:
|
||||||
img2 = image.ComicPage(os.path.join(dirpath, afile), options.profileData)
|
img2 = image.ComicPage(os.path.join(dirpath, afile), opt.profileData)
|
||||||
if img.rotated:
|
if img.rotated:
|
||||||
img2.image = img2.image.rotate(90)
|
img2.image = img2.image.rotate(90)
|
||||||
img2.rotated = True
|
img2.rotated = True
|
||||||
applyImgOptimization(img2, options, 0)
|
applyImgOptimization(img2, opt, 0)
|
||||||
img2.saveToDir(dirpath, options.forcepng, options.forcecolor, True)
|
img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def genEpubStruct(path):
|
def genEpubStruct(path):
|
||||||
global options
|
|
||||||
filelist = []
|
filelist = []
|
||||||
chapterlist = []
|
chapterlist = []
|
||||||
cover = None
|
cover = None
|
||||||
@@ -584,6 +582,7 @@ def getWorkFolder(afile):
|
|||||||
def slugify(value):
|
def slugify(value):
|
||||||
# Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
|
# Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
#noinspection PyArgumentList
|
||||||
value = unicodedata.normalize('NFKD', unicode(value, 'latin1')).encode('ascii', 'ignore')
|
value = unicodedata.normalize('NFKD', unicode(value, 'latin1')).encode('ascii', 'ignore')
|
||||||
value = re.sub('[^\w\s\.-]', '', value).strip().lower()
|
value = re.sub('[^\w\s\.-]', '', value).strip().lower()
|
||||||
value = re.sub('[-\.\s]+', '-', value)
|
value = re.sub('[-\.\s]+', '-', value)
|
||||||
@@ -788,7 +787,7 @@ def Usage():
|
|||||||
|
|
||||||
|
|
||||||
def main(argv=None, qtGUI=None):
|
def main(argv=None, qtGUI=None):
|
||||||
global parser, options, epub_path, GUI
|
global parser, options, GUI
|
||||||
parser = OptionParser(usage="Usage: %prog [options] comic_file|comic_folder", add_help_option=False)
|
parser = OptionParser(usage="Usage: %prog [options] comic_file|comic_folder", add_help_option=False)
|
||||||
mainOptions = OptionGroup(parser, "MAIN")
|
mainOptions = OptionGroup(parser, "MAIN")
|
||||||
processingOptions = OptionGroup(parser, "PROCESSING")
|
processingOptions = OptionGroup(parser, "PROCESSING")
|
||||||
|
|||||||
+15
-15
@@ -54,9 +54,9 @@ def getImageFileName(imgfile):
|
|||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
def sanitizePanelSize(panel, options):
|
def sanitizePanelSize(panel, opt):
|
||||||
newPanels = []
|
newPanels = []
|
||||||
if panel[2] > 8 * options.height:
|
if panel[2] > 8 * opt.height:
|
||||||
diff = (panel[2] / 8)
|
diff = (panel[2] / 8)
|
||||||
newPanels.append([panel[0], panel[1] - diff*7, diff])
|
newPanels.append([panel[0], panel[1] - diff*7, diff])
|
||||||
newPanels.append([panel[1] - diff*7, panel[1] - diff*6, diff])
|
newPanels.append([panel[1] - diff*7, panel[1] - diff*6, diff])
|
||||||
@@ -66,13 +66,13 @@ def sanitizePanelSize(panel, options):
|
|||||||
newPanels.append([panel[1] - diff*3, panel[1] - diff*2, diff])
|
newPanels.append([panel[1] - diff*3, panel[1] - diff*2, diff])
|
||||||
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
|
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
|
||||||
newPanels.append([panel[1] - diff, panel[1], diff])
|
newPanels.append([panel[1] - diff, panel[1], diff])
|
||||||
elif panel[2] > 4 * options.height:
|
elif panel[2] > 4 * opt.height:
|
||||||
diff = (panel[2] / 4)
|
diff = (panel[2] / 4)
|
||||||
newPanels.append([panel[0], panel[1] - diff*3, diff])
|
newPanels.append([panel[0], panel[1] - diff*3, diff])
|
||||||
newPanels.append([panel[1] - diff*3, panel[1] - diff*2, diff])
|
newPanels.append([panel[1] - diff*3, panel[1] - diff*2, diff])
|
||||||
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
|
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
|
||||||
newPanels.append([panel[1] - diff, panel[1], diff])
|
newPanels.append([panel[1] - diff, panel[1], diff])
|
||||||
elif panel[2] > 2 * options.height:
|
elif panel[2] > 2 * opt.height:
|
||||||
newPanels.append([panel[0], panel[1] - (panel[2] / 2), (panel[2] / 2)])
|
newPanels.append([panel[0], panel[1] - (panel[2] / 2), (panel[2] / 2)])
|
||||||
newPanels.append([panel[1] - (panel[2] / 2), panel[1], (panel[2] / 2)])
|
newPanels.append([panel[1] - (panel[2] / 2), panel[1], (panel[2] / 2)])
|
||||||
else:
|
else:
|
||||||
@@ -80,17 +80,17 @@ def sanitizePanelSize(panel, options):
|
|||||||
return newPanels
|
return newPanels
|
||||||
|
|
||||||
|
|
||||||
def splitImage_init(queue, options):
|
def splitImage_init(queue, opt):
|
||||||
splitImage.queue = queue
|
splitImage.queue = queue
|
||||||
splitImage.options = options
|
splitImage.options = opt
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
def splitImage(work):
|
def splitImage(work):
|
||||||
path = work[0]
|
path = work[0]
|
||||||
name = work[1]
|
name = work[1]
|
||||||
options = splitImage.options
|
opt = splitImage.options
|
||||||
# Harcoded options
|
# Harcoded opttions
|
||||||
threshold = 1.0
|
threshold = 1.0
|
||||||
delta = 15
|
delta = 15
|
||||||
print ".",
|
print ".",
|
||||||
@@ -115,8 +115,8 @@ def splitImage(work):
|
|||||||
image = Image.open(filePath)
|
image = Image.open(filePath)
|
||||||
image = image.convert('RGB')
|
image = image.convert('RGB')
|
||||||
widthImg, heightImg = image.size
|
widthImg, heightImg = image.size
|
||||||
if heightImg > options.height:
|
if heightImg > opt.height:
|
||||||
if options.debug:
|
if opt.debug:
|
||||||
from PIL import ImageDraw
|
from PIL import ImageDraw
|
||||||
debugImage = Image.open(filePath)
|
debugImage = Image.open(filePath)
|
||||||
draw = ImageDraw.Draw(debugImage)
|
draw = ImageDraw.Draw(debugImage)
|
||||||
@@ -138,23 +138,23 @@ def splitImage(work):
|
|||||||
if y1 + delta >= heightImg:
|
if y1 + delta >= heightImg:
|
||||||
y1 = heightImg - 1
|
y1 = heightImg - 1
|
||||||
y2Temp = y1
|
y2Temp = y1
|
||||||
if options.debug:
|
if opt.debug:
|
||||||
draw.line([(0, y1Temp), (widthImg, y1Temp)], fill=(0, 255, 0))
|
draw.line([(0, y1Temp), (widthImg, y1Temp)], fill=(0, 255, 0))
|
||||||
draw.line([(0, y2Temp), (widthImg, y2Temp)], fill=(255, 0, 0))
|
draw.line([(0, y2Temp), (widthImg, y2Temp)], fill=(255, 0, 0))
|
||||||
panelHeight = y2Temp - y1Temp
|
panelHeight = y2Temp - y1Temp
|
||||||
if panelHeight > delta:
|
if panelHeight > delta:
|
||||||
# Panels that can't be cut nicely will be forcefully splitted
|
# Panels that can't be cut nicely will be forcefully splitted
|
||||||
panelsCleaned = sanitizePanelSize([y1Temp, y2Temp, panelHeight], options)
|
panelsCleaned = sanitizePanelSize([y1Temp, y2Temp, panelHeight], opt)
|
||||||
for panel in panelsCleaned:
|
for panel in panelsCleaned:
|
||||||
panels.append(panel)
|
panels.append(panel)
|
||||||
if options.debug:
|
if opt.debug:
|
||||||
# noinspection PyUnboundLocalVariable
|
# noinspection PyUnboundLocalVariable
|
||||||
debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG')
|
debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG')
|
||||||
|
|
||||||
# Create virtual pages
|
# Create virtual pages
|
||||||
pages = []
|
pages = []
|
||||||
currentPage = []
|
currentPage = []
|
||||||
pageLeft = options.height
|
pageLeft = opt.height
|
||||||
panelNumber = 0
|
panelNumber = 0
|
||||||
for panel in panels:
|
for panel in panels:
|
||||||
if pageLeft - panel[2] > 0:
|
if pageLeft - panel[2] > 0:
|
||||||
@@ -164,7 +164,7 @@ def splitImage(work):
|
|||||||
else:
|
else:
|
||||||
if len(currentPage) > 0:
|
if len(currentPage) > 0:
|
||||||
pages.append(currentPage)
|
pages.append(currentPage)
|
||||||
pageLeft = options.height - panel[2]
|
pageLeft = opt.height - panel[2]
|
||||||
currentPage = [panelNumber]
|
currentPage = [panelNumber]
|
||||||
panelNumber += 1
|
panelNumber += 1
|
||||||
if len(currentPage) > 0:
|
if len(currentPage) > 0:
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
class ProfileData:
|
class ProfileData:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
Palette4 = [
|
Palette4 = [
|
||||||
0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00,
|
||||||
0x55, 0x55, 0x55,
|
0x55, 0x55, 0x55,
|
||||||
|
|||||||
Reference in New Issue
Block a user