# ICO / CUR fixtures (tools/fixtures.py): icons written by ImageMagick (auto-resize sets with a 256 PNG entry) and # Pillow (PNG and BMP entries), and hand-built ones from Pillow's BMP writer (1 / 4 / 8 / 24 / 32-bit DIBs with AND # masks, a cursor with hotspots); references = Pillow's RGBA decode of every entry, in file order. # tests/gen/ico.luau { { name, data, entries = { { width, height, rgba (bytes) } } } } import struct CODE = r''' import io, struct, subprocess, sys from PIL import Image, IcoImagePlugin magick = sys.argv[1] out = [] def refs(data): if data[2] == 2: # IcoFile reads icons only: decode a cursor's entries as an icon's data = data[:2] + b"\x01" + data[3:] f = IcoImagePlugin.IcoFile(io.BytesIO(data)) order = sorted(range(len(f.entry)), key=lambda i: f.entry[i].offset) res = [] for i in order: im = f.frame(i).convert("RGBA") res.append((im.size[0], im.size[1], im.tobytes())) return res def emit(name, data): out.append((name, data, refs(data))) src = Image.new("RGBA", (64, 64)) px = src.load() for y in range(64): for x in range(64): a = 255 if (x - 32) ** 2 + (y - 32) ** 2 < 900 else (0 if x < 8 else 128) px[x, y] = ((x * 4) % 256, (y * 4) % 256, ((x ^ y) * 8) % 256, a) png = io.BytesIO(); src.save(png, "PNG") r = subprocess.run([magick, "png:-", "-define", "icon:auto-resize=256,48,32,16", "ico:-"], input=png.getvalue(), capture_output=True, check=True) emit("im-autoresize", r.stdout) for fmt in ("png", "bmp"): b = io.BytesIO(); src.save(b, "ICO", sizes=[(16, 16), (32, 32), (64, 64)], bitmap_format=fmt); emit("pil-" + fmt, b.getvalue()) # hand-built DIB entries from Pillow BMPs def dib(im, mask_fn): b = io.BytesIO(); im.save(b, "BMP"); d = b.getvalue()[14:] w, h = im.size hs = struct.unpack("> (x % 8) mask += row return d + bytes(mask) def icon(entries, typ=1, hotspots=None): hdr = struct.pack("