From 97e23c8f507d81ebe6ca8c6900819eefab42f7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Wed, 14 Aug 2013 09:30:31 +0200 Subject: [PATCH] Web...toon mode improvements --- KCC-OSX.ui | 8 ++++---- KCC.ui | 6 +++--- README.md | 4 ++-- kcc/KCC_gui.py | 19 ++++++++++--------- kcc/KCC_ui.py | 14 +++++++------- kcc/KCC_ui_osx.py | 16 ++++++++-------- kcc/comic2ebook.py | 16 ++++++++-------- kcc/comic2panel.py | 23 ++++++++++++----------- 8 files changed, 54 insertions(+), 52 deletions(-) diff --git a/KCC-OSX.ui b/KCC-OSX.ui index dbe63ec..d1e7289 100644 --- a/KCC-OSX.ui +++ b/KCC-OSX.ui @@ -93,13 +93,13 @@ Stretch/Upscale - + true - + 11 @@ -109,10 +109,10 @@ Qt::NoFocus - <html><head/><body><p><span style=" font-weight:600;">EXPERIMENTAL!<br/></span>Enable auto-splitting of webstrips like <span style=" font-style:italic;">Tower of God</span> or <span style=" font-style:italic;">Noblesse</span>.<br/>Files with a low width, high height and vertical panel flow.</p></body></html> + <html><head/><body><p><span style=" font-weight:600;">EXPERIMENTAL!<br/></span>Enable auto-splitting of webtoons like <span style=" font-style:italic;">Tower of God</span> or <span style=" font-style:italic;">Noblesse</span>.<br/>Pages with a low width, high height and vertical panel flow.</p></body></html> - Webstrip mode + Webtoon mode diff --git a/KCC.ui b/KCC.ui index 3ec6959..5387341 100644 --- a/KCC.ui +++ b/KCC.ui @@ -92,15 +92,15 @@ - + Qt::NoFocus - <html><head/><body><p><span style=" font-weight:600;">EXPERIMENTAL!<br/></span>Enable auto-splitting of webstrips like <span style=" font-style:italic;">Tower of God</span> or <span style=" font-style:italic;">Noblesse</span>.<br/>Files with a low width, high height and vertical panel flow.</p></body></html> + <html><head/><body><p><span style=" font-weight:600;">EXPERIMENTAL!<br/></span>Enable auto-splitting of webtoons like <span style=" font-style:italic;">Tower of God</span> or <span style=" font-style:italic;">Noblesse</span>.<br/>Pages with a low width, high height and vertical panel flow.</p></body></html> - Webstrip mode + Webtoon mode diff --git a/README.md b/README.md index 6b439eb..69c1ced 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Options: -m, --manga-style Manga style (Right-to-left reading and splitting) EXPERIMENTAL: - -w, --webstrip Webstrip processing mode + -w, --webtoon Webtoon processing mode OUTPUT SETTINGS: -o OUTPUT, --output=OUTPUT @@ -249,7 +249,7 @@ The app relies and includes the following scripts/binaries: ####3.2: * Too big EPUB files are now splitted before conversion to MOBI -* Added experimental parser of manga webstrips +* Added experimental parser of manga webtoons * Improved error handling ## KNOWN ISSUES diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py index 761cc6d..c387b98 100644 --- a/kcc/KCC_gui.py +++ b/kcc/KCC_gui.py @@ -138,8 +138,8 @@ class WorkerThread(QtCore.QThread): argv.append("--upscale") if GUI.NoDitheringBox.isChecked(): argv.append("--forcepng") - if GUI.WebstripBox.isChecked(): - argv.append("--webstrip") + if GUI.WebtoonBox.isChecked(): + argv.append("--webtoon") if float(self.parent.GammaValue) > 0.09: argv.append("--gamma=" + self.parent.GammaValue) if str(GUI.FormatBox.currentText()) == 'CBZ': @@ -429,16 +429,17 @@ class Ui_KCC(object): GUI.GammaLabel.setText('Gamma: ' + str(value)) self.GammaValue = value - def toggleWebstripBox(self, value): + def toggleWebtoonBox(self, value): if value: - GUI.RotateBox.setEnabled(False) - GUI.RotateBox.setChecked(True) + GUI.NoRotateBox.setEnabled(False) + GUI.NoRotateBox.setChecked(True) GUI.QualityBox.setEnabled(False) GUI.QualityBox.setChecked(False) GUI.BorderBox.setEnabled(False) GUI.BorderBox.setChecked(False) + self.addMessage('If images are color setting Gamma to 1.0 is recommended.', 'info') else: - GUI.RotateBox.setEnabled(True) + GUI.NoRotateBox.setEnabled(True) GUI.QualityBox.setEnabled(True) GUI.BorderBox.setEnabled(True) @@ -544,7 +545,7 @@ class Ui_KCC(object): 'UpscaleBox': GUI.UpscaleBox.checkState(), 'NoRotateBox': GUI.NoRotateBox.checkState(), 'BorderBox': GUI.BorderBox.checkState(), - 'WebstripBox': GUI.WebstripBox.checkState(), + 'WebtoonBox': GUI.WebtoonBox.checkState(), 'NoDitheringBox': GUI.NoDitheringBox.checkState(), 'ColorBox': GUI.ColorBox.checkState(), 'customWidth': GUI.customWidth.text(), @@ -606,7 +607,7 @@ class Ui_KCC(object): GUI.ConvertButton.clicked.connect(self.convertStart) GUI.GammaSlider.valueChanged.connect(self.changeGamma) GUI.NoRotateBox.stateChanged.connect(self.toggleNoSplitRotate) - GUI.WebstripBox.stateChanged.connect(self.toggleWebstripBox) + GUI.WebtoonBox.stateChanged.connect(self.toggleWebtoonBox) GUI.DeviceBox.activated.connect(self.changeDevice) KCC.connect(self.worker, QtCore.SIGNAL("progressBarTick"), self.updateProgressbar) KCC.connect(self.worker, QtCore.SIGNAL("modeConvert"), self.modeConvert) @@ -639,7 +640,7 @@ class Ui_KCC(object): elif str(option) == "GammaSlider": GUI.GammaSlider.setValue(int(self.options[option])) self.changeGamma(int(self.options[option])) - elif str(option) == "StretchBox": + elif str(option) == "StretchBox" or str(option) == "WebstripBox": pass else: eval('GUI.' + str(option)).setCheckState(self.options[option]) diff --git a/kcc/KCC_ui.py b/kcc/KCC_ui.py index 53e8cf9..757b2a8 100644 --- a/kcc/KCC_ui.py +++ b/kcc/KCC_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'KCC.ui' # -# Created: Mon Aug 12 13:54:39 2013 +# Created: Wed Aug 14 08:39:46 2013 # by: PyQt4 UI code generator 4.10.2 # # WARNING! All changes made in this file will be lost! @@ -58,10 +58,10 @@ class Ui_KCC(object): self.UpscaleBox.setTristate(True) self.UpscaleBox.setObjectName(_fromUtf8("UpscaleBox")) self.gridLayout.addWidget(self.UpscaleBox, 1, 1, 1, 1) - self.WebstripBox = QtGui.QCheckBox(self.OptionsAdvanced) - self.WebstripBox.setFocusPolicy(QtCore.Qt.NoFocus) - self.WebstripBox.setObjectName(_fromUtf8("WebstripBox")) - self.gridLayout.addWidget(self.WebstripBox, 3, 1, 1, 1) + self.WebtoonBox = QtGui.QCheckBox(self.OptionsAdvanced) + self.WebtoonBox.setFocusPolicy(QtCore.Qt.NoFocus) + self.WebtoonBox.setObjectName(_fromUtf8("WebtoonBox")) + self.gridLayout.addWidget(self.WebtoonBox, 3, 1, 1, 1) self.NoDitheringBox = QtGui.QCheckBox(self.OptionsAdvanced) self.NoDitheringBox.setFocusPolicy(QtCore.Qt.NoFocus) self.NoDitheringBox.setObjectName(_fromUtf8("NoDitheringBox")) @@ -266,8 +266,8 @@ class Ui_KCC(object): self.ProcessingBox.setText(_translate("KCC", "No optimisation", None)) self.UpscaleBox.setToolTip(_translate("KCC", "

Unchecked - Nothing
Images smaller than device resolution will not be resized.

Indeterminate - Stretching
Images smaller than device resolution will be resized. Aspect ratio will be not preserved.

Checked - Upscaling
Images smaller than device resolution will be resized. Aspect ratio will be preserved.

", None)) self.UpscaleBox.setText(_translate("KCC", "Stretch/Upscale", None)) - self.WebstripBox.setToolTip(_translate("KCC", "

EXPERIMENTAL!
Enable auto-splitting of webstrips like Tower of God or Noblesse.
Files with a low width, high height and vertical panel flow.

", None)) - self.WebstripBox.setText(_translate("KCC", "Webstrip mode", None)) + self.WebtoonBox.setToolTip(_translate("KCC", "

EXPERIMENTAL!
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.

", None)) + self.WebtoonBox.setText(_translate("KCC", "Webtoon mode", None)) self.NoDitheringBox.setToolTip(_translate("KCC", "

Create PNG files instead JPEG.
Only for non-Kindle devices!

", None)) self.NoDitheringBox.setText(_translate("KCC", "PNG output", None)) self.BorderBox.setToolTip(_translate("KCC", "Fill space around images with black color.", None)) diff --git a/kcc/KCC_ui_osx.py b/kcc/KCC_ui_osx.py index 090139b..997a35b 100644 --- a/kcc/KCC_ui_osx.py +++ b/kcc/KCC_ui_osx.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'KCC-OSX.ui' # -# Created: Mon Aug 12 13:54:37 2013 +# Created: Wed Aug 14 08:39:45 2013 # by: PyQt4 UI code generator 4.10.2 # # WARNING! All changes made in this file will be lost! @@ -63,13 +63,13 @@ class Ui_KCC(object): self.UpscaleBox.setTristate(True) self.UpscaleBox.setObjectName(_fromUtf8("UpscaleBox")) self.gridLayout.addWidget(self.UpscaleBox, 1, 1, 1, 1) - self.WebstripBox = QtGui.QCheckBox(self.OptionsAdvanced) + self.WebtoonBox = QtGui.QCheckBox(self.OptionsAdvanced) font = QtGui.QFont() font.setPointSize(11) - self.WebstripBox.setFont(font) - self.WebstripBox.setFocusPolicy(QtCore.Qt.NoFocus) - self.WebstripBox.setObjectName(_fromUtf8("WebstripBox")) - self.gridLayout.addWidget(self.WebstripBox, 3, 1, 1, 1) + self.WebtoonBox.setFont(font) + self.WebtoonBox.setFocusPolicy(QtCore.Qt.NoFocus) + self.WebtoonBox.setObjectName(_fromUtf8("WebtoonBox")) + self.gridLayout.addWidget(self.WebtoonBox, 3, 1, 1, 1) self.NoDitheringBox = QtGui.QCheckBox(self.OptionsAdvanced) font = QtGui.QFont() font.setPointSize(11) @@ -324,8 +324,8 @@ class Ui_KCC(object): self.ProcessingBox.setText(_translate("KCC", "No optimisation", None)) self.UpscaleBox.setToolTip(_translate("KCC", "

Unchecked - Nothing
Images smaller than device resolution will not be resized.

Indeterminate - Stretching
Images smaller than device resolution will be resized. Aspect ratio will be not preserved.

Checked - Upscaling
Images smaller than device resolution will be resized. Aspect ratio will be preserved.

", None)) self.UpscaleBox.setText(_translate("KCC", "Stretch/Upscale", None)) - self.WebstripBox.setToolTip(_translate("KCC", "

EXPERIMENTAL!
Enable auto-splitting of webstrips like Tower of God or Noblesse.
Files with a low width, high height and vertical panel flow.

", None)) - self.WebstripBox.setText(_translate("KCC", "Webstrip mode", None)) + self.WebtoonBox.setToolTip(_translate("KCC", "

EXPERIMENTAL!
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.

", None)) + self.WebtoonBox.setText(_translate("KCC", "Webtoon mode", None)) self.NoDitheringBox.setToolTip(_translate("KCC", "

Create PNG files instead JPEG.
Only for non-Kindle devices!

", None)) self.NoDitheringBox.setText(_translate("KCC", "PNG output", None)) self.BorderBox.setToolTip(_translate("KCC", "

Fill space around images with black color.

", None)) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 4fba275..97c32f4 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -323,9 +323,9 @@ def getImageFileName(imgfile): def applyImgOptimization(img, isSplit, toRight, options, overrideQuality=5): - if not options.webstrip: + if not options.webtoon: img.cropWhiteSpace(10.0) - if options.cutpagenumbers and not options.webstrip: + if options.cutpagenumbers and not options.webtoon: img.cutPageNumber() img.optimizeImage(options.gamma) if overrideQuality != 5: @@ -849,8 +849,8 @@ def main(argv=None, qtGUI=None): help="Outputs a CBZ archive and does not generate EPUB") outputOptions.add_option("--batchsplit", action="store_true", dest="batchsplit", default=False, help="Split output into multiple files"), - experimentalOptions.add_option("-w", "--webstrip", action="store_true", dest="webstrip", default=False, - help="Webstrip processing mode"), + experimentalOptions.add_option("-w", "--webtoon", action="store_true", dest="webtoon", default=False, + help="Webtoon processing mode"), processingOptions.add_option("--blackborders", action="store_true", dest="black_borders", default=False, help="Use black borders instead of white ones") processingOptions.add_option("--forcecolor", action="store_true", dest="forcecolor", default=False, @@ -896,7 +896,7 @@ def main(argv=None, qtGUI=None): parser.print_help() return path = getWorkFolder(args[0]) - if options.webstrip: + if options.webtoon: if GUI: GUI.emit(QtCore.SIGNAL("progressBarTick"), 'status', 'Splitting images') if options.customheight > 0: @@ -967,9 +967,9 @@ def getOutputFilename(srcpath, wantedname, ext, tomeNumber): def checkOptions(): global options - # Webstrip mode mandatory options - if options.webstrip: - options.rotate = True + # Webtoon mode mandatory options + if options.webtoon: + options.nosplitrotate = True options.black_borders = False options.quality = 0 # Landscape mode is only supported by Kindle Touch and Paperwhite. diff --git a/kcc/comic2panel.py b/kcc/comic2panel.py index 7f0097e..e4e9c06 100644 --- a/kcc/comic2panel.py +++ b/kcc/comic2panel.py @@ -110,8 +110,8 @@ def splitImage(work): name = work[1] options = splitImage.options # Harcoded options - threshold = 10.0 - delta = 10 + threshold = 0.5 + delta = 15 print ".", splitImage.queue.put(".") fileExpanded = os.path.splitext(name) @@ -126,7 +126,7 @@ def splitImage(work): # Find panels y1 = 0 - y2 = 10 + y2 = 15 panels = [] while y2 < heightImg: while ImageStat.Stat(image.crop([0, y1, widthImg, y2])).var[0] < threshold and y2 < heightImg: @@ -178,14 +178,15 @@ def splitImage(work): targetHeight = 0 for panel in page: pageHeight += panels[panel][2] - newPage = Image.new('RGB', (widthImg, pageHeight)) - for panel in page: - panelImg = image.crop([0, panels[panel][0], widthImg, panels[panel][1]]) - newPage.paste(panelImg, (0, targetHeight)) - targetHeight += panels[panel][2] - newPage.save(os.path.join(path, fileExpanded[0] + '-' + - str(pageNumber) + '-' + getImageFill(newPage) + '.png'), 'PNG') - pageNumber += 1 + if pageHeight > delta: + newPage = Image.new('RGB', (widthImg, pageHeight)) + for panel in page: + panelImg = image.crop([0, panels[panel][0], widthImg, panels[panel][1]]) + newPage.paste(panelImg, (0, targetHeight)) + targetHeight += panels[panel][2] + newPage.save(os.path.join(path, fileExpanded[0] + '-' + + str(pageNumber) + '-' + getImageFill(newPage) + '.png'), 'PNG') + pageNumber += 1 os.remove(os.path.join(path, name))