nx_normal_decode_gate_t279.nx source
↩ module page · 59 lines · 2997 B
1import "nx_nxa_texbake_lib.nx"
2import "nx_nxa_texbake_region_lib.nx"
3import "nx_png_decoder.nx"
4func main(argc:i64,argv:*i64)->i64{
5 if argc!=2{return 2}
6 let out:*i64=sys_mmap_try(3*__size_of(i64)) as *i64
7 if (out as i64)<=0{return 3}
8 if ntb_normal_decode_rgb8(1,128,128,255,out)!=127||out[0]!=0||out[1]!=0||out[2]!=127{return 4}
9 if ntb_normal_decode_rgb8(1,255,1,128,out)!=127||out[0]!=127||out[1]!=0-127||out[2]!=0{return 5}
10 if ntb_normal_decode_rgb8(2,128,128,255,out)!=255||out[0]!=1||out[1]!=1||out[2]!=255{return 6}
11 if ntb_normal_decode_rgb8(2,255,0,128,out)!=255||out[0]!=255||out[1]!=0-255||out[2]!=1{return 7}
12 out[0]=77;out[1]=78;out[2]=79
13 if ntb_normal_decode_rgb8(0,128,128,255,out)>=0||out[0]!=77||out[1]!=78||out[2]!=79{return 8}
14 if ntb_normal_decode_rgb8(1,0-1,128,255,out)>=0||out[0]!=77{return 9}
15 if ntb_normal_decode_rgb8(1,256,128,255,out)>=0||out[0]!=77{return 9}
16 var v:i64=0
17 while v<=255{
18 if ntb_normal_decode_rgb8(1,v,v,v,out)!=127{return 10}
19 if out[0]+128!=v||out[1]+128!=v||out[2]+128!=v{return 10}
20 if ntb_normal_decode_rgb8(2,v,v,v,out)!=255{return 11}
21 if (out[0]+255)/2!=v||out[0]!=2*v-255{return 11}
22 v=v+1
23 }
24 nt_outs("NORMAL-CONTRACT controls=flat,signed-axes,gltf-preserved,unknown-refused,range-refused,256-byte-roundtrip PASS\n")
25 let lp:*i64=sys_mmap_try(__size_of(i64)) as *i64
26 if (lp as i64)<=0{return 12}
27 let asset:*u8=sys_map_file(argv[1] as *u8,lp)
28 if (asset as i64)<=0{return 12}
29 let o:i64=ntr_texr_find(asset,lp[0]);if o<0{return 13}
30 let w:*i64=asset as *i64
31 let ns:i64=w[o+NTR_W_NSETS];let nj:i64=w[o+NTR_W_NJ];let stride:i64=w[o+NTR_W_SETW]
32 let blob:i64=(o+NTR_HDR_WORDS+nj*NTR_JOINT_WORDS+ns*stride)*NTR_WORD
33 var s:i64=0;var total:i64=0;var zeros:i64=0;var maps:i64=0
34 while s<ns{
35 let set:i64=o+NTR_HDR_WORDS+nj*NTR_JOINT_WORDS+s*stride
36 var m:i64=0
37 while m<NTR_NMAPS{
38 if m==NTR_MAP_NORMAL||m==NTR_MAP_TNORMAL{
39 let rec:i64=set+NTR_SET_META+m*NTR_MAPREC
40 let p:*NxPngResult=nx_png_decode(((asset as i64)+blob+w[rec+1]) as *u8,w[rec+2])
41 if (p as i64)<=0{return 14}
42 if p.error_code!=0||p.pixels_size<=0||p.pixels_size%3!=0{return 14}
43 var i:i64=0
44 while i<p.pixels_size{
45 let r:i64=p.pixels[i] as i64;let g:i64=p.pixels[i+1] as i64;let b:i64=p.pixels[i+2] as i64
46 if ntb_normal_decode_rgb8(1,r,g,b,out)!=127{return 15}
47 if out[0]+128!=r||out[1]+128!=g||out[2]+128!=b{return 16}
48 if r==0||g==0||b==0{zeros=zeros+1}
49 total=total+1;i=i+3
50 }
51 maps=maps+1
52 nt_outs("NORMAL-CONTRACT region=");nt_outn(w[set+NTR_S_REGION]);nt_outs(" kind=");nt_outn(m);nt_outs(" pixels=");nt_outn(p.pixels_size/3);nt_outs(" quantized_roundtrip=exact\n")
53 };m=m+1
54 };s=s+1
55 }
56 nt_outs("NORMAL-CONTRACT maps=");nt_outn(maps);nt_outs(" pixels=");nt_outn(total);nt_outs(" zero_component_pixels=");nt_outn(zeros);nt_outs(" exact_quantized_roundtrip=1 unit_length_proven=0\n")
57 sys_munmap_direct(asset,lp[0]);sys_munmap_direct(lp,__size_of(i64));sys_munmap_direct(out,3*__size_of(i64))
58 return 0
59}