#!/usr/bin/env python3 """Package and structurally validate the selected review-only Ezekiel mask trial.""" from pathlib import Path import hashlib import json import subprocess import sys import numpy as np from PIL import Image HERE = Path(__file__).resolve().parent REVISION = HERE.parents[1] REPO = next(p for p in HERE.parents if (p / "docs/card-layer-pipeline.md").is_file()) sys.path.insert(0, str(REPO / "tools/card-production")) from finish_masks import prepare_illustration ART = REVISION / "source/art-master-candidate-03.png" TEXT = REVISION / "source/text/text-2000.png" LAYERS = REPO / "artifacts/layers/uncommon/v3/exports" RIDGES = HERE / "gated-contrast-ridges-2000.png" EXPORTS = HERE / "selected" def digest(path): return hashlib.sha256(path.read_bytes()).hexdigest() def alpha(path): image = Image.open(path).convert("RGBA") assert image.size == (2000, 2800) return np.asarray(image.getchannel("A"), dtype=np.float32) / 255. def main(): for script in ("build.py", "build-canny.py", "build-gated.py"): subprocess.run([sys.executable, str(HERE / script)], check=True) art = Image.open(ART).convert("RGBA") illustration = prepare_illustration(art) ridges = np.asarray(Image.open(RIDGES).convert("L"), dtype=np.float32) / 255. assert ridges.shape == illustration.pane_weights.shape == (2800, 2000) text = alpha(TEXT) layers = { "normal": LAYERS / "overlay-normal-2000.png", "borderless": LAYERS / "backing-borderless-2000.png", "textless": LAYERS / "frame-textless-2000.png", "boundless": None, } EXPORTS.mkdir(exist_ok=True) reports = {} for printing, overlay_path in layers.items(): oa = 0. if overlay_path is None else alpha(overlay_path) ta = text if printing in ("normal", "borderless") else 0. active = 1 - (1 - oa) * (1 - ta) coverage = np.rint(illustration.pane_weights * (1 - ridges) * (1 - active) * 255).astype(np.uint8) assert coverage.shape == (2800, 2000) if overlay_path is not None: assert np.all(coverage[oa == 1] == 0), printing if isinstance(ta, np.ndarray): assert np.all(coverage[ta == 1] == 0), printing scalar = Image.fromarray(coverage) files = {} for width in (2000, 1000, 500): image = scalar if width == 2000 else scalar.resize((width, width * 7 // 5), Image.Resampling.BILINEAR) rgba = image.convert("RGBA") rgba.putalpha(255) path = EXPORTS / f"{printing}-{width}-finish-mask.png" rgba.save(path) check = Image.open(path).convert("RGBA") channels = np.asarray(check) assert check.size == (width, width * 7 // 5) assert np.all(channels[..., 0] == channels[..., 1]) and np.all(channels[..., 1] == channels[..., 2]) assert np.all(channels[..., 3] == 255) files[str(width)] = {"path": str(path.relative_to(REVISION)), "sha256": digest(path)} reports[printing] = {"overlay": str(overlay_path.relative_to(REPO)) if overlay_path else None, "usesText": isinstance(ta, np.ndarray), "files": files, "meanMasterCoverage": round(float(coverage.mean()) / 255., 5)} report = { "status": "structural checks passed; experimental mask trial only; not selected for production", "candidate": "gated-contrast", "art": {"path": str(ART.relative_to(REPO)), "sha256": digest(ART)}, "ridgeMap": {"path": str(RIDGES.relative_to(REVISION)), "sha256": digest(RIDGES)}, "text": {"path": str(TEXT.relative_to(REPO)), "sha256": digest(TEXT)}, "paneWeightSource": "Exact floating-point weights recomputed by approved prepare_illustration from unchanged art", "printings": reports, "checks": ["2000/1000/500 dimensions", "opaque grayscale RGBA", "opaque overlay protection", "opaque lettering protection", "unchanged source art and card faces"], "staticReview": "pending user review of comparison sheets and mask detail", "movingLightReview": "not performed", "productionReplacement": False, } (HERE / "selected-validation.json").write_text(json.dumps(report, indent=2) + "\n") if __name__ == "__main__": main()