Files
wuffs/std/gif/decode_lzw.puffs
T
2017-06-02 10:57:56 +10:00

43 lines
850 B
Plaintext

use "std/io"
pub struct lzw_decoder?(
literal_width u32[2..8] = 8,
stack[4096] u8,
suffixes[4096] u8,
prefixes[4096] u16,
)
pub func lzw_decoder.decode?(dst ptr io.buf1, src ptr io.buf1, src_final bool)() {
var bits u32
var n_bits u32
// TODO: set clear_code, end_code, etc.
var width u32[..12] = this.literal_width + 1
// TODO: implement.
while true,
pre n_bits < 8,
{
assert n_bits < (width + 8) via "a < (b + c): a < c; 0 <= b"()
while n_bits < width,
inv n_bits < (width + 8),
post n_bits >= width,
{
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
bits |= 0 // TODO.
n_bits += 8
}
// TODO: var code u32[..4095] = bits.low_bits(width)
bits >>= width
// TODO: implement.
break
// TODO: process n_bits further so that (n_bits < 8) and remove this
// temporary hack.
n_bits = 0
}
}