diff --git a/KCC-OSX.ui b/KCC-OSX.ui
index f11dc4a..33db33c 100644
--- a/KCC-OSX.ui
+++ b/KCC-OSX.ui
@@ -145,10 +145,13 @@
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 06a940b..84474e5 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 @@ class Ui_KCC(object): 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 @@ class Ui_KCC(object): 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 bc17424..d5aff24 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 d7b3503..f9a52b1 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 86abf44..b384ba6 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -186,17 +186,12 @@ class ComicPage: 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 @@ class ComicPage: # 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