mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
Tighten std/bzip2 Huffman leaf node bit packing
This commit is contained in:
1 parent
67aa63297c
commit
45a79923e6
4 files changed
+47
-47
No files matched your search
@@ -27,7 +27,7 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
var output : base.u32[..= 255]
|
||||
var run : base.u32[..= 16_777216] // 16_777216 = (2 << 23)
|
||||
var run : base.u32[..= 12_582912] // 12_582912 = (3 << 22)
|
||||
var mtft0 : base.u32[..= 255]
|
||||
|
||||
bits = this.bits
|
||||
@@ -58,7 +58,7 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
table_entry = this.huffman_tables[which][bits >> 24]
|
||||
bits ~mod<<= table_entry >> 12
|
||||
n_bits -= (table_entry >> 12) as base.u32
|
||||
child = table_entry & 0x7FF
|
||||
child = table_entry & 0x3FF
|
||||
while child < 257 {
|
||||
child = this.huffman_trees[which][child][bits >> 31]
|
||||
bits ~mod<<= 1
|
||||
@@ -68,7 +68,7 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
n_bits -= 1
|
||||
} endwhile
|
||||
|
||||
if child < 1280 { // mNN symbol.
|
||||
if child < 0x300 { // mNN symbol.
|
||||
// Move to front.
|
||||
child_ff = (child & 0xFF) as base.u32
|
||||
output = this.mtft[child_ff] as base.u32
|
||||
@@ -85,7 +85,7 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
block_size += 1
|
||||
run_shift = 0
|
||||
continue.outer
|
||||
} else if child > 1281 { // EOB symbol.
|
||||
} else if child == 0x300 { // EOB symbol.
|
||||
this.decode_huffman_finished = true
|
||||
break.outer
|
||||
}
|
||||
@@ -94,7 +94,7 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
if run_shift >= 23 {
|
||||
return "#bad block length"
|
||||
}
|
||||
run = ((child - 1279) as base.u32) << run_shift
|
||||
run = ((child as base.u32) & 3) << run_shift
|
||||
run_shift += 1
|
||||
i = block_size
|
||||
j = run + block_size
|
||||
|
||||
Reference in new issue
Block a user