2023-01-28 14:19:40 +00:00
|
|
|
from PIL import Image
|
|
|
|
from typing import Callable, List
|
|
|
|
|
|
|
|
|
|
|
|
def process_tiles(
|
|
|
|
source: Image.Image,
|
|
|
|
tile: int,
|
|
|
|
scale: int,
|
|
|
|
filters: List[Callable],
|
|
|
|
) -> Image:
|
|
|
|
width, height = source.size
|
|
|
|
image = Image.new('RGB', (width * scale, height * scale))
|
|
|
|
|
|
|
|
tiles_x = width // tile
|
|
|
|
tiles_y = height // tile
|
|
|
|
total = tiles_x * tiles_y
|
|
|
|
|
|
|
|
for y in range(tiles_y):
|
|
|
|
for x in range(tiles_x):
|
|
|
|
idx = (y * tiles_x) + x
|
|
|
|
left = x * tile
|
|
|
|
top = y * tile
|
|
|
|
print('processing tile %s of %s, %s.%s' % (idx, total, y, x))
|
|
|
|
tile_image = source.crop((left, top, left + tile, top + tile))
|
|
|
|
|
|
|
|
for filter in filters:
|
2023-01-28 15:23:18 +00:00
|
|
|
tile_image = filter(tile_image, (left, top, tile))
|
2023-01-28 14:19:40 +00:00
|
|
|
|
|
|
|
image.paste(tile_image, (left * scale, top * scale))
|
|
|
|
|
|
|
|
return image
|