Fill the bottom-left corner in the world composites too; rebuild Lighthouse skirt

Maps with an "aligned" skirt paste their surroundings from
build/world/unified-z6.png (z5/composite fallbacks), so Lighthouse's trimmed
tiles still showed the AI-invented peninsula and the diamond seam west of the
lighthouse island after overall-square.png was fixed. tools/sea_corner.py now
accepts --image for a composite at another scale (masks scaled from the
rotated source, feather from the image's own pixels, no full-size mgrid
planes, no PNG optimize pass on 217 Mpx) and was applied to all four
composites with a sampled sea colour. Lighthouse trimmed tiles rebuilt.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-08-22 11:30:49 -07:00
1 parent 2e26c485c7
commit 08c8445ba1
7 files changed
+87 -41

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+76 -30
View File
@@ -4,6 +4,8 @@
python tools/sea_corner.py bottom_left bottom_right # several corners
python tools/sea_corner.py --color sample # per-corner median of the sea next to it
python tools/sea_corner.py --dry-run # write build/sea-corner-preview.png only
python tools/sea_corner.py --image build/world/unified-z6.png --color sample
# same corner on a world composite (skirts)
tools/square_base.py rotates sources/overall/overall.jpeg by 45 degrees and
outpaints the four empty corner triangles with AI imagery. But the source is
@@ -21,6 +23,15 @@ so the tool is idempotent. Re-run after regenerating overall-square.png, then
retile the base:
rm -rf web/tiles/overall && python tools/build.py overall
Maps with an "aligned" skirt (tile.py render_skirt) paste their surroundings
from build/world/unified-z6.png (or the z5/composite fallbacks), so the same
corner has to be filled there too or the skirt re-imports the invented land:
pass --image for each composite; masks are scaled from the rotated source and
the feather then blends the image's own pixels (not idempotent, run once).
Rebuild the trimmed tiles of every skirted map that touches the corner
afterwards, e.g. rm -rf web/tiles-trimmed/lighthouse && python tools/build.py
lighthouse --trim-only.
"""
from __future__ import annotations
@@ -35,10 +46,12 @@ from PIL import Image, ImageFilter
from common import CONFIG, ROOT
Image.MAX_IMAGE_PIXELS = None # the z6 world composites are 14736 x 14736
CORNERS = ("top_left", "top_right", "bottom_left", "bottom_right")
def corner_masks(source: Path, rotate: float, size: tuple[int, int]):
def corner_masks(source: Path, rotate: float, size: tuple[int, int], corners=CORNERS):
"""(rotated source RGB, its alpha, {corner: empty-triangle mask}, {corner: distance map}).
The distance map gives, for every pixel, its distance in px to the corner
@@ -46,33 +59,46 @@ def corner_masks(source: Path, rotate: float, size: tuple[int, int]):
is just the offset along the diagonal axis.
"""
rotated = Image.open(source).convert("RGBA").rotate(rotate, expand=True, resample=Image.BICUBIC)
if rotated.size != size:
raise SystemExit(f"rotated source is {rotated.size}, square image is {size}; "
"use the same --source/--rotate square_base.py used")
rgb = np.array(rotated.convert("RGB"))
alpha = np.array(rotated.getchannel("A"))
same_size = rotated.size == size
if not same_size:
ratio = size[0] / rotated.width
if abs(size[1] / rotated.height - ratio) > 1e-3:
raise SystemExit(f"rotated source is {rotated.size}, image is {size}: not the same "
"aspect; use the --source/--rotate square_base.py used")
print(f"image is {ratio:.3f}x the rotated source; scaling the corner masks to match")
rgb = np.array(rotated.convert("RGB")) if same_size else None
alpha_img = rotated.getchannel("A")
if not same_size:
# Nearest keeps the edge crisp; a fully opaque/transparent split is all we need.
alpha_img = alpha_img.resize(size, Image.NEAREST)
alpha = np.array(alpha_img)
h, w = alpha.shape
yy, xx = np.mgrid[0:h, 0:w]
# Broadcast row/column vectors instead of full mgrid planes: the z6 world
# composites are 217 Mpx, so every full-size plane costs ~0.9 GB.
xs = np.arange(w, dtype=np.int32)[None, :]
ys = np.arange(h, dtype=np.int32)[:, None]
empty = alpha == 0
left, top = xx < w / 2, yy < h / 2
left = np.broadcast_to(xs < w / 2, (h, w))
top = np.broadcast_to(ys < h / 2, (h, w))
quadrants = {
"top_left": left & top,
"top_right": ~left & top,
"bottom_left": left & ~top,
"bottom_right": ~left & ~top,
"top_left": lambda: left & top,
"top_right": lambda: ~left & top,
"bottom_left": lambda: left & ~top,
"bottom_right": lambda: ~left & ~top,
}
diagonals = { # grows away from the corner point
"top_left": xx + yy,
"top_right": (w - 1 - xx) + yy,
"bottom_left": xx + (h - 1 - yy),
"bottom_right": (w - 1 - xx) + (h - 1 - yy),
"top_left": lambda: xs + ys,
"top_right": lambda: (w - 1 - xs) + ys,
"bottom_left": lambda: xs + (h - 1 - ys),
"bottom_right": lambda: (w - 1 - xs) + (h - 1 - ys),
}
masks, distances = {}, {}
for name, quadrant in quadrants.items():
mask = empty & quadrant
for name in corners:
mask = empty & quadrants[name]()
masks[name] = mask
edge = diagonals[name][mask].max() if mask.any() else -1
distances[name] = np.clip(diagonals[name] - edge, 0, None) / np.sqrt(2.0)
diagonal = diagonals[name]()
edge = int(diagonal[mask].max()) if mask.any() else -1
distances[name] = (np.clip(diagonal - edge, 0, None) / np.sqrt(2.0)).astype(np.float32)
return rgb, alpha, masks, distances
@@ -129,14 +155,17 @@ def main(argv: list[str] | None = None) -> None:
if image_path is None:
raw = json.loads(CONFIG.read_text(encoding="utf-8"))
image_path = ROOT / raw["world"]["image"]
image_path = image_path.resolve()
image = Image.open(image_path).convert("RGB")
rgb = np.array(image)
source_rgb, alpha, masks, distances = corner_masks(args.source, args.rotate, image.size)
corners = list(dict.fromkeys(args.corners or ["bottom_left"]))
source_rgb, alpha, masks, distances = corner_masks(args.source, args.rotate, image.size, corners)
if source_rgb is None:
source_rgb = rgb # scaled composite: feather from the image itself
real = alpha == 255
flat = flatness(source_rgb) if args.feather > 0 else None
out = rgb.copy()
for corner in dict.fromkeys(args.corners or ["bottom_left"]):
for corner in corners:
mask = masks[corner]
colour = args.color or sample_colour(rgb, alpha, mask, args.band)
fill = np.empty((int(mask.sum()), 3), dtype=np.float64)
@@ -147,11 +176,20 @@ def main(argv: list[str] | None = None) -> None:
feathered = 0
if args.feather > 0:
band = real & (distances[corner] > 0) & (distances[corner] < args.feather)
weight = flat[band] * (1.0 - distances[corner][band] / args.feather)
base = source_rgb[band].astype(np.float64) # untouched originals: idempotent
blended = base + (np.array(colour, dtype=np.float64) - base) * weight[:, None]
out[band] = np.clip(np.rint(blended), 0, 255).astype(np.uint8)
feathered = int((weight > 0.01).sum())
rows, cols = np.nonzero(band)
if rows.size:
# Texture analysis only over the band's bounding box, padded
# for the blur footprint -- not the whole (possibly huge) image.
pad = 24
y0, y1 = max(0, rows.min() - pad), min(band.shape[0], rows.max() + pad + 1)
x0, x1 = max(0, cols.min() - pad), min(band.shape[1], cols.max() + pad + 1)
flat_box = flatness(np.ascontiguousarray(source_rgb[y0:y1, x0:x1]))
flat = flat_box[rows - y0, cols - x0]
weight = flat * (1.0 - distances[corner][band] / args.feather)
base = source_rgb[band].astype(np.float64) # untouched originals: idempotent
blended = base + (np.array(colour, dtype=np.float64) - base) * weight[:, None]
out[band] = np.clip(np.rint(blended), 0, 255).astype(np.uint8)
feathered = int((weight > 0.01).sum())
print(f"{corner}: {int(mask.sum())} px -> #{colour[0]:02x}{colour[1]:02x}{colour[2]:02x}"
+ (f" (+noise sigma {args.noise})" if args.noise > 0 else "")
+ (f", feathered {feathered} flat px" if feathered else ""))
@@ -163,8 +201,16 @@ def main(argv: list[str] | None = None) -> None:
return
if args.feather <= 0:
assert np.array_equal(out[alpha > 0], rgb[alpha > 0]), "real pixels must not change"
Image.fromarray(out).save(image_path, optimize=True)
print(f"wrote {image_path.relative_to(ROOT)}")
if args.image is not None:
print("note: a scaled composite is feathered from its own pixels; do not re-run on it")
# optimize=True is worth it for the 1842 px base, far too slow for 217 Mpx.
small = out.shape[0] * out.shape[1] <= 20_000_000
Image.fromarray(out).save(image_path, optimize=small, compress_level=9 if small else 6)
try:
shown = image_path.relative_to(ROOT)
except ValueError:
shown = image_path
print(f"wrote {shown}")
if __name__ == "__main__":
+1 -1
View File
@@ -382,7 +382,7 @@
"maxNativeZoom": 7,
"base": false,
"version": "c2b0a474",
"trimmedVersion": "591f669e",
"trimmedVersion": "04de4b84",
"pxPerMeter": null,
"trim": {
"points": [