code wiki / _hdl_build / nx_imgproof.nx
nx_imgproof.nx source
↩ module page · 34 lines · 1534 B
1// nx_imgproof.nx -- prove the sovereign image DECODE path end-to-end: decode a real JPEG + PNG (in-memory
2// bytes) via nx_img_to_rgb, re-emit as PNG so we can SEE them. Isolates decode (the riskiest piece) from
3// fetch/layout/blit. Riskiest per recon: JPEG=baseline-only, PNG=truecolor-only (no palette/interlace).
4import "nx_syscalls.nx"
5import "nx_img_to_rgb.nx"
6import "nx_png_write.nx"
7
8func ip(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
9func ipn(v: i64) -> i64 {
10 var m: i64 = v
11 if m < 0 { ip("-\x00" as *u8); m = 0 - m }
12 let t: *u8 = sys_mmap(24); var k: i64 = 0
13 if m == 0 { t[0] = 48 as u8; k = 1 } else { while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } }
14 let o: *u8 = sys_mmap(24); var j: i64 = 0
15 while j < k { o[j] = t[k - 1 - j]; j = j + 1 }
16 sys_write(1, o, k); return 0
17}
18
19func do_one(inpath: *u8, outpath: *u8, label: *u8) -> i64 {
20 let wh: *i64 = sys_mmap(16) as *i64
21 let rgb: *u8 = nx_img_to_rgb(inpath, wh)
22 ip(label)
23 if (rgb as i64) == 0 { ip(" DECODE FAILED\n\x00" as *u8); return 1 }
24 ip(" decoded w=\x00" as *u8); ipn(wh[0]); ip(" h=\x00" as *u8); ipn(wh[1])
25 nx_png_write_rgb(outpath, rgb, wh[0], wh[1])
26 ip(" -> wrote PNG\n\x00" as *u8)
27 return 0
28}
29
30func main() -> i64 {
31 do_one("_offc/test.jpg\x00" as *u8, "_offc/imgproof_jpg.png\x00" as *u8, "JPEG\x00" as *u8)
32 do_one("_offc/test.png\x00" as *u8, "_offc/imgproof_png.png\x00" as *u8, "PNG \x00" as *u8)
33 return 0
34}