#!/usr/bin/env python3 """Makes the app's icon file from tools/icons.js's PNGs (build/icons): windows/res/dmodem.ico 16, 32 and 48 in 256 colours (Windows 9x) and in 32-bit colour with alpha (XP on), 256 as PNG The .ico is written by hand: Windows 95 reads only BMP entries.""" import io import os import struct from PIL import Image ROOT = os.path.join(os.path.dirname(__file__), '..') SRC = os.path.join(ROOT, 'build', 'icons') def png(size): return Image.open(os.path.join(SRC, f'{size}.png')).convert('RGBA') def and_mask(img): w, h = img.size stride = ((w + 31) // 32) * 4 rows = [] for y in range(h - 1, -1, -1): bits = bytearray(stride) for x in range(w): if img.getpixel((x, y))[3] < 128: bits[x // 8] |= 0x80 >> (x % 8) rows.append(bytes(bits)) return b''.join(rows) def dib_32(img): w, h = img.size header = struct.pack('