diff --git a/build/lighthouse/trimmed.png b/build/lighthouse/trimmed.png index 4fdd88d..e643dba 100644 --- a/build/lighthouse/trimmed.png +++ b/build/lighthouse/trimmed.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cb5a8becb0ab4fe45237b7560109e40c46cac6cb5a40810cfb12ca9789abc87c -size 104894967 +oid sha256:906373581b5578a2a020ca7bd64a4496da5772780084142383efb418f1b844c0 +size 103376635 diff --git a/build/world/composite-z5.png b/build/world/composite-z5.png index 391b749..dced510 100644 --- a/build/world/composite-z5.png +++ b/build/world/composite-z5.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:38359591f2021bfef3eeac0f51a59ee6fae46b64c1984af33a983515e66b1174 -size 47428993 +oid sha256:737ead6eb5721ccd198dae976446097026c66709c56e44217f9503afd85ff8fb +size 40780670 diff --git a/build/world/composite-z6.png b/build/world/composite-z6.png index 94e801c..da8229c 100644 --- a/build/world/composite-z6.png +++ b/build/world/composite-z6.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cecfe2777f8e19c52cb0b32593acb07ba6de0613c8245aaa354c18cec7a067c2 -size 141721530 +oid sha256:615f98461c3c9da649fc50874c4172be29b5e0df0adfa789368162f1a0637848 +size 123511371 diff --git a/build/world/unified-z5.png b/build/world/unified-z5.png index d5fa9cf..c56d994 100644 --- a/build/world/unified-z5.png +++ b/build/world/unified-z5.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4ee2f73ef9b6d3a23de90ee4bea1b7fbf2bf1ea3ddc347256622de7866066f5f -size 48602354 +oid sha256:6a9ba785e6c6bd597a78b70b61fc7aac87fb05443ab9133b16e4c5854eb6adea +size 42076854 diff --git a/build/world/unified-z6.png b/build/world/unified-z6.png index ccdcd06..e3ba1a5 100644 --- a/build/world/unified-z6.png +++ b/build/world/unified-z6.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d73eb77dac718a38d421bb50b1eef6bdefd52bd7a6f158598c42292fbb7f1349 -size 145332347 +oid sha256:79db1cca970eaad5b74d5b25c8aaf6406c4664984f1bf694e8ba3e8f280d582a +size 121371079 diff --git a/tools/sea_corner.py b/tools/sea_corner.py index 6941a5f..f49a320 100644 --- a/tools/sea_corner.py +++ b/tools/sea_corner.py @@ -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__": diff --git a/web/data/world.json b/web/data/world.json index fed8578..17684c9 100644 --- a/web/data/world.json +++ b/web/data/world.json @@ -382,7 +382,7 @@ "maxNativeZoom": 7, "base": false, "version": "c2b0a474", - "trimmedVersion": "591f669e", + "trimmedVersion": "04de4b84", "pxPerMeter": null, "trim": { "points": [