1
0
mirror of https://github.com/ciromattia/kcc synced 2026-05-29 18:53:07 +00:00

Refactoring of dirImgProcess

This commit is contained in:
Paweł Jastrzębski
2013-05-27 20:06:47 +02:00
parent aba315866e
commit d090d8c2e8
+14 -16
View File
@@ -255,7 +255,7 @@ def buildOPF(profile, dstdir, title, filelist, cover=None):
f.write("</manifest>\n<spine toc=\"ncx\">\n") f.write("</manifest>\n<spine toc=\"ncx\">\n")
splitCountUsed = 1 splitCountUsed = 1
for entry in reflist: for entry in reflist:
if entry.endswith("-1"): if entry.endswith("-000001"):
# noinspection PyRedundantParentheses # noinspection PyRedundantParentheses
if ((options.righttoleft and facing == 'left') or (not options.righttoleft and facing == 'right')) and\ if ((options.righttoleft and facing == 'left') or (not options.righttoleft and facing == 'right')) and\
options.landscapemode: options.landscapemode:
@@ -265,7 +265,7 @@ def buildOPF(profile, dstdir, title, filelist, cover=None):
f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing1 + "\"/>\n") f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing1 + "\"/>\n")
else: else:
f.write("<itemref idref=\"page_" + entry + "\"/>\n") f.write("<itemref idref=\"page_" + entry + "\"/>\n")
elif entry.endswith("-2"): elif entry.endswith("-000002"):
if options.landscapemode: if options.landscapemode:
f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing2 + "\"/>\n") f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing2 + "\"/>\n")
else: else:
@@ -336,14 +336,14 @@ def applyImgOptimization(img, isSplit=False, toRight=False):
def dirImgProcess(path): def dirImgProcess(path):
global options, splitCount global options, splitCount
if options.righttoleft: pagenumber = 0
facing = "right" pagenumbermodifier = 0
else: splitpages = []
facing = "left"
for (dirpath, dirnames, filenames) in os.walk(path): for (dirpath, dirnames, filenames) in os.walk(path):
for afile in filenames: for afile in filenames:
if getImageFileName(afile) is not None: if getImageFileName(afile) is not None:
pagenumber += 1
if options.verbose: if options.verbose:
print "Optimizing " + afile + " for " + options.profile print "Optimizing " + afile + " for " + options.profile
else: else:
@@ -359,15 +359,11 @@ def dirImgProcess(path):
if options.righttoleft: if options.righttoleft:
toRight1 = False toRight1 = False
toRight2 = True toRight2 = True
if facing == "left": splitpages.append(pagenumber)
splitCount += 1
facing = "right"
else: else:
toRight1 = True toRight1 = True
toRight2 = False toRight2 = False
if facing == "right": splitpages.append(pagenumber)
splitCount += 1
facing = "left"
img0 = image.ComicPage(split[0], options.profile) img0 = image.ComicPage(split[0], options.profile)
applyImgOptimization(img0, True, toRight1) applyImgOptimization(img0, True, toRight1)
img0.saveToDir(dirpath, options.forcepng, options.forcecolor, None) img0.saveToDir(dirpath, options.forcepng, options.forcecolor, None)
@@ -375,13 +371,15 @@ def dirImgProcess(path):
applyImgOptimization(img1, True, toRight2) applyImgOptimization(img1, True, toRight2)
img1.saveToDir(dirpath, options.forcepng, options.forcecolor, None) img1.saveToDir(dirpath, options.forcepng, options.forcecolor, None)
else: else:
if facing == "right":
facing = "left"
else:
facing = "right"
applyImgOptimization(img) applyImgOptimization(img)
img.saveToDir(dirpath, options.forcepng, options.forcecolor, split) img.saveToDir(dirpath, options.forcepng, options.forcecolor, split)
splitpages.sort()
for page in splitpages:
if (page + pagenumbermodifier) % 2 == 0:
splitCount += 1
pagenumbermodifier += 1
def genEpubStruct(path): def genEpubStruct(path):
global options global options