From 69b956904ca8af438529b9c22c1874a487e2c220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Sun, 15 Sep 2013 15:02:31 +0200 Subject: [PATCH] Removed support of Virtual Panel View --- kcc/KCC_gui.py | 8 ++- kcc/comic2ebook.py | 158 ++++++++++----------------------------------- kcc/image.py | 30 ++------- 3 files changed, 47 insertions(+), 149 deletions(-) diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py index 5318e49..af65a30 100644 --- a/kcc/KCC_gui.py +++ b/kcc/KCC_gui.py @@ -208,7 +208,8 @@ class WorkerThread(QtCore.QThread): try: self.kindlegenErrorCode = 0 if os.path.getsize(item) < 367001600: - output = Popen('kindlegen -locale en "' + item + '"', stdout=PIPE, stderr=STDOUT, shell=True) + output = Popen('kindlegen -locale en "' + item + '"', stdout=PIPE, stderr=STDOUT, + shell=True) for line in output.stdout: # ERROR: Generic error if "Error(" in line: @@ -439,11 +440,14 @@ class Ui_KCC(object): GUI.QualityBox.setChecked(False) GUI.BorderBox.setEnabled(False) GUI.BorderBox.setChecked(False) + GUI.MangaBox.setEnabled(False) + GUI.MangaBox.setChecked(False) self.addMessage('If images are color setting Gamma to 1.0 is recommended.', 'info') else: GUI.NoRotateBox.setEnabled(True) GUI.QualityBox.setEnabled(True) GUI.BorderBox.setEnabled(True) + GUI.MangaBox.setEnabled(True) def toggleNoSplitRotate(self, value): if value: @@ -467,7 +471,7 @@ class Ui_KCC(object): GUI.BasicModeButton.setEnabled(True) GUI.AdvModeButton.setEnabled(True) self.modeBasic() - if value in [0, 1, 5, 6, 7, 8, 9, 12]: + if value in [0, 1, 5, 6, 12]: GUI.QualityBox.setCheckState(0) GUI.QualityBox.setEnabled(False) else: diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 48ff053..806d949 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -145,22 +145,6 @@ def buildHTML(path, imgfile): return path, imgfile -def buildBlankHTML(path): - f = open(os.path.join(path, 'blank.html'), "w") - f.writelines(["\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - ""]) - f.close() - return path - - def buildNCX(dstdir, title, chapters): from uuid import uuid4 options.uuid = str(uuid4()) @@ -173,16 +157,18 @@ def buildNCX(dstdir, title, chapters): "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", + "\n", "\n", "", title, "\n", "" ]) for chapter in chapters: folder = chapter[0].replace(os.path.join(dstdir, 'OEBPS'), '').lstrip('/').lstrip('\\\\') - title = os.path.basename(folder) + if os.path.basename(folder) != "Text": + title = os.path.basename(folder) filename = getImageFileName(os.path.join(folder, chapter[1])) f.write("" + title + "\n") @@ -197,38 +183,32 @@ def buildOPF(dstdir, title, filelist, cover=None): imgres = str(deviceres[0]) + "x" + str(deviceres[1]) if options.righttoleft: writingmode = "horizontal-rl" - facing = "right" - facing1 = "right" - facing2 = "left" else: writingmode = "horizontal-lr" - facing = "left" - facing1 = "left" - facing2 = "right" f = open(opffile, "w") f.writelines(["\n", - "\n", - "\n", + "\n", + "\n", "", title, "\n", "en-US\n", "", options.uuid, "\n", + "\n", "\n", + "\n", "\n", "\n", + "\n", "\n", "\n", "\n" - ]) - if options.landscapemode: - f.writelines(["\n", - "\n"]) - else: - f.writelines(["\n", - "\n"]) - f.writelines(["\n", + "\n", + "\n", + "\n", "\n", - "\n", + "\n", + "\n", "\n\n\n"]) if cover is not None: @@ -253,44 +233,10 @@ def buildOPF(dstdir, title, filelist, cover=None): mt = 'image/jpeg' f.write("\n") - if options.landscapemode and splitCount > 0: - splitCountUsed = 1 - while splitCountUsed <= splitCount: - f.write("\n") - splitCountUsed += 1 f.write("\n") f.write("\n\n") - splitCountUsed = 1 for entry in reflist: - if "_kcca" in str(entry): - # noinspection PyRedundantParentheses - if ((options.righttoleft and facing == 'left') or (not options.righttoleft and facing == 'right')) and\ - options.landscapemode: - f.write("\n") - splitCountUsed += 1 - if options.landscapemode: - f.write("\n") - else: - f.write("\n") - elif "_kccb" in str(entry): - if options.landscapemode: - f.write("\n") - else: - f.write("\n") - if options.righttoleft: - facing = "right" - else: - facing = "left" - else: - if options.landscapemode: - f.write("\n") - else: - f.write("\n") - if facing == 'right': - facing = 'left' - else: - facing = 'right' + f.write("\n") f.write("\n\n\n\n") f.close() os.mkdir(os.path.join(dstdir, 'META-INF')) @@ -322,24 +268,22 @@ def getImageFileName(imgfile): return filename -def applyImgOptimization(img, isSplit, toRight, options, overrideQuality=5): +def applyImgOptimization(img, options, overrideQuality=5): if not options.webtoon: img.cropWhiteSpace(10.0) if options.cutpagenumbers and not options.webtoon: img.cutPageNumber() img.optimizeImage(options.gamma) if overrideQuality != 5: - img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight, - options.landscapemode, overrideQuality) + img.resizeImage(options.upscale, options.stretch, options.black_borders, overrideQuality) else: - img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight, - options.landscapemode, options.quality) + img.resizeImage(options.upscale, options.stretch, options.black_borders, options.quality) if options.forcepng and not options.forcecolor: img.quantizeImage() def dirImgProcess(path): - global options, splitCount + global options work = [] pagenumber = 0 pagenumbermodifier = 0 @@ -378,7 +322,6 @@ def dirImgProcess(path): splitpages.sort() for page in splitpages: if (page + pagenumbermodifier) % 2 == 0: - splitCount += 1 pagenumbermodifier += 1 pagenumbermodifier += 1 else: @@ -415,34 +358,28 @@ def fileImgProcess(work): if split is not None and split is not "R": if options.verbose: print "Splitted " + afile - if options.righttoleft: - toRight1 = False - toRight2 = True - else: - toRight1 = True - toRight2 = False output = pagenumber img0 = image.ComicPage(split[0], options.profileData) - applyImgOptimization(img0, True, toRight1, options) + applyImgOptimization(img0, options) img0.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe) img1 = image.ComicPage(split[1], options.profileData) - applyImgOptimization(img1, True, toRight2, options) + applyImgOptimization(img1, options) img1.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe) if options.quality == 2: img3 = image.ComicPage(split[0], options.profileData) - applyImgOptimization(img3, True, toRight1, options, 0) + applyImgOptimization(img3, options, 0) img3.saveToDir(dirpath, options.forcepng, options.forcecolor, True) img4 = image.ComicPage(split[1], options.profileData) - applyImgOptimization(img4, True, toRight2, options, 0) + applyImgOptimization(img4, options, 0) img4.saveToDir(dirpath, options.forcepng, options.forcecolor, True) else: - applyImgOptimization(img, False, False, options) + applyImgOptimization(img, options) img.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe, split) if options.quality == 2: img2 = image.ComicPage(os.path.join(dirpath, afile), options.profileData) if split == "R": img2.image = img2.image.rotate(90) - applyImgOptimization(img2, False, False, options, 0) + applyImgOptimization(img2, options, 0) img2.saveToDir(dirpath, options.forcepng, options.forcecolor, True, split) return output @@ -588,13 +525,11 @@ def genEpubStruct(path): 'cover' + getImageFileName(filelist[-1][1])[1]) copyfile(os.path.join(filelist[-1][0], filelist[-1][1]), cover) buildNCX(path, options.title, chapterlist) - # ensure we're sorting files alphabetically + # Ensure we're sorting files alphabetically convert = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] filelist.sort(key=lambda name: (alphanum_key(name[0].lower()), alphanum_key(name[1].lower()))) buildOPF(path, options.title, filelist, cover) - if options.landscapemode and splitCount > 0: - filelist.append(buildBlankHTML(os.path.join(path, 'OEBPS', 'Text'))) def getWorkFolder(afile): @@ -637,8 +572,7 @@ def getWorkFolder(afile): 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 value = unicodedata.normalize('NFKD', unicode(value, 'latin1')).encode('ascii', 'ignore') value = re.sub('[^\w\s\.-]', '', value).strip().lower() @@ -844,7 +778,7 @@ def Usage(): def main(argv=None, qtGUI=None): - global parser, options, epub_path, splitCount, GUI + global parser, options, epub_path, GUI parser = OptionParser(usage="Usage: %prog [options] comic_file|comic_folder", add_help_option=False) mainOptions = OptionGroup(parser, "MAIN") experimentalOptions = OptionGroup(parser, "EXPERIMENTAL") @@ -921,7 +855,6 @@ def main(argv=None, qtGUI=None): comic2panel.main(['-y ' + str(options.customheight), '-i', path], qtGUI) else: comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', path], qtGUI) - splitCount = 0 if options.imgproc: print "\nProcessing images..." if GUI: @@ -985,47 +918,24 @@ def getOutputFilename(srcpath, wantedname, ext, tomeNumber): def checkOptions(): global options - # Landscape mode is only supported by Kindle Touch and Paperwhite. - if options.profile == 'K4T' or options.profile == 'KHD': - options.landscapemode = True - else: - options.landscapemode = False - # Older Kindle don't support Virtual Panel View. We providing them configuration that will fake that feature. - # Ultra quality mode require Real Panel View. Landscape mode don't work correcly without Virtual Panel View. - if options.profile == 'K3' or options.profile == 'K4NT' or options.quality == 2: - # Real Panel View - options.panelview = True - options.landscapemode = False - else: - # Virtual Panel View - options.panelview = False + options.panelview = True # Disabling grayscale conversion for Kindle Fire family. if options.profile == 'KF' or options.profile == 'KFHD' or options.profile == 'KFHD8' or options.forcecolor: options.forcecolor = True else: options.forcecolor = False - # Mixing vertical and horizontal pages require real Panel View. - # Landscape mode don't work correcly without Virtual Panel View. - if options.rotate: - options.panelview = True - options.landscapemode = False # Older Kindle don't need higher resolution files due lack of Panel View. - # Kindle Fire family have very high resolution. Bigger images are not needed. - if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'KDX' or options.profile == 'KDXG'\ - or options.profile == 'KF' or options.profile == 'KFHD' or options.profile == 'KFHD8': + if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'KDX' or options.profile == 'KDXG': options.quality = 0 - if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'KDX' or options.profile == 'KDXG': - options.panelview = False + options.panelview = False # Webtoon mode mandatory options if options.webtoon: options.nosplitrotate = True options.black_borders = False options.quality = 0 - options.landscapemode = False options.panelview = False - # Disable all Kindle features + # Disable all Kindle features for other e-readers if options.profile == 'OTHER': - options.landscapemode = False options.panelview = False options.quality = 0 # Kindle for Android profile require target resolution. diff --git a/kcc/image.py b/kcc/image.py index d05b8c6..f3cb621 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -173,8 +173,7 @@ class ComicPage: palImg.putpalette(self.palette) self.image = self.image.quantize(palette=palImg) - def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False, - landscapeMode=False, qualityMode=0): + def resizeImage(self, upscale=False, stretch=False, black_borders=False, qualityMode=0): method = Image.ANTIALIAS if '-KCCFW' in str(self.filename): fill = 'white' @@ -194,9 +193,6 @@ class ComicPage: else: size = (self.panelviewsize[0], self.panelviewsize[1]) generateBorder = False - # Kindle Paperwhite/Touch - Force upscale of splited pages to increase readability - if isSplit and landscapeMode: - upscale = True 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 @@ -210,7 +206,7 @@ class ComicPage: return self.image else: method = Image.BILINEAR - if stretch: # if stretching call directly resize() without other considerations. + if stretch: # If stretching call directly resize() without other considerations. self.image = self.image.resize(size, method) if generateBorder: if fill == 'white': @@ -224,19 +220,8 @@ class ComicPage: return self.image ratioDev = float(self.size[0]) / float(self.size[1]) if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev: - if isSplit and landscapeMode: - generateBorder = False - diff = int(self.image.size[1] * ratioDev) - self.image.size[0] - self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill) - tempImg = Image.new(self.image.mode, (self.image.size[0] + diff, self.image.size[1]), fill) - if toRight: - tempImg.paste(self.image, (diff, 0)) - else: - tempImg.paste(self.image, (0, 0)) - self.image = tempImg - else: - diff = int(self.image.size[1] * ratioDev) - self.image.size[0] - self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill) + diff = int(self.image.size[1] * ratioDev) - self.image.size[0] + self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill) elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev: diff = int(self.image.size[0] / ratioDev) - self.image.size[1] self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill) @@ -255,19 +240,18 @@ class ComicPage: def splitPage(self, targetdir, righttoleft=False, rotate=False): width, height = self.image.size dstwidth, dstheight = self.size - #print "Image is %d x %d" % (width,height) - # only split if origin is not oriented the same as target + # Only split if origin is not oriented the same as target if (width > height) != (dstwidth > dstheight): if rotate: self.image = self.image.rotate(90) return "R" else: if width > height: - # source is landscape, so split by the width + # Source is landscape, so split by the width leftbox = (0, 0, width / 2, height) rightbox = (width / 2, 0, width, height) else: - # source is portrait and target is landscape, so split by the height + # Source is portrait and target is landscape, so split by the height leftbox = (0, 0, width, height / 2) rightbox = (0, height / 2, width, height) filename = os.path.splitext(self.filename)