Rename a LZW decoder field

This commit is contained in:
Nigel Tao committed 2018-10-21 16:07:36 +11:00
1 parent b0c72867e6
commit 479326cbad
2 files changed
+22 -24

No files matched your search

+10 -14
View File
@@ -2571,7 +2571,7 @@ struct wuffs_lzw__decoder__struct {
uint32_t f_flush_j;
uint8_t f_suffixes[4096][8];
uint16_t f_prefixes[4096];
uint16_t f_prefix_lengths[4096];
uint16_t f_lm1s[4096];
uint8_t f_output[8199];
struct {
@@ -9569,7 +9569,7 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
v_width = (v_literal_width + 1);
v_j = 0;
while (v_j < v_clear_code) {
self->private_impl.f_prefix_lengths[v_j] = 0;
self->private_impl.f_lm1s[v_j] = 0;
self->private_impl.f_suffixes[v_j][0] = ((uint8_t)(v_j));
v_j += 1;
}
@@ -9617,9 +9617,8 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
self->private_impl.f_output[v_j] = ((uint8_t)(v_code));
v_j = ((v_j + 1) & 8191);
if (v_save_code <= 4095) {
v_lm1_a =
((self->private_impl.f_prefix_lengths[v_prev_code] + 1) & 4095);
self->private_impl.f_prefix_lengths[v_save_code] = v_lm1_a;
v_lm1_a = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
self->private_impl.f_lm1s[v_save_code] = v_lm1_a;
if ((v_lm1_a % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code];
@@ -9650,13 +9649,11 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
if (v_code == v_save_code) {
v_c = v_prev_code;
}
v_o = ((v_j + (((uint32_t)(self->private_impl.f_prefix_lengths[v_c])) &
4294967288)) &
v_o = ((v_j +
(((uint32_t)(self->private_impl.f_lm1s[v_c])) & 4294967288)) &
8191);
v_j = ((v_j + 1 +
((uint32_t)(self->private_impl.f_prefix_lengths[v_c]))) &
8191);
v_steps = (((uint32_t)(self->private_impl.f_prefix_lengths[v_c])) >> 3);
v_j = ((v_j + 1 + ((uint32_t)(self->private_impl.f_lm1s[v_c]))) & 8191);
v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
while (true) {
memcpy((self->private_impl.f_output) + (v_o),
(self->private_impl.f_suffixes[v_c]) + (0), 8);
@@ -9674,9 +9671,8 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
v_j = ((v_j + 1) & 8191);
}
if (v_save_code <= 4095) {
v_lm1_b =
((self->private_impl.f_prefix_lengths[v_prev_code] + 1) & 4095);
self->private_impl.f_prefix_lengths[v_save_code] = v_lm1_b;
v_lm1_b = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
self->private_impl.f_lm1s[v_save_code] = v_lm1_b;
if ((v_lm1_b % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code];
+12 -10
View File
@@ -21,7 +21,9 @@ pub struct decoder?(
flush_j base.u32[..8191],
suffixes array[4096] array[8] base.u8,
prefixes array[4096] base.u16[..4095],
prefix_lengths array[4096] base.u16[..4095], // TODO: rename this field.
// lm1s is the "length minus 1"s of the values for the implicit key-value
// table in this decoder. See std/lzw/README.md for more detail.
lm1s array[4096] base.u16[..4095],
output array[8192 + 7] base.u8,
)
@@ -47,11 +49,11 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
var prev_code base.u32[..4095] = end_code
var width base.u32[..12] = literal_width + 1
// First, use the j variable to iterate over prefix_lengths.
// First, use the j variable to initialize some state.
var j base.u32[..8191]
while j < clear_code {
assert j < 256 via "a < b: a < c; c <= b"(c:clear_code)
this.prefix_lengths[j] = 0
this.lm1s[j] = 0
this.suffixes[j][0] = j as base.u8
j += 1
}
@@ -110,8 +112,8 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
this.output[j] = code as base.u8
j = (j + 1) & 8191
if save_code <= 4095 {
var lm1_a base.u16[..4095] = (this.prefix_lengths[prev_code] + 1) & 4095
this.prefix_lengths[save_code] = lm1_a
var lm1_a base.u16[..4095] = (this.lm1s[prev_code] + 1) & 4095
this.lm1s[save_code] = lm1_a
if (lm1_a % 8) != 0 {
this.prefixes[save_code] = this.prefixes[prev_code]
@@ -152,10 +154,10 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
// In the special case that code == save_code, the decoded bytes
// contain an extra copy (at the end) of the first byte, and will
// be written to output[old_j:new_j + 1].
var o base.u32[..8191] = (j + ((this.prefix_lengths[c] as base.u32) & 0xFFFFFFF8)) & 8191
j = (j + 1 + (this.prefix_lengths[c] as base.u32)) & 8191
var o base.u32[..8191] = (j + ((this.lm1s[c] as base.u32) & 0xFFFFFFF8)) & 8191
j = (j + 1 + (this.lm1s[c] as base.u32)) & 8191
var steps base.u32 = (this.prefix_lengths[c] as base.u32) >> 3
var steps base.u32 = (this.lm1s[c] as base.u32) >> 3
while true {
assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b:8)
this.output[o:o + 8].copy_from_slice!(s:this.suffixes[c][0:0 + 8])
@@ -177,8 +179,8 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
}
if save_code <= 4095 {
var lm1_b base.u16[..4095] = (this.prefix_lengths[prev_code] + 1) & 4095
this.prefix_lengths[save_code] = lm1_b
var lm1_b base.u16[..4095] = (this.lm1s[prev_code] + 1) & 4095
this.lm1s[save_code] = lm1_b
if (lm1_b % 8) != 0 {
this.prefixes[save_code] = this.prefixes[prev_code]