linted
This commit is contained in:
parent
332946d8d5
commit
8085015d2a
|
@ -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
|
||||||
|
@ -131,10 +131,10 @@ def blend_tiles(
|
||||||
scaled_bottom = scaled_top + equalized.shape[0]
|
scaled_bottom = scaled_top + equalized.shape[0]
|
||||||
scaled_right = scaled_left + equalized.shape[1]
|
scaled_right = scaled_left + equalized.shape[1]
|
||||||
|
|
||||||
writable_top = max(scaled_top,0)
|
writable_top = max(scaled_top, 0)
|
||||||
writable_left = max(scaled_left,0)
|
writable_left = max(scaled_left, 0)
|
||||||
writable_bottom = min(scaled_bottom,scaled_size[0])
|
writable_bottom = min(scaled_bottom, scaled_size[0])
|
||||||
writable_right = min(scaled_right,scaled_size[1])
|
writable_right = min(scaled_right, scaled_size[1])
|
||||||
|
|
||||||
margin_top = writable_top - scaled_top
|
margin_top = writable_top - scaled_top
|
||||||
margin_left = writable_left - scaled_left
|
margin_left = writable_left - scaled_left
|
||||||
|
@ -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,9 +266,20 @@ 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 = (
|
||||||
tile_image = noise_source_histogram(base_image,(tile,tile),(0,0))
|
source.crop(
|
||||||
tile_image.paste(base_image,(left_margin,top_margin))
|
(
|
||||||
|
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.paste(base_image, (left_margin, top_margin))
|
||||||
else:
|
else:
|
||||||
tile_image = source.crop((left, top, right, bottom)) if source else None
|
tile_image = source.crop((left, top, right, bottom)) if source else None
|
||||||
|
|
||||||
|
@ -304,9 +321,11 @@ 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
|
||||||
height_tile_target = 1
|
height_tile_target = 1
|
||||||
if width > tile:
|
if width > tile:
|
||||||
|
@ -314,13 +333,16 @@ def generate_tile_spiral(
|
||||||
if height > tile:
|
if height > tile:
|
||||||
height_tile_target = 1 + ceil((height - tile) / tile_increment)
|
height_tile_target = 1 + ceil((height - tile) / tile_increment)
|
||||||
|
|
||||||
#calculate the start position of the tiling
|
# calculate the start position of the tiling
|
||||||
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_top = (height - span_y)/2 #guaranteed to be an integer because width and span will both be even
|
|
||||||
|
|
||||||
|
tile_left = (
|
||||||
|
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,42 +351,44 @@ 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 = []
|
||||||
|
|
||||||
# start walking from the north-west corner, heading east
|
# start walking from the north-west corner, heading east
|
||||||
class WalkState(Enum):
|
class WalkState(Enum):
|
||||||
EAST = (1,0)
|
EAST = (1, 0)
|
||||||
SOUTH = (0,1)
|
SOUTH = (0, 1)
|
||||||
WEST = (-1,0)
|
WEST = (-1, 0)
|
||||||
NORTH = (0,-1)
|
NORTH = (0, -1)
|
||||||
|
|
||||||
#initialize the tile_left placement
|
# initialize the tile_left placement
|
||||||
tile_left -= tile_increment
|
tile_left -= tile_increment
|
||||||
height_tile_target -= 1
|
height_tile_target -= 1
|
||||||
|
|
||||||
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(
|
||||||
#check if done
|
map(
|
||||||
|
lambda coord, val: abs(coord * val),
|
||||||
|
state.value,
|
||||||
|
(width_tile_target, height_tile_target),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# check if done
|
||||||
if accum_tile_target == 0:
|
if accum_tile_target == 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
#reset tile count
|
# reset tile count
|
||||||
accum_tiles = 0
|
accum_tiles = 0
|
||||||
while accum_tiles < accum_tile_target:
|
while accum_tiles < accum_tile_target:
|
||||||
# move to the next
|
# move to the next
|
||||||
tile_left += tile_increment*state.value[0]
|
tile_left += tile_increment * state.value[0]
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue