nx_h264_mc_luma_gate.nx source
↩ module page · 81 lines · 3322 B
1// nx_h264_mc_luma_gate.nx -- gate luma quarter-pel interpolation (8.4.2.2.1).
2// (a) FLAT ref (all 100): every one of the 16 frac positions returns 100 (taps sum to 1).
3// (b) hand-computed: row [.,.,10,20,30,40,50,60] -> halfH(b)=35, integer(G)=30, quarter(a)=33.
4// (c) col version -> halfV(h)=35.
5// Exit 0/1. license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_h264_mc_luma.nx"
8
9func gp(fd: i64, s: *u8) -> i64 {
10 var n: i64 = 0
11 while s[n] != (0 as u8) { n = n + 1 }
12 sys_write(1, s, n); if fd > 0 { sys_write(fd, s, n) }
13 return 0
14}
15func gn(fd: i64, v: i64) -> i64 {
16 let bb: *u8 = sys_mmap(28); var m: i64 = v
17 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if fd > 0 { sys_write(fd, "-\x00" as *u8, 1) } m = 0 - m }
18 let t: *u8 = sys_mmap(28); var k: i64 = 0
19 if m == 0 { t[0] = 48 as u8; k = 1 }
20 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
21 var i: i64 = 0
22 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
23 sys_write(1, bb, k); if fd > 0 { sys_write(fd, bb, k) }
24 return 0
25}
26
27func main() -> i64 {
28 let fd: i64 = sys_openat_append("knowledge/status/h264_mc_luma_gate.log\x00" as *u8, 0x1a4)
29 gp(fd, "H264-MC-LUMA-GATE\n\x00" as *u8)
30 var ok: i64 = 1
31 let W: i64 = 12
32 let H: i64 = 12
33 let ref: *u8 = sys_mmap(W * H + 16)
34
35 // (a) FLAT -> all 16 frac positions = 100
36 var i: i64 = 0
37 while i < W * H { ref[i] = 100 as u8; i = i + 1 }
38 var flatpass: i64 = 0
39 var yf: i64 = 0
40 while yf < 4 {
41 var xf: i64 = 0
42 while xf < 4 {
43 if nx_h264_mc_luma_sample(ref, W, H, 6, 6, xf, yf) == 100 { flatpass = flatpass + 1 }
44 xf = xf + 1
45 }
46 yf = yf + 1
47 }
48 gp(fd, " flat 16-frac all=100 passing=\x00" as *u8); gn(fd, flatpass); gp(fd, "/16\n\x00" as *u8)
49 if flatpass != 16 { ok = 0 }
50
51 // (b) horizontal: row 6, x=4..9 = 10,20,30,40,50,60 (halfH at x=6 uses ref(4..9))
52 i = 0
53 while i < W * H { ref[i] = 0 as u8; i = i + 1 }
54 ref[6*W+4]=10 as u8; ref[6*W+5]=20 as u8; ref[6*W+6]=30 as u8; ref[6*W+7]=40 as u8; ref[6*W+8]=50 as u8; ref[6*W+9]=60 as u8
55 let g: i64 = nx_h264_mc_luma_sample(ref, W, H, 6, 6, 0, 0)
56 let b: i64 = nx_h264_mc_luma_sample(ref, W, H, 6, 6, 2, 0)
57 let a: i64 = nx_h264_mc_luma_sample(ref, W, H, 6, 6, 1, 0)
58 gp(fd, " G(int)=\x00" as *u8); gn(fd, g); gp(fd, " b(halfH)=\x00" as *u8); gn(fd, b); gp(fd, " a(qpel)=\x00" as *u8); gn(fd, a); gp(fd, " (expect 30 35 33)\n\x00" as *u8)
59 if g != 30 { ok = 0 }
60 if b != 35 { ok = 0 }
61 if a != 33 { ok = 0 }
62
63 // (c) vertical: col 6, y=4..9 = 10..60 (halfV at y=6 uses ref(.,4..9))
64 i = 0
65 while i < W * H { ref[i] = 0 as u8; i = i + 1 }
66 ref[4*W+6]=10 as u8; ref[5*W+6]=20 as u8; ref[6*W+6]=30 as u8; ref[7*W+6]=40 as u8; ref[8*W+6]=50 as u8; ref[9*W+6]=60 as u8
67 let hh: i64 = nx_h264_mc_luma_sample(ref, W, H, 6, 6, 0, 2)
68 gp(fd, " h(halfV)=\x00" as *u8); gn(fd, hh); gp(fd, " (expect 35)\n\x00" as *u8)
69 if hh != 35 { ok = 0 }
70
71 if ok == 1 {
72 gp(fd, "H264-MC-LUMA-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8)
73 if fd > 0 { sys_close(fd) }
74 sys_exit(0)
75 return 0
76 }
77 gp(fd, "H264-MC-LUMA-GATE result=FAIL verdict=RED\n\x00" as *u8)
78 if fd > 0 { sys_close(fd) }
79 sys_exit(1)
80 return 1
81}