mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Have init_huff take a slice of the code_lengths.
This commit is contained in:
1 parent
ea935e1f8c
commit
bf51551eda
5 files changed
+32
-27
No files matched your search
@@ -977,15 +977,16 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
g.writes("if (status) { goto suspend; }\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "init_huff", 2) {
|
||||
} else if isThisMethod(g.tm, n, "init_huff", 3) {
|
||||
g.printf("status = %s%s_init_huff(self,",
|
||||
g.pkgPrefix, g.perFunc.funk.Receiver().String(g.tm))
|
||||
if err := g.writeExpr(n.Args()[0].Arg().Value(), replaceNothing, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
g.writes(",")
|
||||
if err := g.writeExpr(n.Args()[1].Arg().Value(), replaceNothing, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
for i, o := range n.Args() {
|
||||
if i != 0 {
|
||||
g.writes(",")
|
||||
}
|
||||
if err := g.writeExpr(o.Arg().Value(), replaceNothing, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
g.writes(");\n")
|
||||
if err := g.writeLoadExprDerivedVars(n); err != nil {
|
||||
|
||||
+11
-8
@@ -353,7 +353,8 @@ puffs_flate_status puffs_flate_decoder_init_huffs(puffs_flate_decoder* self,
|
||||
|
||||
puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self,
|
||||
uint32_t a_which,
|
||||
uint32_t a_n_codes);
|
||||
uint32_t a_n_codes0,
|
||||
uint32_t a_n_codes1);
|
||||
|
||||
// ---------------- Constructor and Destructor Implementations
|
||||
|
||||
@@ -823,7 +824,7 @@ puffs_flate_status puffs_flate_decoder_init_huffs(puffs_flate_decoder* self,
|
||||
v_i += 1;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
status = puffs_flate_decoder_init_huff(self, 0, 19);
|
||||
status = puffs_flate_decoder_init_huff(self, 0, 0, 19);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
@@ -965,7 +966,8 @@ short_read_src:
|
||||
|
||||
puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self,
|
||||
uint32_t a_which,
|
||||
uint32_t a_n_codes) {
|
||||
uint32_t a_n_codes0,
|
||||
uint32_t a_n_codes1) {
|
||||
puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
|
||||
|
||||
uint32_t v_i;
|
||||
@@ -1006,8 +1008,8 @@ puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self,
|
||||
self->private_impl.f_counts[v_i] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < a_n_codes) {
|
||||
v_i = a_n_codes0;
|
||||
while (v_i < a_n_codes1) {
|
||||
if (self->private_impl.f_counts[self->private_impl.f_code_lengths[v_i]] >=
|
||||
289) {
|
||||
status =
|
||||
@@ -1017,7 +1019,8 @@ puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self,
|
||||
self->private_impl.f_counts[self->private_impl.f_code_lengths[v_i]] += 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if (((uint32_t)(self->private_impl.f_counts[0])) == a_n_codes) {
|
||||
if ((((uint32_t)(self->private_impl.f_counts[0])) + a_n_codes0) ==
|
||||
a_n_codes1) {
|
||||
status = PUFFS_FLATE_ERROR_NO_HUFFMAN_CODES;
|
||||
goto exit;
|
||||
}
|
||||
@@ -1040,8 +1043,8 @@ puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self,
|
||||
v_total = (v_total + v_count);
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < a_n_codes) {
|
||||
v_i = a_n_codes0;
|
||||
while (v_i < a_n_codes1) {
|
||||
if (self->private_impl.f_code_lengths[v_i] != 0) {
|
||||
self->private_impl
|
||||
.f_symbols[v_offsets[self->private_impl.f_code_lengths[v_i]]] =
|
||||
|
||||
@@ -650,7 +650,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
||||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
|
||||
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_dynamic", 2) ||
|
||||
isThisMethod(q.tm, n, "init_huffs", 1) || isThisMethod(q.tm, n, "init_huff", 2) {
|
||||
isThisMethod(q.tm, n, "init_huffs", 1) || isThisMethod(q.tm, n, "init_huff", 3) {
|
||||
|
||||
for _, o := range n.Args() {
|
||||
// TODO: check that the arg range at the caller and the
|
||||
|
||||
+1
-1
@@ -350,7 +350,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
||||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
|
||||
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_dynamic", 2) ||
|
||||
isThisMethod(q.tm, n, "init_huffs", 1) || isThisMethod(q.tm, n, "init_huff", 2) {
|
||||
isThisMethod(q.tm, n, "init_huffs", 1) || isThisMethod(q.tm, n, "init_huff", 3) {
|
||||
|
||||
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||
return err
|
||||
|
||||
@@ -162,7 +162,7 @@ pri func decoder.init_huffs?(src reader1)() {
|
||||
this.code_lengths[code_order[i]] = 0
|
||||
i += 1
|
||||
}
|
||||
this.init_huff?(which:0, n_codes:19)
|
||||
this.init_huff?(which:0, n_codes0:0, n_codes1:19)
|
||||
|
||||
// Decode the code lengths for the next two Huffman tables.
|
||||
var mask u32[..511] = ((1 as u32) << this.n_huffs_bits[0]) - 1
|
||||
@@ -275,9 +275,10 @@ pri func decoder.init_huffs?(src reader1)() {
|
||||
// TODO: skip generating PUFFS_COROUTINE_SUSPENSION_POINTs for this function,
|
||||
// and its callers, as it can only return errors, not suspensions.
|
||||
|
||||
pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() {
|
||||
pri func decoder.init_huff?(which u32[..1], n_codes0 u32[..289], n_codes1 u32[..289])() {
|
||||
// For the clcode example in this package's README.md:
|
||||
// - n_codes = 19
|
||||
// - n_codes0 = 0
|
||||
// - n_codes1 = 19
|
||||
// - code_lengths[ 0] = 3
|
||||
// - code_lengths[ 1] = 0
|
||||
// - code_lengths[ 2] = 0
|
||||
@@ -303,9 +304,9 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() {
|
||||
this.counts[i] = 0
|
||||
i += 1
|
||||
}
|
||||
i = 0
|
||||
while i < in.n_codes {
|
||||
assert i < 289 via "a < b: a < c; c <= b"(c:in.n_codes)
|
||||
i = in.n_codes0
|
||||
while i < in.n_codes1 {
|
||||
assert i < 289 via "a < b: a < c; c <= b"(c:in.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 this.counts[this.code_lengths[i]] >= 289 {
|
||||
@@ -314,7 +315,7 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() {
|
||||
this.counts[this.code_lengths[i]] += 1
|
||||
i += 1
|
||||
}
|
||||
if (this.counts[0] as u32) == in.n_codes {
|
||||
if ((this.counts[0] as u32) + in.n_codes0) == in.n_codes1 {
|
||||
return error "no Huffman codes"
|
||||
}
|
||||
|
||||
@@ -355,9 +356,9 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() {
|
||||
// - offsets[6] = 10
|
||||
// - all other offsets elements are 10.
|
||||
|
||||
i = 0
|
||||
while i < in.n_codes {
|
||||
assert i < 289 via "a < b: a < c; c <= b"(c:in.n_codes)
|
||||
i = in.n_codes0
|
||||
while i < in.n_codes1 {
|
||||
assert i < 289 via "a < b: a < c; c <= b"(c:in.n_codes1)
|
||||
if this.code_lengths[i] != 0 {
|
||||
this.symbols[offsets[this.code_lengths[i]]] = i as u16
|
||||
if offsets[this.code_lengths[i]] >= 289 {
|
||||
|
||||
Reference in new issue
Block a user