diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 517d2e4..ce64abc 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -310,7 +310,7 @@ def getImageFileName(imgfile): def applyImgOptimization(img, opt, hqImage=None): if not img.fill: - img.getImageFill(opt.webtoon) + img.getImageFill() if not opt.webtoon: img.cropWhiteSpace(10.0) if opt.cutpagenumbers and not opt.webtoon: diff --git a/kcc/image.py b/kcc/image.py index b54c068..8d41196 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -404,7 +404,7 @@ class ComicPage: self.image = self.image.crop((0, 0, widthImg - diff, heightImg)) return self.image - def getImageHistogram(self, image, new=True): + def getImageHistogram(self, image): histogram = image.histogram() RBGW = [] pixelCount = 0 @@ -413,78 +413,51 @@ class ComicPage: RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i]) white = 0 black = 0 - for i in range(251, 256): + for i in range(253, 256): white += RBGW[i] - for i in range(5): + for i in range(3): black += RBGW[i] - if new: - if black > 0 and white == 0: - return 1 - elif white > 0 and black == 0: - return -1 - else: - return False + if black > pixelCount*0.5 and white == 0: + return 1 + elif white > pixelCount*0.5 and black == 0: + return -1 else: - if black > white and black > pixelCount*0.5: - return True - else: - return False + return False - def getImageFill(self, isWebToon): - if isWebToon: - fill = 0 - fill += self.getImageHistogram(self.image.crop((0, 0, self.image.size[0], 5)), False) - fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-5, self.image.size[0], - self.image.size[1])), False) - if fill == 2: - self.fill = 'black' - elif fill == 0: - self.fill = 'white' - else: - fill = 0 - fill += self.getImageHistogram(self.image.crop((0, 0, 5, 5)), False) - fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, 0, self.image.size[0], 5)), False) - fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-5, 5, self.image.size[1])), False) - fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, self.image.size[1]-5, - self.image.size[0], self.image.size[1])), False) - if fill > 1: - self.fill = 'black' - else: - self.fill = 'white' + def getImageFill(self): + fill = 0 + # Search fom horizontal solid lines + startY = 0 + stopY = 4 + searching = True + while stopY <= self.image.size[1]: + checkSolid = self.getImageHistogram(self.image.crop((0, startY, self.image.size[0], stopY))) + if checkSolid: + fill += checkSolid + startY = stopY + 1 + stopY = startY + 4 + if stopY > self.image.size[1] and searching: + startY = self.image.size[1] - 4 + stopY = self.image.size[1] + searching = False + # Search fom vertical solid lines + startX = 0 + stopX = 4 + searching = True + while stopX <= self.image.size[0]: + checkSolid = self.getImageHistogram(self.image.crop((startX, 0, stopX, self.image.size[1]))) + if checkSolid: + fill += checkSolid + startX = stopX + 1 + stopX = startX + 4 + if stopX > self.image.size[0] and searching: + startX = self.image.size[0] - 4 + stopX = self.image.size[0] + searching = False + if fill > 0: + self.fill = 'black' else: - fill = 0 - # Search fom horizontal solid lines - startY = 0 - stopY = 3 - searching = True - while stopY <= self.image.size[1]: - checkSolid = self.getImageHistogram(self.image.crop((0, startY, self.image.size[0], stopY))) - if checkSolid: - fill += checkSolid - startY = stopY + 1 - stopY = startY + 3 - if stopY > self.image.size[1] and searching: - startY = self.image.size[1] - 3 - stopY = self.image.size[1] - searching = False - # Search fom vertical solid lines - startX = 0 - stopX = 3 - searching = True - while stopX <= self.image.size[0]: - checkSolid = self.getImageHistogram(self.image.crop((startX, 0, stopX, self.image.size[1]))) - if checkSolid: - fill += checkSolid - startX = stopX + 1 - stopX = startX + 3 - if stopX > self.image.size[0] and searching: - startX = self.image.size[0] - 3 - stopX = self.image.size[0] - searching = False - if fill > 0: - self.fill = 'black' - else: - self.fill = 'white' + self.fill = 'white' def isImageColor(self, image): v = ImageStat.Stat(image).var