mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Restore deflate.decoder.n_huffs_bits's refinement
This commit is contained in:
1 parent
b075fcbed9
commit
5aeb98c701
5 files changed
+20
-28
No files matched your search
@@ -2878,6 +2878,7 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint32_t f_history_index;
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
bool f_end_of_block;
|
||||
|
||||
uint32_t p_decode_io_writer[1];
|
||||
@@ -2889,7 +2890,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
|
||||
struct {
|
||||
uint32_t f_huffs[2][1024];
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
uint8_t f_history[32768];
|
||||
uint8_t f_code_lengths[320];
|
||||
|
||||
@@ -6944,9 +6944,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(wuffs_deflate__decoder* self,
|
||||
status = v_status;
|
||||
goto exit;
|
||||
}
|
||||
v_mask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[0], 9)) -
|
||||
1);
|
||||
v_mask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_i = 0;
|
||||
label_0_continue:;
|
||||
while (v_i < (v_n_lit + v_n_dist)) {
|
||||
@@ -7196,9 +7194,9 @@ label_0_break:;
|
||||
}
|
||||
label_1_break:;
|
||||
if (v_max_cl <= 9) {
|
||||
self->private_data.f_n_huffs_bits[a_which] = v_max_cl;
|
||||
self->private_impl.f_n_huffs_bits[a_which] = v_max_cl;
|
||||
} else {
|
||||
self->private_data.f_n_huffs_bits[a_which] = 9;
|
||||
self->private_impl.f_n_huffs_bits[a_which] = 9;
|
||||
}
|
||||
v_i = 0;
|
||||
if ((v_n_symbols != ((uint32_t)(v_offsets[v_max_cl]))) ||
|
||||
@@ -7380,12 +7378,8 @@ wuffs_deflate__decoder__decode_huffman_fast(wuffs_deflate__decoder* self,
|
||||
}
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[0], 9)) -
|
||||
1);
|
||||
v_dmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[1], 9)) -
|
||||
1);
|
||||
v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
label_0_continue:;
|
||||
while ((((uint64_t)(io1_a_dst - iop_a_dst)) >= 258) &&
|
||||
(((uint64_t)(io1_a_src - iop_a_src)) >= 12)) {
|
||||
@@ -7721,12 +7715,8 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self,
|
||||
}
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[0], 9)) -
|
||||
1);
|
||||
v_dmask = ((((uint32_t)(1)) << wuffs_base__u32__min(
|
||||
self->private_data.f_n_huffs_bits[1], 9)) -
|
||||
1);
|
||||
v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
label_0_continue:;
|
||||
while (!(self->private_impl.p_decode_huffman_slow[0] != 0)) {
|
||||
while (true) {
|
||||
|
||||
@@ -150,12 +150,12 @@ typedef struct wuffs_deflate__decoder__struct {
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint32_t f_history_index;
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
bool f_end_of_block;
|
||||
} private_impl;
|
||||
struct {
|
||||
// 1024 is huffs_table_size in std/deflate/decode_deflate.wuffs.
|
||||
uint32_t f_huffs[2][1024];
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
uint8_t f_history[32768];
|
||||
uint8_t f_code_lengths[320];
|
||||
} private_data;
|
||||
@@ -278,8 +278,8 @@ wuffs_base__status c_wuffs_deflate__decoder__decode_huffman_fast(
|
||||
|
||||
// Initialize other local variables.
|
||||
uint8_t* pdst_mark = a_dst.private_impl.mark ? a_dst.private_impl.mark : pdst;
|
||||
uint32_t lmask = MASK(self->private_data.f_n_huffs_bits[0]);
|
||||
uint32_t dmask = MASK(self->private_data.f_n_huffs_bits[1]);
|
||||
uint32_t lmask = MASK(self->private_impl.f_n_huffs_bits[0]);
|
||||
uint32_t dmask = MASK(self->private_impl.f_n_huffs_bits[1]);
|
||||
|
||||
outer_loop:
|
||||
while ((pdst <= qdst) && (psrc <= qsrc)) {
|
||||
|
||||
@@ -69,6 +69,9 @@ pub struct decoder?(
|
||||
// history_index indexes the history array, defined below.
|
||||
history_index base.u32,
|
||||
|
||||
// n_huffs_bits is discussed in the huffs field comment.
|
||||
n_huffs_bits array[2] base.u32[..9],
|
||||
|
||||
// end_of_block is whether decode_huffman_xxx saw an end-of-block code.
|
||||
//
|
||||
// TODO: can decode_huffman_xxx signal this in band instead of out of band?
|
||||
@@ -106,8 +109,7 @@ pub struct decoder?(
|
||||
// - bits 3 .. 0 are the number of decoder.bits to consume.
|
||||
//
|
||||
// Exactly one of the eight bits 31-24 should be set.
|
||||
huffs array[2] array[huffs_table_size] base.u32,
|
||||
n_huffs_bits array[2] base.u32,
|
||||
huffs array[2] array[huffs_table_size] base.u32,
|
||||
|
||||
// history holds up to the last 32KiB of decoded output, if the decoding
|
||||
// was incomplete (e.g. due to a short read or write). RFC 1951 (DEFLATE)
|
||||
@@ -389,7 +391,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
}
|
||||
|
||||
// Decode the code lengths for the next two Huffman tables.
|
||||
mask = ((1 as base.u32) << (this.n_huffs_bits[0].min(x:9))) - 1
|
||||
mask = ((1 as base.u32) << (this.n_huffs_bits[0])) - 1
|
||||
i = 0
|
||||
while i < (n_lit + n_dist) {
|
||||
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist)
|
||||
|
||||
@@ -41,8 +41,8 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
|
||||
bits = this.bits
|
||||
n_bits = this.n_bits
|
||||
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0].min(x:9)) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1].min(x:9)) - 1
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1
|
||||
|
||||
// Check up front, on each iteration, that we have enough buffer space to
|
||||
// both read (12 bytes) and write (258 bytes) as much as we need to. Doing
|
||||
|
||||
@@ -45,8 +45,8 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
bits = this.bits
|
||||
n_bits = this.n_bits
|
||||
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0].min(x:9)) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1].min(x:9)) - 1
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1
|
||||
|
||||
while:loop not coroutine_resumed {
|
||||
// Decode an lcode symbol from H-L.
|
||||
|
||||
Reference in new issue
Block a user