code wiki / (root) / nx_vdeblock.nx

nx_vdeblock.nx source

↩ module page · 45 lines · 2265 B

1// nx_vdeblock.nx -- wires the already-built H.264 luma deblocking edge filter (nx_h264_deblock, spec 8.7.2.3) into a 2// FRAME-LEVEL pass. Block-transform codecs leave a DC "blocking" step at 4x4/MB edges after quantization; this filter 3// smooths those false edges while preserving true ones (it only acts when |p0-q0|<alpha && |p1-p0|<beta && |q1-q0|<beta, 4// the signature of a quantization artifact rather than real content). Applied as a DISPLAY/post pass here so the 5// inter-prediction reference stays pre-filter and encoder+decoder remain in sync; making it IN-LOOP (deblocked frame = 6// reference) is the next refinement. Composes nx_h264_deblock; caller owns scratch line[8]. license_tier: ORIGINAL 7import "nx_h264_deblock.nx" 8 9// deblock every internal 4x4 block boundary of a WxH 8bpp luma frame in place. bs = boundary strength (1..3), 10// qp selects the alpha/beta/tc0 thresholds. line = caller scratch of 8 i64 ([p3,p2,p1,p0,q0,q1,q2,q3] across an edge). 11func vc_deblock_frame(recon: *u8, W: i64, H: i64, qp: i64, bs: i64, line: *i64) -> i64 { 12 // vertical edges (filter horizontally across columns x = 4,8,...): modifies the 2 px each side of the edge 13 var x: i64 = 4 14 while x < W { 15 var y: i64 = 0 16 while y < H { 17 var k: i64 = 0 18 while k < 8 { line[k] = recon[y*W + (x-4+k)] as i64; k = k + 1 } 19 nx_deblock_luma_edge(line, bs, qp) 20 recon[y*W + (x-2)] = line[2] as u8 // p1 21 recon[y*W + (x-1)] = line[3] as u8 // p0 22 recon[y*W + (x+0)] = line[4] as u8 // q0 23 recon[y*W + (x+1)] = line[5] as u8 // q1 24 y = y + 1 25 } 26 x = x + 4 27 } 28 // horizontal edges (filter vertically across rows y = 4,8,...) 29 var yy: i64 = 4 30 while yy < H { 31 var xx: i64 = 0 32 while xx < W { 33 var k: i64 = 0 34 while k < 8 { line[k] = recon[(yy-4+k)*W + xx] as i64; k = k + 1 } 35 nx_deblock_luma_edge(line, bs, qp) 36 recon[(yy-2)*W + xx] = line[2] as u8 37 recon[(yy-1)*W + xx] = line[3] as u8 38 recon[(yy+0)*W + xx] = line[4] as u8 39 recon[(yy+1)*W + xx] = line[5] as u8 40 xx = xx + 1 41 } 42 yy = yy + 4 43 } 44 return 0 45}