mirror of
https://github.com/ciromattia/kcc
synced 2025-12-27 00:22:54 +00:00
Draft of FakePanelView Landscape mode
This commit is contained in:
@@ -274,6 +274,8 @@ def applyImgOptimization(img, isSplit=False, toRight=False):
|
||||
img.cutPageNumber()
|
||||
if options.fakepanelview:
|
||||
img.resizeImage(True, False, options.black_borders, False, False, False)
|
||||
elif options.fakepanelviewlandscape:
|
||||
img.resizeImage(False, False, options.black_borders, False, False, False, True)
|
||||
else:
|
||||
img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight, options.landscapemode)
|
||||
if not options.notquantize:
|
||||
@@ -351,6 +353,23 @@ def dirImgProcess(path):
|
||||
img14 = image.ComicPage(splitB[4], options.profile)
|
||||
applyImgOptimization(img14)
|
||||
img14.saveToDir(dirpath, options.notquantize)
|
||||
elif options.fakepanelviewlandscape:
|
||||
img0 = image.ComicPage(split[0], options.profile)
|
||||
splitA = img0.splitPageFakePanelViewLandscape(dirpath, options.righttoleft)
|
||||
img01 = image.ComicPage(splitA[0], options.profile)
|
||||
applyImgOptimization(img01)
|
||||
img01.saveToDir(dirpath, options.notquantize)
|
||||
img02 = image.ComicPage(splitA[1], options.profile)
|
||||
applyImgOptimization(img02)
|
||||
img02.saveToDir(dirpath, options.notquantize)
|
||||
img1 = image.ComicPage(split[1], options.profile)
|
||||
splitB = img1.splitPageFakePanelViewLandscape(dirpath, options.righttoleft)
|
||||
img11 = image.ComicPage(splitB[0], options.profile)
|
||||
applyImgOptimization(img11)
|
||||
img11.saveToDir(dirpath, options.notquantize)
|
||||
img12 = image.ComicPage(splitB[1], options.profile)
|
||||
applyImgOptimization(img12)
|
||||
img12.saveToDir(dirpath, options.notquantize)
|
||||
else:
|
||||
img0 = image.ComicPage(split[0], options.profile)
|
||||
applyImgOptimization(img0, True, toRight1)
|
||||
@@ -380,6 +399,14 @@ def dirImgProcess(path):
|
||||
img4 = image.ComicPage(split[4], options.profile)
|
||||
applyImgOptimization(img4)
|
||||
img4.saveToDir(dirpath, options.notquantize)
|
||||
elif options.fakepanelviewlandscape:
|
||||
split = img.splitPageFakePanelViewLandscape(dirpath, options.righttoleft)
|
||||
img1 = image.ComicPage(split[0], options.profile)
|
||||
applyImgOptimization(img1)
|
||||
img1.saveToDir(dirpath, options.notquantize)
|
||||
img2 = image.ComicPage(split[1], options.profile)
|
||||
applyImgOptimization(img2)
|
||||
img2.saveToDir(dirpath, options.notquantize)
|
||||
else:
|
||||
applyImgOptimization(img)
|
||||
img.saveToDir(dirpath, options.notquantize)
|
||||
@@ -499,6 +526,8 @@ def main(argv=None):
|
||||
help="Manga style (Right-to-left reading and splitting) [Default=False]")
|
||||
parser.add_option("--fakepanelview", action="store_true", dest="fakepanelview", default=False,
|
||||
help="Emulate Panel View feature (For Kindle 4 NT or older) [Default=False]")
|
||||
parser.add_option("--fakepanelviewlandscape", action="store_true", dest="fakepanelviewlandscape", default=False,
|
||||
help="Emulate Panel View feature - Landscape mode (For Kindle 4 NT or older) [Default=False]")
|
||||
parser.add_option("--noprocessing", action="store_false", dest="imgproc", default=True,
|
||||
help="Do not apply image preprocessing (Page splitting and optimizations) [Default=True]")
|
||||
parser.add_option("--nodithering", action="store_true", dest="notquantize", default=False,
|
||||
@@ -559,14 +588,17 @@ def checkOptions():
|
||||
options.landscapemode = True
|
||||
else:
|
||||
options.landscapemode = False
|
||||
if options.fakepanelview and options.profile == 'KHD':
|
||||
if (options.fakepanelview or options.fakepanelviewlandscape) and options.profile == 'KHD':
|
||||
options.fakepanelview = False
|
||||
if options.fakepanelview and options.landscapemode:
|
||||
options.fakepanelviewlandscape = False
|
||||
if (options.fakepanelview or options.fakepanelviewlandscape) and options.landscapemode:
|
||||
options.landscapemode = False
|
||||
if options.fakepanelview:
|
||||
if options.fakepanelview or options.fakepanelviewlandscape:
|
||||
options.imgproc = True
|
||||
options.rotate = False
|
||||
options.nosplitrotate = False
|
||||
if options.fakepanelview and options.fakepanelviewlandscape:
|
||||
options.fakepanelviewlandscape = False
|
||||
|
||||
|
||||
def getEpubPath():
|
||||
|
||||
26
kcc/image.py
26
kcc/image.py
@@ -139,12 +139,14 @@ class ComicPage:
|
||||
palImg.putpalette(self.palette)
|
||||
self.image = self.image.quantize(palette=palImg)
|
||||
|
||||
def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False, landscapeMode=False):
|
||||
def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False, landscapeMode=False, fakepanelviewlandscape=False):
|
||||
method = Image.ANTIALIAS
|
||||
if black_borders:
|
||||
fill = 'black'
|
||||
else:
|
||||
fill = 'white'
|
||||
if fakepanelviewlandscape:
|
||||
self.image = self.image.rotate(90)
|
||||
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
|
||||
if not upscale:
|
||||
if isSplit and landscapeMode:
|
||||
@@ -262,6 +264,28 @@ class ComicPage:
|
||||
return file0, file1, file2, file3, file4
|
||||
|
||||
|
||||
def splitPageFakePanelViewLandscape(self, targetdir, righttoleft=False):
|
||||
width, height = self.image.size
|
||||
topbox = (0, 0, width, ((height / 2) + (height/9)))
|
||||
bottombox = (0, ((height / 2) - (height/9)), width, height)
|
||||
filename = os.path.splitext(os.path.basename(self.origFileName))
|
||||
file1 = targetdir + '/' + filename[0] + '-1' + filename[1]
|
||||
file2 = targetdir + '/' + filename[0] + '-2' + filename[1]
|
||||
try:
|
||||
page1 = self.image.crop(topbox)
|
||||
page2 = self.image.crop(bottombox)
|
||||
if page1.mode == "P":
|
||||
page1.save(file1, "PNG")
|
||||
page2.save(file2, "PNG")
|
||||
else:
|
||||
page1.save(file1)
|
||||
page2.save(file2)
|
||||
os.remove(self.origFileName)
|
||||
except IOError as e:
|
||||
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
||||
return file1, file2
|
||||
|
||||
|
||||
def frameImage(self):
|
||||
foreground = tuple(self.palette[:3])
|
||||
background = tuple(self.palette[-3:])
|
||||
|
||||
Reference in New Issue
Block a user