"""Create labelled inspection sheets; leaves all six evidence files untouched.

The source, output on #f8f8f8 and output on #202630 share a display size.
Compositing uses the exported alpha as-is, with no threshold or edge repair.
"""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont

ROOT = Path(__file__).resolve().parent
CASES = [("coffee", "coffee.png"), ("chelsea", "chelsea.png"), ("rocket", "rocket.jpg")]
font = ImageFont.load_default(size=18)

for case, source in CASES:
    original = Image.open(ROOT / source).convert("RGB")
    output = Image.open(ROOT / f"{case}-output.png").convert("RGBA")
    scale = min(512 / output.width, 460 / output.height)
    display = (round(output.width * scale), round(output.height * scale))
    sheet = Image.new("RGB", (1536, 512), "#dddddd")
    draw = ImageDraw.Draw(sheet)
    source_preview = original.resize(display, Image.Resampling.LANCZOS)
    images = [source_preview]
    for color in ["#f8f8f8", "#202630"]:
        background = Image.new("RGBA", output.size, color)
        background.alpha_composite(output)
        images.append(background.convert("RGB").resize(display, Image.Resampling.LANCZOS))
    for column, (label, image) in enumerate(zip(["SOURCE PHOTO", "OUTPUT ON LIGHT", "OUTPUT ON DARK"], images)):
        draw.text((column * 512 + 14, 14), label, fill="black", font=font)
        sheet.paste(image, (column * 512 + (512 - display[0]) // 2, 52 + (460 - display[1]) // 2))
    sheet.save(ROOT / f"{case}-review.png")
