code wiki / (root) / nx_h264_nc.nx

nx_h264_nc.nx source

↩ module page · 33 lines · 1381 B

1// nx_h264_nc.nx -- CAVLC neighbour context nC (spec 9.2.1) + coeff_token table 2// selection. nC picks which coeff_token VLC table a 4x4 block uses, from the 3// TotalCoeff of its LEFT (nA) and TOP (nB) neighbour blocks: 4// both available -> nC = (nA + nB + 1) >> 1 5// left only -> nC = nA ; top only -> nC = nB ; neither -> nC = 0 6// chroma DC -> nC = -1 (special table) 7// Table index by nC: 0 (0<=nC<2), 1 (2<=nC<4), 2 (4<=nC<8), 3 (FLC, nC>=8), 8// 4 (chroma DC, nC=-1). 9// The MB loop tracks per-4x4-block TotalCoeff to feed nA/nB. This is the key 10// missing algorithm for decoding blocks beyond the first (which was nC=0). 11// 12// genealogy_id: itu_t_h264_sec9_2_1_nC_derivation 13// lineage_id: neighbour_totalcoeff_average + coeff_token_table_select 14// license_tier: ORIGINAL 15import "nx_syscalls.nx" 16 17const NX_NC_CHROMA_DC: i64 = 0 - 1 18 19func nx_h264_nc_luma(nA: i64, availA: i64, nB: i64, availB: i64) -> i64 { 20 if availA == 1 { if availB == 1 { return (nA + nB + 1) >> 1 } } 21 if availA == 1 { if availB == 0 { return nA } } 22 if availA == 0 { if availB == 1 { return nB } } 23 return 0 24} 25 26// which coeff_token table (0..4) for a given nC 27func nx_h264_coeff_token_table(nC: i64) -> i64 { 28 if nC == NX_NC_CHROMA_DC { return 4 } 29 if nC < 2 { return 0 } 30 if nC < 4 { return 1 } 31 if nC < 8 { return 2 } 32 return 3 33}