#!/usr/bin/env python3 """Real offscreen production GLES fragment shader, decoded silent pose frames. OES is replaced with a 2D decoded surrogate; no Android GPU/performance claim. The one-pixel test texture verifies opacity=0 body bypass, not a runtime mouth pack. """ import argparse import importlib.util import json import os from pathlib import Path import re import subprocess import tempfile import numpy as np ROOT=Path(__file__).resolve().parents[1] def check(index,output): m=json.loads(index.read_bytes());source=(ROOT/'app/src/main/java/com/gorios/lanvoice/avatar/ContinuousBodyRenderer.kt').read_text() vertex=re.search(r'const val VERTEX="""([\s\S]*?)"""',source)[1] fragment=re.search(r'const val FRAGMENT="""([\s\S]*?)"""',source)[1].replace('#extension GL_OES_EGL_image_external : require','').replace('samplerExternalOES','sampler2D') spec=importlib.util.spec_from_file_location('golden',ROOT/'scripts/check-avatar-shader.py');module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module) rows=[] with tempfile.TemporaryDirectory(prefix='waiting-pose-gles-') as td: tmp=Path(td);(tmp/'vertex').write_text(vertex);(tmp/'fragment').write_text(fragment) subprocess.run(['cc','-O2',str(ROOT/'tests/avatar-pixels/gles-golden.c'),'-lEGL','-lGLESv2','-lm','-o',str(tmp/'golden')],check=True) env=dict(os.environ,EGL_PLATFORM='surfaceless',LIBGL_ALWAYS_SOFTWARE='1') for pose in m['waiting']['poses']: clip=pose['clip'];w,h=clip['width'],clip['height'];frames=[0,clip['frameCount']//2,clip['frameCount']-1] raw=subprocess.check_output(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-xerror','-i',str(index.parent/clip['path']),'-vf','select='+ '+'.join(f'eq(n\\,{i})' for i in frames),'-fps_mode','vfr','-f','rawvideo','-pix_fmt','rgba','-'],timeout=60) assert len(raw)==len(frames)*w*h*4 # Deliberately opaque bright test patch: body-only must bypass even this texture. patch=np.array([[[255,0,255,255]]],dtype=np.uint8);(tmp/'patch.rgba').write_bytes(patch.tobytes()) for j,i in enumerate(frames): body=np.frombuffer(raw[j*w*h*4:(j+1)*w*h*4],np.uint8).reshape(h,w,4);(tmp/'body.rgba').write_bytes(body.tobytes()) for vw,vh in [(w,h),(360,800),(800,480)]: r=subprocess.run([str(tmp/'golden'),str(tmp/'vertex'),str(tmp/'fragment'),str(tmp/'body.rgba'),str(tmp/'patch.rgba'),str(tmp/'out.rgba'),'1','1','0','0','0',str(vw),str(vh),'0',str(w),str(h),'1','.5'],env=env,capture_output=True,text=True,check=True) actual=np.frombuffer((tmp/'out.rgba').read_bytes(),np.uint8).reshape(vh,vw,4)[::-1,:,:3] expected=module.golden(body,patch,0,0,0,vw,vh,0) diff=np.abs(actual.astype(int)-expected.astype(int));assert diff.max()<=2 if (vw,vh)==(w,h):assert np.array_equal(actual,body[:,:,:3]),'native smile/body must be pixel exact' rows.append({'pose':pose['id'],'frame':i,'viewport':[vw,vh],'mouthOpacity':0,'maxAbsRGB':int(diff.max()),'gl':r.stdout.strip()}) output.parent.mkdir(parents=True,exist_ok=True);output.write_text(json.dumps({'status':'passed','cases':rows,'device':'not_run','runtimeMouthTextures':0},indent=2)+'\n') print(f'PASS: {len(rows)} real GLES decoded pose/no-mouth/native-face/Fit pixel comparisons; Android GPU not_run') if __name__=='__main__': p=argparse.ArgumentParser(description=__doc__);p.add_argument('--index',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args();check(a.index,a.output)