mirror of
https://github.com/exoticorn/upkr.git
synced 2026-01-20 11:36:42 +01:00
Compare commits
2 Commits
08c86af06f
...
2e7983fc65
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e7983fc65 | |||
| f7f891e154 |
@@ -6,7 +6,7 @@ const UPDATE_ADD: u32 = 8;
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ContextState {
|
pub struct ContextState {
|
||||||
contexts: Vec<u16>,
|
contexts: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
@@ -17,7 +17,7 @@ pub struct Context<'a> {
|
|||||||
impl ContextState {
|
impl ContextState {
|
||||||
pub fn new(size: usize) -> ContextState {
|
pub fn new(size: usize) -> ContextState {
|
||||||
ContextState {
|
ContextState {
|
||||||
contexts: vec![INIT_PROB; size],
|
contexts: vec![INIT_PROB as u8; size],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,15 +28,15 @@ impl ContextState {
|
|||||||
|
|
||||||
impl<'a> Context<'a> {
|
impl<'a> Context<'a> {
|
||||||
pub fn prob(&self) -> u16 {
|
pub fn prob(&self) -> u16 {
|
||||||
self.state.contexts[self.index]
|
self.state.contexts[self.index] as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, bit: bool) {
|
pub fn update(&mut self, bit: bool) {
|
||||||
let old = self.state.contexts[self.index];
|
let old = self.state.contexts[self.index];
|
||||||
self.state.contexts[self.index] = if bit {
|
self.state.contexts[self.index] = if bit {
|
||||||
old + ((ONE_PROB - old as u32 + UPDATE_ADD) >> UPDATE_RATE) as u16
|
old + ((ONE_PROB - old as u32 + UPDATE_ADD) >> UPDATE_RATE) as u8
|
||||||
} else {
|
} else {
|
||||||
old - ((old + UPDATE_ADD as u16) >> UPDATE_RATE)
|
old - ((old as u32 + UPDATE_ADD) >> UPDATE_RATE) as u8
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ impl Op {
|
|||||||
|
|
||||||
pub fn encode_eof(coder: &mut dyn EntropyCoder, state: &mut CoderState) {
|
pub fn encode_eof(coder: &mut dyn EntropyCoder, state: &mut CoderState) {
|
||||||
encode_bit(coder, state, 0, true);
|
encode_bit(coder, state, 0, true);
|
||||||
encode_bit(coder, state, 256, true);
|
if !state.prev_was_match {
|
||||||
|
encode_bit(coder, state, 256, true);
|
||||||
|
}
|
||||||
encode_length(coder, state, 257, 1);
|
encode_length(coder, state, 257, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user