"""Generate the synthetic RGB input used in Photoshot Retouch Part 2."""

from pathlib import Path

import numpy as np
from PIL import Image

WIDTH = 448
HEIGHT = 288


def sample_rgb() -> np.ndarray:
    y, x = np.indices((HEIGHT, WIDTH), dtype=np.int32)
    ramp = 64 + x // 4 + y // 16
    rgb = np.stack((ramp + 22, ramp + 7, ramp - 9), axis=-1)

    # A small, dark mark makes the unchanged texture easy to recognize.
    distance_squared = (x - 210) ** 2 + (y - 140) ** 2
    shadow = 35 * np.clip(1 - distance_squared / 100, 0, 1)
    return np.rint(rgb - shadow[..., None]).astype(np.uint8)


if __name__ == "__main__":
    path = Path("input.png")
    Image.fromarray(sample_rgb()).save(path)
    print(f"Wrote {path} ({WIDTH} x {HEIGHT}, RGB)")
