mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Rename the implicit in variable to args
This commit is contained in:
1 parent
58ded30954
commit
ca06083f8a
19 files changed
+254
-252
No files matched your search
@@ -84,10 +84,10 @@ func (g *gen) writeBuiltinIO(b *buffer, recv *a.Expr, method t.ID, args []*a.Nod
|
||||
p0, p1 := "", ""
|
||||
// TODO: don't hard-code these.
|
||||
switch recv.Str(g.tm) {
|
||||
case "in.dst":
|
||||
case "args.dst":
|
||||
p0 = "iobounds1_dst"
|
||||
p1 = "ioptr_dst"
|
||||
case "in.src":
|
||||
case "args.src":
|
||||
p0 = "iobounds1_src"
|
||||
p1 = "ioptr_src"
|
||||
case "w":
|
||||
@@ -190,7 +190,7 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), rp, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: don't assume that the last argument is "in.src".
|
||||
// TODO: don't assume that the last argument is "args.src".
|
||||
b.printf(", &ioptr_src, iobounds1_src)")
|
||||
return nil
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
||||
|
||||
case t.IDDot:
|
||||
lhs := n.LHS().AsExpr()
|
||||
if lhs.Ident() == t.IDIn {
|
||||
if lhs.Ident() == t.IDArgs {
|
||||
b.writes(aPrefix)
|
||||
b.writes(n.Ident().Str(g.tm))
|
||||
return nil
|
||||
|
||||
@@ -44,7 +44,7 @@ func (g *gen) needDerivedVar(name t.ID) bool {
|
||||
return nil
|
||||
}
|
||||
q = q.LHS().AsExpr()
|
||||
if q.Operator() != 0 || q.Ident() != t.IDIn {
|
||||
if q.Operator() != 0 || q.Ident() != t.IDArgs {
|
||||
return nil
|
||||
}
|
||||
return errNeedDerivedVar
|
||||
@@ -81,7 +81,7 @@ func (g *gen) findDerivedVars() {
|
||||
|
||||
func (g *gen) writeLoadDerivedVar(b *buffer, hack string, name t.ID, typ *a.TypeExpr, header bool) error {
|
||||
// TODO: remove this hack. We're picking up the wrong name for "src:r,
|
||||
// dummy:in.src".
|
||||
// dummy:args.src".
|
||||
if name.Str(g.tm) == "dummy" {
|
||||
name = g.tm.ByName("src")
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, hack string, name t.ID, typ *a.Type
|
||||
|
||||
func (g *gen) writeSaveDerivedVar(b *buffer, hack string, name t.ID, typ *a.TypeExpr) error {
|
||||
// TODO: remove this hack. We're picking up the wrong name for "src:r,
|
||||
// dummy:in.src".
|
||||
// dummy:args.src".
|
||||
if name.Str(g.tm) == "dummy" {
|
||||
name = g.tm.ByName("src")
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (g *gen) writeLoadExprDerivedVars(b *buffer, n *a.Expr) error {
|
||||
o := o.AsArg()
|
||||
// TODO: don't hard-code these.
|
||||
hack := ""
|
||||
if s := o.Value().Str(g.tm); s != "in.dst" && s != "in.src" && s != "w" {
|
||||
if s := o.Value().Str(g.tm); s != "args.dst" && s != "args.src" && s != "w" {
|
||||
continue
|
||||
} else if s == "w" {
|
||||
hack = "w"
|
||||
@@ -208,7 +208,7 @@ func (g *gen) writeSaveExprDerivedVars(b *buffer, n *a.Expr) error {
|
||||
o := o.AsArg()
|
||||
// TODO: don't hard-code these.
|
||||
hack := ""
|
||||
if s := o.Value().Str(g.tm); s != "in.dst" && s != "in.src" && s != "w" {
|
||||
if s := o.Value().Str(g.tm); s != "args.dst" && s != "args.src" && s != "w" {
|
||||
continue
|
||||
} else if s == "w" {
|
||||
hack = "w"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
- Added a `use` keyword.
|
||||
- Added a `yield` keyword.
|
||||
- Changed func out-type from struct to bare type.
|
||||
- Renamed the implicit `in` variable to `args`.
|
||||
- Added `std/adler32`, `std/crc32` and `std/gzip`.
|
||||
- Spun `std/lzw` out of `std/gif`.
|
||||
- Spun `std/zlib` out of `std/flate`.
|
||||
|
||||
@@ -196,9 +196,9 @@ loop:
|
||||
}
|
||||
// o is a yield statement.
|
||||
//
|
||||
// Drop any facts involving in or this.
|
||||
// Drop any facts involving args or this.
|
||||
if err := q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
||||
if x.Mentions(exprIn) || x.Mentions(exprThis) {
|
||||
if x.Mentions(exprArgs) || x.Mentions(exprThis) {
|
||||
return nil, nil
|
||||
}
|
||||
return x, nil
|
||||
@@ -857,8 +857,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (a.Bounds, error) {
|
||||
return a.Bounds{}, err
|
||||
}
|
||||
|
||||
// TODO: delete this hack that only matches "in".
|
||||
if n.LHS().AsExpr().Ident() == t.IDIn {
|
||||
// TODO: delete this hack that only matches "args".
|
||||
if n.LHS().AsExpr().Ident() == t.IDArgs {
|
||||
for _, o := range q.astFunc.In().Fields() {
|
||||
o := o.AsField()
|
||||
if o.Name() == n.Ident() {
|
||||
|
||||
+2
-2
@@ -418,7 +418,7 @@ func (c *Checker) checkStructDecl(node *a.Node) error {
|
||||
setPlaceholderMBoundsMType(n.AsNode())
|
||||
|
||||
// A struct declaration implies a reset method.
|
||||
in := a.NewStruct(0, n.Filename(), n.Line(), t.IDIn, nil)
|
||||
in := a.NewStruct(0, n.Filename(), n.Line(), t.IDArgs, nil)
|
||||
f := a.NewFunc(0, n.Filename(), n.Line(), qid[1], t.IDReset, in, nil, nil, nil)
|
||||
if qid[0] != 0 {
|
||||
f.AsNode().AsRaw().SetPackage(c.tm, qid[0])
|
||||
@@ -548,7 +548,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
|
||||
inTyp.AsNode().SetMType(typeExprTypeExpr)
|
||||
|
||||
localVars := typeMap{
|
||||
t.IDIn: inTyp,
|
||||
t.IDArgs: inTyp,
|
||||
}
|
||||
if qqid[1] != 0 {
|
||||
if _, ok := c.structs[t.QID{qqid[0], qqid[1]}]; !ok {
|
||||
|
||||
@@ -27,9 +27,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
exprIn = a.NewExpr(0, 0, 0, t.IDIn, nil, nil, nil, nil)
|
||||
exprThis = a.NewExpr(0, 0, 0, t.IDThis, nil, nil, nil, nil)
|
||||
exprArgs = a.NewExpr(0, 0, 0, t.IDArgs, nil, nil, nil, nil)
|
||||
exprNullptr = a.NewExpr(0, 0, 0, t.IDNullptr, nil, nil, nil, nil)
|
||||
exprThis = a.NewExpr(0, 0, 0, t.IDThis, nil, nil, nil, nil)
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
+1
-1
@@ -632,7 +632,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
s := (*a.Struct)(nil)
|
||||
if q.astFunc != nil && lQID[0] == 0 && lQID[1] == t.IDIn {
|
||||
if q.astFunc != nil && lQID[0] == 0 && lQID[1] == t.IDArgs {
|
||||
s = q.astFunc.In()
|
||||
}
|
||||
if s == nil {
|
||||
|
||||
+7
-7
@@ -194,13 +194,13 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
flags |= a.FlagsImpure | a.FlagsSuspendible
|
||||
p.src = p.src[1:]
|
||||
}
|
||||
inFields, err := p.parseList(t.IDCloseParen, (*parser).parseFieldNode)
|
||||
argFields, err := p.parseList(t.IDCloseParen, (*parser).parseFieldNode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outTyp := (*a.TypeExpr)(nil)
|
||||
out := (*a.TypeExpr)(nil)
|
||||
if p.peek1() != t.IDOpenCurly {
|
||||
outTyp, err = p.parseTypeExpr()
|
||||
out, err = p.parseTypeExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -225,8 +225,8 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
return nil, fmt.Errorf(`parse: expected (implicit) ";", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
in := a.NewStruct(0, p.filename, line, t.IDIn, inFields)
|
||||
return a.NewFunc(flags, p.filename, line, id0, id1, in, outTyp, asserts, body).AsNode(), nil
|
||||
in := a.NewStruct(0, p.filename, line, t.IDArgs, argFields)
|
||||
return a.NewFunc(flags, p.filename, line, id0, id1, in, out, asserts, body).AsNode(), nil
|
||||
|
||||
case t.IDError, t.IDSuspension:
|
||||
keyword := p.src[0].ID
|
||||
@@ -863,11 +863,11 @@ func (p *parser) parseIOBindExprNode() (*a.Node, error) {
|
||||
case 0:
|
||||
return e.AsNode(), nil
|
||||
case t.IDDot:
|
||||
if lhs := e.LHS().AsExpr(); lhs.Operator() == 0 && lhs.Ident() == t.IDIn {
|
||||
if lhs := e.LHS().AsExpr(); lhs.Operator() == 0 && lhs.Ident() == t.IDArgs {
|
||||
return e.AsNode(), nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf(`parse: expected "in.something", got %q at %s:%d`, e.Str(p.tm), p.filename, p.line())
|
||||
return nil, fmt.Errorf(`parse: expected "args.something", got %q at %s:%d`, e.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
|
||||
func (p *parser) parseIterateVarNode() (*a.Node, error) {
|
||||
|
||||
+5
-5
@@ -443,9 +443,9 @@ const (
|
||||
IDU32 = ID(0x126)
|
||||
IDU64 = ID(0x127)
|
||||
|
||||
IDThis = ID(0x130)
|
||||
IDIn = ID(0x131)
|
||||
IDBase = ID(0x132)
|
||||
IDArgs = ID(0x130)
|
||||
IDBase = ID(0x131)
|
||||
IDThis = ID(0x132)
|
||||
|
||||
// TODO Read/Write 24 bits? It might be useful for RGB triples.
|
||||
|
||||
@@ -732,9 +732,9 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDU32: "u32",
|
||||
IDU64: "u64",
|
||||
|
||||
IDThis: "this",
|
||||
IDIn: "in",
|
||||
IDArgs: "args",
|
||||
IDBase: "base",
|
||||
IDThis: "this",
|
||||
|
||||
IDUndoByte: "undo_byte",
|
||||
IDReadU8: "read_u8",
|
||||
|
||||
@@ -32,14 +32,14 @@ pub func hasher.update!(x slice base.u8) base.u32 {
|
||||
var s1 base.u32 = this.state.low_bits(n:16)
|
||||
var s2 base.u32 = this.state.high_bits(n:16)
|
||||
|
||||
while in.x.length() > 0 {
|
||||
while args.x.length() > 0 {
|
||||
var remaining slice base.u8
|
||||
if in.x.length() > 5552 {
|
||||
remaining = in.x[5552:]
|
||||
in.x = in.x[:5552]
|
||||
if args.x.length() > 5552 {
|
||||
remaining = args.x[5552:]
|
||||
args.x = args.x[:5552]
|
||||
}
|
||||
|
||||
iterate (p slice base.u8 =: in.x)(length:1, unroll:8) {
|
||||
iterate (p slice base.u8 =: args.x)(length:1, unroll:8) {
|
||||
s1 ~mod+= p[0] as base.u32
|
||||
s2 ~mod+= s1
|
||||
}
|
||||
@@ -47,7 +47,7 @@ pub func hasher.update!(x slice base.u8) base.u32 {
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
|
||||
in.x = remaining
|
||||
args.x = remaining
|
||||
}
|
||||
|
||||
// TODO: check that you can't assign to this.foo unless the method's effect
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct ieee_hasher?(
|
||||
pub func ieee_hasher.update!(x slice base.u8) base.u32 {
|
||||
var s base.u32 = 0xFFFFFFFF ^ this.state
|
||||
|
||||
iterate (p slice base.u8 =: in.x)(length:8, unroll:8) {
|
||||
iterate (p slice base.u8 =: args.x)(length:8, unroll:8) {
|
||||
// TODO: explain the slicing-by-8 algorithm.
|
||||
s ^= ((p[0] as base.u32) << 0) |
|
||||
((p[1] as base.u32) << 8) |
|
||||
|
||||
@@ -113,7 +113,8 @@ pub struct decoder?(
|
||||
|
||||
// code_lengths is used to pass out-of-band data to init_huff.
|
||||
//
|
||||
// code_lengths[in.n_codes0 + i] holds the number of bits in the i'th code.
|
||||
// code_lengths[args.n_codes0 + i] holds the number of bits in the i'th
|
||||
// code.
|
||||
code_lengths array[320] base.u8[..15],
|
||||
|
||||
// end_of_block is whether decode_huffman_xxx saw an end-of-block code.
|
||||
@@ -124,15 +125,15 @@ pub struct decoder?(
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
while true {
|
||||
in.dst.set_mark!()
|
||||
var z base.status = try this.decode_blocks?(dst:in.dst, src:in.src)
|
||||
args.dst.set_mark!()
|
||||
var z base.status = try this.decode_blocks?(dst:args.dst, src:args.src)
|
||||
if not z.is_suspension() {
|
||||
return z
|
||||
}
|
||||
// TODO: should "since_mark" be "since_mark!", as the return value lets
|
||||
// you modify the state of in.dst, so future mutations (via the slice)
|
||||
// can change the veracity of any in.dst assertions?
|
||||
var written slice base.u8 = in.dst.since_mark()
|
||||
// you modify the state of args.dst, so future mutations (via the
|
||||
// slice) can change the veracity of any args.dst assertions?
|
||||
var written slice base.u8 = args.dst.since_mark()
|
||||
// Append written, the decoded output, to the history ringbuffer.
|
||||
if written.length() >= 0x8000 {
|
||||
// If written is longer than the ringbuffer, we can ignore the
|
||||
@@ -180,7 +181,7 @@ pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
|
||||
while this.n_bits < 3,
|
||||
post this.n_bits >= 3,
|
||||
{
|
||||
this.bits |= (in.src.read_u8?() as base.u32) << this.n_bits
|
||||
this.bits |= (args.src.read_u8?() as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
}
|
||||
final = this.bits & 0x01
|
||||
@@ -189,22 +190,22 @@ pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
|
||||
this.n_bits -= 3
|
||||
|
||||
if type == 0 {
|
||||
this.decode_uncompressed?(dst:in.dst, src:in.src)
|
||||
this.decode_uncompressed?(dst:args.dst, src:args.src)
|
||||
continue
|
||||
} else if type == 1 {
|
||||
this.init_fixed_huffman?()
|
||||
} else if type == 2 {
|
||||
this.init_dynamic_huffman?(src:in.src)
|
||||
this.init_dynamic_huffman?(src:args.src)
|
||||
} else {
|
||||
return error "bad block"
|
||||
}
|
||||
|
||||
this.end_of_block = false
|
||||
this.decode_huffman_fast?(dst:in.dst, src:in.src)
|
||||
this.decode_huffman_fast?(dst:args.dst, src:args.src)
|
||||
if this.end_of_block {
|
||||
continue
|
||||
}
|
||||
this.decode_huffman_slow?(dst:in.dst, src:in.src)
|
||||
this.decode_huffman_slow?(dst:args.dst, src:args.src)
|
||||
if this.end_of_block {
|
||||
continue
|
||||
}
|
||||
@@ -224,18 +225,18 @@ pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
|
||||
this.n_bits = 0
|
||||
this.bits = 0
|
||||
|
||||
var length base.u32 = in.src.read_u32le?()
|
||||
var length base.u32 = args.src.read_u32le?()
|
||||
if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
|
||||
return error "inconsistent stored block length"
|
||||
}
|
||||
length = length.low_bits(n:16)
|
||||
while true {
|
||||
var n_copied base.u32 = in.dst.copy_n_from_reader!(n:length, r:in.src)
|
||||
var n_copied base.u32 = args.dst.copy_n_from_reader!(n:length, r:args.src)
|
||||
if length <= n_copied {
|
||||
return
|
||||
}
|
||||
length -= n_copied
|
||||
if in.dst.available() == 0 {
|
||||
if args.dst.available() == 0 {
|
||||
// TODO: "closed for writes" instead?
|
||||
yield suspension "short write"
|
||||
} else {
|
||||
@@ -278,7 +279,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
while n_bits < 14,
|
||||
post n_bits >= 14,
|
||||
{
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
var n_lit base.u32[257..288] = bits.low_bits(n:5) + 257
|
||||
@@ -302,7 +303,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
inv i < n_clen,
|
||||
post n_bits >= 3,
|
||||
{
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
assert i < 19 via "a < b: a < c; c <= b"(c:n_clen)
|
||||
@@ -336,7 +337,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
break
|
||||
}
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
// For H-CL, there should be no redirections and all symbols should be
|
||||
@@ -384,7 +385,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
post n_bits >= n_extra_bits,
|
||||
{
|
||||
assert n_bits < 7 via "a < b: a < c; c <= b"(c:n_extra_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
rep_count += bits.low_bits(n:n_extra_bits)
|
||||
@@ -457,9 +458,9 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
// - counts[5] = 2
|
||||
// - all other counts elements are 0.
|
||||
var counts array[16] base.u16[..320]
|
||||
var i base.u32 = in.n_codes0
|
||||
while i < in.n_codes1 {
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c:in.n_codes1)
|
||||
var i base.u32 = args.n_codes0
|
||||
while i < args.n_codes1 {
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
|
||||
// TODO: this if should be unnecessary. Have some way to assert that,
|
||||
// for all j, counts[j] <= i, and thus counts[j]++ will not overflow.
|
||||
if counts[this.code_lengths[i]] >= 320 {
|
||||
@@ -468,7 +469,7 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
counts[this.code_lengths[i]] += 1
|
||||
i += 1
|
||||
}
|
||||
if ((counts[0] as base.u32) + in.n_codes0) == in.n_codes1 {
|
||||
if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 {
|
||||
return error "no Huffman codes"
|
||||
}
|
||||
|
||||
@@ -542,20 +543,20 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
// - offsets[4] = 8, formerly 7
|
||||
// - offsets[5] = 10, formerly 8
|
||||
var symbols array[320] base.u16[..319]
|
||||
i = in.n_codes0
|
||||
while i < in.n_codes1,
|
||||
i = args.n_codes0
|
||||
while i < args.n_codes1,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c:in.n_codes1)
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
|
||||
// TODO: this if check should be unnecessary.
|
||||
if i < in.n_codes0 {
|
||||
if i < args.n_codes0 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
if this.code_lengths[i] != 0 {
|
||||
if offsets[this.code_lengths[i]] >= 320 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
symbols[offsets[this.code_lengths[i]]] = (i - in.n_codes0) as base.u16
|
||||
symbols[offsets[this.code_lengths[i]]] = (i - args.n_codes0) as base.u16
|
||||
offsets[this.code_lengths[i]] += 1
|
||||
}
|
||||
i += 1
|
||||
@@ -592,12 +593,12 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
max_cl -= 1
|
||||
}
|
||||
if max_cl <= 9 {
|
||||
this.n_huffs_bits[in.which] = max_cl
|
||||
this.n_huffs_bits[args.which] = max_cl
|
||||
} else {
|
||||
this.n_huffs_bits[in.which] = 9
|
||||
this.n_huffs_bits[args.which] = 9
|
||||
}
|
||||
|
||||
// Calculate this.huffs[in.which].
|
||||
// Calculate this.huffs[args.which].
|
||||
//
|
||||
// For the clcode example in this package's README.md:
|
||||
// - this.huffs[0][0b..000] = 0x80000003 (literal, symbols[0]=0x00, code_length=3)
|
||||
@@ -614,7 +615,7 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
if (n_symbols != (offsets[max_cl] as base.u32)) or (n_symbols != (offsets[15] as base.u32)) {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
if (in.n_codes0 + (symbols[0] as base.u32)) >= 320 {
|
||||
if (args.n_codes0 + (symbols[0] as base.u32)) >= 320 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
@@ -622,7 +623,7 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
if max_cl < 9 {
|
||||
initial_high_bits = (1 as base.u32) << max_cl
|
||||
}
|
||||
var prev_cl base.u32[..15] = this.code_lengths[in.n_codes0 + (symbols[0] as base.u32)] as base.u32
|
||||
var prev_cl base.u32[..15] = this.code_lengths[args.n_codes0 + (symbols[0] as base.u32)] as base.u32
|
||||
var prev_redirect_key base.u32 = 0xFFFFFFFF
|
||||
var top base.u32[..1234]
|
||||
var next_top base.u32[..1234] = 512
|
||||
@@ -634,10 +635,10 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
pre i < 288,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
if (in.n_codes0 + (symbols[i] as base.u32)) >= 320 {
|
||||
if (args.n_codes0 + (symbols[i] as base.u32)) >= 320 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
var cl base.u32[..15] = this.code_lengths[in.n_codes0 + (symbols[i] as base.u32)] as base.u32
|
||||
var cl base.u32[..15] = this.code_lengths[args.n_codes0 + (symbols[i] as base.u32)] as base.u32
|
||||
if cl > prev_cl {
|
||||
code <<= cl - prev_cl
|
||||
if code >= (1 << 15) {
|
||||
@@ -694,7 +695,7 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
next_top = top + ((1 as base.u32) << tmp)
|
||||
|
||||
redirect_key = (reverse8[redirect_key >> 1] as base.u32) | ((redirect_key & 1) << 8)
|
||||
this.huffs[in.which][redirect_key] = 0x10000009 | (top << 8) | (tmp << 4)
|
||||
this.huffs[args.which][redirect_key] = 0x10000009 | (top << 8) | (tmp << 4)
|
||||
}
|
||||
}
|
||||
if (key >= (1 << 9)) or (counts[prev_cl] <= 0) {
|
||||
@@ -709,13 +710,13 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
if symbol == 256 {
|
||||
// End-of-block.
|
||||
value = 0x20000000 | cl
|
||||
} else if (symbol < 256) and (in.which == 0) {
|
||||
} else if (symbol < 256) and (args.which == 0) {
|
||||
// Literal.
|
||||
value = 0x80000000 | (symbol << 8) | cl
|
||||
} else if symbol >= in.base_symbol {
|
||||
} else if symbol >= args.base_symbol {
|
||||
// Base number + extra bits.
|
||||
symbol -= in.base_symbol
|
||||
if in.which == 0 {
|
||||
symbol -= args.base_symbol
|
||||
if args.which == 0 {
|
||||
value = lcode_magic_numbers[symbol & 31] | cl
|
||||
} else {
|
||||
value = dcode_magic_numbers[symbol & 31] | cl
|
||||
@@ -738,7 +739,7 @@ pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_cod
|
||||
if (top + ((high_bits | reversed_key) & 511)) >= 1234 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
this.huffs[in.which][top + ((high_bits | reversed_key) & 511)] = value
|
||||
this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value
|
||||
}
|
||||
|
||||
i += 1
|
||||
|
||||
@@ -45,13 +45,13 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// For reading, strictly speaking, we only need 6 bytes (48 bits) of
|
||||
// available input, because the H-L length/literal code is up to 15 bits
|
||||
// plus up to 5 extra bits, the H-D distance code is up to 15 bits plus up
|
||||
// to 13 extra bits and 15 + 5 + 15 + 13 == 48. However, in.src.available()
|
||||
// assertions are made in terms of bytes, not bits.
|
||||
// to 13 extra bits and 15 + 5 + 15 + 13 == 48. However,
|
||||
// args.src.available() assertions are made in terms of bytes, not bits.
|
||||
//
|
||||
// In theory, we could write assertions that mixed bytes and bits, such as:
|
||||
//
|
||||
// assert ((in.src.available() >= 6) and (n_bits >= 5)) or
|
||||
// ((in.src.available() >= 4) and (n_bits >= 21))
|
||||
// assert ((args.src.available() >= 6) and (n_bits >= 5)) or
|
||||
// ((args.src.available() >= 4) and (n_bits >= 21))
|
||||
//
|
||||
// but that looks clumsy and makes the proofs more complicated. Instead, we
|
||||
// are conservative and work in terms of bytes only. In bytes, each code
|
||||
@@ -59,24 +59,24 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// for each. There are also up to 13 extra bits, or 2 bytes. Thus, each
|
||||
// code requires up to 2 + 2 + 2 == 6 bytes, and there are two codes (one
|
||||
// from H-L and one from H-D). Therefore, we check for at least 12 bytes.
|
||||
while:loop(in.dst.available() >= 258) and (in.src.available() >= 12) {
|
||||
while:loop(args.dst.available() >= 258) and (args.src.available() >= 12) {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
assert n_bits >= 15
|
||||
} else {
|
||||
assert in.src.available() >= 10
|
||||
assert args.src.available() >= 10
|
||||
}
|
||||
// These assertions are redundant, but are listed explicitly for
|
||||
// clarity. They must hold regardless of which branch was taken for the
|
||||
// if statement above.
|
||||
assert in.src.available() >= 10
|
||||
assert args.src.available() >= 10
|
||||
assert n_bits >= 15
|
||||
|
||||
// Decode an lcode symbol from H-L.
|
||||
@@ -87,11 +87,11 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
|
||||
if (table_entry >> 31) != 0 {
|
||||
// Literal.
|
||||
in.dst.write_fast_u8!(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
args.dst.write_fast_u8!(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
continue:loop
|
||||
} else if (table_entry >> 30) != 0 {
|
||||
// No-op; code continues past the if-else chain.
|
||||
assert in.src.available() >= 8
|
||||
assert args.src.available() >= 8
|
||||
} else if (table_entry >> 29) != 0 {
|
||||
// End of block.
|
||||
this.end_of_block = true
|
||||
@@ -102,18 +102,18 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
assert n_bits >= 15
|
||||
} else {
|
||||
assert in.src.available() >= 8
|
||||
assert args.src.available() >= 8
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert in.src.available() >= 8
|
||||
assert args.src.available() >= 8
|
||||
assert n_bits >= 15
|
||||
|
||||
var redir_top base.u32[..0xFFFF] = (table_entry >> 8) & 0xFFFF
|
||||
@@ -128,7 +128,7 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
|
||||
if (table_entry >> 31) != 0 {
|
||||
// Literal.
|
||||
in.dst.write_fast_u8!(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
args.dst.write_fast_u8!(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
continue:loop
|
||||
} else if (table_entry >> 30) != 0 {
|
||||
// No-op; code continues past the if-else chain.
|
||||
@@ -145,7 +145,7 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
}
|
||||
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert in.src.available() >= 8
|
||||
assert args.src.available() >= 8
|
||||
|
||||
} else if (table_entry >> 27) != 0 {
|
||||
return error "bad Huffman code"
|
||||
@@ -160,18 +160,18 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
assert n_bits >= 15
|
||||
} else {
|
||||
assert in.src.available() >= 6
|
||||
assert args.src.available() >= 6
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert in.src.available() >= 6
|
||||
assert args.src.available() >= 6
|
||||
assert n_bits >= 15
|
||||
|
||||
length = (length + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
@@ -179,7 +179,7 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
n_bits -= table_entry_n_bits
|
||||
|
||||
} else {
|
||||
assert in.src.available() >= 6
|
||||
assert args.src.available() >= 6
|
||||
}
|
||||
if length > 258 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
@@ -188,18 +188,18 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
assert n_bits >= 15
|
||||
} else {
|
||||
assert in.src.available() >= 4
|
||||
assert args.src.available() >= 4
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert in.src.available() >= 4
|
||||
assert args.src.available() >= 4
|
||||
assert n_bits >= 15
|
||||
|
||||
// Decode a dcode symbol from H-D.
|
||||
@@ -213,18 +213,18 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
assert n_bits >= 15
|
||||
} else {
|
||||
assert in.src.available() >= 2
|
||||
assert args.src.available() >= 2
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert in.src.available() >= 2
|
||||
assert args.src.available() >= 2
|
||||
assert n_bits >= 15
|
||||
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
@@ -237,7 +237,7 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
} else {
|
||||
assert in.src.available() >= 2
|
||||
assert args.src.available() >= 2
|
||||
}
|
||||
|
||||
// For H-D, all symbols should be base_number + extra_bits.
|
||||
@@ -260,11 +260,11 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
bits |= (in.src.peek_u8() as base.u32) << n_bits
|
||||
in.src.skip_fast!(actual:1, worst_case:1)
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
n_bits += 8
|
||||
assert n_bits >= 15
|
||||
}
|
||||
@@ -282,16 +282,16 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre length <= 258,
|
||||
pre in.dst.available() >= 258,
|
||||
pre args.dst.available() >= 258,
|
||||
{
|
||||
// Copy from this.history.
|
||||
if ((dist_minus_1 + 1) as base.u64) > in.dst.since_mark().length() {
|
||||
if ((dist_minus_1 + 1) as base.u64) > args.dst.since_mark().length() {
|
||||
// Set (hlen, hdist) to be the length-distance pair to copy
|
||||
// from this.history, and (length, distance) to be the
|
||||
// remaining length-distance pair to copy from in.dst.
|
||||
// remaining length-distance pair to copy from args.dst.
|
||||
var hlen base.u32[..0x7FFF]
|
||||
var hdist base.u32 =
|
||||
(((dist_minus_1 + 1) as base.u64) - in.dst.since_mark().length()) as base.u32
|
||||
(((dist_minus_1 + 1) as base.u64) - args.dst.since_mark().length()) as base.u32
|
||||
if length > hdist {
|
||||
assert hdist < length via "a < b: b > a"()
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c:length)
|
||||
@@ -318,69 +318,69 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// in.dst.available() is large enough.
|
||||
// args.dst.available() is large enough.
|
||||
//
|
||||
// The "while true { etc; break }" is a redundant version of
|
||||
// "etc", but its presence minimizes the diff between
|
||||
// decode_huffman_fast and decode_huffman_slow.
|
||||
while true,
|
||||
inv length <= 258,
|
||||
inv in.dst.available() >= 258,
|
||||
inv args.dst.available() >= 258,
|
||||
{
|
||||
// TODO: copy_from_slice32 should probably update the
|
||||
// "in.dst.available() >= 258" fact. It should certainly
|
||||
// "args.dst.available() >= 258" fact. It should certainly
|
||||
// invalidate any fact that was "<=" instead of ">=".
|
||||
n_copied = in.dst.copy_n_from_slice!(
|
||||
n_copied = args.dst.copy_n_from_slice!(
|
||||
n:hlen, s:this.history[hdist & 0x7FFF:])
|
||||
if hlen <= n_copied {
|
||||
break
|
||||
}
|
||||
hlen -= n_copied
|
||||
in.dst.copy_n_from_slice!(n:hlen, s:this.history[:])
|
||||
args.dst.copy_n_from_slice!(n:hlen, s:this.history[:])
|
||||
break
|
||||
}
|
||||
|
||||
if length == 0 {
|
||||
// No need to copy from in.dst.
|
||||
// No need to copy from args.dst.
|
||||
continue:loop
|
||||
}
|
||||
|
||||
if ((dist_minus_1 + 1) as base.u64) > in.dst.since_mark().length() {
|
||||
if ((dist_minus_1 + 1) as base.u64) > args.dst.since_mark().length() {
|
||||
return error "internal error: inconsistent distance"
|
||||
}
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert length <= 258
|
||||
assert ((dist_minus_1 + 1) as base.u64) <= in.dst.since_mark().length()
|
||||
assert in.dst.available() >= 258
|
||||
assert ((dist_minus_1 + 1) as base.u64) <= args.dst.since_mark().length()
|
||||
assert args.dst.available() >= 258
|
||||
|
||||
// We can therefore prove:
|
||||
assert (dist_minus_1 + 1) > 0
|
||||
assert (length as base.u64) <= 258
|
||||
assert (length as base.u64) <= in.dst.available() via "a <= b: a <= c; c <= b"(c:258)
|
||||
assert (length as base.u64) <= args.dst.available() via "a <= b: a <= c; c <= b"(c:258)
|
||||
|
||||
// Copy from in.dst.
|
||||
in.dst.copy_n_from_history_fast!(n:length, distance:(dist_minus_1 + 1))
|
||||
// Copy from args.dst.
|
||||
args.dst.copy_n_from_history_fast!(n:length, distance:(dist_minus_1 + 1))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure n_bits < 8 by rewindng in.src, if we loaded too many of its bytes
|
||||
// into the bits variable.
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
//
|
||||
// Note that we can unconditionally call undo_read (without resulting in an
|
||||
// "invalid I/O operation" error code) only because this whole function can
|
||||
// never suspend, as all of its I/O operations were checked beforehand for
|
||||
// sufficient buffer space. Otherwise, resuming from the suspension could
|
||||
// mean that the (possibly different) in.src is no longer rewindable, even
|
||||
// if conceptually, this function was responsible for reading the bytes we
|
||||
// want to rewind.
|
||||
// mean that the (possibly different) args.src is no longer rewindable,
|
||||
// even if conceptually, this function was responsible for reading the
|
||||
// bytes we want to rewind.
|
||||
while n_bits >= 8,
|
||||
post n_bits < 8,
|
||||
{
|
||||
n_bits -= 8
|
||||
if in.src.can_undo_byte() {
|
||||
in.src.undo_byte!()
|
||||
if args.src.can_undo_byte() {
|
||||
args.src.undo_byte!()
|
||||
} else {
|
||||
return error "internal error: inconsistent I/O"
|
||||
}
|
||||
|
||||
@@ -41,13 +41,13 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
break
|
||||
}
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
|
||||
if (table_entry >> 31) != 0 {
|
||||
// Literal.
|
||||
in.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
continue:loop
|
||||
} else if (table_entry >> 30) != 0 {
|
||||
// No-op; code continues past the if-else chain.
|
||||
@@ -71,13 +71,13 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
break
|
||||
}
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
|
||||
if (table_entry >> 31) != 0 {
|
||||
// Literal.
|
||||
in.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||
continue:loop
|
||||
} else if (table_entry >> 30) != 0 {
|
||||
// No-op; code continues past the if-else chain.
|
||||
@@ -107,7 +107,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
post n_bits >= table_entry_n_bits,
|
||||
{
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
length = (length + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
@@ -125,7 +125,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
break
|
||||
}
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
// Check for a redirect.
|
||||
@@ -144,7 +144,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
break
|
||||
}
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
post n_bits >= table_entry_n_bits,
|
||||
{
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
dist_minus_1 = (dist_minus_1 + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
@@ -181,13 +181,13 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
var n_copied base.u32
|
||||
while true {
|
||||
// Copy from this.history.
|
||||
if ((dist_minus_1 + 1) as base.u64) > in.dst.since_mark().length() {
|
||||
if ((dist_minus_1 + 1) as base.u64) > args.dst.since_mark().length() {
|
||||
// Set (hlen, hdist) to be the length-distance pair to copy
|
||||
// from this.history, and (length, distance) to be the
|
||||
// remaining length-distance pair to copy from in.dst.
|
||||
// remaining length-distance pair to copy from args.dst.
|
||||
var hlen base.u32[..0x7FFF]
|
||||
var hdist base.u32 =
|
||||
(((dist_minus_1 + 1) as base.u64) - in.dst.since_mark().length()) as base.u32
|
||||
(((dist_minus_1 + 1) as base.u64) - args.dst.since_mark().length()) as base.u32
|
||||
if length > hdist {
|
||||
assert hdist < length via "a < b: b > a"()
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c:length)
|
||||
@@ -206,7 +206,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
while true {
|
||||
n_copied = in.dst.copy_n_from_slice!(
|
||||
n_copied = args.dst.copy_n_from_slice!(
|
||||
n:hlen, s:this.history[hdist & 0x7FFF:])
|
||||
if hlen <= n_copied {
|
||||
hlen = 0
|
||||
@@ -226,7 +226,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
// Copy from the start of this.history, if we wrapped around.
|
||||
if hlen > 0 {
|
||||
while true {
|
||||
n_copied = in.dst.copy_n_from_slice!(
|
||||
n_copied = args.dst.copy_n_from_slice!(
|
||||
n:hlen, s:this.history[hdist & 0x7FFF:])
|
||||
if hlen <= n_copied {
|
||||
hlen = 0
|
||||
@@ -240,13 +240,13 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
}
|
||||
|
||||
if length == 0 {
|
||||
// No need to copy from in.dst.
|
||||
// No need to copy from args.dst.
|
||||
continue:loop
|
||||
}
|
||||
}
|
||||
|
||||
// Copy from in.dst.
|
||||
n_copied = in.dst.copy_n_from_history!(n:length, distance:(dist_minus_1 + 1))
|
||||
// Copy from args.dst.
|
||||
n_copied = args.dst.copy_n_from_history!(n:length, distance:(dist_minus_1 + 1))
|
||||
if length <= n_copied {
|
||||
length = 0
|
||||
break
|
||||
|
||||
+64
-64
@@ -70,8 +70,8 @@ pub struct decoder?(
|
||||
//
|
||||
// Where:
|
||||
// - F is decode_frame, implicit means skip_frame
|
||||
// - FC is decode_frame_config, implicit means nullptr in.dst
|
||||
// - IC is decode_image_config, implicit means nullptr in.dst
|
||||
// - FC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - IC is decode_image_config, implicit means nullptr args.dst
|
||||
call_sequence base.u8,
|
||||
|
||||
end_of_data base.bool,
|
||||
@@ -126,9 +126,9 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
|
||||
if this.call_sequence >= 1 {
|
||||
return error "invalid call sequence"
|
||||
}
|
||||
this.decode_header?(src:in.src)
|
||||
this.decode_lsd?(src:in.src)
|
||||
this.decode_up_to_id_part1?(src:in.src)
|
||||
this.decode_header?(src:args.src)
|
||||
this.decode_lsd?(src:args.src)
|
||||
this.decode_up_to_id_part1?(src:args.src)
|
||||
|
||||
// TODO: if this.end_of_data, return an error and/or set dst to zero?
|
||||
|
||||
@@ -144,12 +144,12 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
|
||||
(this.frame_rect_y1 == this.height) and
|
||||
(this.has_full_palette)
|
||||
|
||||
if in.dst != nullptr {
|
||||
if args.dst != nullptr {
|
||||
// TODO: rename initialize to set?
|
||||
//
|
||||
// TODO: a Wuffs (not just C) name for the
|
||||
// WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED magic pixfmt constant.
|
||||
in.dst.initialize!(pixfmt:0x22088888, pixsub:0,
|
||||
args.dst.initialize!(pixfmt:0x22088888, pixsub:0,
|
||||
width:this.width, height:this.height, num_loops:num_loops, first_frame_is_opaque:ffio)
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ pub func decoder.work_buffer_size() base.range_ii_u64 {
|
||||
pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_reader) {
|
||||
if not this.end_of_data {
|
||||
if this.call_sequence == 0 {
|
||||
this.decode_image_config?(dst:nullptr, src:in.src)
|
||||
this.decode_image_config?(dst:nullptr, src:args.src)
|
||||
} else if this.call_sequence != 1 {
|
||||
if this.call_sequence == 2 {
|
||||
this.skip_frame?(src:in.src)
|
||||
this.skip_frame?(src:args.src)
|
||||
}
|
||||
this.decode_up_to_id_part1?(src:in.src)
|
||||
this.decode_up_to_id_part1?(src:args.src)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,8 +201,8 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
|
||||
this.previous_use_global_palette =
|
||||
not (this.use_local_palette or this.gc_has_transparent_index)
|
||||
|
||||
if in.dst != nullptr {
|
||||
in.dst.update!(bounds:this.util.make_rect_ie_u32(
|
||||
if args.dst != nullptr {
|
||||
args.dst.update!(bounds:this.util.make_rect_ie_u32(
|
||||
min_incl_x:this.frame_rect_x0,
|
||||
min_incl_y:this.frame_rect_y0,
|
||||
max_excl_x:this.frame_rect_x1,
|
||||
@@ -216,8 +216,8 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
|
||||
}
|
||||
|
||||
pri func decoder.skip_frame?(src base.io_reader) {
|
||||
var lw base.u8 = in.src.read_u8?()
|
||||
this.skip_blocks?(src:in.src)
|
||||
var lw base.u8 = args.src.read_u8?()
|
||||
this.skip_blocks?(src:args.src)
|
||||
|
||||
// The Image Descriptor is mandatory, but the Graphic Control extension is
|
||||
// optional. Reset the GC related fields for the next decode_frame call.
|
||||
@@ -234,10 +234,10 @@ pri func decoder.skip_frame?(src base.io_reader) {
|
||||
// TODO: honor pixbuf_origin_x and pixbuf_origin_y args.
|
||||
pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u32, pixbuf_origin_y base.u32, src base.io_reader, work_buffer slice base.u8) {
|
||||
if this.call_sequence != 2 {
|
||||
this.decode_frame_config?(dst:nullptr, src:in.src)
|
||||
this.decode_frame_config?(dst:nullptr, src:args.src)
|
||||
}
|
||||
|
||||
this.decode_id_part1?(dst:in.dst, src:in.src)
|
||||
this.decode_id_part1?(dst:args.dst, src:args.src)
|
||||
|
||||
// The Image Descriptor is mandatory, but the Graphic Control extension is
|
||||
// optional. Reset the GC related fields for the next decode_frame call.
|
||||
@@ -253,11 +253,11 @@ pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u
|
||||
|
||||
pri func decoder.decode_up_to_id_part1?(src base.io_reader) {
|
||||
while true {
|
||||
var block_type base.u8 = in.src.read_u8?()
|
||||
var block_type base.u8 = args.src.read_u8?()
|
||||
if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer".
|
||||
this.decode_extension?(src:in.src)
|
||||
this.decode_extension?(src:args.src)
|
||||
} else if block_type == 0x2C { // The spec calls 0x2C the "Image Separator".
|
||||
this.decode_id_part0?(src:in.src)
|
||||
this.decode_id_part0?(src:args.src)
|
||||
break
|
||||
} else if block_type == 0x3B { // The spec calls 0x3B the "Trailer".
|
||||
this.end_of_data = true
|
||||
@@ -275,7 +275,7 @@ pri func decoder.decode_header?(src base.io_reader) {
|
||||
var c array[6] base.u8
|
||||
var i base.u32
|
||||
while i < 6 {
|
||||
c[i] = in.src.read_u8?()
|
||||
c[i] = args.src.read_u8?()
|
||||
i += 1
|
||||
}
|
||||
if (c[0] != 0x47) or (c[1] != 0x49) or (c[2] != 0x46) or (c[3] != 0x38) or
|
||||
@@ -288,11 +288,11 @@ pri func decoder.decode_header?(src base.io_reader) {
|
||||
//
|
||||
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
||||
pri func decoder.decode_lsd?(src base.io_reader) {
|
||||
this.width = in.src.read_u16le?() as base.u32
|
||||
this.height = in.src.read_u16le?() as base.u32
|
||||
var flags base.u8 = in.src.read_u8?()
|
||||
this.width = args.src.read_u16le?() as base.u32
|
||||
this.height = args.src.read_u16le?() as base.u32
|
||||
var flags base.u8 = args.src.read_u8?()
|
||||
// Ignore the Background Color Index and Pixel Aspect Ratio bytes.
|
||||
in.src.skip?(n:2)
|
||||
args.src.skip?(n:2)
|
||||
|
||||
// Read the optional Global Color Table.
|
||||
if (flags & 0x80) != 0 {
|
||||
@@ -302,7 +302,7 @@ pri func decoder.decode_lsd?(src base.io_reader) {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
|
||||
// Convert from RGB (in memory order) to ARGB (in native u32 order)
|
||||
// to BGRA (in memory order).
|
||||
var argb base.u32 = in.src.read_u24be?() | 0xFF000000
|
||||
var argb base.u32 = args.src.read_u24be?() | 0xFF000000
|
||||
this.palettes[0][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
|
||||
this.palettes[0][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
|
||||
this.palettes[0][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
@@ -330,26 +330,26 @@ pri func decoder.decode_lsd?(src base.io_reader) {
|
||||
// - section 25 "Plain Text Extension" on page 18.
|
||||
// - section 26 "Application Extension" on page 21.
|
||||
pri func decoder.decode_extension?(src base.io_reader) {
|
||||
var label base.u8 = in.src.read_u8?()
|
||||
var label base.u8 = args.src.read_u8?()
|
||||
if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label".
|
||||
this.decode_gc?(src:in.src)
|
||||
this.decode_gc?(src:args.src)
|
||||
return
|
||||
} else if label == 0xFF { // The spec calls 0xFF the "Application Extension Label".
|
||||
this.decode_ae?(src:in.src)
|
||||
this.decode_ae?(src:args.src)
|
||||
return
|
||||
}
|
||||
// We skip over all other extensions, including 0x01 "Plain Text Label" and
|
||||
// 0xFE "Comment Label".
|
||||
this.skip_blocks?(src:in.src)
|
||||
this.skip_blocks?(src:args.src)
|
||||
}
|
||||
|
||||
pri func decoder.skip_blocks?(src base.io_reader) {
|
||||
while true {
|
||||
var block_size base.u8 = in.src.read_u8?()
|
||||
var block_size base.u8 = args.src.read_u8?()
|
||||
if block_size == 0 {
|
||||
return
|
||||
}
|
||||
in.src.skip?(n:block_size as base.u32)
|
||||
args.src.skip?(n:block_size as base.u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
|
||||
// "break", but using "break"s throughout simplifies the control flow.
|
||||
while true {
|
||||
var c base.u8
|
||||
var block_size base.u8 = in.src.read_u8?()
|
||||
var block_size base.u8 = args.src.read_u8?()
|
||||
if block_size == 0 {
|
||||
return
|
||||
}
|
||||
@@ -379,14 +379,14 @@ pri func decoder.decode_ae?(src base.io_reader) {
|
||||
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
|
||||
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
|
||||
if block_size != 11 {
|
||||
in.src.skip?(n:block_size as base.u32)
|
||||
args.src.skip?(n:block_size as base.u32)
|
||||
break
|
||||
}
|
||||
var not_animexts base.bool
|
||||
var not_netscape base.bool
|
||||
block_size = 0 // Re-purpose the block_size variable as a counter.
|
||||
while block_size < 11 {
|
||||
c = in.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
not_animexts = not_animexts or (c != animexts1dot0[block_size])
|
||||
not_netscape = not_netscape or (c != netscape2dot0[block_size])
|
||||
block_size += 1
|
||||
@@ -397,17 +397,17 @@ pri func decoder.decode_ae?(src base.io_reader) {
|
||||
|
||||
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
|
||||
// count.
|
||||
block_size = in.src.read_u8?()
|
||||
block_size = args.src.read_u8?()
|
||||
if block_size != 3 {
|
||||
in.src.skip?(n:block_size as base.u32)
|
||||
args.src.skip?(n:block_size as base.u32)
|
||||
break
|
||||
}
|
||||
c = in.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
if c != 0x01 {
|
||||
in.src.skip?(n:2)
|
||||
args.src.skip?(n:2)
|
||||
break
|
||||
}
|
||||
this.num_loops = in.src.read_u16le?() as base.u32
|
||||
this.num_loops = args.src.read_u16le?() as base.u32
|
||||
this.seen_num_loops = true
|
||||
|
||||
// A loop count of N, in the wire format, actually means "repeat N
|
||||
@@ -426,7 +426,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
|
||||
|
||||
break
|
||||
}
|
||||
this.skip_blocks?(src:in.src)
|
||||
this.skip_blocks?(src:args.src)
|
||||
}
|
||||
|
||||
// decode_gc reads a Graphic Control.
|
||||
@@ -434,12 +434,12 @@ pri func decoder.decode_gc?(src base.io_reader) {
|
||||
if this.seen_graphic_control {
|
||||
return error "bad graphic control"
|
||||
}
|
||||
var c base.u8 = in.src.read_u8?()
|
||||
var c base.u8 = args.src.read_u8?()
|
||||
if c != 4 {
|
||||
return error "bad graphic control"
|
||||
}
|
||||
|
||||
var flags base.u8 = in.src.read_u8?()
|
||||
var flags base.u8 = args.src.read_u8?()
|
||||
this.gc_has_transparent_index = (flags & 0x01) != 0
|
||||
|
||||
// Convert the disposal method from GIF's wire format to Wuffs constants.
|
||||
@@ -461,10 +461,10 @@ pri func decoder.decode_gc?(src base.io_reader) {
|
||||
}
|
||||
|
||||
// There are 7056000 flicks per centisecond.
|
||||
this.gc_duration = (in.src.read_u16le?() as base.u64) * 7056000
|
||||
this.gc_transparent_index = in.src.read_u8?()
|
||||
this.gc_duration = (args.src.read_u16le?() as base.u64) * 7056000
|
||||
this.gc_transparent_index = args.src.read_u8?()
|
||||
|
||||
c = in.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
if c != 0 {
|
||||
return error "bad graphic control"
|
||||
}
|
||||
@@ -480,10 +480,10 @@ pri func decoder.decode_gc?(src base.io_reader) {
|
||||
// overall image's width and height also requires decoding the first frame's
|
||||
// bounds (but doesn't require decoding the first frame's pixels).
|
||||
pri func decoder.decode_id_part0?(src base.io_reader) {
|
||||
this.frame_rect_x0 = in.src.read_u16le?() as base.u32
|
||||
this.frame_rect_y0 = in.src.read_u16le?() as base.u32
|
||||
this.frame_rect_x1 = this.frame_rect_x0 ~mod+ (in.src.read_u16le?() as base.u32)
|
||||
this.frame_rect_y1 = this.frame_rect_y0 ~mod+ (in.src.read_u16le?() as base.u32)
|
||||
this.frame_rect_x0 = args.src.read_u16le?() as base.u32
|
||||
this.frame_rect_y0 = args.src.read_u16le?() as base.u32
|
||||
this.frame_rect_x1 = this.frame_rect_x0 ~mod+ (args.src.read_u16le?() as base.u32)
|
||||
this.frame_rect_y1 = this.frame_rect_y0 ~mod+ (args.src.read_u16le?() as base.u32)
|
||||
this.dst_x = this.frame_rect_x0
|
||||
this.dst_y = this.frame_rect_y0
|
||||
|
||||
@@ -497,7 +497,7 @@ pri func decoder.decode_id_part0?(src base.io_reader) {
|
||||
this.height = this.height.max(x:this.frame_rect_y1)
|
||||
}
|
||||
|
||||
var flags base.u8 = in.src.read_u8?()
|
||||
var flags base.u8 = args.src.read_u8?()
|
||||
if (flags & 0x40) != 0 {
|
||||
this.interlace = 4
|
||||
} else {
|
||||
@@ -515,7 +515,7 @@ pri func decoder.decode_id_part0?(src base.io_reader) {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
|
||||
// Convert from RGB (in memory order) to ARGB (in native u32 order)
|
||||
// to BGRA (in memory order).
|
||||
var argb base.u32 = in.src.read_u24be?() | 0xFF000000
|
||||
var argb base.u32 = args.src.read_u24be?() | 0xFF000000
|
||||
this.palettes[1][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
|
||||
this.palettes[1][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
|
||||
this.palettes[1][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
@@ -546,7 +546,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
|
||||
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 2] = 0x00
|
||||
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 3] = 0x00
|
||||
}
|
||||
in.dst.set_palette!(palette:this.palettes[this.which_palette & 1][:])
|
||||
args.dst.set_palette!(palette:this.palettes[this.which_palette & 1][:])
|
||||
|
||||
// Other GIF implementations accept GIF files that aren't completely spec
|
||||
// compliant. For example, the test/data/gifplayer-muybridge.gif file
|
||||
@@ -567,7 +567,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
|
||||
this.lzw.reset()
|
||||
}
|
||||
|
||||
var lw base.u8 = in.src.read_u8?()
|
||||
var lw base.u8 = args.src.read_u8?()
|
||||
if (lw < 2) or (8 < lw) {
|
||||
return error "bad literal width"
|
||||
}
|
||||
@@ -575,7 +575,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
|
||||
|
||||
this.previous_lzw_decode_ended_abruptly = true
|
||||
while true {
|
||||
var block_size base.u64 = in.src.read_u8?() as base.u64
|
||||
var block_size base.u64 = args.src.read_u8?() as base.u64
|
||||
if block_size == 0 {
|
||||
break
|
||||
}
|
||||
@@ -583,7 +583,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
|
||||
|
||||
while:inner true {
|
||||
var w base.io_writer
|
||||
io_bind (in.src, w) {
|
||||
io_bind (args.src, w) {
|
||||
w.set!(s:this.uncompressed[this.uncompressed_wi:])
|
||||
// TODO: enforce that calling r.set_limit has a precondition
|
||||
// that r.is_bound(), and that you can't suspend inside an
|
||||
@@ -591,15 +591,15 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
|
||||
// complicated if we must save and re-apply limits.
|
||||
//
|
||||
// Should calling r.set_mark also require r.is_bound()?
|
||||
in.src.set_limit!(l:block_size)
|
||||
in.src.set_mark!()
|
||||
var z base.status = try this.lzw.decode?(dst:w, src:in.src)
|
||||
args.src.set_limit!(l:block_size)
|
||||
args.src.set_mark!()
|
||||
var z base.status = try this.lzw.decode?(dst:w, src:args.src)
|
||||
this.uncompressed_wi = 4096 - (w.available().min(x:4096) as base.u32)
|
||||
block_size ~sat-= in.src.since_mark().length()
|
||||
block_size ~sat-= args.src.since_mark().length()
|
||||
}
|
||||
|
||||
if z.is_ok() or (z == suspension "short write") {
|
||||
this.copy_to_image_buffer?(pb:in.dst)
|
||||
this.copy_to_image_buffer?(pb:args.dst)
|
||||
|
||||
if z == suspension "short write" {
|
||||
continue:inner
|
||||
@@ -616,7 +616,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
|
||||
}
|
||||
|
||||
if this.uncompressed_ri != this.uncompressed_wi {
|
||||
this.copy_to_image_buffer?(pb:in.dst)
|
||||
this.copy_to_image_buffer?(pb:args.dst)
|
||||
}
|
||||
|
||||
// TODO: check for "not enough pixel data".
|
||||
@@ -630,7 +630,7 @@ pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
|
||||
// TODO: we shouldn't need this temporary variable.
|
||||
var new_ri base.u32
|
||||
|
||||
var tab table base.u8 = in.pb.plane(p:0)
|
||||
var tab table base.u8 = args.pb.plane(p:0)
|
||||
|
||||
while this.uncompressed_wi > this.uncompressed_ri {
|
||||
assert this.uncompressed_ri < this.uncompressed_wi via "a < b: b > a"()
|
||||
@@ -641,7 +641,7 @@ pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
|
||||
}
|
||||
|
||||
// First, copy from src to that part of the frame rect that is inside
|
||||
// in.pb's bounds.
|
||||
// args.pb's bounds.
|
||||
|
||||
dst = tab.row(y:this.dst_y)
|
||||
if (this.dst_x as base.u64) < dst.length() {
|
||||
@@ -676,7 +676,7 @@ pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
|
||||
}
|
||||
|
||||
// Second, skip over src for that part of the frame rect that is
|
||||
// outside in.pb's bounds. This second step should be infrequent.
|
||||
// outside args.pb's bounds. This second step should be infrequent.
|
||||
|
||||
// Set n to the number of pixels (i.e. the number of bytes) to skip.
|
||||
n = this.frame_rect_x1 - this.dst_x
|
||||
|
||||
+17
-17
@@ -29,31 +29,31 @@ pub struct decoder?(
|
||||
)
|
||||
|
||||
pub func decoder.set_ignore_checksum!(ic base.bool) {
|
||||
this.ignore_checksum = in.ic
|
||||
this.ignore_checksum = args.ic
|
||||
}
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
// Read the header.
|
||||
var c base.u8 = in.src.read_u8?()
|
||||
var c base.u8 = args.src.read_u8?()
|
||||
if c != 0x1F {
|
||||
return error "bad header"
|
||||
}
|
||||
c = in.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
if c != 0x8B {
|
||||
return error "bad header"
|
||||
}
|
||||
c = in.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
if c != 0x08 {
|
||||
return error "bad compression method"
|
||||
}
|
||||
var flags base.u8 = in.src.read_u8?()
|
||||
var flags base.u8 = args.src.read_u8?()
|
||||
// TODO: API for returning the header's MTIME field.
|
||||
in.src.skip?(n:6)
|
||||
args.src.skip?(n:6)
|
||||
|
||||
// Handle FEXTRA.
|
||||
if (flags & 0x04) != 0 {
|
||||
var xlen base.u16 = in.src.read_u16le?()
|
||||
in.src.skip?(n:xlen as base.u32)
|
||||
var xlen base.u16 = args.src.read_u16le?()
|
||||
args.src.skip?(n:xlen as base.u32)
|
||||
}
|
||||
|
||||
// Handle FNAME.
|
||||
@@ -63,7 +63,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
// filename length to NAME_MAX, which is 255.
|
||||
if (flags & 0x08) != 0 {
|
||||
while true {
|
||||
c = in.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
break
|
||||
}
|
||||
@@ -73,7 +73,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
// Handle FCOMMENT.
|
||||
if (flags & 0x10) != 0 {
|
||||
while true {
|
||||
c = in.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
break
|
||||
}
|
||||
@@ -82,7 +82,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
|
||||
// Handle FHCRC.
|
||||
if (flags & 0x02) != 0 {
|
||||
in.src.skip?(n:2)
|
||||
args.src.skip?(n:2)
|
||||
}
|
||||
|
||||
// Reserved flags bits must be zero.
|
||||
@@ -94,19 +94,19 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
var checksum_got base.u32
|
||||
var decoded_length_got base.u32
|
||||
while true {
|
||||
in.dst.set_mark!()
|
||||
var z base.status = try this.flate.decode?(dst:in.dst, src:in.src)
|
||||
args.dst.set_mark!()
|
||||
var z base.status = try this.flate.decode?(dst:args.dst, src:args.src)
|
||||
if not this.ignore_checksum {
|
||||
checksum_got = this.checksum.update!(x:in.dst.since_mark())
|
||||
decoded_length_got ~mod+= ((in.dst.since_mark().length() & 0xFFFFFFFF) as base.u32)
|
||||
checksum_got = this.checksum.update!(x:args.dst.since_mark())
|
||||
decoded_length_got ~mod+= ((args.dst.since_mark().length() & 0xFFFFFFFF) as base.u32)
|
||||
}
|
||||
if z.is_ok() {
|
||||
break
|
||||
}
|
||||
yield z
|
||||
}
|
||||
var checksum_want base.u32 = in.src.read_u32le?()
|
||||
var decoded_length_want base.u32 = in.src.read_u32le?()
|
||||
var checksum_want base.u32 = args.src.read_u32le?()
|
||||
var decoded_length_want base.u32 = args.src.read_u32le?()
|
||||
if (not this.ignore_checksum) and
|
||||
((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) {
|
||||
return error "bad checksum"
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct decoder?(
|
||||
)
|
||||
|
||||
pub func decoder.set_literal_width!(lw base.u32[2..8]) {
|
||||
this.literal_width = in.lw
|
||||
this.literal_width = args.lw
|
||||
}
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
@@ -59,7 +59,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
post n_bits >= width,
|
||||
{
|
||||
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
|
||||
bits |= (in.src.read_u8?() as base.u32) << n_bits
|
||||
bits |= (args.src.read_u8?() as base.u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
var code base.u32[..4095] = bits.low_bits(n:width)
|
||||
@@ -68,7 +68,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
|
||||
if code < clear_code {
|
||||
assert code < 256 via "a < b: a < c; c <= b"(c:clear_code)
|
||||
in.dst.write_u8?(x:code as base.u8)
|
||||
args.dst.write_u8?(x:code as base.u8)
|
||||
if save_code <= 4095 {
|
||||
this.suffixes[save_code] = code as base.u8
|
||||
this.prefixes[save_code] = prev_code as base.u16
|
||||
@@ -118,7 +118,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
inv c < 256,
|
||||
{
|
||||
var expansion slice base.u8 = this.stack[s:]
|
||||
var n_copied base.u64 = in.dst.copy_from_slice!(s:expansion)
|
||||
var n_copied base.u64 = args.dst.copy_from_slice!(s:expansion)
|
||||
if n_copied == expansion.length() {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ pub struct decoder?(
|
||||
)
|
||||
|
||||
pub func decoder.set_ignore_checksum!(ic base.bool) {
|
||||
this.ignore_checksum = in.ic
|
||||
this.ignore_checksum = args.ic
|
||||
}
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
var x base.u16 = in.src.read_u16be?()
|
||||
var x base.u16 = args.src.read_u16be?()
|
||||
if ((x >> 8) & 0x0F) != 0x08 {
|
||||
return error "bad compression method"
|
||||
}
|
||||
@@ -52,17 +52,17 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
// Decode and checksum the DEFLATE-encoded payload.
|
||||
var checksum_got base.u32
|
||||
while true {
|
||||
in.dst.set_mark!()
|
||||
var z base.status = try this.flate.decode?(dst:in.dst, src:in.src)
|
||||
args.dst.set_mark!()
|
||||
var z base.status = try this.flate.decode?(dst:args.dst, src:args.src)
|
||||
if not this.ignore_checksum {
|
||||
checksum_got = this.checksum.update!(x:in.dst.since_mark())
|
||||
checksum_got = this.checksum.update!(x:args.dst.since_mark())
|
||||
}
|
||||
if z.is_ok() {
|
||||
break
|
||||
}
|
||||
yield z
|
||||
}
|
||||
var checksum_want base.u32 = in.src.read_u32be?()
|
||||
var checksum_want base.u32 = args.src.read_u32be?()
|
||||
if (not this.ignore_checksum) and (checksum_got != checksum_want) {
|
||||
return error "bad checksum"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user