mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 00:47:28 +01:00
Rename lzw's flush_j field
This commit is contained in:
1 parent
c2826e87e3
commit
00c5f77c19
2 files changed
+48
-46
No files matched your search
+26
-26
@@ -33,7 +33,7 @@ pub struct decoder?(
|
||||
width base.u32[..12],
|
||||
bits base.u32,
|
||||
n_bits base.u32[..31],
|
||||
flush_j base.u32[..8191],
|
||||
output_wi base.u32[..8191],
|
||||
|
||||
// read_from return value. The read_from method effectively returns a
|
||||
// base.u32 to show how decode should continue after calling write_to. That
|
||||
@@ -48,7 +48,7 @@ pub struct decoder?(
|
||||
// table in this decoder. See std/lzw/README.md for more detail.
|
||||
lm1s array[4096] base.u16[..4095],
|
||||
|
||||
// output[:flush_j] is the buffered output, connecting read_from with
|
||||
// output[:output_wi] is the buffered output, connecting read_from with
|
||||
// write_to and flush.
|
||||
output array[8192 + 7] base.u8,
|
||||
)
|
||||
@@ -70,7 +70,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
this.width = this.literal_width + 1
|
||||
this.bits = 0
|
||||
this.n_bits = 0
|
||||
this.flush_j = 0
|
||||
this.output_wi = 0
|
||||
var i base.u32[..8191]
|
||||
while i < this.clear_code {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c:this.clear_code)
|
||||
@@ -82,7 +82,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
while true {
|
||||
this.read_from!(src:args.src)
|
||||
|
||||
if this.flush_j > 0 {
|
||||
if this.output_wi > 0 {
|
||||
this.write_to!??(dst:args.dst)
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
var width base.u32[..12] = this.width
|
||||
var bits base.u32 = this.bits
|
||||
var n_bits base.u32[..31] = this.n_bits
|
||||
var j base.u32[..8191] = this.flush_j
|
||||
var output_wi base.u32[..8191] = this.output_wi
|
||||
|
||||
while true {
|
||||
if n_bits < width {
|
||||
@@ -152,8 +152,8 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
|
||||
if code < clear_code {
|
||||
assert code < 256 via "a < b: a < c; c <= b"(c:clear_code)
|
||||
this.output[j] = code as base.u8
|
||||
j = (j + 1) & 8191
|
||||
this.output[output_wi] = code as base.u8
|
||||
output_wi = (output_wi + 1) & 8191
|
||||
if save_code <= 4095 {
|
||||
var lm1_a base.u16[..4095] = (this.lm1s[prev_code] + 1) & 4095
|
||||
this.lm1s[save_code] = lm1_a
|
||||
@@ -189,17 +189,17 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
c = prev_code
|
||||
}
|
||||
|
||||
// Letting old_j and new_j denote the values of j before and after
|
||||
// these two lines of code, the decoded bytes will be written to
|
||||
// output[old_j:new_j]. They will be written back-to-front, 8 bytes
|
||||
// at a time, starting by writing output[o:o + 8], which will
|
||||
// contain output[new_j - 1].
|
||||
// Letting old_wi and new_wi denote the values of output_wi before
|
||||
// and after these two lines of code, the decoded bytes will be
|
||||
// written to output[old_wi:new_wi]. They will be written
|
||||
// back-to-front, 8 bytes at a time, starting by writing
|
||||
// output[o:o + 8], which will contain output[new_wi - 1].
|
||||
//
|
||||
// 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.lm1s[c] as base.u32) & 0xFFFFFFF8)) & 8191
|
||||
j = (j + 1 + (this.lm1s[c] as base.u32)) & 8191
|
||||
// be written to output[old_wi:new_wi + 1].
|
||||
var o base.u32[..8191] = (output_wi + ((this.lm1s[c] as base.u32) & 0xFFFFFFF8)) & 8191
|
||||
output_wi = (output_wi + 1 + (this.lm1s[c] as base.u32)) & 8191
|
||||
|
||||
var steps base.u32 = (this.lm1s[c] as base.u32) >> 3
|
||||
while true {
|
||||
@@ -223,8 +223,8 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
var first_byte base.u8 = this.suffixes[c][0]
|
||||
|
||||
if code == save_code {
|
||||
this.output[j] = first_byte
|
||||
j = (j + 1) & 8191
|
||||
this.output[output_wi] = first_byte
|
||||
output_wi = (output_wi + 1) & 8191
|
||||
}
|
||||
|
||||
if save_code <= 4095 {
|
||||
@@ -255,8 +255,8 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
// Flush the output if it could be too full to contain the entire
|
||||
// decoding of the next code. The longest possible decoding is slightly
|
||||
// less than 4096 and output's length is 8192, so a conservative
|
||||
// threshold is ensuring that j <= 4095.
|
||||
if j > 4095 {
|
||||
// threshold is ensuring that output_wi <= 4095.
|
||||
if output_wi > 4095 {
|
||||
this.read_from_return_value = 1
|
||||
break
|
||||
}
|
||||
@@ -281,19 +281,19 @@ pri func decoder.read_from!(src base.io_reader) {
|
||||
this.width = width
|
||||
this.bits = bits
|
||||
this.n_bits = n_bits
|
||||
this.flush_j = j
|
||||
this.output_wi = output_wi
|
||||
}
|
||||
|
||||
pri func decoder.write_to!??(dst base.io_writer) {
|
||||
var i base.u32[..8191]
|
||||
while this.flush_j > 0 {
|
||||
if i > this.flush_j {
|
||||
while this.output_wi > 0 {
|
||||
if i > this.output_wi {
|
||||
return "?internal error: inconsistent I/O"
|
||||
}
|
||||
var s slice base.u8 = this.output[i:this.flush_j]
|
||||
var s slice base.u8 = this.output[i:this.output_wi]
|
||||
var n base.u64 = args.dst.copy_from_slice!(s:s)
|
||||
if n == s.length() {
|
||||
this.flush_j = 0
|
||||
this.output_wi = 0
|
||||
return ok
|
||||
}
|
||||
i = (i + ((n & 8191) as base.u32)) & 8191
|
||||
@@ -306,7 +306,7 @@ pri func decoder.write_to!??(dst base.io_writer) {
|
||||
// without regressing benchmarks.
|
||||
|
||||
pub func decoder.flush!() slice base.u8 {
|
||||
var s slice base.u8 = this.output[:this.flush_j]
|
||||
this.flush_j = 0
|
||||
var s slice base.u8 = this.output[:this.output_wi]
|
||||
this.output_wi = 0
|
||||
return s
|
||||
}
|
||||
Reference in new issue
Block a user