1
0
mirror of https://github.com/ciromattia/kcc synced 2026-06-19 21:10:47 +00:00

Panel View support overhaul - Round 2

This commit is contained in:
Paweł Jastrzębski
2013-12-05 15:41:47 +01:00
parent e5be31f9d5
commit 3b0e5cc309
2 changed files with 49 additions and 35 deletions
+19 -17
View File
@@ -142,35 +142,35 @@ def buildHTML(path, imgfile):
xr = borders[2].lstrip("0") xr = borders[2].lstrip("0")
yd = borders[3].lstrip("0") yd = borders[3].lstrip("0")
if xl != "": if xl != "":
xl = "-" + str(xl) + "px" xl = "-" + str(float(xl)/100) + "%"
else: else:
xl = "0px" xl = "0%"
if xr != "": if xr != "":
xr = "-" + str(xr) + "px" xr = "-" + str(float(xr)/100) + "%"
else: else:
xr = "0px" xr = "0%"
if yu != "": if yu != "":
yu = "-" + str(yu) + "px" yu = "-" + str(float(yu)/100) + "%"
else: else:
yu = "0px" yu = "0%"
if yd != "": if yd != "":
yd = "-" + str(yd) + "px" yd = "-" + str(float(yd)/100) + "%"
else: else:
yd = "0px" yd = "0%"
else: else:
xl = "0px" xl = "0%"
yu = "0px" yu = "0%"
xr = "0px" xr = "0%"
yd = "0px" yd = "0%"
boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";", boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";",
"BoxTR": "right:" + xr + ";top:" + yu + ";", "BoxTR": "right:" + xr + ";top:" + yu + ";",
"BoxBL": "left:" + xl + ";bottom:" + yd + ";", "BoxBL": "left:" + xl + ";bottom:" + yd + ";",
"BoxBR": "right:" + xr + ";bottom:" + yd + ";", "BoxBR": "right:" + xr + ";bottom:" + yd + ";",
"BoxT": "left:-25%;top:" + yu + ";", "BoxT": "left:" + xl + ";top:" + yu + ";",
"BoxB": "left:-25%;bottom:" + yd + ";", "BoxB": "left:" + xl + ";bottom:" + yd + ";",
"BoxL": "left:" + xl + ";top:-25%;", "BoxL": "left:" + xl + ";top:" + yu + ";",
"BoxR": "right:" + xr + ";top:-25%;", "BoxR": "right:" + xr + ";top:" + yu + ";",
"BoxC": "right:-25%;top:-25%;" "BoxC": "left:" + xl + ";top:" + yu + ";"
} }
for box in boxes: for box in boxes:
f.writelines(["<div id=\"" + box + "-Panel-Parent\" class=\"target-mag-parent\"><div id=\"", f.writelines(["<div id=\"" + box + "-Panel-Parent\" class=\"target-mag-parent\"><div id=\"",
@@ -321,6 +321,8 @@ def applyImgOptimization(img, opt, hqImage=None):
img.calculateBorder(hqImage) img.calculateBorder(hqImage)
else: else:
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, opt.quality) img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, opt.quality)
if opt.panelview and opt.quality != 2:
img.calculateBorder(img)
if opt.forcepng and not opt.forcecolor: if opt.forcepng and not opt.forcecolor:
img.quantizeImage() img.quantizeImage()
+30 -18
View File
@@ -233,26 +233,34 @@ class ComicPage:
# Quantize is deprecated but new function call it internally anyway... # Quantize is deprecated but new function call it internally anyway...
self.image = self.image.quantize(palette=palImg) self.image = self.image.quantize(palette=palImg)
def calculateBorderPercent(self, x, img, isWidth):
if isWidth:
return int(round(float(x)/float(img.image.size[0]), 4) * 10000 * 1.5)
else:
return int(round(float(x)/float(img.image.size[1]), 4) * 10000 * 1.5)
def calculateBorder(self, sourceImage): def calculateBorder(self, sourceImage):
if self.fill == 'white': if self.fill == 'white':
border = ImageOps.invert(sourceImage.image).getbbox() border = ImageOps.invert(sourceImage.image).getbbox()
else: else:
border = sourceImage.image.getbbox() border = sourceImage.image.getbbox()
if border is not None: if border is not None:
if border[2]-border[0] < self.size[0]: self.border = [self.calculateBorderPercent(border[0], sourceImage, True),
self.calculateBorderPercent(border[1], sourceImage, False),
self.calculateBorderPercent((sourceImage.image.size[0] - border[2]), sourceImage, True),
self.calculateBorderPercent((sourceImage.image.size[1] - border[3]), sourceImage, False)]
if int((border[2] - border[0]) * 1.5) < self.size[0]:
self.noHPV = True self.noHPV = True
if border[3]-border[1] < self.size[1]: self.border[0] /= 2
if int((border[3] - border[1]) * 1.5) < self.size[1]:
self.noVPV = True self.noVPV = True
self.border = [border[0], border[1], self.border[1] /= 2
sourceImage.image.size[0] - border[2], sourceImage.image.size[1] - border[3]]
else: else:
self.border = [0, 0] self.border = [0, 0, 0, 0]
self.noHPV = True self.noHPV = True
self.noVPV = True self.noVPV = True
def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0): def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0):
# High-quality downscaling filter
method = Image.ANTIALIAS
if bordersColor: if bordersColor:
fill = bordersColor fill = bordersColor
else: else:
@@ -262,28 +270,32 @@ class ComicPage:
size = (self.size[0], self.size[1]) size = (self.size[0], self.size[1])
else: else:
size = (self.panelviewsize[0], self.panelviewsize[1]) size = (self.panelviewsize[0], self.panelviewsize[1])
# If image is smaller than target size and upscale is off - Just expand it by adding margins # If image is smaller than device resolution and upscale is off - Just expand it by adding margins
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]: if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1] and not upscale:
if not upscale: borderw = (self.size[0] - self.image.size[0]) / 2
borderw = (size[0] - self.image.size[0]) / 2 borderh = (self.size[1] - self.image.size[1]) / 2
borderh = (size[1] - self.image.size[1]) / 2 self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill) return self.image
return self.image
else:
# Cubic spline interpolation in a 4x4 environment
method = Image.BICUBIC
# If stretching is on - Resize without other considerations # If stretching is on - Resize without other considerations
if stretch: if stretch:
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
method = Image.BICUBIC
else:
method = Image.ANTIALIAS
self.image = self.image.resize(size, method) self.image = self.image.resize(size, method)
return self.image return self.image
# Otherwise - Upscale/Downscale # Otherwise - Upscale/Downscale
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=(diff / 2, 0), fill=fill) self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=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, diff / 2), fill=fill) self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill)
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
method = Image.BICUBIC
else:
method = Image.ANTIALIAS
self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5)) self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5))
return self.image return self.image