diff options
Diffstat (limited to 'scripts/make-p45-char-crop.py')
| -rw-r--r-- | scripts/make-p45-char-crop.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/make-p45-char-crop.py b/scripts/make-p45-char-crop.py new file mode 100644 index 0000000..430bc72 --- /dev/null +++ b/scripts/make-p45-char-crop.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +"""P45 evidence: crop the avatar cell from the real LV_P45_SHOT frames and upscale 4x. + +Reads the shot log for the character destination rect printed by the game +(`dest=x,y,w,h`), crops that region (plus a small margin) from the full 1280x720 +screenshot and upscales exactly 4x with NEAREST. Pure function of real frames. + +Usage: + python3 scripts/make-p45-char-crop.py <record-dir> <shot-log> <out-dir> +""" + +import re +import sys +from pathlib import Path + +from PIL import Image + +MARGIN = 8 +SCALE = 4 +DEST_RE = re.compile(r"p45-shot=(\S+) tick=(\d+) facing=(\S+) moving=(\w+) dest=(\d+),(\d+),(\d+),(\d+) frame=(.+)") + + +def main(argv): + if len(argv) != 4: + sys.stderr.write(__doc__) + return 2 + record_dir = Path(argv[1]) + log_text = Path(argv[2]).read_text(encoding="utf-8") + out_dir = Path(argv[3]) + out_dir.mkdir(parents=True, exist_ok=True) + count = 0 + for line in log_text.splitlines(): + m = DEST_RE.search(line) + if not m: + continue + name = m.group(1) + x, y, w, h = (int(m.group(i)) for i in range(5, 9)) + box = (x - MARGIN, y - MARGIN, x + w + MARGIN, y + h + MARGIN) + source = Image.open(record_dir / f"{name}.png").convert("RGBA") + crop = source.crop(box) + doubled = crop.resize((crop.width * SCALE, crop.height * SCALE), Image.NEAREST) + doubled.save(out_dir / f"{name}.png") + print(f"ok {name}.png {doubled.width}x{doubled.height} from {box} (facing={m.group(3)} moving={m.group(4)} frame={m.group(9)})") + count += 1 + if count == 0: + sys.stderr.write("no p45-shot dest lines found\n") + return 1 + return 0 + + +if __name__ == "__main__": + raise SystemExit(main(sys.argv)) |
