From 2077c17b23441c2873c6adb0b83c722e0c22eeeb Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:06:24 +0100 Subject: [PATCH] Fit slightly rectangular ore layers without changing their proportions --- tools/compile-realistic-stone-family.py | 16 ++++++++++------ tools/test_realistic_stone_family.py | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/compile-realistic-stone-family.py b/tools/compile-realistic-stone-family.py index 4402abeb..6bbcb2fd 100644 --- a/tools/compile-realistic-stone-family.py +++ b/tools/compile-realistic-stone-family.py @@ -6,7 +6,7 @@ import json from pathlib import Path import numpy as np -from PIL import Image, ImageDraw, ImageEnhance, ImageFilter +from PIL import Image, ImageDraw, ImageEnhance, ImageFilter, ImageOps SIZE = 256 EDGE = 12 @@ -80,13 +80,17 @@ def seamless(image): def source_tile(path, mode): with Image.open(path) as image: - if image.width != image.height or image.width < SIZE: - raise ValueError(f"{path.name} must be a square image of at least {SIZE} pixels") + if min(image.size) < SIZE: + raise ValueError(f"{path.name} must be at least {SIZE} pixels on each side") if mode == "RGBA": - alpha = image.convert("RGBA").getchannel("A") - if alpha.getextrema()[0] != 0 or alpha.getextrema()[1] < 128: + layer = image.convert("RGBA") + minimum, maximum = layer.getchannel("A").getextrema() + if minimum != 0 or maximum < 128: raise ValueError(f"{path.name} requires a transparent background and visible deposits") - return image.convert(mode).resize((SIZE, SIZE), Image.Resampling.LANCZOS) + return ImageOps.pad(layer, (SIZE, SIZE), method=Image.Resampling.LANCZOS, color=(0, 0, 0, 0)) + if image.width != image.height: + raise ValueError(f"{path.name} must be a square albedo") + return image.convert("RGB").resize((SIZE, SIZE), Image.Resampling.LANCZOS) def masonry(image, columns, rows, stagger): diff --git a/tools/test_realistic_stone_family.py b/tools/test_realistic_stone_family.py index e8021ece..c86ec024 100644 --- a/tools/test_realistic_stone_family.py +++ b/tools/test_realistic_stone_family.py @@ -30,7 +30,7 @@ class StoneFamilyTest(unittest.TestCase): inputs.mkdir() for name in compiler.CORE + compiler.OPTIONAL: Image.new("RGB", (256, 256), (122, 118, 110)).save(inputs / f"{name}-source.png") - ore = Image.new("RGBA", (256, 256)) + ore = Image.new("RGBA", (260, 256)) ImageDraw.Draw(ore).rectangle((104, 104, 151, 151), fill=(200, 30, 55, 255)) for name in compiler.MINERALS + ("quartz", "ancient_debris"): ore.save(inputs / f"{name}-deposit.png")