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

Removed support of Virtual Panel View

This commit is contained in:
Paweł Jastrzębski
2013-09-15 15:02:31 +02:00
parent 6e3888f295
commit 69b956904c
3 changed files with 47 additions and 149 deletions

View File

@@ -208,7 +208,8 @@ class WorkerThread(QtCore.QThread):
try:
self.kindlegenErrorCode = 0
if os.path.getsize(item) < 367001600:
output = Popen('kindlegen -locale en "' + item + '"', stdout=PIPE, stderr=STDOUT, shell=True)
output = Popen('kindlegen -locale en "' + item + '"', stdout=PIPE, stderr=STDOUT,
shell=True)
for line in output.stdout:
# ERROR: Generic error
if "Error(" in line:
@@ -439,11 +440,14 @@ class Ui_KCC(object):
GUI.QualityBox.setChecked(False)
GUI.BorderBox.setEnabled(False)
GUI.BorderBox.setChecked(False)
GUI.MangaBox.setEnabled(False)
GUI.MangaBox.setChecked(False)
self.addMessage('If images are color setting <i>Gamma</i> to 1.0 is recommended.', 'info')
else:
GUI.NoRotateBox.setEnabled(True)
GUI.QualityBox.setEnabled(True)
GUI.BorderBox.setEnabled(True)
GUI.MangaBox.setEnabled(True)
def toggleNoSplitRotate(self, value):
if value:
@@ -467,7 +471,7 @@ class Ui_KCC(object):
GUI.BasicModeButton.setEnabled(True)
GUI.AdvModeButton.setEnabled(True)
self.modeBasic()
if value in [0, 1, 5, 6, 7, 8, 9, 12]:
if value in [0, 1, 5, 6, 12]:
GUI.QualityBox.setCheckState(0)
GUI.QualityBox.setEnabled(False)
else:

View File

@@ -145,22 +145,6 @@ def buildHTML(path, imgfile):
return path, imgfile
def buildBlankHTML(path):
f = open(os.path.join(path, 'blank.html'), "w")
f.writelines(["<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" ",
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n",
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
"<head>\n",
"<title></title>\n",
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n",
"</head>\n",
"<body>\n",
"</body>\n",
"</html>"])
f.close()
return path
def buildNCX(dstdir, title, chapters):
from uuid import uuid4
options.uuid = str(uuid4())
@@ -173,16 +157,18 @@ def buildNCX(dstdir, title, chapters):
"<ncx version=\"2005-1\" xml:lang=\"en-US\" xmlns=\"http://www.daisy.org/z3986/2005/ncx/\">\n",
"<head>\n",
"<meta name=\"dtb:uid\" content=\"", options.uuid, "\"/>\n",
"<meta name=\"dtb:depth\" content=\"2\"/>\n",
"<meta name=\"dtb:depth\" content=\"1\"/>\n",
"<meta name=\"dtb:totalPageCount\" content=\"0\"/>\n",
"<meta name=\"dtb:maxPageNumber\" content=\"0\"/>\n",
"<meta name=\"generated\" content=\"true\"/>\n",
"</head>\n",
"<docTitle><text>", title, "</text></docTitle>\n",
"<navMap>"
])
for chapter in chapters:
folder = chapter[0].replace(os.path.join(dstdir, 'OEBPS'), '').lstrip('/').lstrip('\\\\')
title = os.path.basename(folder)
if os.path.basename(folder) != "Text":
title = os.path.basename(folder)
filename = getImageFileName(os.path.join(folder, chapter[1]))
f.write("<navPoint id=\"" + folder.replace('/', '_').replace('\\', '_') + "\"><navLabel><text>" + title
+ "</text></navLabel><content src=\"" + filename[0].replace("\\", "/") + ".html\"/></navPoint>\n")
@@ -197,38 +183,32 @@ def buildOPF(dstdir, title, filelist, cover=None):
imgres = str(deviceres[0]) + "x" + str(deviceres[1])
if options.righttoleft:
writingmode = "horizontal-rl"
facing = "right"
facing1 = "right"
facing2 = "left"
else:
writingmode = "horizontal-lr"
facing = "left"
facing1 = "left"
facing2 = "right"
f = open(opffile, "w")
f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
"<package version=\"2.0\" unique-identifier=\"BookID\" xmlns=\"http://www.idpf.org/2007/opf\">\n",
"<metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\" ",
"xmlns:opf=\"http://www.idpf.org/2007/opf\">\n",
"<package version=\"2.0\" unique-identifier=\"BookID\" ",
"xmlns=\"http://www.idpf.org/2007/opf\">\n",
"<metadata xmlns:opf=\"http://www.idpf.org/2007/opf\" ",
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n",
"<dc:title>", title, "</dc:title>\n",
"<dc:language>en-US</dc:language>\n",
"<dc:identifier id=\"BookID\" opf:scheme=\"UUID\">", options.uuid, "</dc:identifier>\n",
"<meta name=\"generator\" content=\"KindleComicConverter-" + __version__ + "\"/>\n",
"<meta name=\"RegionMagnification\" content=\"true\"/>\n",
"<meta name=\"region-mag\" content=\"true\"/>\n",
"<meta name=\"cover\" content=\"cover\"/>\n",
"<meta name=\"book-type\" content=\"comic\"/>\n",
"<meta name=\"rendition:layout\" content=\"pre-paginated\"/>\n",
"<meta name=\"zero-gutter\" content=\"true\"/>\n",
"<meta name=\"zero-margin\" content=\"true\"/>\n",
"<meta name=\"fixed-layout\" content=\"true\"/>\n"
])
if options.landscapemode:
f.writelines(["<meta name=\"rendition:orientation\" content=\"auto\"/>\n",
"<meta name=\"orientation-lock\" content=\"none\"/>\n"])
else:
f.writelines(["<meta name=\"rendition:orientation\" content=\"portrait\"/>\n",
"<meta name=\"orientation-lock\" content=\"portrait\"/>\n"])
f.writelines(["<meta name=\"original-resolution\" content=\"", imgres, "\"/>\n",
"<meta name=\"rendition:orientation\" content=\"portrait\"/>\n",
"<meta name=\"orientation-lock\" content=\"portrait\"/>\n",
"<meta name=\"original-resolution\" content=\"", imgres, "\"/>\n",
"<meta name=\"primary-writing-mode\" content=\"", writingmode, "\"/>\n",
"<meta name=\"rendition:layout\" content=\"pre-paginated\"/>\n",
"<meta name=\"ke-border-color\" content=\"#ffffff\"/>\n",
"<meta name=\"ke-border-width\" content=\"0\"/>\n",
"</metadata>\n<manifest>\n<item id=\"ncx\" href=\"toc.ncx\" ",
"media-type=\"application/x-dtbncx+xml\"/>\n"])
if cover is not None:
@@ -253,44 +233,10 @@ def buildOPF(dstdir, title, filelist, cover=None):
mt = 'image/jpeg'
f.write("<item id=\"img_" + uniqueid + "\" href=\"" + folder + "/" + path[1] + "\" media-type=\""
+ mt + "\"/>\n")
if options.landscapemode and splitCount > 0:
splitCountUsed = 1
while splitCountUsed <= splitCount:
f.write("<item id=\"blank-page" + str(splitCountUsed) +
"\" href=\"Text/blank.html\" media-type=\"application/xhtml+xml\"/>\n")
splitCountUsed += 1
f.write("<item id=\"css\" href=\"Text/style.css\" media-type=\"text/css\"/>\n")
f.write("</manifest>\n<spine toc=\"ncx\">\n")
splitCountUsed = 1
for entry in reflist:
if "_kcca" in str(entry):
# noinspection PyRedundantParentheses
if ((options.righttoleft and facing == 'left') or (not options.righttoleft and facing == 'right')) and\
options.landscapemode:
f.write("<itemref idref=\"blank-page" + str(splitCountUsed) + "\" properties=\"layout-blank\"/>\n")
splitCountUsed += 1
if options.landscapemode:
f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing1 + "\"/>\n")
else:
f.write("<itemref idref=\"page_" + entry + "\"/>\n")
elif "_kccb" in str(entry):
if options.landscapemode:
f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing2 + "\"/>\n")
else:
f.write("<itemref idref=\"page_" + entry + "\"/>\n")
if options.righttoleft:
facing = "right"
else:
facing = "left"
else:
if options.landscapemode:
f.write("<itemref idref=\"page_" + entry + "\" properties=\"page-spread-" + facing + "\"/>\n")
else:
f.write("<itemref idref=\"page_" + entry + "\"/>\n")
if facing == 'right':
facing = 'left'
else:
facing = 'right'
f.write("<itemref idref=\"page_" + entry + "\"/>\n")
f.write("</spine>\n<guide>\n</guide>\n</package>\n")
f.close()
os.mkdir(os.path.join(dstdir, 'META-INF'))
@@ -322,24 +268,22 @@ def getImageFileName(imgfile):
return filename
def applyImgOptimization(img, isSplit, toRight, options, overrideQuality=5):
def applyImgOptimization(img, options, overrideQuality=5):
if not options.webtoon:
img.cropWhiteSpace(10.0)
if options.cutpagenumbers and not options.webtoon:
img.cutPageNumber()
img.optimizeImage(options.gamma)
if overrideQuality != 5:
img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight,
options.landscapemode, overrideQuality)
img.resizeImage(options.upscale, options.stretch, options.black_borders, overrideQuality)
else:
img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight,
options.landscapemode, options.quality)
img.resizeImage(options.upscale, options.stretch, options.black_borders, options.quality)
if options.forcepng and not options.forcecolor:
img.quantizeImage()
def dirImgProcess(path):
global options, splitCount
global options
work = []
pagenumber = 0
pagenumbermodifier = 0
@@ -378,7 +322,6 @@ def dirImgProcess(path):
splitpages.sort()
for page in splitpages:
if (page + pagenumbermodifier) % 2 == 0:
splitCount += 1
pagenumbermodifier += 1
pagenumbermodifier += 1
else:
@@ -415,34 +358,28 @@ def fileImgProcess(work):
if split is not None and split is not "R":
if options.verbose:
print "Splitted " + afile
if options.righttoleft:
toRight1 = False
toRight2 = True
else:
toRight1 = True
toRight2 = False
output = pagenumber
img0 = image.ComicPage(split[0], options.profileData)
applyImgOptimization(img0, True, toRight1, options)
applyImgOptimization(img0, options)
img0.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe)
img1 = image.ComicPage(split[1], options.profileData)
applyImgOptimization(img1, True, toRight2, options)
applyImgOptimization(img1, options)
img1.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe)
if options.quality == 2:
img3 = image.ComicPage(split[0], options.profileData)
applyImgOptimization(img3, True, toRight1, options, 0)
applyImgOptimization(img3, options, 0)
img3.saveToDir(dirpath, options.forcepng, options.forcecolor, True)
img4 = image.ComicPage(split[1], options.profileData)
applyImgOptimization(img4, True, toRight2, options, 0)
applyImgOptimization(img4, options, 0)
img4.saveToDir(dirpath, options.forcepng, options.forcecolor, True)
else:
applyImgOptimization(img, False, False, options)
applyImgOptimization(img, options)
img.saveToDir(dirpath, options.forcepng, options.forcecolor, wipe, split)
if options.quality == 2:
img2 = image.ComicPage(os.path.join(dirpath, afile), options.profileData)
if split == "R":
img2.image = img2.image.rotate(90)
applyImgOptimization(img2, False, False, options, 0)
applyImgOptimization(img2, options, 0)
img2.saveToDir(dirpath, options.forcepng, options.forcecolor, True, split)
return output
@@ -588,13 +525,11 @@ def genEpubStruct(path):
'cover' + getImageFileName(filelist[-1][1])[1])
copyfile(os.path.join(filelist[-1][0], filelist[-1][1]), cover)
buildNCX(path, options.title, chapterlist)
# ensure we're sorting files alphabetically
# Ensure we're sorting files alphabetically
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
filelist.sort(key=lambda name: (alphanum_key(name[0].lower()), alphanum_key(name[1].lower())))
buildOPF(path, options.title, filelist, cover)
if options.landscapemode and splitCount > 0:
filelist.append(buildBlankHTML(os.path.join(path, 'OEBPS', 'Text')))
def getWorkFolder(afile):
@@ -637,8 +572,7 @@ def getWorkFolder(afile):
def slugify(value):
# Normalizes string, converts to lowercase, removes non-alpha characters,
# and converts spaces to hyphens.
# Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
import unicodedata
value = unicodedata.normalize('NFKD', unicode(value, 'latin1')).encode('ascii', 'ignore')
value = re.sub('[^\w\s\.-]', '', value).strip().lower()
@@ -844,7 +778,7 @@ def Usage():
def main(argv=None, qtGUI=None):
global parser, options, epub_path, splitCount, GUI
global parser, options, epub_path, GUI
parser = OptionParser(usage="Usage: %prog [options] comic_file|comic_folder", add_help_option=False)
mainOptions = OptionGroup(parser, "MAIN")
experimentalOptions = OptionGroup(parser, "EXPERIMENTAL")
@@ -921,7 +855,6 @@ def main(argv=None, qtGUI=None):
comic2panel.main(['-y ' + str(options.customheight), '-i', path], qtGUI)
else:
comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', path], qtGUI)
splitCount = 0
if options.imgproc:
print "\nProcessing images..."
if GUI:
@@ -985,47 +918,24 @@ def getOutputFilename(srcpath, wantedname, ext, tomeNumber):
def checkOptions():
global options
# Landscape mode is only supported by Kindle Touch and Paperwhite.
if options.profile == 'K4T' or options.profile == 'KHD':
options.landscapemode = True
else:
options.landscapemode = False
# Older Kindle don't support Virtual Panel View. We providing them configuration that will fake that feature.
# Ultra quality mode require Real Panel View. Landscape mode don't work correcly without Virtual Panel View.
if options.profile == 'K3' or options.profile == 'K4NT' or options.quality == 2:
# Real Panel View
options.panelview = True
options.landscapemode = False
else:
# Virtual Panel View
options.panelview = False
options.panelview = True
# 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
else:
options.forcecolor = False
# Mixing vertical and horizontal pages require real Panel View.
# Landscape mode don't work correcly without Virtual Panel View.
if options.rotate:
options.panelview = True
options.landscapemode = False
# Older Kindle don't need higher resolution files due lack of Panel View.
# Kindle Fire family have very high resolution. Bigger images are not needed.
if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'KDX' or options.profile == 'KDXG'\
or options.profile == 'KF' or options.profile == 'KFHD' or options.profile == 'KFHD8':
if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'KDX' or options.profile == 'KDXG':
options.quality = 0
if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'KDX' or options.profile == 'KDXG':
options.panelview = False
options.panelview = False
# Webtoon mode mandatory options
if options.webtoon:
options.nosplitrotate = True
options.black_borders = False
options.quality = 0
options.landscapemode = False
options.panelview = False
# Disable all Kindle features
# Disable all Kindle features for other e-readers
if options.profile == 'OTHER':
options.landscapemode = False
options.panelview = False
options.quality = 0
# Kindle for Android profile require target resolution.

View File

@@ -173,8 +173,7 @@ 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, qualityMode=0):
def resizeImage(self, upscale=False, stretch=False, black_borders=False, qualityMode=0):
method = Image.ANTIALIAS
if '-KCCFW' in str(self.filename):
fill = 'white'
@@ -194,9 +193,6 @@ class ComicPage:
else:
size = (self.panelviewsize[0], self.panelviewsize[1])
generateBorder = False
# Kindle Paperwhite/Touch - Force upscale of splited pages to increase readability
if isSplit and landscapeMode:
upscale = True
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
if not upscale:
borderw = (self.size[0] - self.image.size[0]) / 2
@@ -210,7 +206,7 @@ class ComicPage:
return self.image
else:
method = Image.BILINEAR
if stretch: # if stretching call directly resize() without other considerations.
if stretch: # If stretching call directly resize() without other considerations.
self.image = self.image.resize(size, method)
if generateBorder:
if fill == 'white':
@@ -224,19 +220,8 @@ class ComicPage:
return self.image
ratioDev = float(self.size[0]) / float(self.size[1])
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
if isSplit and landscapeMode:
generateBorder = False
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill)
tempImg = Image.new(self.image.mode, (self.image.size[0] + diff, self.image.size[1]), fill)
if toRight:
tempImg.paste(self.image, (diff, 0))
else:
tempImg.paste(self.image, (0, 0))
self.image = tempImg
else:
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill)
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill)
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill)
@@ -255,19 +240,18 @@ class ComicPage:
def splitPage(self, targetdir, righttoleft=False, rotate=False):
width, height = self.image.size
dstwidth, dstheight = self.size
#print "Image is %d x %d" % (width,height)
# only split if origin is not oriented the same as target
# Only split if origin is not oriented the same as target
if (width > height) != (dstwidth > dstheight):
if rotate:
self.image = self.image.rotate(90)
return "R"
else:
if width > height:
# source is landscape, so split by the width
# Source is landscape, so split by the width
leftbox = (0, 0, width / 2, height)
rightbox = (width / 2, 0, width, height)
else:
# source is portrait and target is landscape, so split by the height
# Source is portrait and target is landscape, so split by the height
leftbox = (0, 0, width, height / 2)
rightbox = (0, height / 2, width, height)
filename = os.path.splitext(self.filename)