2022-05-16 23:48:22 +00:00
|
|
|
init python:
|
|
|
|
whitespace_dict = {}
|
2022-09-21 18:22:14 +00:00
|
|
|
with renpy.open_file("images.whitespace") as fp:
|
2022-05-16 23:48:22 +00:00
|
|
|
line = fp.readline()
|
|
|
|
while line:
|
|
|
|
path, area = line.strip("\r\n").split(':')
|
2022-09-21 20:57:04 +00:00
|
|
|
whitespace_dict[path] = list(map(int, area.split(',')))
|
2022-05-16 23:48:22 +00:00
|
|
|
line = fp.readline()
|
|
|
|
|
|
|
|
def crop_whitespace(path):
|
|
|
|
# Return box from whitespace_dict, or calculate and store it
|
2023-06-08 16:41:06 +00:00
|
|
|
|
|
|
|
def _find_file_surface(obj):
|
|
|
|
if isinstance(obj, str):
|
|
|
|
return obj, Image(obj).load()
|
|
|
|
elif isinstance(obj, im.Image):
|
|
|
|
return obj.filename, obj.load()
|
|
|
|
elif isinstance(obj, Transform):
|
|
|
|
return _find_file_surface(obj.child)
|
|
|
|
|
2022-05-16 23:48:22 +00:00
|
|
|
if path in whitespace_dict:
|
|
|
|
box = whitespace_dict[path]
|
|
|
|
else:
|
2023-06-08 16:41:06 +00:00
|
|
|
path, surf = _find_file_surface(path)
|
|
|
|
size = surf.get_size()
|
2022-05-16 23:48:22 +00:00
|
|
|
box = tuple(surf.get_bounding_rect())
|
2023-06-08 16:41:06 +00:00
|
|
|
|
2023-07-26 23:54:03 +00:00
|
|
|
if "/clothes/" in path and size[0] != 1010:
|
2023-06-08 16:41:06 +00:00
|
|
|
ratio = size[0] / 1010
|
|
|
|
box = tuple(v/ratio for v in box)
|
2023-07-26 23:54:03 +00:00
|
|
|
whitespace_dict[path] = tuple(map(int, box))
|
2022-05-16 23:48:22 +00:00
|
|
|
return box
|
|
|
|
|
2024-10-16 19:59:14 +00:00
|
|
|
def crop_whitespace_surface(displayable):
|
|
|
|
surf = renpy.render_to_surface(displayable, width=1010, height=1200)
|
|
|
|
size = surf.get_size()
|
2024-10-22 14:26:41 +00:00
|
|
|
box = (int(i) for i in surf.get_bounding_rect())
|
2024-10-16 19:59:14 +00:00
|
|
|
if size[0] != 1010:
|
|
|
|
ratio = size[0]/1010
|
2024-10-22 14:26:41 +00:00
|
|
|
box = tuple(int(v//ratio) for v in box)
|
2024-10-16 19:59:14 +00:00
|
|
|
return box
|
|
|
|
|
2022-05-16 23:48:22 +00:00
|
|
|
def crop_image_zoom(path, xsize, ysize, grayscale=False):
|
|
|
|
x, y, w, h = crop_whitespace(path)
|
2024-11-10 15:23:13 +00:00
|
|
|
matrix = SaturationMatrix(0)*BrightnessMatrix(-0.15) if grayscale else None
|
2022-05-16 23:48:22 +00:00
|
|
|
sprite = Image(path)
|
|
|
|
|
|
|
|
return Transform(sprite, crop=(x, y, w, h), xsize=xsize, ysize=ysize, fit="contain", matrixcolor=matrix, subpixel=True)
|