nx_lbp_imgio.nx source
↩ module page · 33 lines · 1516 B
1// nx_lbp_imgio.nx -- shared SOVEREIGN image loader for the LBP face-descriptor arc (NO main): PNG file ->
2// 8-bit luma grayscale, plus a fixed-size variant for the spatial-grid descriptor. Honest scope: 8-bit
3// samples + RGB(A) (nch>=3) only -- matches the gallery PNGs; other encodings return failure, not garbage.
4// license_tier: ORIGINAL
5import "nx_syscalls.nx"
6import "nx_png_decoder.nx"
7import "nx_lbp_core.nx"
8
9// decode a PNG file -> freshly-mmap'd 8-bit luma grayscale buffer; sets wout/hout; returns 0 on fail
10func load_gray(path: *u8, wout: *i64, hout: *i64) -> *u8 {
11 let szp: *i64 = sys_mmap(16) as *i64
12 let buf: *u8 = sys_read_file(path, szp)
13 if (buf as i64) == 0 { return 0 as *u8 }
14 let r: *NxPngResult = nx_png_decode(buf, szp[0])
15 if r.error_code != 0 { return 0 as *u8 }
16 let hdr: *NxPngHeader = r.header
17 if hdr.bit_depth != 8 { return 0 as *u8 }
18 if r.n_channels < 3 { return 0 as *u8 }
19 let w: i64 = hdr.width; let h: i64 = hdr.height
20 let gray: *u8 = sys_mmap(w*h)
21 rgb_to_gray(r.pixels, gray, w, h, r.n_channels)
22 wout[0] = w; hout[0] = h
23 return gray
24}
25
26// decode + grayscale + box-resize to a fixed dw x dh into caller-provided dst; returns 0 ok / <0 fail
27func load_gray_fixed(path: *u8, dw: i64, dh: i64, dst: *u8) -> i64 {
28 let wp: *i64 = sys_mmap(8) as *i64; let hp: *i64 = sys_mmap(8) as *i64
29 let g: *u8 = load_gray(path, wp, hp)
30 if (g as i64) == 0 { return 0 - 1 }
31 gray_resize_box(g, wp[0], hp[0], dst, dw, dh)
32 return 0
33}