#!/usr/bin/env python3
import argparse
from pathlib import Path


def write_header(input_path, output_path, symbol, source_label):
    data = Path(input_path).read_bytes()
    guard = f"{symbol.upper()}_H"

    with Path(output_path).open("w", encoding="ascii", newline="\n") as out:
        out.write(f"/* Auto-generated from {source_label}. Do not edit. */\n")
        out.write(f"#ifndef {guard}\n")
        out.write(f"#define {guard}\n\n")
        out.write(f"static const unsigned char {symbol}[] = {{\n")
        for start in range(0, len(data), 12):
            chunk = data[start:start + 12]
            out.write("  ")
            out.write(", ".join(f"0x{byte:02x}" for byte in chunk))
            out.write(",\n")
        out.write("};\n\n")
        out.write(f"static const unsigned int {symbol}_len = {len(data)};\n\n")
        out.write(f"#endif /* {guard} */\n")


def main():
    parser = argparse.ArgumentParser(
        description="Embed a PNG as a C header with a byte array.")
    parser.add_argument("input")
    parser.add_argument("output")
    parser.add_argument("symbol")
    parser.add_argument("source_label")
    args = parser.parse_args()

    write_header(args.input, args.output, args.symbol, args.source_label)


if __name__ == "__main__":
    main()
