nx_png_probe.nx source
↩ module page · 38 lines · 1923 B
1// nx_png_probe.nx -- Rule-2 verification: does the existing nx_png_decode
2// actually decode a REAL gallery PNG (not just the synthetic 1x1 smoke)?
3// Reads one real file, decodes, prints error_code + dims + first pixel.
4// license_tier: ORIGINAL
5import "nx_syscalls.nx"
6import "nx_tier.nx"
7import "nx_png_decoder.nx"
8
9func gp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func gn(v: i64) -> i64 {
11 let bb: *u8 = sys_mmap(28)
12 var m: i64 = v
13 if m < 0 { sys_write(1, "-\x00" as *u8, 1); m = 0 - m }
14 let t: *u8 = sys_mmap(28)
15 var k: i64 = 0
16 if m == 0 { t[0] = 48 as u8; k = 1 }
17 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
18 var i: i64 = 0
19 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
20 sys_write(1, bb, k)
21 return 0
22}
23
24func main() -> i64 {
25 let szp: *i64 = sys_mmap(16) as *i64
26 let buf: *u8 = sys_read_file("knowledge/staging/media/gallery/20260612_000008_c21f8b7c_3860894667_laptop.png\x00" as *u8, szp)
27 if (buf as i64) == 0 { gp("PROBE: no file\n\x00" as *u8); return 1 }
28 gp("PROBE bytes=\x00" as *u8); gn(szp[0]); gp("\n\x00" as *u8)
29 let r: *NxPngResult = nx_png_decode(buf, szp[0])
30 if (r as i64) == 0 { gp("PROBE: null result\n\x00" as *u8); return 2 }
31 gp("PROBE error_code=\x00" as *u8); gn(r.error_code); gp("\n\x00" as *u8)
32 if r.error_code != NX_PNG_OK { gp("PROBE: decode failed (see code above)\n\x00" as *u8); return 3 }
33 gp("PROBE w=\x00" as *u8); gn(r.header.width); gp(" h=\x00" as *u8); gn(r.header.height)
34 gp(" color_type=\x00" as *u8); gn(r.header.color_type); gp(" ch=\x00" as *u8); gn(r.n_channels)
35 gp(" bpp=\x00" as *u8); gn(r.bytes_per_pix); gp("\n\x00" as *u8)
36 gp("PROBE px0=\x00" as *u8); gn(r.pixels[0] as i64); gp(",\x00" as *u8); gn(r.pixels[1] as i64); gp(",\x00" as *u8); gn(r.pixels[2] as i64); gp("\n\x00" as *u8)
37 return 0
38}