code wiki / (root) / nx_media_convert_jpeg_gate.nx

nx_media_convert_jpeg_gate.nx source

↩ module page · 41 lines · 1892 B

1// nx_media_convert_jpeg_gate.nx -- proves the unified file converter handles 2// real JPEG input (sovereign decode) AND PNG input via one sniff-dispatch 3// entry, and fails closed on unknown formats. Verified by RE-DECODING the 4// output and asserting dimensions -- no image-content rendering needed. 5 6import "nx_syscalls.nx" 7import "nx_img_resample.nx" 8import "nx_png_decoder.nx" 9import "nx_seg_store.nx" 10import "nx_media_convert.nx" 11 12// Re-decode a PNG and check its dimensions + RGB. 0 ok, else nonzero. 13func _dims_ok(path: *u8, ew: i64, eh: i64) -> i64 { 14 let szbox: *i64 = sys_mmap(16) as *i64 15 let b: *u8 = ss_readall(path, szbox) 16 if szbox[0] <= 0 { return 1 } 17 let r: *NxPngResult = nx_png_decode(b, szbox[0]) 18 if r.error_code != NX_PNG_OK { return 2 } 19 let hd: *NxPngHeader = r.header 20 if hd.width != ew { return 3 } 21 if hd.height != eh { return 4 } 22 if r.n_channels != 3 { return 5 } 23 return 0 24} 25 26func main() -> i64 { 27 // JPEG input: real source.jpg (239x178) -> bicubic 120x90 -> PNG 28 let jout: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/_sv_jpg_out.png" as *u8 29 if nx_media_convert_file("/mnt/c/Users/elder/nishi-browser-proofs/source.jpg" as *u8, NX_RS_BICUBIC, 120, 90, jout) != 0 { return 10 } 30 if _dims_ok(jout, 120, 90) != 0 { return 11 } 31 32 // PNG input through the SAME unified converter (sniff): _sv_mc_src.png 24x24 -> 48x48 33 let pout: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/_sv_png_out.png" as *u8 34 if nx_media_convert_file("/mnt/c/Users/elder/nishi-core/nxc2/_sv_mc_src.png" as *u8, NX_RS_BILINEAR, 48, 48, pout) != 0 { return 20 } 35 if _dims_ok(pout, 48, 48) != 0 { return 21 } 36 37 // unknown format (a .nx source file) -> -6 fail-closed 38 if nx_media_convert_file("/mnt/c/Users/elder/nishi-core/nxc2/runtime/nx_media_convert.nx" as *u8, NX_RS_BILINEAR, 10, 10, pout) != (0 - 6) { return 30 } 39 40 return 0 41}