change entropy coder from Range to rANS

This commit is contained in:
2021-11-22 23:14:24 +01:00
parent 479a2e2c89
commit 470b778340
8 changed files with 155 additions and 126 deletions

View File

@@ -1,4 +1,6 @@
const INIT_PROB: u16 = 0x8000;
use crate::rans::{PROB_BITS, ONE_PROB};
const INIT_PROB: u16 = 1 << (PROB_BITS - 1);
const UPDATE_RATE: u32 = 4;
#[derive(Clone)]
@@ -31,7 +33,7 @@ impl<'a> Context<'a> {
pub fn update(&mut self, bit: bool) {
let old = self.state.contexts[self.index];
self.state.contexts[self.index] = if bit {
old + (((1 << 16) - old as u32) >> UPDATE_RATE) as u16
old + ((ONE_PROB - old as u32) >> UPDATE_RATE) as u16
} else {
old - (old >> UPDATE_RATE)
};