49 lines
3.4 KiB
Python
49 lines
3.4 KiB
Python
"""Verify the native Full HD bitmap path and malformed-resource fallback."""
|
|
from pathlib import Path
|
|
import argparse,io,struct,subprocess,hashlib
|
|
import numpy as np
|
|
from PIL import Image
|
|
from check_artifacts import toolchain
|
|
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
OUT=ROOT/'build/cinematic-v8'
|
|
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser();parser.add_argument('--production',action='store_true');args=parser.parse_args()
|
|
fixture=OUT/'fixtures';fixture.mkdir(parents=True,exist_ok=True)
|
|
(OUT/'hd-error.bin').unlink(missing_ok=True)
|
|
header=struct.pack('<4s7I',b'HFM4',4,1920,1080,24,384,2*1024*1024,16000)
|
|
data=io.BytesIO();Image.new('RGB',(1920,1080),(20,40,60)).save(data,format='JPEG',quality=94)
|
|
for name,chunk in [('valid',data.getvalue()),('bad',b'\0')]:
|
|
index=b''.join(struct.pack('<2I',32+384*8+i*len(chunk),len(chunk)) for i in range(384))
|
|
(fixture/(name+'.hfm')).write_bytes(header+index+chunk*384)
|
|
(fixture/'short.hfm').write_bytes(b'HFM4')
|
|
before={p:hashlib.sha256(p.read_bytes()).digest() for p in (ROOT/'runtime').rglob('*') if p.is_file()}
|
|
source=(ROOT/'poker.asm').read_text(encoding='cp1251')
|
|
source=source.replace('main PROC','GetObjectA PROTO :DWORD,:DWORD,:DWORD\ninclude tools\\tests\\studio_hd_probe.inc\nmain PROC\n call RunStudioHDProbe\n invoke ExitProcess,eax',1)
|
|
(OUT/'hd-probe.asm').write_bytes(source.encode('cp1251'))
|
|
ml,link=toolchain();sdk=Path('C:/Program Files (x86)/Windows Kits/10/Lib')
|
|
lib=next(p/'um/x86' for p in sorted(sdk.iterdir(),reverse=True) if (p/'um/x86/kernel32.lib').exists())
|
|
flags=['/DSTUDIO_HD_REAL=1'] if args.production else []
|
|
for cmd in [[ml,*flags,'/c','/coff','/Cp','/nologo','/I.','/Fobuild/cinematic-v8/hd-probe.obj','build/cinematic-v8/hd-probe.asm'],
|
|
[link,'/nologo','/SUBSYSTEM:CONSOLE','/LIBPATH:'+str(lib),'/OUT:build/cinematic-v8/hd-probe.exe','build/cinematic-v8/hd-probe.obj','kernel32.lib','winmm.lib','user32.lib','ws2_32.lib','gdi32.lib'],
|
|
[OUT/'hd-probe.exe']]:
|
|
subprocess.run([str(v) for v in cmd],cwd=ROOT,check=True,timeout=120)
|
|
assert before=={p:hashlib.sha256(p.read_bytes()).digest() for p in (ROOT/'runtime').rglob('*') if p.is_file()}
|
|
path=(ROOT/'assets/animations/intro/eblan-studio-v8.hfm') if args.production else fixture/'valid.hfm'
|
|
raw=path.read_bytes();offset,size=struct.unpack_from('<2I',raw,32+24*8)
|
|
expected=np.asarray(Image.open(io.BytesIO(raw[offset:offset+size])).convert('RGB'),dtype=np.int16)
|
|
for w,h,x,y in [(1920,1080,0,0),(1920,1440,0,180),(2560,1080,320,0),
|
|
(1921,1080,0,0),(1920,1081,0,0)]:
|
|
pixels=np.frombuffer((OUT/f'hd-native-{w}x{h}.bgra').read_bytes(),dtype=np.uint8).reshape(h,w,4)
|
|
rgb=pixels[:,:,:3][:,:,::-1]
|
|
diff=np.abs(rgb[y:y+1080,x:x+1920].astype(np.int16)-expected)
|
|
assert diff.mean()<.8 and diff.max()<=8,(w,h,float(diff.mean()),int(diff.max()))
|
|
assert not rgb[:y].any() and not rgb[y+1080:].any(),'Letterbox not cleared'
|
|
assert not rgb[:,:x].any() and not rgb[:,x+1920:].any(),'Pillarbox not cleared'
|
|
if w==1920 and h==1080:Image.fromarray(rgb).save(OUT/'hd-native-presenter.png')
|
|
print('PASS: all 384 '+('production' if args.production else 'fixture')+' Full HD frames; actual 1920x1080 presentation pixels, letterbox/pillarbox, frame cache/seeking, malformed/missing input, fallback and cleanup; profiles/bank/RNG unchanged.')
|
|
|
|
|
|
if __name__=='__main__':main()
|