some slight tweaks to the compressed format

This commit is contained in:
2021-12-27 16:58:39 +01:00
parent 7d280bd533
commit 08c86af06f
3 changed files with 23 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ use crate::rans::{PROB_BITS, ONE_PROB};
const INIT_PROB: u16 = 1 << (PROB_BITS - 1);
const UPDATE_RATE: u32 = 4;
const UPDATE_ADD: u32 = 8;
#[derive(Clone)]
pub struct ContextState {
@@ -33,9 +34,9 @@ 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 + ((ONE_PROB - old as u32) >> UPDATE_RATE) as u16
old + ((ONE_PROB - old as u32 + UPDATE_ADD) >> UPDATE_RATE) as u16
} else {
old - (old >> UPDATE_RATE)
old - ((old + UPDATE_ADD as u16) >> UPDATE_RATE)
};
}
}