"""Original CC0 synthetic fixtures. Requires Pillow 11.3.0 with AVIF support.
Generation outputs are inputs/references, never claimed as Filepetal conversions.
Run in this directory. AVIF uses quality 80, 4:4:4, speed 6.
"""
from PIL import Image, ImageDraw
import PIL, hashlib, json
from pathlib import Path
from datetime import datetime, timezone
base=Path(__file__).resolve().parent
opts=dict(quality=80,subsampling='4:4:4',speed=6,max_threads=2)
def save(im,name,**kw): im.save(base/(name+'.avif'),format='AVIF',**opts,**kw)
im=Image.new('RGBA',(320,192))
d=ImageDraw.Draw(im)
for i,a in enumerate([0,64,128,255]):d.rectangle((i*80,0,(i+1)*80-1,191),fill=(18,140,160,a))
save(im,'alpha-bands')
frames=[]
for index,color in enumerate(['#25836d','#df794e','#567ec1']):
    im=Image.new('RGB',(241,161),color);d=ImageDraw.Draw(im)
    d.rectangle((20+index*60,45,55+index*60,115),fill='white');d.text((12,12),f'FRAME {index+1}',fill='white');frames.append(im)
save(frames[0],'three-frames',save_all=True,append_images=frames[1:],duration=[120,360,720],loop=0)
im=Image.new('RGB',(513,257));im.putdata([((x*17+y*31)%256,(x*7+y*13)%256,(x*3+y*47)%256) for y in range(257) for x in range(513)])
save(im,'odd-detail')
im=Image.new('RGB',(240,160),'#f3eddf');d=ImageDraw.Draw(im);d.rectangle((0,0,55,55),fill='#cc5b36');d.text((65,18),'TOP LEFT',fill='black');d.line((120,50,120,140),fill='black',width=5)
ex=Image.Exif();ex[274]=6
save(im,'rotated-marker',exif=ex)
save(Image.new('RGB',(4097,96),'#567ec1'),'over-width')
(base/'invalid-header.avif').write_bytes(b'Not an AVIF image. Synthetic negative fixture.\n')
(base/'truncated.avif').write_bytes((base/'alpha-bands.avif').read_bytes()[:64])
records=[]
for p in sorted(base.glob('*.avif')):
    item={'name':p.name,'bytes':p.stat().st_size,'sha256':hashlib.sha256(p.read_bytes()).hexdigest()}
    try:
        im=Image.open(p);item.update(dimensions=list(im.size),frames=im.n_frames,mode=im.mode,exif_orientation=im.getexif().get(274))
        item['frame_records']=[]
        for i in range(im.n_frames):
            im.seek(i);im.load();ref=base/(p.stem+f'-reference-{i+1}.png');im.save(ref)
            item['frame_records'].append({'index':i+1,'dimensions':list(im.size),'duration_ms':im.info.get('duration'),'reference':ref.name,'reference_sha256':hashlib.sha256(ref.read_bytes()).hexdigest()})
    except Exception as exc:item['expected_decode_failure']=str(exc).replace(str(base), '[sample directory]')
    records.append(item)
(base/'sample-manifest.json').write_text(json.dumps({'generated_at':datetime.now(timezone.utc).isoformat(),'generation_date_bjt':'2026-10-11','license':'CC0 synthetic images created for Filepetal','pillow':PIL.__version__,'encoder_options':opts,'scope':'8-bit synthetic AVIF, one animation and one orientation transform; no HDR/10-bit/phone-file coverage','inputs':records},indent=2)+'\n',encoding='utf8')
print(json.dumps(records,indent=2))
