mirror of
https://github.com/ciromattia/kcc
synced 2025-12-19 12:41:47 +00:00
Dropped HQ PV option
This commit is contained in:
@@ -95,8 +95,6 @@ def buildHTML(path, imgfile, imgfilepath):
|
|||||||
additionalStyle = 'background-color:#FFFFFF;'
|
additionalStyle = 'background-color:#FFFFFF;'
|
||||||
htmlpath = ''
|
htmlpath = ''
|
||||||
postfix = ''
|
postfix = ''
|
||||||
size = ''
|
|
||||||
imgfilepv = ''
|
|
||||||
backref = 1
|
backref = 1
|
||||||
head = path
|
head = path
|
||||||
while True:
|
while True:
|
||||||
@@ -122,15 +120,7 @@ def buildHTML(path, imgfile, imgfilepath):
|
|||||||
"<body style=\"background-image: ",
|
"<body style=\"background-image: ",
|
||||||
"url('", "../" * backref, "Images/", postfix, imgfile, "'); " + additionalStyle + "\">\n"])
|
"url('", "../" * backref, "Images/", postfix, imgfile, "'); " + additionalStyle + "\">\n"])
|
||||||
if options.iskindle and options.panelview:
|
if options.iskindle and options.panelview:
|
||||||
if options.hqmode:
|
sizeTmp = Image.open(os.path.join(head, "Images", postfix, imgfile)).size
|
||||||
imgfilepv = list(os.path.splitext(imgfile))
|
|
||||||
imgfilepv[0] += "-hq"
|
|
||||||
imgfilepv = "".join(imgfilepv)
|
|
||||||
if os.path.isfile(os.path.join(head, "Images", postfix, imgfilepv)):
|
|
||||||
size = Image.open(os.path.join(head, "Images", postfix, imgfilepv)).size
|
|
||||||
if not options.hqmode or not size:
|
|
||||||
imgfilepv = imgfile
|
|
||||||
sizeTmp = Image.open(os.path.join(head, "Images", postfix, imgfilepv)).size
|
|
||||||
size = (int(sizeTmp[0] * 1.5), int(sizeTmp[1] * 1.5))
|
size = (int(sizeTmp[0] * 1.5), int(sizeTmp[1] * 1.5))
|
||||||
if size[0] <= deviceres[0]:
|
if size[0] <= deviceres[0]:
|
||||||
noHorizontalPV = True
|
noHorizontalPV = True
|
||||||
@@ -193,7 +183,7 @@ def buildHTML(path, imgfile, imgfilepath):
|
|||||||
for box in boxes:
|
for box in boxes:
|
||||||
f.writelines(["<div class=\"PV-P\" id=\"" + box + "-P\" style=\"" + additionalStyle + "\">\n",
|
f.writelines(["<div class=\"PV-P\" id=\"" + box + "-P\" style=\"" + additionalStyle + "\">\n",
|
||||||
"<img style=\"" + boxStyles[box] + "\" src=\"", "../" * backref, "Images/", postfix,
|
"<img style=\"" + boxStyles[box] + "\" src=\"", "../" * backref, "Images/", postfix,
|
||||||
imgfilepv, "\" width=\"" + str(size[0]) + "\" height=\"" + str(size[1]) + "\"/>\n",
|
imgfile, "\" width=\"" + str(size[0]) + "\" height=\"" + str(size[1]) + "\"/>\n",
|
||||||
"</div>\n"])
|
"</div>\n"])
|
||||||
f.writelines(["</body>\n",
|
f.writelines(["</body>\n",
|
||||||
"</html>\n"])
|
"</html>\n"])
|
||||||
@@ -437,8 +427,6 @@ def buildEPUB(path, chapterNames, tomeNumber):
|
|||||||
chapter = False
|
chapter = False
|
||||||
dirnames, filenames = walkSort(dirnames, filenames)
|
dirnames, filenames = walkSort(dirnames, filenames)
|
||||||
for afile in filenames:
|
for afile in filenames:
|
||||||
filename = getImageFileName(afile)
|
|
||||||
if not filename[0].endswith('-hq'):
|
|
||||||
filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
|
filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
|
||||||
if not chapter:
|
if not chapter:
|
||||||
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
||||||
@@ -964,8 +952,6 @@ def makeParser():
|
|||||||
help="Set cropping mode. 0: Disabled 1: Margins 2: Margins + page numbers [Default=2]")
|
help="Set cropping mode. 0: Disabled 1: Margins 2: Margins + page numbers [Default=2]")
|
||||||
processingOptions.add_option("--cp", "--croppingpower", type="float", dest="croppingp", default="1.0",
|
processingOptions.add_option("--cp", "--croppingpower", type="float", dest="croppingp", default="1.0",
|
||||||
help="Set cropping power [Default=1.0]")
|
help="Set cropping power [Default=1.0]")
|
||||||
processingOptions.add_option("--hq", action="store_true", dest="hqmode", default=False,
|
|
||||||
help="Enable high quality Panel View")
|
|
||||||
processingOptions.add_option("--blackborders", action="store_true", dest="black_borders", default=False,
|
processingOptions.add_option("--blackborders", action="store_true", dest="black_borders", default=False,
|
||||||
help="Disable autodetection and force black borders")
|
help="Disable autodetection and force black borders")
|
||||||
processingOptions.add_option("--whiteborders", action="store_true", dest="white_borders", default=False,
|
processingOptions.add_option("--whiteborders", action="store_true", dest="white_borders", default=False,
|
||||||
@@ -1015,20 +1001,16 @@ def checkOptions():
|
|||||||
# Older Kindle don't need higher resolution files due lack of Panel View.
|
# Older Kindle don't need higher resolution files due lack of Panel View.
|
||||||
if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'K3' or options.profile == 'KDX':
|
if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'K3' or options.profile == 'KDX':
|
||||||
options.panelview = False
|
options.panelview = False
|
||||||
options.hqmode = False
|
|
||||||
# Webtoon mode mandatory options
|
# Webtoon mode mandatory options
|
||||||
if options.webtoon:
|
if options.webtoon:
|
||||||
options.panelview = False
|
options.panelview = False
|
||||||
options.hqmode = False
|
|
||||||
options.righttoleft = False
|
options.righttoleft = False
|
||||||
options.upscale = True
|
options.upscale = True
|
||||||
# Disable all Kindle features for other e-readers
|
# Disable all Kindle features for other e-readers
|
||||||
if options.profile == 'OTHER':
|
if options.profile == 'OTHER':
|
||||||
options.panelview = False
|
options.panelview = False
|
||||||
options.hqmode = False
|
|
||||||
if 'Ko' in options.profile:
|
if 'Ko' in options.profile:
|
||||||
options.panelview = False
|
options.panelview = False
|
||||||
options.hqmode = False
|
|
||||||
# CBZ files on Kindle DX/DXG support higher resolution
|
# CBZ files on Kindle DX/DXG support higher resolution
|
||||||
if options.profile == 'KDX' and options.format == 'CBZ':
|
if options.profile == 'KDX' and options.format == 'CBZ':
|
||||||
options.customheight = 1200
|
options.customheight = 1200
|
||||||
@@ -1041,7 +1023,7 @@ def checkOptions():
|
|||||||
if options.customheight != 0:
|
if options.customheight != 0:
|
||||||
Y = options.customheight
|
Y = options.customheight
|
||||||
newProfile = ("Custom", (int(X), int(Y)), image.ProfileData.Palette16,
|
newProfile = ("Custom", (int(X), int(Y)), image.ProfileData.Palette16,
|
||||||
image.ProfileData.Profiles[options.profile][3], (int(int(X) * 1.5), int(int(Y) * 1.5)))
|
image.ProfileData.Profiles[options.profile][3])
|
||||||
image.ProfileData.Profiles["Custom"] = newProfile
|
image.ProfileData.Profiles["Custom"] = newProfile
|
||||||
options.profile = "Custom"
|
options.profile = "Custom"
|
||||||
options.profileData = image.ProfileData.Profiles[options.profile]
|
options.profileData = image.ProfileData.Profiles[options.profile]
|
||||||
|
|||||||
81
kcc/image.py
81
kcc/image.py
@@ -78,21 +78,21 @@ class ProfileData:
|
|||||||
]
|
]
|
||||||
|
|
||||||
Profiles = {
|
Profiles = {
|
||||||
'K1': ("Kindle 1", (600, 670), Palette4, 1.8, (900, 1005)),
|
'K1': ("Kindle 1", (600, 670), Palette4, 1.8),
|
||||||
'K2': ("Kindle 2", (600, 670), Palette15, 1.8, (900, 1005)),
|
'K2': ("Kindle 2", (600, 670), Palette15, 1.8),
|
||||||
'K3': ("Kindle", (600, 800), Palette16, 1.8, (900, 1200)),
|
'K3': ("Kindle", (600, 800), Palette16, 1.8),
|
||||||
'K45': ("Kindle", (600, 800), Palette16, 1.8, (900, 1200)),
|
'K45': ("Kindle", (600, 800), Palette16, 1.8),
|
||||||
'KDX': ("Kindle DX/DXG", (824, 1000), Palette16, 1.8, (1236, 1500)),
|
'KDX': ("Kindle DX/DXG", (824, 1000), Palette16, 1.8),
|
||||||
'KPW': ("Kindle Paperwhite 1/2", (758, 1024), Palette16, 1.8, (1137, 1536)),
|
'KPW': ("Kindle Paperwhite 1/2", (758, 1024), Palette16, 1.8),
|
||||||
'KV': ("Kindle Paperwhite 3/Voyage/Oasis", (1072, 1448), Palette16, 1.8, (1608, 2172)),
|
'KV': ("Kindle Paperwhite 3/Voyage/Oasis", (1072, 1448), Palette16, 1.8),
|
||||||
'KoMT': ("Kobo Mini/Touch", (600, 800), Palette16, 1.8, (900, 1200)),
|
'KoMT': ("Kobo Mini/Touch", (600, 800), Palette16, 1.8),
|
||||||
'KoG': ("Kobo Glo", (768, 1024), Palette16, 1.8, (1152, 1536)),
|
'KoG': ("Kobo Glo", (768, 1024), Palette16, 1.8),
|
||||||
'KoGHD': ("Kobo Glo HD", (1072, 1448), Palette16, 1.8, (1608, 2172)),
|
'KoGHD': ("Kobo Glo HD", (1072, 1448), Palette16, 1.8),
|
||||||
'KoA': ("Kobo Aura", (758, 1024), Palette16, 1.8, (1137, 1536)),
|
'KoA': ("Kobo Aura", (758, 1024), Palette16, 1.8),
|
||||||
'KoAHD': ("Kobo Aura HD", (1080, 1440), Palette16, 1.8, (1620, 2160)),
|
'KoAHD': ("Kobo Aura HD", (1080, 1440), Palette16, 1.8),
|
||||||
'KoAH2O': ("Kobo Aura H2O", (1080, 1430), Palette16, 1.8, (1620, 2145)),
|
'KoAH2O': ("Kobo Aura H2O", (1080, 1430), Palette16, 1.8),
|
||||||
'KoAO': ("Kobo Aura ONE", (1404, 1872), Palette16, 1.8, (2106, 2808)),
|
'KoAO': ("Kobo Aura ONE", (1404, 1872), Palette16, 1.8),
|
||||||
'OTHER': ("Other", (0, 0), Palette16, 1.8, (0, 0)),
|
'OTHER': ("Other", (0, 0), Palette16, 1.8),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,8 +106,6 @@ class ComicPageParser:
|
|||||||
self.color = self.colorCheck()
|
self.color = self.colorCheck()
|
||||||
self.fill = self.fillCheck()
|
self.fill = self.fillCheck()
|
||||||
self.splitCheck()
|
self.splitCheck()
|
||||||
if self.opt.hqmode:
|
|
||||||
self.sizeCheck()
|
|
||||||
|
|
||||||
def getImageHistogram(self, image):
|
def getImageHistogram(self, image):
|
||||||
histogram = image.histogram()
|
histogram = image.histogram()
|
||||||
@@ -206,29 +204,16 @@ class ComicPageParser:
|
|||||||
else:
|
else:
|
||||||
return 'white'
|
return 'white'
|
||||||
|
|
||||||
def sizeCheck(self):
|
|
||||||
additionalPayload = []
|
|
||||||
width, height = self.image.size
|
|
||||||
dstwidth, dstheight = self.size
|
|
||||||
for work in self.payload:
|
|
||||||
if width > dstwidth and height > dstheight:
|
|
||||||
additionalPayload.append([work[0] + '+', work[1], work[2].copy(), work[3], work[4]])
|
|
||||||
self.payload = self.payload + additionalPayload
|
|
||||||
|
|
||||||
|
|
||||||
class ComicPage:
|
class ComicPage:
|
||||||
def __init__(self, mode, path, image, color, fill, options):
|
def __init__(self, mode, path, image, color, fill, options):
|
||||||
self.opt = options
|
self.opt = options
|
||||||
_, self.size, self.palette, self.gamma, self.panelviewsize = self.opt.profileData
|
_, self.size, self.palette, self.gamma = self.opt.profileData
|
||||||
self.image = image
|
self.image = image
|
||||||
self.color = color
|
self.color = color
|
||||||
self.fill = fill
|
self.fill = fill
|
||||||
self.rotated = False
|
self.rotated = False
|
||||||
self.orgPath = os.path.join(path[0], path[1])
|
self.orgPath = os.path.join(path[0], path[1])
|
||||||
if '+' in mode:
|
|
||||||
self.hqMode = True
|
|
||||||
else:
|
|
||||||
self.hqMode = False
|
|
||||||
if 'N' in mode:
|
if 'N' in mode:
|
||||||
self.targetPath = os.path.join(path[0], os.path.splitext(path[1])[0]) + '-KCC'
|
self.targetPath = os.path.join(path[0], os.path.splitext(path[1])[0]) + '-KCC'
|
||||||
elif 'R' in mode:
|
elif 'R' in mode:
|
||||||
@@ -248,8 +233,6 @@ class ComicPage:
|
|||||||
flags.append('Rotated')
|
flags.append('Rotated')
|
||||||
if self.fill != 'white':
|
if self.fill != 'white':
|
||||||
flags.append('BlackFill')
|
flags.append('BlackFill')
|
||||||
if self.hqMode:
|
|
||||||
self.targetPath += '-HQ'
|
|
||||||
if self.opt.forcepng:
|
if self.opt.forcepng:
|
||||||
self.targetPath += '.png'
|
self.targetPath += '.png'
|
||||||
self.image.save(self.targetPath, 'PNG', optimize=1)
|
self.image.save(self.targetPath, 'PNG', optimize=1)
|
||||||
@@ -283,41 +266,35 @@ class ComicPage:
|
|||||||
self.image = self.image.quantize(palette=palImg)
|
self.image = self.image.quantize(palette=palImg)
|
||||||
|
|
||||||
def resizeImage(self):
|
def resizeImage(self):
|
||||||
if self.hqMode:
|
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
|
||||||
size = (self.panelviewsize[0], self.panelviewsize[1])
|
|
||||||
if self.image.size[0] > size[0] or self.image.size[1] > size[1]:
|
|
||||||
self.image.thumbnail(size, Image.LANCZOS)
|
|
||||||
else:
|
|
||||||
size = (self.size[0], self.size[1])
|
|
||||||
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
|
|
||||||
method = Image.BICUBIC
|
method = Image.BICUBIC
|
||||||
else:
|
else:
|
||||||
method = Image.LANCZOS
|
method = Image.LANCZOS
|
||||||
if self.opt.stretch:
|
if self.opt.stretch:
|
||||||
self.image = self.image.resize(size, method)
|
self.image = self.image.resize(self.size, method)
|
||||||
elif self.image.size[0] <= size[0] and self.image.size[1] <= size[1] and not self.opt.upscale:
|
elif self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1] and not self.opt.upscale:
|
||||||
if self.opt.format == 'CBZ':
|
if self.opt.format == 'CBZ':
|
||||||
borderw = int((size[0] - self.image.size[0]) / 2)
|
borderw = int((self.size[0] - self.image.size[0]) / 2)
|
||||||
borderh = int((size[1] - self.image.size[1]) / 2)
|
borderh = int((self.size[1] - self.image.size[1]) / 2)
|
||||||
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=self.fill)
|
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=self.fill)
|
||||||
if self.image.size[0] != size[0] or self.image.size[1] != size[1]:
|
if self.image.size[0] != self.size[0] or self.image.size[1] != self.size[1]:
|
||||||
self.image = ImageOps.fit(self.image, size, method=Image.BICUBIC, centering=(0.5, 0.5))
|
self.image = ImageOps.fit(self.image, self.size, method=Image.BICUBIC, centering=(0.5, 0.5))
|
||||||
else:
|
else:
|
||||||
if self.opt.format == 'CBZ':
|
if self.opt.format == 'CBZ':
|
||||||
ratioDev = float(size[0]) / float(size[1])
|
ratioDev = float(self.size[0]) / float(self.size[1])
|
||||||
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
|
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
|
||||||
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
|
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
|
||||||
self.image = ImageOps.expand(self.image, border=(int(diff / 2), 0), fill=self.fill)
|
self.image = ImageOps.expand(self.image, border=(int(diff / 2), 0), fill=self.fill)
|
||||||
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
|
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
|
||||||
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
|
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
|
||||||
self.image = ImageOps.expand(self.image, border=(0, int(diff / 2)), fill=self.fill)
|
self.image = ImageOps.expand(self.image, border=(0, int(diff / 2)), fill=self.fill)
|
||||||
self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5))
|
self.image = ImageOps.fit(self.image, self.size, method=method, centering=(0.5, 0.5))
|
||||||
else:
|
else:
|
||||||
hpercent = size[1] / float(self.image.size[1])
|
hpercent = self.size[1] / float(self.image.size[1])
|
||||||
wsize = int((float(self.image.size[0]) * float(hpercent)))
|
wsize = int((float(self.image.size[0]) * float(hpercent)))
|
||||||
self.image = self.image.resize((wsize, size[1]), method)
|
self.image = self.image.resize((wsize, self.size[1]), method)
|
||||||
if self.image.size[0] > size[0] or self.image.size[1] > size[1]:
|
if self.image.size[0] > self.size[0] or self.image.size[1] > self.size[1]:
|
||||||
self.image.thumbnail(size, Image.LANCZOS)
|
self.image.thumbnail(self.size, Image.LANCZOS)
|
||||||
|
|
||||||
def getBoundingBox(self, tmpImg):
|
def getBoundingBox(self, tmpImg):
|
||||||
min_margin = [int(0.005 * i + 0.5) for i in tmpImg.size]
|
min_margin = [int(0.005 * i + 0.5) for i in tmpImg.size]
|
||||||
|
|||||||
Reference in New Issue
Block a user