Improve icon generation and whitespace detection
This commit is contained in:
parent
59788d5f16
commit
65690ca90c
@ -182,27 +182,27 @@ init python:
|
|||||||
matrix = SaturationMatrix(0.0)
|
matrix = SaturationMatrix(0.0)
|
||||||
sprites = [i for i in self.build_image(hash, matrix=matrix) if not i[0] == "mask"]
|
sprites = [i for i in self.build_image(hash, matrix=matrix) if not i[0] == "mask"]
|
||||||
|
|
||||||
try:
|
icon_sprite = Fixed(*[i[1] for i in sprites], fit_first=True)
|
||||||
bounds = self.get_layers(hash).get("outline", [sprites[0][1]])[0]
|
|
||||||
except IndexError:
|
|
||||||
print(f"Missing textures:\n{self.__repr__()}")
|
|
||||||
return Text(f"TexErr\n{{color=#00ffff}}{{size=-6}}ID:{self.id}{{/size}}{{/color}}", color="#ff0000")
|
|
||||||
sprites.extend(self.char.body.build_image(self.char.body._hash, matrix=matrix))
|
sprites.extend(self.char.body.build_image(self.char.body._hash, matrix=matrix))
|
||||||
sprites.sort(key=itemgetter(2))
|
sprites.sort(key=itemgetter(2))
|
||||||
|
|
||||||
wmax, hmax = self.sizes
|
wmax, hmax = self.sizes
|
||||||
wmin = hmin = 256
|
wmin = hmin = 128
|
||||||
|
padding = 32
|
||||||
|
|
||||||
x, y, w, h = crop_whitespace(bounds)
|
x, y, w, h = crop_whitespace_surface(icon_sprite)
|
||||||
xoffset, yoffset = w/2, h/2
|
xoffset, yoffset = w//2, h//2
|
||||||
|
w = h = max(w, h)
|
||||||
|
|
||||||
w = h = max(w, h, wmin, hmin)
|
if w == 0 or h == 0:
|
||||||
|
return Null()
|
||||||
|
|
||||||
w = max(wmin, w + w/2)
|
w = max(wmin, w + padding)
|
||||||
h = max(hmin, h + h/2)
|
h = max(hmin, h + padding)
|
||||||
|
|
||||||
x = clamp( (x - w/2) + xoffset, 0, wmax)
|
x = clamp( (x - w//2) + xoffset, 0, wmax)
|
||||||
y = clamp( (y - h/2) + yoffset, 0, hmax)
|
y = clamp( (y - h//2) + yoffset, 0, hmax)
|
||||||
|
|
||||||
# Forbid exceeding the image height.
|
# Forbid exceeding the image height.
|
||||||
if y+h > hmax:
|
if y+h > hmax:
|
||||||
|
@ -170,6 +170,8 @@ init python:
|
|||||||
matrix = SaturationMatrix(0.0)
|
matrix = SaturationMatrix(0.0)
|
||||||
sprites = [i for i in self.build_image(hash, matrix=matrix) if not i[0] == "mask"]
|
sprites = [i for i in self.build_image(hash, matrix=matrix) if not i[0] == "mask"]
|
||||||
|
|
||||||
|
icon_sprite = Fixed(*[i[1] for i in sprites], fit_first=True)
|
||||||
|
|
||||||
if not tracking_object is None:
|
if not tracking_object is None:
|
||||||
sprites.extend([i for i in tracking_object.build_image(tracking_object._hash, matrix=matrix) if not i[0] == "mask"])
|
sprites.extend([i for i in tracking_object.build_image(tracking_object._hash, matrix=matrix) if not i[0] == "mask"])
|
||||||
|
|
||||||
@ -178,18 +180,21 @@ init python:
|
|||||||
bounds = self.get_layers(hash).get("outline", [sprites[0][1]])[0]
|
bounds = self.get_layers(hash).get("outline", [sprites[0][1]])[0]
|
||||||
|
|
||||||
wmax, hmax = self.sizes
|
wmax, hmax = self.sizes
|
||||||
wmin = hmin = 96
|
wmin = hmin = 128
|
||||||
|
padding = 32
|
||||||
|
|
||||||
x, y, w, h = crop_whitespace(bounds)
|
x, y, w, h = crop_whitespace_surface(icon_sprite)
|
||||||
xoffset, yoffset = w/2, h/2
|
xoffset, yoffset = w//2, h//2
|
||||||
|
w = h = max(w, h)
|
||||||
|
|
||||||
w = h = max(w, h, wmin, hmin)
|
if w == 0 or h == 0:
|
||||||
|
return Null()
|
||||||
|
|
||||||
w = max(wmin, w + w/2)
|
w = max(wmin, w + padding)
|
||||||
h = max(hmin, h + h/2)
|
h = max(hmin, h + padding)
|
||||||
|
|
||||||
x = clamp( (x - w/2) + xoffset, 0, wmax)
|
x = clamp( (x - w//2) + xoffset, 0, wmax)
|
||||||
y = clamp( (y - h/2) + yoffset, 0, hmax)
|
y = clamp( (y - h//2) + yoffset, 0, hmax)
|
||||||
|
|
||||||
# Forbid exceeding the image height.
|
# Forbid exceeding the image height.
|
||||||
if y+h > hmax:
|
if y+h > hmax:
|
||||||
|
@ -31,6 +31,15 @@ init python:
|
|||||||
whitespace_dict[path] = tuple(map(int, box))
|
whitespace_dict[path] = tuple(map(int, box))
|
||||||
return box
|
return box
|
||||||
|
|
||||||
|
def crop_whitespace_surface(displayable):
|
||||||
|
surf = renpy.render_to_surface(displayable, width=1010, height=1200)
|
||||||
|
size = surf.get_size()
|
||||||
|
box = tuple(surf.get_bounding_rect())
|
||||||
|
if size[0] != 1010:
|
||||||
|
ratio = size[0]/1010
|
||||||
|
box = tuple(v//ratio for v in box)
|
||||||
|
return box
|
||||||
|
|
||||||
def crop_image_zoom(path, xsize, ysize, grayscale=False):
|
def crop_image_zoom(path, xsize, ysize, grayscale=False):
|
||||||
x, y, w, h = crop_whitespace(path)
|
x, y, w, h = crop_whitespace(path)
|
||||||
matrix = SaturationMatrix(0)*BrightnessMatrix(-0.25)*OpacityMatrix(0.5) if grayscale else None
|
matrix = SaturationMatrix(0)*BrightnessMatrix(-0.25)*OpacityMatrix(0.5) if grayscale else None
|
||||||
|
Loading…
Reference in New Issue
Block a user