From a28ad2b0c778789f0f7de0df142db0ac3022a003 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Unchecked - Nothing Indeterminate - Stretching Checked - Upscaling EXPERIMENTAL!
Images smaller than device resolution will not be resized.
Images smaller than device resolution will be resized. Aspect ratio will be not preserved.
Images smaller than device resolution will be resized. Aspect ratio will be preserved.
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Create PNG files instead JPEG.
Only for non-Kindle devices!
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.
EXPERIMENTAL!
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Create PNG files instead JPEG.
Only for non-Kindle devices!
Create PNG files instead JPEG.
Only for non-Kindle devices!
Unchecked - Autodetection
Color of margins fill will be detected automatically.
Indeterminate - White
Margins will be filled with white color.
Checked - Black
Margins will be filled with black color.
Disable splitting and rotation.
", None)) self.NoRotateBox.setText(_translate("KCC", "No split/rotate", None)) self.DeviceBox.setToolTip(_translate("KCC", "Target device.", None)) diff --git a/kcc/KCC_ui_osx.py b/kcc/KCC_ui_osx.py index 06a940b8..84474e5f 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: Sat Sep 14 10:28:47 2013 +# Created: Sun Sep 15 16:18:48 2013 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -82,6 +82,7 @@ def setupUi(self, KCC): font.setPointSize(11) self.BorderBox.setFont(font) self.BorderBox.setFocusPolicy(QtCore.Qt.NoFocus) + self.BorderBox.setTristate(True) self.BorderBox.setObjectName(_fromUtf8("BorderBox")) self.gridLayout.addWidget(self.BorderBox, 3, 0, 1, 1) self.NoRotateBox = QtGui.QCheckBox(self.OptionsAdvanced) @@ -328,8 +329,8 @@ def retranslateUi(self, KCC): self.WebtoonBox.setText(_translate("KCC", "Webtoon mode", None)) self.NoDitheringBox.setToolTip(_translate("KCC", "Create PNG files instead JPEG.
Only for non-Kindle devices!
Fill space around images with black color.
", None)) - self.BorderBox.setText(_translate("KCC", "Black borders", None)) + self.BorderBox.setToolTip(_translate("KCC", "Unchecked - Autodetection
Color of margins fill will be detected automatically.
Indeterminate - White
Margins will be filled with white color.
Checked - Black
Margins will be filled with black color.
Disable splitting and rotation.
", None)) self.NoRotateBox.setText(_translate("KCC", "No split/rotate", None)) self.DeviceBox.setToolTip(_translate("KCC", "Target device.", None)) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index bc17424f..d5aff24b 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -275,9 +275,9 @@ def applyImgOptimization(img, options, overrideQuality=5): img.cutPageNumber() img.optimizeImage(options.gamma) if overrideQuality != 5: - img.resizeImage(options.upscale, options.stretch, options.black_borders, overrideQuality) + img.resizeImage(options.upscale, options.stretch, options.bordersColor, overrideQuality) else: - img.resizeImage(options.upscale, options.stretch, options.black_borders, options.quality) + img.resizeImage(options.upscale, options.stretch, options.bordersColor, options.quality) if options.forcepng and not options.forcecolor: img.quantizeImage() @@ -804,7 +804,9 @@ def main(argv=None, qtGUI=None): 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") + help="Disable autodetection and force black borders") + processingOptions.add_option("--whiteborders", action="store_true", dest="white_borders", default=False, + help="Disable autodetection and force white borders") processingOptions.add_option("--forcecolor", action="store_true", dest="forcecolor", default=False, help="Don't convert images to grayscale") processingOptions.add_option("--forcepng", action="store_true", dest="forcepng", default=False, @@ -919,6 +921,11 @@ def getOutputFilename(srcpath, wantedname, ext, tomeNumber): def checkOptions(): global options options.panelview = True + options.bordersColor = None + if options.white_borders: + options.bordersColor = "white" + if options.black_borders: + options.bordersColor = "black" # 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 @@ -931,7 +938,6 @@ def checkOptions(): # Webtoon mode mandatory options if options.webtoon: options.nosplitrotate = True - options.black_borders = False options.quality = 0 options.panelview = False # Disable all Kindle features for other e-readers diff --git a/kcc/comic2panel.py b/kcc/comic2panel.py index d7b35039..f9a52b16 100644 --- a/kcc/comic2panel.py +++ b/kcc/comic2panel.py @@ -53,45 +53,6 @@ def getImageFileName(imgfile): return filename -def getImageHistogram(image): - histogram = image.histogram() - RBGW = [] - for i in range(256): - RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i]) - white = 0 - black = 0 - for i in range(245, 256): - white += RBGW[i] - for i in range(11): - black += RBGW[i] - if white > black: - return False - else: - return True - - -def getImageFill(image): - imageSize = image.size - imageT = image.crop((0, 0, imageSize[0], 1)) - imageB = image.crop((0, imageSize[1]-1, imageSize[0], imageSize[1])) - fill = 0 - fill += getImageHistogram(imageT) - fill += getImageHistogram(imageB) - if fill == 2: - return 'KCCFB' - elif fill == 0: - return 'KCCFW' - else: - imageL = image.crop((0, 0, 1, imageSize[1])) - imageR = image.crop((imageSize[0]-1, 0, imageSize[0], imageSize[1])) - fill += getImageHistogram(imageL) - fill += getImageHistogram(imageR) - if fill >= 2: - return 'KCCFB' - else: - return 'KCCFW' - - def sanitizePanelSize(panel, options): newPanels = [] if panel[2] > 8 * options.height: @@ -222,7 +183,7 @@ def splitImage(work): newPage.paste(panelImg, (0, targetHeight)) targetHeight += panels[panel][2] newPage.save(os.path.join(path, fileExpanded[0] + '-' + - str(pageNumber) + '-' + getImageFill(newPage) + '.png'), 'PNG') + str(pageNumber) + '.png'), 'PNG') pageNumber += 1 os.remove(filePath) diff --git a/kcc/image.py b/kcc/image.py index 86abf442..b384ba69 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -186,17 +186,12 @@ def quantizeImage(self): palImg.putpalette(self.palette) self.image = self.image.quantize(palette=palImg) - def resizeImage(self, upscale=False, stretch=False, black_borders=False, qualityMode=0): + def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0): method = Image.ANTIALIAS - if '-KCCFW' in str(self.filename): - fill = 'white' - elif '-KCCFB' in str(self.filename): - fill = 'black' + if bordersColor: + fill = bordersColor else: - if black_borders: - fill = 'black' - else: - fill = 'white' + fill = self.getImageFill() if qualityMode == 0: size = (self.size[0], self.size[1]) generateBorder = True @@ -379,4 +374,40 @@ def cropWhiteSpace(self, threshold): # print "Right crop: %s"%diff self.image = self.image.crop((0, 0, widthImg - diff, heightImg)) # print "New size: %sx%s"%(self.image.size[0],self.image.size[1]) - return self.image \ No newline at end of file + return self.image + + def getImageHistogram(self, image): + histogram = image.histogram() + RBGW = [] + for i in range(256): + RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i]) + white = 0 + black = 0 + for i in range(245, 256): + white += RBGW[i] + for i in range(11): + black += RBGW[i] + if white > black: + return False + else: + return True + + def getImageFill(self): + imageT = self.image.crop((0, 0, self.image.size[0], 1)) + imageB = self.image.crop((0, self.image.size[1]-1, self.image.size[0], self.image.size[1])) + fill = 0 + fill += self.getImageHistogram(imageT) + fill += self.getImageHistogram(imageB) + if fill == 2: + return 'black' + elif fill == 0: + return 'white' + else: + imageL = self.image.crop((0, 0, 1, self.image.size[1])) + imageR = self.image.crop((self.image.size[0]-1, 0, self.image.size[0], self.image.size[1])) + fill += self.getImageHistogram(imageL) + fill += self.getImageHistogram(imageR) + if fill >= 2: + return 'black' + else: + return 'white' \ No newline at end of file From 9b400573c8dd19d2faad0853bbb07aa6e2a8f5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?=Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Create PNG files instead JPEG.
Only for non-Kindle devices!
Create PNG files instead JPEG.
", None)) self.NoDitheringBox.setText(_translate("KCC", "PNG output", None)) self.BorderBox.setToolTip(_translate("KCC", "Unchecked - Autodetection
Color of margins fill will be detected automatically.
Indeterminate - White
Margins will be filled with white color.
Checked - Black
Margins will be filled with black color.
Disable image optimizations.
", None)) 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.
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.
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Create PNG files instead JPEG.
Only for non-Kindle devices!
Create PNG files instead JPEG.
", None)) self.NoDitheringBox.setText(_translate("KCC", "PNG output", None)) - self.BorderBox.setToolTip(_translate("KCC", "Unchecked - Autodetection
Color of margins fill will be detected automatically.
Indeterminate - White
Margins will be filled with white color.
Checked - Black
Margins will be filled with black color.
Unchecked - Autodetection
Color of margins fill will be detected automatically.
Indeterminate - White
Margins will be filled with white color.
Checked - Black
Margins will be filled with black color.
Disable splitting and rotation.
", None)) self.NoRotateBox.setText(_translate("KCC", "No split/rotate", None)) From a58d98f0dc6d1306c11bee729436f475cd7b44d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?=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.
Enable auto-splitting of webtoons like Tower of God or Noblesse.
Pages with a low width, high height and vertical panel flow.
Create PNG files instead JPEG.
", None)) + self.NoDitheringBox.setText(_translate("KCC", "PNG output", None)) + self.BorderBox.setToolTip(_translate("KCC", "Unchecked - Autodetection
Color of margins fill will be detected automatically.
Indeterminate - White
Margins will be filled with white color.
Checked - Black
Margins will be filled with black color.
Disable splitting and rotation.
", None)) + self.NoRotateBox.setText(_translate("KCC", "No split/rotate", None)) + self.DeviceBox.setToolTip(_translate("KCC", "Target device.", None)) + self.FormatBox.setToolTip(_translate("KCC", "Output format.", None)) + self.ConvertButton.setText(_translate("KCC", "Convert", None)) + self.DirectoryButton.setText(_translate("KCC", "Add directory", None)) + self.FileButton.setText(_translate("KCC", "Add file", None)) + self.ClearButton.setText(_translate("KCC", "Clear list", None)) + self.MangaBox.setToolTip(_translate("KCC", "Enable right-to-left reading.", None)) + self.MangaBox.setText(_translate("KCC", "Manga mode", None)) + self.QualityBox.setToolTip(_translate("KCC", "\n" +"\n" +"Unchecked - Normal quality mode
Use it when Panel View support is not needed.
- Maximum quality when zoom is not enabled.
- Poor quality when zoom is enabled.
- Lowest file size.
Indeterminate - High quality mode
Not zoomed image might be a little blurry.
- Medium/High quality when zoom is not enabled.
- Maximum quality when zoom is enabled.
Checked - Ultra quality mode
Maximum possible quality.
- Maximum quality when zoom is not enabled.
- Maximum quality when zoom is enabled.
- Very high file size.
Disable page spliting.
They will be rotated instead.
When converting color images setting this option to 1.0 might improve readability.
", None)) + self.GammaLabel.setText(_translate("KCC", "Gamma: Auto", None)) + self.GammaSlider.setToolTip(_translate("KCC", "When converting color images setting this option to 1.0 might improve readability.
", None)) + self.ColorBox.setToolTip(_translate("KCC", "Do not convert images to grayscale.", None)) + self.ColorBox.setText(_translate("KCC", "Color mode", None)) + self.wLabel.setToolTip(_translate("KCC", "Resolution of target device.", None)) + self.wLabel.setText(_translate("KCC", "Custom width: ", None)) + self.customWidth.setToolTip(_translate("KCC", "Resolution of target device.", None)) + self.customWidth.setInputMask(_translate("KCC", "0000; ", None)) + self.hLabel.setToolTip(_translate("KCC", "Resolution of target device.", None)) + self.hLabel.setText(_translate("KCC", "Custom height: ", None)) + self.customHeight.setToolTip(_translate("KCC", "Resolution of target device.", None)) + self.customHeight.setInputMask(_translate("KCC", "0000; ", None)) + self.ActionBasic.setText(_translate("KCC", "Basic", None)) + self.ActionAdvanced.setText(_translate("KCC", "Advanced", None)) + +import KCC_rc From 7907a45ca25f9ad2ea64e4ecd7d06fd76df97fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?=Disable splitting and rotation.
", None)) self.NoRotateBox.setText(_translate("KCC", "No split/rotate", None)) - self.DeviceBox.setToolTip(_translate("KCC", "Target device.", None)) - self.FormatBox.setToolTip(_translate("KCC", "Output format.", None)) + self.DeviceBox.setToolTip(_translate("KCC", "Target device.
", None)) + self.FormatBox.setToolTip(_translate("KCC", "Output format.
", None)) self.ConvertButton.setText(_translate("KCC", "Convert", None)) self.DirectoryButton.setText(_translate("KCC", "Add directory", None)) self.FileButton.setText(_translate("KCC", "Add file", None)) self.ClearButton.setText(_translate("KCC", "Clear list", None)) self.MangaBox.setToolTip(_translate("KCC", "Enable right-to-left reading.
", None)) self.MangaBox.setText(_translate("KCC", "Manga mode", None)) - self.QualityBox.setToolTip(_translate("KCC", "Unchecked - Normal quality mode
Use it when Panel View support is not needed.
- Maximum quality when zoom is not enabled.
- Poor quality when zoom is enabled.
- Lowest file size.
Indeterminate - High quality mode
Not zoomed image might be a little blurry.
- Medium/High quality when zoom is not enabled.
- Maximum quality when zoom is enabled.
Checked - Ultra quality mode
Maximum possible quality.
- Maximum quality when zoom is not enabled.
- Maximum quality when zoom is enabled.
- Very high file size.
Unchecked - Normal quality mode
Use it when Panel View support is not needed.
- Maximum quality when zoom is not enabled.
- Poor quality when zoom is enabled.
- Lowest file size.
Indeterminate - High quality mode
Not zoomed image might be a little blurry.
- Medium/High quality when zoom is not enabled.
- Maximum quality when zoom is enabled.
Checked - Ultra quality mode
Maximum possible quality.
- Maximum quality when zoom is not enabled.
- Maximum quality when zoom is enabled.
- Very high file size.
Disable page spliting.
They will be rotated instead.
When converting color images setting this option to 1.0 MIGHT improve readability.
", None)) + self.GammaLabel.setToolTip(_translate("KCC", "When converting color images setting this option to 1.0 might improve readability.
", None)) self.GammaLabel.setText(_translate("KCC", "Gamma: Auto", None)) self.GammaSlider.setToolTip(_translate("KCC", "When converting color images setting this option to 1.0 might improve readability.
", None)) self.ColorBox.setToolTip(_translate("KCC", "Do not convert images to grayscale.
", None)) From 4890727692f05129d5d38cd79e08902bf9cb0362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?=