"""Independently inspect .ico files beside this script (Pillow 11.3.0)."""
from pathlib import Path
import struct, io, json, hashlib
from PIL import Image
root=Path(__file__).resolve().parent
for p in sorted(root.glob('*.ico')):
    raw=p.read_bytes(); reserved,kind,count=struct.unpack_from('<HHH',raw)
    assert reserved==0 and kind==1
    entries=[]
    for i in range(count):
        width,height,colors,res,planes,depth,length,offset=struct.unpack_from('<BBBBHHII',raw,6+i*16)
        assert offset+length<=len(raw)
        im=Image.open(io.BytesIO(raw[offset:offset+length])).convert('RGBA');im.load()
        assert im.size==(width or 256,height or 256)
        entries.append({'width':im.width,'height':im.height,'bytes':length,'offset':offset,'mode':im.mode,'alpha_bbox_exclusive':im.getchannel('A').getbbox(),'alpha_band_centers':[im.getpixel((x,128))[3] for x in [32,96,160,224]]})
    print(json.dumps({'file':p.name,'bytes':len(raw),'sha256':hashlib.sha256(raw).hexdigest(),'entry_count':count,'entries':entries}))
