Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Tomáš Král <tomas@kral.hk>
Wonwoo Choi <chwo9843@gmail.com>
Zoltan Szabadka
Mert Alev <101130780+mertalev@users.noreply.github.com>
Cody Neiman <neiman@cody.to>
14 changes: 9 additions & 5 deletions jxl/src/entropy_coding/ans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,15 @@ impl AnsHistogram {
let symbol = (alias_symbol * map_to_alias) | (i as u32 * (1 - map_to_alias));
let offset = offset + pos;

let next_state = (*state >> LOG_SUM_PROBS) * dist + offset;
let select_appended = (next_state < (1 << 16)) as u32;
let appended_state = (next_state << 16) | (br.peek(16) as u32);
*state = (appended_state * select_appended) | (next_state * (1 - select_appended));
br.consume_optimistic((16 * select_appended) as usize);
let mut next_state = (*state >> LOG_SUM_PROBS) * dist + offset;

// Use an explicit branch to bypass the BitReader's internal
// bounds-checks when state normalization isn't required.
if next_state < (1 << 16) {
next_state = (next_state << 16) | (br.read_optimistic(16) as u32);
}
*state = next_state;

symbol
}

Expand Down
Loading