1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00

Webtoon mode improvements

This commit is contained in:
Paweł Jastrzębski
2013-08-17 16:03:36 +02:00
parent f645b65a9e
commit a98fac2e95
2 changed files with 18 additions and 26 deletions

View File

@@ -28,7 +28,7 @@ from shutil import rmtree, copytree, move
from optparse import OptionParser, OptionGroup from optparse import OptionParser, OptionGroup
from multiprocessing import Pool, Queue, freeze_support from multiprocessing import Pool, Queue, freeze_support
try: try:
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences,PyPackageRequirements
from PIL import Image, ImageStat from PIL import Image, ImageStat
except ImportError: except ImportError:
print "ERROR: Pillow is not installed!" print "ERROR: Pillow is not installed!"
@@ -65,28 +65,26 @@ def getImageHistogram(image):
for i in range(11): for i in range(11):
black += RBGW[i] black += RBGW[i]
if white > black: if white > black:
return False return 0
else: else:
return True return 1
def getImageFill(image, y): def getImageFill(image):
imageSize = image.size imageSize = image.size
image = image.crop((0, 0, imageSize[0], y)) imageT = image.crop((0, 0, imageSize[0], 1))
histogram = image.histogram() imageB = image.crop((0, imageSize[1]-1, imageSize[0], imageSize[1]))
RBGW = [] imageL = image.crop((0, 0, 1, imageSize[1]))
for i in range(256): imageR = image.crop((imageSize[0]-1, 0, imageSize[0], imageSize[1]))
RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i]) fill = 0
white = 0 fill += getImageHistogram(imageT)
black = 0 fill += getImageHistogram(imageB)
for i in range(245, 256): fill += getImageHistogram(imageL)
white += RBGW[i] fill += getImageHistogram(imageR)
for i in range(11): if fill > 2:
black += RBGW[i]
if white > black:
return 'KCCFW'
else:
return 'KCCFB' return 'KCCFB'
else:
return 'KCCFW'
def sanitizePanelSize(panel, options): def sanitizePanelSize(panel, options):
@@ -159,8 +157,6 @@ def splitImage(work):
# Find panels # Find panels
y1 = 0 y1 = 0
y2 = 15 y2 = 15
fillDataNeeded = True
yFill = 1
panels = [] panels = []
while y2 < heightImg: while y2 < heightImg:
while ImageStat.Stat(image.crop([0, y1, widthImg, y2])).var[0] < threshold and y2 < heightImg: while ImageStat.Stat(image.crop([0, y1, widthImg, y2])).var[0] < threshold and y2 < heightImg:
@@ -178,14 +174,10 @@ def splitImage(work):
draw.line([(0, y2Temp), (widthImg, y2Temp)], fill=(255, 0, 0)) draw.line([(0, y2Temp), (widthImg, y2Temp)], fill=(255, 0, 0))
panelHeight = y2Temp - y1Temp panelHeight = y2Temp - y1Temp
if y2Temp < heightImg: if y2Temp < heightImg:
if fillDataNeeded:
fillDataNeeded = False
yFill = y1Temp
# Panels that can't be cut nicely will be forcefully splitted # Panels that can't be cut nicely will be forcefully splitted
panelsCleaned = sanitizePanelSize([y1Temp, y2Temp, panelHeight], options) panelsCleaned = sanitizePanelSize([y1Temp, y2Temp, panelHeight], options)
for panel in panelsCleaned: for panel in panelsCleaned:
panels.append(panel) panels.append(panel)
fill = getImageFill(image, yFill)
if options.debug: if options.debug:
# noinspection PyUnboundLocalVariable # noinspection PyUnboundLocalVariable
debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG') debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG')
@@ -223,7 +215,7 @@ def splitImage(work):
newPage.paste(panelImg, (0, targetHeight)) newPage.paste(panelImg, (0, targetHeight))
targetHeight += panels[panel][2] targetHeight += panels[panel][2]
newPage.save(os.path.join(path, fileExpanded[0] + '-' + newPage.save(os.path.join(path, fileExpanded[0] + '-' +
str(pageNumber) + '-' + fill + '.png'), 'PNG') str(pageNumber) + '-' + getImageFill(newPage) + '.png'), 'PNG')
pageNumber += 1 pageNumber += 1
os.remove(filePath) os.remove(filePath)

View File

@@ -21,7 +21,7 @@ __docformat__ = 'restructuredtext en'
import os import os
try: try:
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences,PyPackageRequirements
from PIL import Image, ImageOps, ImageStat, ImageChops from PIL import Image, ImageOps, ImageStat, ImageChops
except ImportError: except ImportError:
print "ERROR: Pillow is not installed!" print "ERROR: Pillow is not installed!"