nx_vcodec_inter.nx source
↩ module page · 38 lines · 2218 B
1// nx_vcodec_inter.nx -- RUNG H6 of the sovereign s-class codec: COLOR inter-prediction (P-frames). Each
2// plane block is coded as the RESIDUAL (cur - prev): unchanged blocks SKIP (zero bytes, exact copy of
3// prev), changed blocks carry only the quantized residual. This is the temporal-compression / fps lever --
4// on a mostly-static video call the vast majority of blocks skip, so bandwidth collapses and fps climbs at
5// the same uplink. Built on H5's transform/quant block codec. Pure integer, sovereign. license_tier: ORIGINAL
6import "nx_vcodec_color_frame.nx"
7
8// inter-code one plane: rec = reconstructed cur. SKIP blocks copy prev EXACTLY. changed[0] = changed block
9// count. returns total nonzero residual coeffs (the byte-cost proxy).
10func inter_code_plane(prev: *u8, cur: *u8, W: i64, H: i64, QSTEP: i64, rec: *u8, changed: *i64) -> i64 {
11 let res: *i64 = sys_mmap(8*16) as *i64; let q: *i64 = sys_mmap(8*16) as *i64
12 let tmp: *i64 = sys_mmap(8*16) as *i64; let T: *i64 = sys_mmap(8*16) as *i64; let rb: *i64 = sys_mmap(8*16) as *i64
13 var total_nz: i64=0; var nchanged: i64=0
14 let BX: i64=W/4; let BY: i64=H/4
15 var by: i64=0
16 while by<BY { var bx: i64=0
17 while bx<BX {
18 var i: i64=0; var any: i64=0
19 while i<4 { var j: i64=0; while j<4 { let p: i64=(by*4+i)*W+(bx*4+j); let d: i64=(cur[p] as i64)-(prev[p] as i64); res[i*4+j]=d; if d!=0 {any=1} j=j+1 } i=i+1 }
20 var did_skip: i64=0
21 if any==1 {
22 let nz: i64 = enc_block(res, tmp, T, q, QSTEP)
23 if nz==0 { did_skip=1 } else {
24 nchanged=nchanged+1; total_nz=total_nz+nz
25 dec_block(q, tmp, T, rb, QSTEP)
26 i=0; while i<4 { var j: i64=0; while j<4 { let p: i64=(by*4+i)*W+(bx*4+j); var v: i64=(prev[p] as i64)+rb[i*4+j]; if v<0{v=0} if v>255{v=255} rec[p]=v as u8; j=j+1 } i=i+1 }
27 }
28 } else { did_skip=1 }
29 if did_skip==1 { i=0; while i<4 { var j: i64=0; while j<4 { let p: i64=(by*4+i)*W+(bx*4+j); rec[p]=prev[p]; j=j+1 } i=i+1 } }
30 bx=bx+1
31 }
32 by=by+1
33 }
34 changed[0]=nchanged
35 return total_nz
36}
37
38func main() -> i64 { return 0 }