Files
argo/SUB Control/build_icon.py
2026-08-28 17:40:43 +02:00

15 lines
669 B
Python

"""Package the original PNG in a Windows ICO without altering its pixels."""
from pathlib import Path
import struct
root = Path(__file__).resolve().parent
png = (root / "assets" / "sub-control-icon.png").read_bytes()
if png[:8] != b"\x89PNG\r\n\x1a\n":
raise ValueError("Icon source must be PNG")
width, height = struct.unpack(">II", png[16:24])
if not (1 <= width <= 256 and 1 <= height <= 256):
raise ValueError("Windows icon source must be at most 256 x 256")
header = struct.pack("<HHH", 0, 1, 1)
entry = struct.pack("<BBBBHHII", width % 256, height % 256, 0, 0, 1, 32, len(png), 22)
(root / "assets" / "sub-control.ico").write_bytes(header + entry + png)