nx_texr_images_gate_t278.nx source
↩ module page · 31 lines · 1543 B
1import "nx_nxa_texbake_region_lib.nx"
2import "nx_png_decoder.nx"
3func main(argc:i64,argv:*i64)->i64{
4 if argc!=2{return 2}
5 let lp:*i64=sys_mmap_try(__size_of(i64)) as *i64
6 let b:*u8=sys_map_file(argv[1] as *u8,lp);if (b as i64)<=0{return 3}
7 let at:i64=ntr_texr_find(b,lp[0]);if at<0{return 4}
8 let w:*i64=b as *i64;let ns:i64=w[at+NTR_W_NSETS];let nj:i64=w[at+NTR_W_NJ]
9 let stride:i64=w[at+NTR_W_SETW]
10 let blob:i64=(at+NTR_HDR_WORDS+nj*NTR_JOINT_WORDS+ns*stride)*NTR_WORD
11 var s:i64=0;var total:i64=0
12 while s<ns{
13 let set:i64=at+NTR_HDR_WORDS+nj*NTR_JOINT_WORDS+s*stride
14 var m:i64=0
15 while m<NTR_NMAPS{
16 let rec:i64=set+NTR_SET_META+m*NTR_MAPREC
17 let p:*u8=((b as i64)+blob+w[rec+1]) as *u8
18 let decoded:*NxPngResult=nx_png_decode(p,w[rec+2])
19 if (decoded as i64)<=0{return 5}
20 if decoded.error_code!=0{nt_outs("PNG-DECODE error=");nt_outn(decoded.error_code);nt_outs("\n");return 6}
21 var expected:i64=w[at+NTR_W_RES];if m>=NTR_MAP_TDISP{expected=w[at+NTR_W_MPX]}
22 if decoded.header.width!=expected || decoded.header.height!=expected{return 7}
23 if decoded.n_channels!=3 || decoded.bytes_per_pix!=3 || decoded.pixels_size!=expected*expected*3{return 8}
24 nt_outs("PASS region=");nt_outn(w[set+NTR_S_REGION]);nt_outs(" map=");nt_outn(m);nt_outs(" decoded_bytes=");nt_outn(decoded.pixels_size);nt_outs("\n")
25 total=total+1;m=m+1
26 };s=s+1
27 }
28 sys_munmap_direct(b,lp[0]);sys_munmap_direct(lp as *u8,__size_of(i64))
29 nt_outs("TEXR-IMAGES decoded=");nt_outn(total);nt_outs(" physical_accuracy=unverified\n")
30 return 0
31}