"""Run the board to a frame and compare it, by colour index, with detector pictures. python scripts/compare_pictures.py CART --frames 300 tests/mame_traces/coleco-Zaxxon/snap/coleco/0000.png \ tests/runs/gearcoleco-zaxxon-300.png [--mame] [--png ours.png] ``CART`` may be ``-`` for an empty slot. Prints the differing pixel count per detector (0 and 1 count as one class: both detectors draw them black). """ from __future__ import annotations import argparse import sys from colecovision_python import BoardOptions, ColecoVision, mame_options from colecovision_python.pictures import detector_indices, differences from colecovision_python.video import write_png def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("cart") parser.add_argument("detectors", nargs="+") parser.add_argument("--frames", type=int, default=300) parser.add_argument("--mame", action="store_true", help="MAME's choice on every switch") parser.add_argument("--png") args = parser.parse_args() options = mame_options() if args.mame else BoardOptions() console = ColecoVision(None if args.cart == "-" else args.cart, options=options) frame = console.run_frames(args.frames) if args.png: write_png(args.png, frame.pixels) worst = 0 for path in args.detectors: count = differences(frame.pixels, detector_indices(path)) worst = max(worst, count) print(f"{count:6d} pixels differ {path}") return 1 if worst else 0 if __name__ == "__main__": sys.exit(main())