code wiki / (root) / nx_img_scale_diff.nx

nx_img_scale_diff.nx source

↩ module page · 48 lines · 1555 B

1// nx_img_scale_diff.nx -- measured-exceed harness, step 3 (diff). 2// 3// Reads my sovereign output (/tmp/sv_mine.raw) and the ffmpeg swscale-bilinear 4// reference (/tmp/sv_ref.raw), measures max + mean absolute per-pixel deviation, 5// and writes the RAW numbers to /tmp/sv_diff.txt (no-wave: show the measurement). 6// Exit 0 = measured successfully (both present, same size). 7// license_tier: ORIGINAL 8 9import "nx_syscalls.nx" 10import "nx_seg_store.nx" 11 12func main() -> i64 { 13 let szmine: *i64 = sys_mmap(16) as *i64 14 let szref: *i64 = sys_mmap(16) as *i64 15 let mine: *u8 = ss_readall("/tmp/sv_mine.raw" as *u8, szmine) 16 let refp: *u8 = ss_readall("/tmp/sv_ref.raw" as *u8, szref) 17 if szmine[0] <= 0 { return 1 } 18 if szref[0] <= 0 { return 2 } 19 if szmine[0] != szref[0] { return 3 } 20 let n: i64 = szmine[0] 21 22 var maxd: i64 = 0 23 var sumd: i64 = 0 24 var i: i64 = 0 25 while i < n { 26 let a: i64 = mine[i] as i64 27 let b: i64 = refp[i] as i64 28 var d: i64 = a - b 29 if d < 0 { d = 0 - d } 30 if d > maxd { maxd = d } 31 sumd = sumd + d 32 i = i + 1 33 } 34 let mean_x1000: i64 = sumd * 1000 / n 35 36 let out: *u8 = sys_mmap(256) 37 var o: i64 = 0 38 o = ss_cat(out, o, "max_abs_dev=" as *u8) 39 o = ss_catn(out, o, maxd) 40 o = ss_cat(out, o, " mean_abs_dev_x1000=" as *u8) 41 o = ss_catn(out, o, mean_x1000) 42 o = ss_cat(out, o, " pixels=" as *u8) 43 o = ss_catn(out, o, n) 44 out[o] = 10 as u8 45 o = o + 1 46 ss_writefile("/tmp/sv_diff.txt" as *u8, out, o) 47 return 0 48}