code wiki / (root) / nx_rangecoder.nx

nx_rangecoder.nx

buildroot/runtime/nx_rangecoder.nx

9364 B158 linesdepth 2pulls 2 transitivereach 110 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_rangecoder.nx -- sovereign BINARY RANGE CODER (CABAC/VP8-class), the entropy-coding SOTA lever (task #31). The current nx_ventropy is CAVLC (fixed 4-bit run + 5-bit level-length) -> wasteful when the real symbol distribution is skewed (it almost always is). A range coder with ADAPTIVE per-context probabilities codes each binary decision at its true entropy (a p=0.97 flag costs ~0.04 bit, not 1). Design = the LZMA range coder (carry via a cache byte + a pending-0xFF counter -- exact, well-understood), 12-bit probabilities, adaptive update toward the observed bit. Bit-exact by construction; a divergence shows in the roundtrip gate. license_tier: ORIGINAL

dependencies 1 imports · 5 importers

nx_ventropy.nx nx_rangecoder.nx nx_rangecoder_gain_gate.nx nx_rangecoder_sig.nx nx_vcodec.nx nx_vcodec_ffv1_entropy_gate.nx nx_vcodec_sigcoder_gate.nx

imports: nx_ventropy.nx

imported by: nx_rangecoder_gain_gate.nxnx_rangecoder_sig.nxnx_vcodec.nxnx_vcodec_ffv1_entropy_gate.nxnx_vcodec_sigcoder_gate.nx

structs

none

consts

10const RC_MAGIC_4096: i64 = 4096
11const RC_MAGIC_4095: i64 = 4095
12const RC_NCTX: i64 = 11 // contexts used by rc_block_encode/decode (probs array must be >= this, seeded 2048)
13const RC_NCTX8: i64 = 24 // total contexts when 8x8 blocks are in the stream (11 for 4x4 + 13 for 8x8, below)

functions

20func rc_enc_init(st: *i64) -> i64 { st[0]=0; st[1]=0xFFFFFFFF; st[2]=0; st[3]=1; st[4]=0; return 0 }
22func rc_shift_low(st: *i64, out: *u8) -> i64
40func rc_enc_bit(st: *i64, out: *u8, p: i64, bit: i64) -> i64
called by 1: rc_enc_ctx calls 1: rc_shift_low
46func rc_enc_flush(st: *i64, out: *u8) -> i64 { var i: i64=0; while i < 5 { rc_shift_low(st, out); i=i+1 } return st[4] }
49func rc_dec_init(st: *i64, in_: *u8) -> i64
54func rc_dec_bit(st: *i64, in_: *u8, p: i64) -> i64
called by 1: rc_dec_ctx
63func rc_p_update(p: i64, bit: i64) -> i64 { if bit == 0 { return p + ((RC_MAGIC_4096 - p) >> 5) } return p - (p >> 5) }
68func rc_bits_q8(p: i64, bit: i64) -> i64
81func rc_enc_ctx(st: *i64, out: *u8, probs: *i64, ctx: i64, bit: i64) -> i64
83func rc_dec_ctx(st: *i64, in_: *u8, probs: *i64, ctx: i64) -> i64
90func rc_block_encode(coeffs: *i64, st: *i64, out: *u8, probs: *i64) -> i64
105func rc_block_decode(coeffs: *i64, st: *i64, in_: *u8, probs: *i64) -> i64
124func rc_block64_encode(coeffs: *i64, st: *i64, out: *u8, probs: *i64, zz8: *i64) -> i64
139func rc_block64_decode(coeffs: *i64, st: *i64, in_: *u8, probs: *i64, zz8: *i64) -> i64
called by 1: vc_dec_sub8 calls 2: rc_dec_ctxve_zzd