1
0
Fork 0
This commit is contained in:
HoopyFreud 2023-07-08 10:17:35 -04:00
parent 332946d8d5
commit 8085015d2a
1 changed files with 78 additions and 54 deletions

View File

@ -1,5 +1,5 @@
from enum import Enum
import itertools import itertools
from enum import Enum
from logging import getLogger from logging import getLogger
from math import ceil from math import ceil
from typing import List, Optional, Protocol, Tuple from typing import List, Optional, Protocol, Tuple
@ -154,10 +154,16 @@ def blend_tiles(
) )
# accumulation # accumulation
value[writable_top:writable_bottom, writable_left:writable_right, :] += equalized[ value[
margin_top : equalized.shape[0] + margin_bottom, margin_left : equalized.shape[1] + margin_right, : writable_top:writable_bottom, writable_left:writable_right, :
] += equalized[
margin_top : equalized.shape[0] + margin_bottom,
margin_left : equalized.shape[1] + margin_right,
:,
] ]
count[writable_top:writable_bottom, writable_left:writable_right, :] += np.repeat( count[
writable_top:writable_bottom, writable_left:writable_right, :
] += np.repeat(
mask[ mask[
margin_top : equalized.shape[0] + margin_bottom, margin_top : equalized.shape[0] + margin_bottom,
margin_left : equalized.shape[1] + margin_right, margin_left : equalized.shape[1] + margin_right,
@ -260,7 +266,18 @@ def process_tile_spiral(
bottom_margin = height - bottom bottom_margin = height - bottom
if needs_margin: if needs_margin:
base_image = source.crop((left+left_margin, top+top_margin, right-right_margin, bottom-bottom_margin)) if source else None base_image = (
source.crop(
(
left + left_margin,
top + top_margin,
right - right_margin,
bottom - bottom_margin,
)
)
if source
else None
)
tile_image = noise_source_histogram(base_image, (tile, tile), (0, 0)) tile_image = noise_source_histogram(base_image, (tile, tile), (0, 0))
tile_image.paste(base_image, (left_margin, top_margin)) tile_image.paste(base_image, (left_margin, top_margin))
else: else:
@ -304,7 +321,9 @@ def generate_tile_spiral(
) -> List[Tuple[int, int]]: ) -> List[Tuple[int, int]]:
spacing = 1.0 - overlap spacing = 1.0 - overlap
tile_increment = round(tile * spacing/2)*2 #dividing and then multiplying by 2 ensures this will be an even number, which is necessary for the initial tile placement calculation tile_increment = (
round(tile * spacing / 2) * 2
) # dividing and then multiplying by 2 ensures this will be an even number, which is necessary for the initial tile placement calculation
# calculate the number of tiles needed # calculate the number of tiles needed
width_tile_target = 1 width_tile_target = 1
@ -318,9 +337,12 @@ def generate_tile_spiral(
span_x = tile + (width_tile_target - 1) * tile_increment span_x = tile + (width_tile_target - 1) * tile_increment
span_y = tile + (height_tile_target - 1) * tile_increment span_y = tile + (height_tile_target - 1) * tile_increment
tile_left = (width - span_x)/2 #guaranteed to be an integer because width and span will both be even tile_left = (
tile_top = (height - span_y)/2 #guaranteed to be an integer because width and span will both be even width - span_x
) / 2 # guaranteed to be an integer because width and span will both be even
tile_top = (
height - span_y
) / 2 # guaranteed to be an integer because width and span will both be even
logger.debug( logger.debug(
"image size %s x %s, tiling to %s x %s, starting at %s, %s", "image size %s x %s, tiling to %s x %s, starting at %s, %s",
@ -329,7 +351,7 @@ def generate_tile_spiral(
width_tile_target, width_tile_target,
height_tile_target, height_tile_target,
tile_left, tile_left,
tile_top tile_top,
) )
tile_coords = [] tile_coords = []
@ -347,7 +369,13 @@ def generate_tile_spiral(
for state in itertools.cycle(WalkState): for state in itertools.cycle(WalkState):
# This expression is stupid, but all it does is calculate the number of tiles we need in the appropriate direction # This expression is stupid, but all it does is calculate the number of tiles we need in the appropriate direction
accum_tile_target = max(map(lambda coord,val: abs(coord*val),state.value,(width_tile_target,height_tile_target))) accum_tile_target = max(
map(
lambda coord, val: abs(coord * val),
state.value,
(width_tile_target, height_tile_target),
)
)
# check if done # check if done
if accum_tile_target == 0: if accum_tile_target == 0:
break break
@ -360,11 +388,7 @@ def generate_tile_spiral(
tile_top += tile_increment * state.value[1] tile_top += tile_increment * state.value[1]
# add a tile # add a tile
logger.debug( logger.debug("adding tile at %s:%s", tile_left, tile_top)
"adding tile at %s:%s",
tile_left,
tile_top
)
tile_coords.append((int(tile_left), int(tile_top))) tile_coords.append((int(tile_left), int(tile_top)))
accum_tiles += 1 accum_tiles += 1