mirror of
https://github.com/google/wuffs.git
synced 2026-01-18 17:11:32 +01:00
lang: remove endwhile keyword
This commit is contained in:
@@ -38,6 +38,7 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
|
||||
- Let `std/png` decode PNG color type 4 to `PIXEL_FORMAT__YA_NONPREMUL` (two
|
||||
channels) instead of `PIXEL_FORMAT__BGRA_NONPREMUL` (four channels).
|
||||
- Removed the `std/gif -> std/lzw` dependency.
|
||||
- Removed `endwhile` keyword.
|
||||
- Removed `example/bzcat`.
|
||||
- Set image decoder pixel width and height inclusive maximum to `0xFF_FFFF`,
|
||||
down from `0x7FFF_FFFF`.
|
||||
|
||||
@@ -756,24 +756,6 @@ func (p *parser) parseLabel() (t.ID, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (p *parser) parseEndwhile(label t.ID) bool {
|
||||
if p.peek1() != t.IDEndwhile {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if label != 0 {
|
||||
if p.peek1() != t.IDDot {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() != label {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
x := p.peek1()
|
||||
if x == t.IDVar {
|
||||
@@ -930,14 +912,21 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
n.SetBody(body)
|
||||
p.loops.Pop()
|
||||
|
||||
if !p.parseEndwhile(label) {
|
||||
dotLabel := ""
|
||||
if label != 0 {
|
||||
dotLabel = "." + label.Str(p.tm)
|
||||
if label != 0 {
|
||||
seenDotLabel := false
|
||||
if p.peek1() == t.IDDot {
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() == label {
|
||||
p.src = p.src[1:]
|
||||
seenDotLabel = true
|
||||
}
|
||||
}
|
||||
if !seenDotLabel {
|
||||
return nil, fmt.Errorf(`parse: expected .%s at %s:%d`,
|
||||
label.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
return nil, fmt.Errorf(`parse: expected endwhile%s at %s:%d`,
|
||||
dotLabel, p.filename, p.line())
|
||||
}
|
||||
|
||||
if !doubleCurly {
|
||||
// No-op.
|
||||
} else if n.HasContinue() {
|
||||
|
||||
@@ -375,26 +375,25 @@ const (
|
||||
IDConst = ID(0xB4)
|
||||
IDContinue = ID(0xB5)
|
||||
IDElse = ID(0xB6)
|
||||
IDEndwhile = ID(0xB7)
|
||||
IDFunc = ID(0xB8)
|
||||
IDIOBind = ID(0xB9)
|
||||
IDIOForgetHistory = ID(0xBA)
|
||||
IDIOLimit = ID(0xBB)
|
||||
IDIf = ID(0xBC)
|
||||
IDImplements = ID(0xBD)
|
||||
IDInv = ID(0xBE)
|
||||
IDIterate = ID(0xBF)
|
||||
IDPost = ID(0xC0)
|
||||
IDPre = ID(0xC1)
|
||||
IDPri = ID(0xC2)
|
||||
IDPub = ID(0xC3)
|
||||
IDReturn = ID(0xC4)
|
||||
IDStruct = ID(0xC5)
|
||||
IDUse = ID(0xC6)
|
||||
IDVar = ID(0xC7)
|
||||
IDVia = ID(0xC8)
|
||||
IDWhile = ID(0xC9)
|
||||
IDYield = ID(0xCA)
|
||||
IDFunc = ID(0xB7)
|
||||
IDIOBind = ID(0xB8)
|
||||
IDIOForgetHistory = ID(0xB9)
|
||||
IDIOLimit = ID(0xBA)
|
||||
IDIf = ID(0xBB)
|
||||
IDImplements = ID(0xBC)
|
||||
IDInv = ID(0xBD)
|
||||
IDIterate = ID(0xBE)
|
||||
IDPost = ID(0xBF)
|
||||
IDPre = ID(0xC0)
|
||||
IDPri = ID(0xC1)
|
||||
IDPub = ID(0xC2)
|
||||
IDReturn = ID(0xC3)
|
||||
IDStruct = ID(0xC4)
|
||||
IDUse = ID(0xC5)
|
||||
IDVar = ID(0xC6)
|
||||
IDVia = ID(0xC7)
|
||||
IDWhile = ID(0xC8)
|
||||
IDYield = ID(0xC9)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -826,7 +825,6 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDConst: "const",
|
||||
IDContinue: "continue",
|
||||
IDElse: "else",
|
||||
IDEndwhile: "endwhile",
|
||||
IDFunc: "func",
|
||||
IDIOBind: "io_bind",
|
||||
IDIOForgetHistory: "io_forget_history",
|
||||
|
||||
@@ -71,7 +71,7 @@ pri func hasher.up!(x: roslice base.u8),
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ pri func hasher.up_arm_neon!(x: roslice base.u8),
|
||||
s1 ~mod+= args.x[0] as base.u32
|
||||
s2 ~mod+= s1
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
|
||||
@@ -186,6 +186,6 @@ pri func hasher.up_arm_neon!(x: roslice base.u8),
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
}
|
||||
|
||||
@@ -172,6 +172,6 @@ pri func hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -411,7 +411,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -457,7 +457,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -510,7 +510,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
args.src.skip_u32?(n: this.pending_pad)
|
||||
this.pending_pad = 0
|
||||
@@ -551,7 +551,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
}
|
||||
this.pending_pad -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while.inner true {
|
||||
if this.dst_x == this.width {
|
||||
@@ -591,7 +591,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
}
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
@@ -599,7 +599,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
@@ -610,8 +610,8 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -700,7 +700,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
assert p0 < 255 via "a < b: a < c; c <= b"(c: this.rle_length)
|
||||
this.scratch[p0] = code
|
||||
p0 += 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
indexes[0] = (code >> 4) as base.u8
|
||||
indexes[1] = code & 0x0F
|
||||
@@ -710,7 +710,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
this.scratch[p0 + 0] = indexes[0]
|
||||
this.scratch[p0 + 1] = indexes[1]
|
||||
p0 += 2
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
@@ -774,7 +774,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
this.scratch[p0 + 0x03] = (0x0F & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 255) + 0x04
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
p0 = p0.min(no_more_than: this.rle_length)
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
@@ -849,18 +849,18 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
dst_palette: dst_palette,
|
||||
num_pixels: 0xFFFF_FFFF_FFFF_FFFF)
|
||||
code -= 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
rle_state = RLE_STATE_NEUTRAL
|
||||
continue.middle
|
||||
|
||||
} endwhile.inner
|
||||
}} endwhile.goto_suspend
|
||||
}.inner
|
||||
}}.goto_suspend
|
||||
this.rle_state = rle_state
|
||||
return "@internal note: short read"
|
||||
} endwhile.middle
|
||||
} endwhile.outer
|
||||
}.middle
|
||||
}.outer
|
||||
|
||||
while this.dst_y < this.height {
|
||||
row = tab.row_u32(y: this.dst_y)
|
||||
@@ -872,7 +872,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
dst_palette: dst_palette,
|
||||
num_pixels: 0xFFFF_FFFF_FFFF_FFFF)
|
||||
this.dst_y ~mod+= this.dst_y_inc
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -916,7 +916,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
||||
}
|
||||
this.pending_pad -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while.inner true {
|
||||
if this.dst_x == this.width {
|
||||
@@ -970,17 +970,17 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
||||
{
|
||||
c |= c ~mod<< num_bits
|
||||
num_bits *= 2
|
||||
} endwhile
|
||||
}
|
||||
c >>= num_bits - 16
|
||||
this.scratch[(8 * p0) + (2 * channel) + 0] = (0xFF & (c >> 0)) as base.u8
|
||||
this.scratch[(8 * p0) + (2 * channel) + 1] = (0xFF & (c >> 8)) as base.u8
|
||||
}
|
||||
|
||||
channel += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
p0 += 1
|
||||
} endwhile
|
||||
}
|
||||
// -------- END convert to PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE.
|
||||
|
||||
dst = tab.row_u32(y: this.dst_y)
|
||||
@@ -1000,8 +1000,8 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -1064,12 +1064,12 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
args.src.skip_u32_fast!(actual: 256, worst_case: 256)
|
||||
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 64))
|
||||
chunk_count -= 64
|
||||
} endwhile
|
||||
}
|
||||
while (chunk_count >= 8) and (args.src.length() >= 32) {
|
||||
args.src.skip_u32_fast!(actual: 32, worst_case: 32)
|
||||
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 8))
|
||||
chunk_count -= 8
|
||||
} endwhile
|
||||
}
|
||||
while chunk_count > 0 {
|
||||
if args.src.length() < 4 {
|
||||
return "@internal note: short read"
|
||||
@@ -1077,7 +1077,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 1))
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
continue.loop
|
||||
}
|
||||
dst = dst[i ..]
|
||||
@@ -1125,7 +1125,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
this.scratch[p0 + 0x1F] = (0x01 & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 511) + 0x20
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else if this.bits_per_pixel == 2 {
|
||||
// Calculate the remaining number of 32-bit chunks. At 2 bits per
|
||||
@@ -1153,7 +1153,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
this.scratch[p0 + 0x0F] = (0x03 & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 511) + 0x10
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
// Calculate the remaining number of 32-bit chunks. At 4 bits per
|
||||
@@ -1173,7 +1173,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
this.scratch[p0 + 0x07] = (0x0F & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 511) + 0x08
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
p0 = p0.min(no_more_than: this.width ~sat- this.dst_x)
|
||||
@@ -1185,7 +1185,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile.loop
|
||||
}.loop
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -1241,7 +1241,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
@@ -1279,7 +1279,7 @@ pri func decoder.read_palette?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.src_palette[(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
while (i < 256) and (this.padding >= 4) {
|
||||
this.padding -= 4
|
||||
@@ -1290,7 +1290,7 @@ pri func decoder.read_palette?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.src_palette[(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
while i < 256 {
|
||||
@@ -1299,7 +1299,7 @@ pri func decoder.read_palette?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = 0x00
|
||||
this.src_palette[(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.process_masks?() {
|
||||
@@ -1316,7 +1316,7 @@ pri func decoder.process_masks?() {
|
||||
{
|
||||
n ~mod+= 1
|
||||
mask >>= 1
|
||||
} endwhile
|
||||
}
|
||||
this.channel_shifts[i] = (n & 31) as base.u8
|
||||
|
||||
n = 0
|
||||
@@ -1325,7 +1325,7 @@ pri func decoder.process_masks?() {
|
||||
{
|
||||
n ~mod+= 1
|
||||
mask >>= 1
|
||||
} endwhile
|
||||
}
|
||||
if (mask <> 0) or (n > 32) {
|
||||
return "#bad header"
|
||||
}
|
||||
@@ -1335,5 +1335,5 @@ pri func decoder.process_masks?() {
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -185,7 +185,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if tag == 0x1772_4538_5090 {
|
||||
break
|
||||
@@ -209,7 +209,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
this.decode_huffman_slow?(src: args.src)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.invert_bwt!()
|
||||
|
||||
@@ -228,7 +228,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
this.flush_slow?(dst: args.dst)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.block_checksum_have ^= 0xFFFF_FFFF
|
||||
if (not this.ignore_checksum) and (this.block_checksum_have <> this.block_checksum_want) {
|
||||
@@ -237,7 +237,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
this.final_checksum_have = this.block_checksum_have ^ (
|
||||
(this.final_checksum_have >> 31) |
|
||||
(this.final_checksum_have ~mod<< 1))
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the 32-bit final checksum.
|
||||
final_checksum_want = 0
|
||||
@@ -254,7 +254,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (not this.ignore_checksum) and (this.final_checksum_have <> final_checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
@@ -284,7 +284,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the "block randomized" bit.
|
||||
if this.n_bits <= 0 {
|
||||
@@ -314,14 +314,14 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Reset the presence bitmap.
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.presence[i] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the 16-bit high-level presence bitmap.
|
||||
i = 0
|
||||
@@ -338,7 +338,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 16
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the 16-bit low-level presence bitmaps.
|
||||
this.scratch = 0
|
||||
@@ -363,8 +363,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
if (i & 15) == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
if (this.scratch < 1) or (256 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
@@ -385,7 +385,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (this.scratch < 2) or (6 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
@@ -406,7 +406,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (this.scratch < 1) or (18001 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
@@ -418,7 +418,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
assert i < 6 via "a < b: a < c; c <= b"(c: this.num_huffman_codes)
|
||||
this.mtft[i] = i as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read each section's Huffman code selector, applying the MTFT.
|
||||
i = 0
|
||||
@@ -447,7 +447,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
if selector >= this.num_huffman_codes {
|
||||
return "#bad block header"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Move to front.
|
||||
if selector == 0 {
|
||||
@@ -462,7 +462,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the Huffman codes.
|
||||
i = 0
|
||||
@@ -475,7 +475,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
}
|
||||
this.build_huffman_table!(which: i)
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Initialize the MTFT state.
|
||||
i = 0
|
||||
@@ -486,14 +486,14 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
j ~mod+= 1
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Initialize the letter counts.
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.letter_counts[i] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
@@ -517,7 +517,7 @@ pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the code lengths.
|
||||
i = 0
|
||||
@@ -557,12 +557,12 @@ pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
}
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.code_lengths_bitmask |= (1 as base.u32) << (code_length & 31)
|
||||
this.bwt[i] = code_length
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// build_huffman_tree builds a canonical Huffman tree given the symbols' code
|
||||
@@ -669,7 +669,7 @@ pri func decoder.build_huffman_tree!(which: base.u32[..= 5]) base.status {
|
||||
this.huffman_trees[args.which][num_branch_nodes][1] = 0
|
||||
num_branch_nodes += 1
|
||||
stack_height += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
node_index = stack_values[stack_height - 1]
|
||||
if symbol_index < 2 {
|
||||
@@ -694,13 +694,13 @@ pri func decoder.build_huffman_tree!(which: base.u32[..= 5]) base.status {
|
||||
break
|
||||
}
|
||||
stack_height -= 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
symbol_index += 1
|
||||
} endwhile
|
||||
}
|
||||
code_length += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if stack_height <> 0 {
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
@@ -724,10 +724,10 @@ pri func decoder.build_huffman_table!(which: base.u32[..= 5]) {
|
||||
child = this.huffman_trees[args.which][child][bits >> 31]
|
||||
bits ~mod<<= 1
|
||||
n_bits += 1
|
||||
} endwhile
|
||||
}
|
||||
this.huffman_tables[args.which][i] = (child | (n_bits << 12)) as base.u16
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// invert_bwt performs "two passes over the data, and one pass over the
|
||||
@@ -748,7 +748,7 @@ pri func decoder.invert_bwt!() {
|
||||
sum ~mod+= this.letter_counts[i]
|
||||
this.letter_counts[i] = old_sum
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Second data pass, but per the README.md file, calculate the U column
|
||||
// instead of the BWT technical report's T column.
|
||||
@@ -759,7 +759,7 @@ pri func decoder.invert_bwt!() {
|
||||
this.bwt[this.letter_counts[letter] & 1_048575] |= i << 12
|
||||
this.letter_counts[letter] ~mod+= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// The table below was created by script/print-crc32-magic-numbers.go with the
|
||||
|
||||
@@ -56,12 +56,12 @@ pri func decoder.flush_fast!(dst: base.io_writer) {
|
||||
args.dst.write_u8_fast!(a: flush_prev)
|
||||
}
|
||||
flush_repeat_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
flush_repeat_count = 0
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.flush_pointer = flush_pointer
|
||||
this.flush_repeat_count = flush_repeat_count
|
||||
|
||||
@@ -54,12 +54,12 @@ pri func decoder.flush_slow?(dst: base.io_writer) {
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8?(a: flush_prev)
|
||||
flush_repeat_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
flush_repeat_count = 0
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.flush_pointer = flush_pointer
|
||||
this.flush_repeat_count = flush_repeat_count
|
||||
|
||||
@@ -62,7 +62,7 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if child < 0x300 { // mNN symbol.
|
||||
// Move to front.
|
||||
@@ -108,8 +108,8 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
assert i < 900000 via "a < b: a < c; c <= b"(c: j)
|
||||
this.bwt[i] = mtft0
|
||||
i += 1
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
}
|
||||
}.outer
|
||||
|
||||
this.bits = bits
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -94,8 +94,8 @@ pri func decoder.decode_huffman_slow?(src: base.io_reader) {
|
||||
assert i < 900000 via "a < b: a < c; c <= b"(c: j)
|
||||
this.bwt[i] = mtft0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
}
|
||||
}.outer
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
return "#internal error: inconsistent I/O"
|
||||
}} endwhile.goto_have_string_length
|
||||
}}.goto_have_string_length
|
||||
}
|
||||
|
||||
if c_major == 0 {
|
||||
@@ -362,7 +362,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
} endwhile
|
||||
}
|
||||
// -------- END Major type 2: a byte string.
|
||||
|
||||
} else if c_major == 3 {
|
||||
@@ -447,7 +447,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
} endwhile
|
||||
}
|
||||
// -------- END Major type 3: a text string.
|
||||
|
||||
} else if c_major == 4 {
|
||||
@@ -459,7 +459,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
while (token_length > 0) and (args.src.can_undo_byte()) {
|
||||
args.src.undo_byte!()
|
||||
token_length -= 1
|
||||
} endwhile
|
||||
}
|
||||
return "#unsupported recursion depth"
|
||||
}
|
||||
|
||||
@@ -526,7 +526,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
while (token_length > 0) and (args.src.can_undo_byte()) {
|
||||
args.src.undo_byte!()
|
||||
token_length -= 1
|
||||
} endwhile
|
||||
}
|
||||
return "#unsupported recursion depth"
|
||||
}
|
||||
|
||||
@@ -713,14 +713,14 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
// -------- END Major type 7: miscellaneous.
|
||||
}
|
||||
break.goto_fail
|
||||
}} endwhile.goto_fail
|
||||
}}.goto_fail
|
||||
|
||||
if args.src.can_undo_byte() {
|
||||
args.src.undo_byte!()
|
||||
return "#bad input"
|
||||
}
|
||||
return "#internal error: inconsistent I/O"
|
||||
}} endwhile.goto_parsed_a_leaf_value
|
||||
}}.goto_parsed_a_leaf_value
|
||||
|
||||
// We've just parsed a leaf (non-container) value, or the (explicit or
|
||||
// implicit) close of a container (array or object).
|
||||
@@ -753,7 +753,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
{
|
||||
yield? base."$short write"
|
||||
continue
|
||||
} endwhile
|
||||
}
|
||||
depth -= 1
|
||||
|
||||
// Fill in FROM_ETC.
|
||||
@@ -787,11 +787,11 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
value_minor: vminor_alt,
|
||||
continued: 0,
|
||||
length: 0)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// We've parsed the top-level value and we're therefore done overall.
|
||||
break.outer
|
||||
} endwhile.outer
|
||||
}.outer
|
||||
|
||||
this.end_of_data = true
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pri func ieee_hasher.up_arm_crc32!(x: roslice base.u8),
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = s.crc32b(b: args.x[0])
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
iterate (p = args.x)(length: 8, advance: 8, unroll: 16) {
|
||||
s = s.crc32d(b: p.peek_u64le())
|
||||
|
||||
@@ -38,7 +38,7 @@ pri func ieee_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if args.x.length() >= 128 {
|
||||
// BEGIN script/print-crc32-x86-sse42-code.go generated code.
|
||||
@@ -87,7 +87,7 @@ pri func ieee_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
y7 = y7._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x70 .. 0x80]))
|
||||
x7 = x7._mm_xor_si128(b: y7)
|
||||
args.x = args.x[128 ..]
|
||||
} endwhile
|
||||
}
|
||||
kk = util.make_m128i_multiple_u32(a00: 0xAE68_9191, a01: 0, a02: 0xCCAA_009E, a03: 0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
@@ -139,12 +139,12 @@ pri func ieee_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
_mm_clmulepi64_si128(b: kk, imm8: 0x10).
|
||||
_mm_extract_epi32(imm8: 2)
|
||||
args.x = args.x[8 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while args.x.length() > 0 {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ pri func ecma_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = ECMA_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while.chain2 true {{
|
||||
while.chain4 true {{
|
||||
@@ -118,7 +118,7 @@ pri func ecma_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
xh._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x70 .. 0x80]))
|
||||
args.x = args.x[0x80 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Reduce 8 chains down to 4.
|
||||
mu4 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD4[.. 16])
|
||||
@@ -151,7 +151,7 @@ pri func ecma_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
}
|
||||
|
||||
break.chain4
|
||||
}} endwhile.chain4
|
||||
}}.chain4
|
||||
// Reduce 4 chains down to 2.
|
||||
mu2 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD2[.. 16])
|
||||
xa = xa._mm_clmulepi64_si128(b: mu2, imm8: 0x00)._mm_xor_si128(b:
|
||||
@@ -171,7 +171,7 @@ pri func ecma_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
}
|
||||
|
||||
break.chain2
|
||||
}} endwhile.chain2
|
||||
}}.chain2
|
||||
// Reduce 2 chains down to 1.
|
||||
mu1 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD1[.. 16])
|
||||
xa = xa._mm_clmulepi64_si128(b: mu1, imm8: 0x00)._mm_xor_si128(b:
|
||||
|
||||
@@ -224,7 +224,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -245,7 +245,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
// can change the veracity of any args.dst assertions?
|
||||
this.add_history!(hist: args.dst.since(mark: mark))
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
@@ -261,7 +261,7 @@ pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
this.bits |= b0 << (this.n_bits & 3)
|
||||
this.n_bits = (this.n_bits & 3) + 8
|
||||
} endwhile
|
||||
}
|
||||
final = this.bits & 0x01
|
||||
type = (this.bits >> 1) & 0x03
|
||||
this.bits >>= 3
|
||||
@@ -304,8 +304,8 @@ pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
if this.end_of_block {
|
||||
continue.outer
|
||||
}
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
}
|
||||
}.outer
|
||||
}
|
||||
|
||||
// decode_uncompressed decodes an uncompresed block as per the RFC section
|
||||
@@ -339,7 +339,7 @@ pri func decoder.decode_uncompressed?(dst: base.io_writer, src: base.io_reader)
|
||||
} else {
|
||||
yield? base."$short read"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6.
|
||||
@@ -350,23 +350,23 @@ pri func decoder.init_fixed_huffman!() base.status {
|
||||
while i < 144 {
|
||||
this.code_lengths[i] = 8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 256 {
|
||||
this.code_lengths[i] = 9
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 280 {
|
||||
this.code_lengths[i] = 7
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 288 {
|
||||
this.code_lengths[i] = 8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 320 {
|
||||
this.code_lengths[i] = 5
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
status = this.init_huff!(which: 0, n_codes0: 0, n_codes1: 288, base_symbol: 257)
|
||||
if status.is_error() {
|
||||
@@ -407,7 +407,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
bits |= b0 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
n_lit = bits.low_bits(n: 5) + 257
|
||||
if n_lit > 286 {
|
||||
return "#bad literal/length code count"
|
||||
@@ -432,17 +432,17 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b1 = args.src.read_u8_as_u32?()
|
||||
bits |= b1 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
assert i < 19 via "a < b: a < c; c <= b"(c: n_clen)
|
||||
this.code_lengths[CODE_ORDER[i]] = (bits & 0x07) as base.u8
|
||||
bits >>= 3
|
||||
n_bits -= 3
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 19 {
|
||||
this.code_lengths[CODE_ORDER[i]] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
status = this.init_huff!(which: 0, n_codes0: 0, n_codes1: 19, base_symbol: 0xFFF)
|
||||
if status.is_error() {
|
||||
return status
|
||||
@@ -469,7 +469,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b2 = args.src.read_u8_as_u32?()
|
||||
bits |= b2 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
// For H-CL, there should be no redirections and all symbols should be
|
||||
// literals.
|
||||
if (table_entry >> 24) <> 0x80 {
|
||||
@@ -518,7 +518,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b3 = args.src.read_u8_as_u32?()
|
||||
bits |= b3 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
rep_count += bits.low_bits(n: n_extra_bits)
|
||||
bits >>= n_extra_bits
|
||||
n_bits -= n_extra_bits
|
||||
@@ -532,8 +532,8 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
this.code_lengths[i] = rep_symbol
|
||||
i += 1
|
||||
rep_count -= 1
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
if i <> (n_lit + n_dist) {
|
||||
return "#bad Huffman code length count"
|
||||
@@ -626,7 +626,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
counts[this.code_lengths[i] & 15] += 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 {
|
||||
return "#no Huffman codes"
|
||||
}
|
||||
@@ -645,7 +645,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
remaining -= counts[i] as base.u32
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if remaining <> 0 {
|
||||
// As a special case, allow a degenerate H-D Huffman table, with only
|
||||
// one 1-bit code.
|
||||
@@ -661,7 +661,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
return ok
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
@@ -690,7 +690,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
// bounds checking can handle it.
|
||||
n_symbols = n_symbols + count
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if n_symbols > 288 {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
@@ -730,7 +730,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
offsets[this.code_lengths[i] & 15] += 1
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate min_cl and max_cl.
|
||||
//
|
||||
@@ -748,7 +748,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
return "#bad Huffman minimum code length"
|
||||
}
|
||||
min_cl += 1
|
||||
} endwhile
|
||||
}
|
||||
max_cl = 15
|
||||
while true,
|
||||
inv n_symbols <= 288,
|
||||
@@ -760,7 +760,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
return "#no Huffman codes"
|
||||
}
|
||||
max_cl -= 1
|
||||
} endwhile
|
||||
}
|
||||
if max_cl <= 9 {
|
||||
this.n_huffs_bits[args.which] = max_cl
|
||||
} else {
|
||||
@@ -848,7 +848,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
remaining <<= 1
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
if (j <= 9) or (15 < j) {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
@@ -909,7 +909,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
assert (top + ((high_bits | reversed_key) & 511)) < 1024 via "a < b: a < c; c <= b"(c: HUFFS_TABLE_SIZE)
|
||||
this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
if i >= n_symbols {
|
||||
@@ -920,6 +920,6 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
if code >= (1 << 15) {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.loop
|
||||
}
|
||||
}.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
@@ -291,7 +291,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bits = (bits & (((1 as base.u64) << n_bits) - 1)) as base.u32
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -366,8 +366,8 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.loop
|
||||
}
|
||||
}.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
@@ -388,7 +388,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bits = bits & (((1 as base.u32) << n_bits) - 1)
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -265,8 +265,8 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.loop
|
||||
}
|
||||
}.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
@@ -290,7 +290,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bits = (bits & (((1 as base.u64) << n_bits) - 1)) as base.u32
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -58,7 +58,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
bits |= b0 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (table_entry >> 31) <> 0 {
|
||||
// Literal.
|
||||
@@ -86,7 +86,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b1 = args.src.read_u8_as_u32?()
|
||||
bits |= b1 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (table_entry >> 31) <> 0 {
|
||||
// Literal.
|
||||
@@ -126,7 +126,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b2 = args.src.read_u8_as_u32?()
|
||||
bits |= b2 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
// The "+ 253" is the same as "- 3", after the "& 0xFF", but the
|
||||
// plus form won't require an underflow check.
|
||||
length = ((length + 253 + bits.low_bits(n: table_entry_n_bits)) & 0xFF) + 3
|
||||
@@ -147,7 +147,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b3 = args.src.read_u8_as_u32?()
|
||||
bits |= b3 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
// Check for a redirect.
|
||||
if (table_entry >> 28) == 1 {
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
@@ -164,7 +164,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b4 = args.src.read_u8_as_u32?()
|
||||
bits |= b4 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// For H-D, all symbols should be base_number + extra_bits.
|
||||
@@ -191,7 +191,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b5 = args.src.read_u8_as_u32?()
|
||||
bits |= b5 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
dist_minus_1 = (dist_minus_1 + bits.low_bits(n: table_entry_n_bits)) & 0x7FFF
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
@@ -243,8 +243,8 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
}
|
||||
length -= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile.inner
|
||||
} endwhile.loop
|
||||
}.inner
|
||||
}.loop
|
||||
|
||||
// TODO: "assert n_bits < 8"? What about (bits >> n_bits)?
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -205,7 +205,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
@@ -249,7 +249,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
}
|
||||
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
|
||||
chunk_length = args.src.peek_u8_as_u64()
|
||||
if chunk_length <= 0 {
|
||||
@@ -278,7 +278,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
}
|
||||
|
||||
yield? base."$even more information"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if args.minfo <> nullptr {
|
||||
args.minfo.set!(
|
||||
@@ -363,7 +363,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -411,7 +411,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
post args.src.length() > 0,
|
||||
{
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
flags = args.src.peek_u8()
|
||||
if (flags & 0x80) <> 0 {
|
||||
background_color = this.black_color_u32_argb_premul
|
||||
@@ -477,7 +477,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: honor args.opts.
|
||||
@@ -548,7 +548,7 @@ pri func decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
||||
this.call_sequence = 0x60
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// decode_header reads either "GIF87a" or "GIF89a".
|
||||
@@ -597,7 +597,7 @@ pri func decoder.decode_lsd?(src: base.io_reader) {
|
||||
this.palettes[0][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.palettes[0][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.quirks[QUIRK_HONOR_BACKGROUND_COLOR - QUIRKS_BASE] {
|
||||
if (background_color_index <> 0) and
|
||||
@@ -626,7 +626,7 @@ pri func decoder.decode_lsd?(src: base.io_reader) {
|
||||
this.palettes[0][(4 * i) + 2] = 0x00
|
||||
this.palettes[0][(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// decode_extension reads an extension. The Extension Introducer byte has
|
||||
@@ -662,7 +662,7 @@ pri func decoder.skip_blocks?(src: base.io_reader) {
|
||||
return ok
|
||||
}
|
||||
args.src.skip_u32?(n: block_size as base.u32)
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// decode_ae reads an Application Extension.
|
||||
@@ -706,7 +706,7 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
is_iccp = is_iccp and (c8 == ICCRGBG1012[block_size])
|
||||
is_xmp = is_xmp and (c8 == XMPDATAXMP[block_size])
|
||||
block_size += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if is_animexts or is_netscape {
|
||||
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
|
||||
@@ -755,7 +755,7 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
this.skip_blocks?(src: args.src)
|
||||
}
|
||||
@@ -866,7 +866,7 @@ pri func decoder.decode_id_part1?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
this.palettes[1][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.palettes[1][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
// Set the remaining palette entries to opaque black.
|
||||
while i < 256 {
|
||||
this.palettes[1][(4 * i) + 0] = 0x00
|
||||
@@ -874,7 +874,7 @@ pri func decoder.decode_id_part1?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
this.palettes[1][(4 * i) + 2] = 0x00
|
||||
this.palettes[1][(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
} else if this.quirks[QUIRK_REJECT_EMPTY_PALETTE - QUIRKS_BASE] and (not this.has_global_palette) {
|
||||
return "#bad palette"
|
||||
} else if this.gc_has_transparent_index {
|
||||
@@ -953,7 +953,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
while args.src.length() == 0 {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.compressed_ri == this.compressed_wi {
|
||||
this.compressed_ri = 0
|
||||
@@ -978,7 +978,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
block_size = args.src.peek_u8_as_u64()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while.inner true {
|
||||
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
|
||||
@@ -1032,8 +1032,8 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return "#bad LZW code"
|
||||
}
|
||||
return "#internal error: inconsistent I/O"
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
|
||||
this.compressed_ri = 0
|
||||
this.compressed_wi = 0
|
||||
@@ -1138,7 +1138,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
replicate_dst = tab.row_u32(y: replicate_y0)
|
||||
replicate_dst.copy_from_slice!(s: replicate_src)
|
||||
replicate_y0 += 1
|
||||
} endwhile
|
||||
}
|
||||
this.dirty_max_excl_y = this.dirty_max_excl_y.max(no_less_than: replicate_y1)
|
||||
}
|
||||
|
||||
@@ -1146,7 +1146,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
while (this.interlace > 0) and (this.dst_y >= this.frame_rect_y1) {
|
||||
this.interlace -= 1
|
||||
this.dst_y = this.frame_rect_y0 ~sat+ INTERLACE_START[this.interlace]
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1172,7 +1172,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
while (this.interlace > 0) and (this.dst_y >= this.frame_rect_y1) {
|
||||
this.interlace -= 1
|
||||
this.dst_y = this.frame_rect_y0 ~sat+ INTERLACE_START[this.interlace]
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1180,6 +1180,6 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ pri func decoder.lzw_init!() {
|
||||
this.lzw_lm1s[i] = 0
|
||||
this.lzw_suffixes[i][0] = i as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
@@ -194,7 +194,7 @@ pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
// in practice, but is necessary for the overflow checker.
|
||||
o = (o ~mod- 8) & 8191
|
||||
c = this.lzw_prefixes[c] as base.u32
|
||||
} endwhile
|
||||
}
|
||||
first_byte = this.lzw_suffixes[c][0]
|
||||
|
||||
if code == save_code {
|
||||
@@ -235,7 +235,7 @@ pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
this.lzw_read_from_return_value = 1
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Rewind args.src, if we're not in "$short read" and we've read too many
|
||||
// bits.
|
||||
@@ -248,7 +248,7 @@ pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
this.lzw_read_from_return_value = 5
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.lzw_save_code = save_code
|
||||
|
||||
@@ -65,7 +65,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -113,7 +113,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Handle FCOMMENT.
|
||||
@@ -123,7 +123,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Handle FHCRC.
|
||||
@@ -148,7 +148,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
checksum_want = args.src.read_u32le?()
|
||||
decoded_length_want = args.src.read_u32le?()
|
||||
if (not this.ignore_checksum) and
|
||||
|
||||
@@ -628,7 +628,7 @@ pri func decoder.decode_idct_x86_avx2!(dst_buffer: slice base.u8, dst_stride: ba
|
||||
// intermediatedh = i16x16 [in.d0 .. in.d3 in.d4 .. in.d7 in.h0 .. in.h4 in.h5 .. in.h7]
|
||||
|
||||
break.goto_do_second_pass
|
||||
}} endwhile.goto_do_second_pass
|
||||
}}.goto_do_second_pass
|
||||
|
||||
// ----
|
||||
|
||||
|
||||
@@ -342,7 +342,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -373,7 +373,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
}
|
||||
// Getting here is invalid according to the JPEG spec, but libjpeg
|
||||
// treats this as a warning (JWRN_EXTRANEOUS_DATA), not an error.
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0xFF {
|
||||
@@ -382,7 +382,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
}
|
||||
// Section B.1.1.2: "Any marker may optionally be preceded by any
|
||||
// number of [0xFF] fill bytes".
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if marker == 0x00 {
|
||||
// Ignore byte stuffing.
|
||||
@@ -472,7 +472,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
|
||||
args.src.skip_u32?(n: this.payload_length)
|
||||
this.payload_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
choose decode_idct = [
|
||||
// TODO: decode_idct_arm_neon,
|
||||
@@ -522,7 +522,7 @@ pri func decoder.decode_dqt?(src: base.io_reader) {
|
||||
while i < 64 {
|
||||
i += 1
|
||||
this.quant_tables[q][UNZIG[i]] = args.src.read_u8_as_u16?()
|
||||
} endwhile
|
||||
}
|
||||
this.seen_dqt[q] = true
|
||||
|
||||
if this.sof_marker == 0 {
|
||||
@@ -530,10 +530,10 @@ pri func decoder.decode_dqt?(src: base.io_reader) {
|
||||
while i < 64 {
|
||||
this.saved_quant_tables[q][i] = this.quant_tables[q][i]
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
this.saved_seen_dqt[q] = true
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_dri?(src: base.io_reader) {
|
||||
@@ -596,7 +596,7 @@ pri func decoder.decode_appn?(src: base.io_reader, marker: base.u8) {
|
||||
}
|
||||
}
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
args.src.skip_u32?(n: this.payload_length)
|
||||
this.payload_length = 0
|
||||
@@ -692,10 +692,10 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
return "#bad SOF marker"
|
||||
}
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.num_components == 1 {
|
||||
// The first (and only) component's H and V factors are effectively
|
||||
@@ -721,7 +721,7 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
has_v24 = has_v24 or (this.components_v[i] == 2) or (this.components_v[i] == 4)
|
||||
has_v3 = has_v3 or (this.components_v[i] == 3)
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (has_h24 and has_h3) or (has_v24 and has_v3) {
|
||||
return "#unsupported fractional sampling"
|
||||
}
|
||||
@@ -786,9 +786,9 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
{
|
||||
this.block_smoothing_lowest_scan_al[i][j] = 16
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.components_workbuf_offsets[0] = 0
|
||||
@@ -829,7 +829,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -896,7 +896,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
}
|
||||
|
||||
yield? ddf_status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -954,7 +954,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
// Getting here is invalid according to the JPEG spec, but libjpeg
|
||||
// treats this as a warning (JWRN_EXTRANEOUS_DATA), not an error.
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0xFF {
|
||||
@@ -963,7 +963,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
// Section B.1.1.2: "Any marker may optionally be preceded by any
|
||||
// number of [0xFF] fill bytes".
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if marker == 0x00 {
|
||||
// Ignore byte stuffing.
|
||||
@@ -1038,7 +1038,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
|
||||
args.src.skip_u32?(n: this.payload_length)
|
||||
this.payload_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
@@ -1080,14 +1080,14 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
while i < 16 {
|
||||
this.dht_temp_counts[i] = args.src.read_u8?()
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
working_total_count = 0
|
||||
i = 0
|
||||
while i < 16 {
|
||||
working_total_count =
|
||||
(working_total_count + (this.dht_temp_counts[i] as base.u32)) & 0xFFFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (working_total_count <= 0) or (256 < working_total_count) {
|
||||
return "#bad DHT marker"
|
||||
}
|
||||
@@ -1103,11 +1103,11 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c: total_count)
|
||||
this.huff_tables_symbols[tc4_th][i] = args.src.read_u8?()
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 256 {
|
||||
this.huff_tables_symbols[tc4_th][i] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// For tc == 0 (DC, not AC tables), the symbols must not exceed 15 (for
|
||||
// lossy JPEG) or 16 (for lossless JPEG). We only support lossy.
|
||||
@@ -1119,7 +1119,7 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
return "#bad DHT marker"
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
failed = this.calculate_huff_tables!(tc4_th: tc4_th, total_count: total_count)
|
||||
@@ -1128,7 +1128,7 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
this.seen_dht[tc4_th] = true
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: base.u32[..= 256]) base.bool {
|
||||
@@ -1155,12 +1155,12 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
{
|
||||
k = 0
|
||||
bit_length_minus_one = (bit_length_minus_one + 1) & 15
|
||||
} endwhile
|
||||
}
|
||||
assert k < 255 via "a < b: a < c; c <= b"(c: this.dht_temp_counts[bit_length_minus_one])
|
||||
k += 1
|
||||
this.dht_temp_bit_lengths[i] = (bit_length_minus_one + 1) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate dht_temp_bit_strings.
|
||||
bit_length = 0
|
||||
@@ -1176,7 +1176,7 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
}
|
||||
bit_length += 1
|
||||
bit_string ~mod<<= 1
|
||||
} endwhile
|
||||
}
|
||||
this.dht_temp_bit_strings[i] = (bit_string & 0xFFFF) as base.u16
|
||||
bit_string ~mod+= 1
|
||||
|
||||
@@ -1188,7 +1188,7 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate huff_tables_slow[args.tc4_th].
|
||||
k = 0
|
||||
@@ -1208,14 +1208,14 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
if bit_length_minus_one == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate huff_tables_fast[args.tc4_th].
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.huff_tables_fast[args.tc4_th][i] = 0xFFFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
j = 0
|
||||
bit_length_minus_one = 0
|
||||
while bit_length_minus_one < 8 {
|
||||
@@ -1236,13 +1236,13 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
this.huff_tables_fast[args.tc4_th][prefix] = fast
|
||||
prefix ~mod+= 1
|
||||
reps -= 1
|
||||
} endwhile
|
||||
}
|
||||
k += 1
|
||||
j ~mod+= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
bit_length_minus_one += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -1321,8 +1321,8 @@ pri func decoder.decode_sos?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
break.fill_bitstream
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile.fill_bitstream
|
||||
} endwhile.decode_mcu
|
||||
}.fill_bitstream
|
||||
}.decode_mcu
|
||||
|
||||
if this.sof_marker >= 0xC2 {
|
||||
this.save_mcu_blocks!(mx: mx, my: my, workbuf: args.workbuf)
|
||||
@@ -1350,9 +1350,9 @@ pri func decoder.decode_sos?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
}
|
||||
|
||||
mx += 1
|
||||
} endwhile
|
||||
}
|
||||
my += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.scan_count ~sat+= 1
|
||||
}
|
||||
@@ -1399,7 +1399,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
break
|
||||
}
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Section B.2.3: "the value of C_sj shall be different from the values
|
||||
// of C_s1 to C_sj–1".
|
||||
@@ -1412,7 +1412,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
c8 = args.src.read_u8?()
|
||||
if ((c8 >> 4) > 3) or ((c8 & 0x0F) > 3) {
|
||||
@@ -1429,7 +1429,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.sof_marker < 0xC2 {
|
||||
// At this point, for sequential (not progressive) JPEGs, we should
|
||||
@@ -1506,10 +1506,10 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
assert j <= 9 via "a <= b: a <= c; c <= b"(c: j_max_incl)
|
||||
this.block_smoothing_lowest_scan_al[this.scan_comps_cselector[i]][j] = this.scan_al
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.scan_num_components == 1 {
|
||||
this.calculate_single_component_scan_fields!()
|
||||
@@ -1607,10 +1607,10 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
}
|
||||
}
|
||||
hv -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if total_hv > 10 {
|
||||
return true
|
||||
}
|
||||
@@ -1629,7 +1629,7 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
this.mcu_blocks_dc_hselector[b] = 0 | this.scan_comps_td[ssel]
|
||||
this.mcu_blocks_ac_hselector[b] = 4 | this.scan_comps_ta[ssel]
|
||||
b += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.scan_width_in_mcus = this.width_in_mcus
|
||||
this.scan_height_in_mcus = this.height_in_mcus
|
||||
@@ -1675,7 +1675,7 @@ pri func decoder.fill_bitstream!(src: base.io_reader) {
|
||||
wi += 1
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// If we hit a "\xFF\x??" marker then pad the bitstream. In this method
|
||||
// invocation, insert up to 264 bytes of implicit zeroes. Repeated calls to
|
||||
@@ -1738,7 +1738,7 @@ pri func decoder.load_mcu_blocks!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2
|
||||
this.mcu_blocks[b .. (b + 1)].bulk_load_host_endian!(src: args.workbuf[offset ..])
|
||||
}
|
||||
b += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.save_mcu_blocks!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2000], workbuf: slice base.u8) {
|
||||
@@ -1768,7 +1768,7 @@ pri func decoder.save_mcu_blocks!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2
|
||||
this.mcu_blocks[b .. (b + 1)].bulk_save_host_endian!(dst: args.workbuf[offset ..])
|
||||
}
|
||||
b += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.skip_past_the_next_restart_marker?(src: base.io_reader) {
|
||||
@@ -1810,7 +1810,7 @@ pri func decoder.skip_past_the_next_restart_marker?(src: base.io_reader) {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.next_restart_marker = (this.next_restart_marker ~mod+ 1) & 7
|
||||
}
|
||||
@@ -1846,7 +1846,7 @@ pri func decoder.apply_progressive_idct!(workbuf: slice base.u8) {
|
||||
block_smoothing_applicable = false
|
||||
}
|
||||
csel += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
csel = 0
|
||||
while csel < this.num_components {
|
||||
@@ -1906,12 +1906,12 @@ pri func decoder.apply_progressive_idct!(workbuf: slice base.u8) {
|
||||
}
|
||||
|
||||
mx += 1
|
||||
} endwhile
|
||||
}
|
||||
my += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
csel += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.mcu_blocks[.. 1].bulk_load_host_endian!(src: stashed_mcu_blocks_0[..])
|
||||
}
|
||||
@@ -1955,7 +1955,7 @@ pri func decoder.swizzle_gray!(dst: ptr base.pixel_buffer, workbuf: slice base.u
|
||||
args.workbuf = this.util.empty_slice_u8()
|
||||
}
|
||||
y += 1
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -2073,9 +2073,9 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
{
|
||||
this.quant_tables[i][j] = this.saved_quant_tables[i][j]
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 4 {
|
||||
@@ -2085,15 +2085,15 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
{
|
||||
this.block_smoothing_lowest_scan_al[i][j] = 16
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 8 {
|
||||
this.seen_dht[i] = false
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -92,9 +92,9 @@ pri func decoder.load_mcu_blocks_for_single_component_smooth!(mx: base.u32[..= 0
|
||||
}
|
||||
|
||||
dx += 1
|
||||
} endwhile
|
||||
}
|
||||
dy += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
q = this.components_tq[args.csel]
|
||||
q_00 = this.quant_tables[q][0x00] as base.u32
|
||||
|
||||
@@ -115,7 +115,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
dc_extend = EXTEND[dc_symbol]
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Process the dc_value in the next dc_symbol (up to 15) bits.
|
||||
@@ -134,7 +134,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
|
||||
this.mcu_zig_index = 1
|
||||
break.dc_component
|
||||
} endwhile.dc_component
|
||||
}.dc_component
|
||||
|
||||
// Ensure that we have enough bits for this iteration of the
|
||||
// while.block loop body. Worst case, there are 64 components and
|
||||
@@ -234,7 +234,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
ac_symbol = 0
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Split the 8-bit ac_symbol into two 4-bit halves, per section
|
||||
@@ -256,7 +256,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
} else if ac_rrrr < 15 {
|
||||
break.ac_components
|
||||
}
|
||||
} endwhile.ac_components
|
||||
}.ac_components
|
||||
|
||||
assert this.mcu_current_block < 10
|
||||
mcb = this.mcu_current_block
|
||||
@@ -278,11 +278,11 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
q: this.components_tq[csel] as base.u32)
|
||||
|
||||
}
|
||||
} endwhile.block
|
||||
}.block
|
||||
this.mcu_current_block = 0
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -147,7 +147,7 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
ac_symbol = 0
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Split the 8-bit ac_symbol into two 4-bit halves, per section
|
||||
@@ -176,13 +176,13 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
}
|
||||
break.ac_components
|
||||
}
|
||||
} endwhile.ac_components
|
||||
}.ac_components
|
||||
|
||||
break.block
|
||||
} endwhile.block
|
||||
}.block
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -105,7 +105,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
ac_symbol = 0
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Split the 8-bit ac_symbol into two 4-bit halves, per section
|
||||
@@ -169,7 +169,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
}
|
||||
assert this.mcu_zig_index < 63 via "a < b: a < c; c <= b"(c: (this.scan_se as base.u32))
|
||||
this.mcu_zig_index += 1
|
||||
} endwhile.refine_non_zeroes
|
||||
}.refine_non_zeroes
|
||||
|
||||
if ac_value <> 0 {
|
||||
this.mcu_blocks[0][UNZIG[1 + this.mcu_zig_index]] = ac_value
|
||||
@@ -180,10 +180,10 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
}
|
||||
assert this.mcu_zig_index < 63 via "a < b: a < c; c <= b"(c: (this.scan_se as base.u32))
|
||||
this.mcu_zig_index += 1
|
||||
} endwhile.ac_components
|
||||
}.ac_components
|
||||
|
||||
break.block
|
||||
}} endwhile.goto_do_eob
|
||||
}}.goto_do_eob
|
||||
|
||||
if this.eob_run <= 0 {
|
||||
ret = 2 // Internal error.
|
||||
@@ -222,15 +222,15 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
}
|
||||
assert this.mcu_zig_index < 63 via "a < b: a < c; c <= b"(c: (this.scan_se as base.u32))
|
||||
this.mcu_zig_index += 1
|
||||
} endwhile.refine_eob_non_zeroes
|
||||
}.refine_eob_non_zeroes
|
||||
|
||||
this.eob_run -= 1
|
||||
|
||||
break.block
|
||||
} endwhile.block
|
||||
}.block
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -95,7 +95,7 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
|
||||
dc_extend = EXTEND[dc_symbol]
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Process the dc_value in the next dc_symbol (up to 15) bits.
|
||||
@@ -113,15 +113,15 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
|
||||
this.mcu_previous_dc_values[csel] ~mod<< this.scan_al
|
||||
|
||||
break.dc_component
|
||||
} endwhile.dc_component
|
||||
}.dc_component
|
||||
|
||||
assert this.mcu_current_block < 10
|
||||
this.mcu_current_block += 1
|
||||
} endwhile.block
|
||||
}.block
|
||||
this.mcu_current_block = 0
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -63,15 +63,15 @@ pri func decoder.decode_mcu_progressive_dc_low_bit!(workbuf: slice base.u8, mx:
|
||||
n_bits ~mod-= 1
|
||||
|
||||
break.dc_component
|
||||
} endwhile.dc_component
|
||||
}.dc_component
|
||||
|
||||
assert this.mcu_current_block < 10
|
||||
this.mcu_current_block += 1
|
||||
} endwhile.block
|
||||
}.block
|
||||
this.mcu_current_block = 0
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -199,7 +199,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
whitespace_length += 1
|
||||
} endwhile.ws
|
||||
}.ws
|
||||
|
||||
// Emit whitespace.
|
||||
if whitespace_length > 0 {
|
||||
@@ -296,7 +296,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.string_loop_outer
|
||||
}
|
||||
string_length += 4
|
||||
} endwhile
|
||||
}
|
||||
|
||||
c8 = args.src.peek_u8()
|
||||
char = LUT_CHARS[c8]
|
||||
@@ -826,8 +826,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.string_loop_outer
|
||||
}
|
||||
return "#bad UTF-8"
|
||||
} endwhile.string_loop_inner
|
||||
} endwhile.string_loop_outer
|
||||
}.string_loop_inner
|
||||
}.string_loop_outer
|
||||
|
||||
// Emit the trailing '"'.
|
||||
while true {
|
||||
@@ -853,7 +853,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continued: 0,
|
||||
length: 1)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// As above, expect must have contained EXPECT_STRING. If it didn't
|
||||
// also contain EXPECT_NUMBER (excluding EXPECT_COMMENT) then we
|
||||
@@ -936,7 +936,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if number_status == 1 {
|
||||
if this.quirks[QUIRK_ALLOW_INF_NAN_NUMBERS - QUIRKS_BASE] {
|
||||
@@ -952,9 +952,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse numbers.
|
||||
|
||||
@@ -1185,7 +1185,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
|
||||
return "#bad input"
|
||||
}} endwhile.goto_parsed_a_leaf_value
|
||||
}}.goto_parsed_a_leaf_value
|
||||
|
||||
// We've just parsed a leaf (non-container) value: literal (null,
|
||||
// false, true), number or string.
|
||||
@@ -1193,7 +1193,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
break.outer
|
||||
}
|
||||
expect = expect_after_value
|
||||
} endwhile.outer
|
||||
}.outer
|
||||
|
||||
if this.quirks[QUIRK_ALLOW_TRAILING_FILLER - QUIRKS_BASE] or
|
||||
this.quirks[QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF - QUIRKS_BASE] {
|
||||
@@ -1335,7 +1335,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
n = this.decode_digits!(src: args.src, n: n)
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
return n | floating_point
|
||||
}
|
||||
@@ -1371,7 +1371,7 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u
|
||||
}
|
||||
n += 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
if n == args.n {
|
||||
n |= 0x100
|
||||
}
|
||||
@@ -1424,7 +1424,7 @@ pri func decoder.decode_leading?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
@@ -1446,7 +1446,7 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
return ok
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
c16 = args.src.peek_u16le()
|
||||
|
||||
if (c16 == '/*'le) and this.quirks[QUIRK_ALLOW_COMMENT_BLOCK - QUIRKS_BASE] {
|
||||
@@ -1473,7 +1473,7 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
@@ -1503,12 +1503,12 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
length += 1
|
||||
} endwhile.comment_block
|
||||
}.comment_block
|
||||
|
||||
} else if (c16 == '//'le) and this.quirks[QUIRK_ALLOW_COMMENT_LINE - QUIRKS_BASE] {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
@@ -1540,7 +1540,7 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
@@ -1569,12 +1569,12 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
length += 1
|
||||
} endwhile.comment_line
|
||||
}.comment_line
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1686,7 +1686,7 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
return "#bad input"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
@@ -1747,6 +1747,6 @@ pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue.outer
|
||||
}
|
||||
whitespace_length += 1
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -129,7 +129,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Check the checksum.
|
||||
checksum_want = args.src.read_u32le?()
|
||||
@@ -164,12 +164,12 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break.outer
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
c32 = args.src.peek_u32le()
|
||||
if c32 <> 'LZIP'le {
|
||||
break.outer
|
||||
}
|
||||
this.crc32.reset!()
|
||||
this.lzma.reset!()
|
||||
} endwhile.outer
|
||||
}.outer
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
assert args.dst.length() >= 282
|
||||
|
||||
@@ -269,7 +269,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len_state = CLAMP_NO_MORE_THAN_3[tree_node & 0x07] as base.u32
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
@@ -338,7 +338,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
@@ -389,12 +389,12 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
break.goto_have_len
|
||||
}} endwhile.goto_have_len
|
||||
}}.goto_have_len
|
||||
|
||||
// AlgOve23 slot = decodeSlot(min(len-2, 3))
|
||||
slot = 1
|
||||
@@ -425,7 +425,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
slot &= 0x3F
|
||||
|
||||
// AlgOve24 distBiasedBy1 = decodeDistBiasedBy1(slot)
|
||||
@@ -474,7 +474,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
|
||||
} else {
|
||||
@@ -511,7 +511,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
if num_extra_bits <= 4 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
dist_extra_bits ~mod<<= 4
|
||||
|
||||
// Read 4 "zzzz" bits.
|
||||
@@ -551,7 +551,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
if num_extra_bits <= 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
}
|
||||
|
||||
@@ -789,7 +789,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
@@ -858,7 +858,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
@@ -909,15 +909,15 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
|
||||
break.goto_after_decode_len
|
||||
}} endwhile.goto_after_decode_len
|
||||
}}.goto_after_decode_len
|
||||
break.goto_do_the_lz_copy
|
||||
}} endwhile.goto_do_the_lz_copy
|
||||
}}.goto_do_the_lz_copy
|
||||
assert args.dst.length() >= 282
|
||||
|
||||
// AlgOve90 labelDoTheLZCopy:
|
||||
@@ -945,7 +945,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
inv dist >= 1,
|
||||
{
|
||||
wb_index ~mod+= this.dict_size as base.u64
|
||||
} endwhile
|
||||
}
|
||||
if wb_index >= args.workbuf.length() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
@@ -1008,7 +1008,7 @@ pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader
|
||||
match_byte = match_cusp >> 8
|
||||
prev_byte = (match_cusp & 0xFF) as base.u8
|
||||
}
|
||||
} endwhile.outer
|
||||
}.outer
|
||||
|
||||
this.stashed_bytes[0] = prev_byte
|
||||
this.stashed_bytes[1] = (match_byte & 0xFF) as base.u8
|
||||
|
||||
@@ -187,7 +187,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile.high_state
|
||||
}.high_state
|
||||
|
||||
} else {
|
||||
tree_node = 1
|
||||
@@ -211,7 +211,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile.low_state
|
||||
}.low_state
|
||||
}
|
||||
|
||||
// AlgOve03 emitLiteral(literal)
|
||||
@@ -294,7 +294,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len_state = CLAMP_NO_MORE_THAN_3[tree_node & 0x07] as base.u32
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
@@ -349,7 +349,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
@@ -390,12 +390,12 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
break.goto_have_len
|
||||
}} endwhile.goto_have_len
|
||||
}}.goto_have_len
|
||||
|
||||
// AlgOve23 slot = decodeSlot(min(len-2, 3))
|
||||
slot = 1
|
||||
@@ -421,7 +421,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
slot &= 0x3F
|
||||
|
||||
// AlgOve24 distBiasedBy1 = decodeDistBiasedBy1(slot)
|
||||
@@ -465,7 +465,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
|
||||
} else {
|
||||
@@ -497,7 +497,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
if num_extra_bits <= 4 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
dist_extra_bits ~mod<<= 4
|
||||
|
||||
// Read 4 "zzzz" bits.
|
||||
@@ -532,7 +532,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
if num_extra_bits <= 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
}
|
||||
|
||||
@@ -741,7 +741,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
@@ -796,7 +796,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
@@ -837,15 +837,15 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
|
||||
break.goto_after_decode_len
|
||||
}} endwhile.goto_after_decode_len
|
||||
}}.goto_after_decode_len
|
||||
break.goto_do_the_lz_copy
|
||||
}} endwhile.goto_do_the_lz_copy
|
||||
}}.goto_do_the_lz_copy
|
||||
|
||||
// AlgOve90 labelDoTheLZCopy:
|
||||
// AlgOve94 emitCopy(len, mrud[0])
|
||||
@@ -866,7 +866,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
post 274 <= args.dst.length(),
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
assert (len as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 274)
|
||||
|
||||
// Copy from the args.workbuf history, if necessary.
|
||||
@@ -880,7 +880,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
inv dist >= 1,
|
||||
{
|
||||
wb_index ~mod+= this.dict_size as base.u64
|
||||
} endwhile
|
||||
}
|
||||
if wb_index >= args.workbuf.length() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
@@ -934,7 +934,7 @@ pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader
|
||||
up_to: len, distance: dist)
|
||||
match_byte = match_cusp >> 8
|
||||
prev_byte = (match_cusp & 0xFF) as base.u8
|
||||
} endwhile.outer
|
||||
}.outer
|
||||
|
||||
this.stashed_bytes[0] = prev_byte
|
||||
this.stashed_bytes[1] = (match_byte & 0xFF) as base.u8
|
||||
|
||||
@@ -356,7 +356,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return ah_status
|
||||
}
|
||||
yield? dti_status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: roslice base.u8) {
|
||||
@@ -422,7 +422,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
post args.src.length() > 0,
|
||||
{
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if args.src.peek_u8() == 0x00 {
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -456,7 +456,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
} else {
|
||||
yield? base."$short read"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
}
|
||||
this.decoded_length = header_byte as base.u64
|
||||
@@ -523,7 +523,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
|
||||
while args.workbuf.length() < ((this.dict_size as base.u64) + 273) {
|
||||
yield? base."$short workbuf"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while true {
|
||||
smark = args.src.mark()
|
||||
@@ -533,7 +533,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.decoded_length == 0xFFFF_FFFF_FFFF_FFFF {
|
||||
if this.stashed_bits <> 0 {
|
||||
@@ -557,7 +557,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
} else if this.lzma2_encoded_length_have <> this.lzma2_encoded_length_want {
|
||||
return "#bad LZMA2 header"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_bitstream?(dst: base.io_writer, src: base.io_reader, workbuf: roslice base.u8) {
|
||||
@@ -576,7 +576,7 @@ pri func decoder.decode_bitstream?(dst: base.io_writer, src: base.io_reader, wor
|
||||
if this.end_of_chunk {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.update_stashed_bytes?(dst: base.io_writer, workbuf: roslice base.u8) {
|
||||
@@ -587,7 +587,7 @@ pri func decoder.update_stashed_bytes?(dst: base.io_writer, workbuf: roslice bas
|
||||
|
||||
while args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
dist = 1
|
||||
which = 0
|
||||
@@ -607,7 +607,7 @@ pri func decoder.update_stashed_bytes?(dst: base.io_writer, workbuf: roslice bas
|
||||
inv which < 2,
|
||||
{
|
||||
wb_index ~mod+= this.dict_size as base.u64
|
||||
} endwhile
|
||||
}
|
||||
if wb_index >= args.workbuf.length() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
@@ -616,7 +616,7 @@ pri func decoder.update_stashed_bytes?(dst: base.io_writer, workbuf: roslice bas
|
||||
|
||||
dist = 1 + this.stashed_rep0
|
||||
which += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Preconditions:
|
||||
@@ -637,7 +637,7 @@ pri func decoder.decode_optional_end_of_stream?(src: base.io_reader, workbuf: ro
|
||||
return "#bad bitstream trailer"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
this.stashed_pos_end = this.stashed_pos
|
||||
}
|
||||
|
||||
@@ -658,37 +658,37 @@ pri func decoder.initialize_probs!() {
|
||||
while i < (12 << 4) {
|
||||
this.probs_ao00[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao20[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao40[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < (12 << 4) {
|
||||
this.probs_ao41[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao60[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao63[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
@@ -698,9 +698,9 @@ pri func decoder.initialize_probs!() {
|
||||
{
|
||||
this.probs_match_len_low[i][j] = 1024
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
@@ -710,15 +710,15 @@ pri func decoder.initialize_probs!() {
|
||||
{
|
||||
this.probs_match_len_mid[i][j] = 1024
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.probs_match_len_high[0][i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
@@ -728,9 +728,9 @@ pri func decoder.initialize_probs!() {
|
||||
{
|
||||
this.probs_longrep_len_low[i][j] = 1024
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
@@ -740,15 +740,15 @@ pri func decoder.initialize_probs!() {
|
||||
{
|
||||
this.probs_longrep_len_mid[i][j] = 1024
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.probs_longrep_len_high[0][i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 4 {
|
||||
@@ -758,21 +758,21 @@ pri func decoder.initialize_probs!() {
|
||||
{
|
||||
this.probs_slot[i][j] = 1024
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 128 {
|
||||
this.probs_small_dist[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
this.probs_large_dist[i] = 1024
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
@@ -782,9 +782,9 @@ pri func decoder.initialize_probs!() {
|
||||
{
|
||||
this.probs_lit[i][j] = 1024
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Reset some other LZMA state too. They're not probabilities, but they
|
||||
// need resetting whenever the probabilities do.
|
||||
|
||||
@@ -117,7 +117,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
this.lm1s[i] = 0
|
||||
this.suffixes[i][0] = i as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while true {
|
||||
this.read_from!(src: args.src)
|
||||
@@ -139,7 +139,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.read_from!(src: base.io_reader) {
|
||||
@@ -292,7 +292,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
||||
// in practice, but is necessary for the overflow checker.
|
||||
o = (o ~mod- 8) & 8191
|
||||
c = this.prefixes[c] as base.u32
|
||||
} endwhile
|
||||
}
|
||||
first_byte = this.suffixes[c][0]
|
||||
|
||||
if code == save_code {
|
||||
@@ -333,7 +333,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
||||
this.read_from_return_value = 1
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Rewind args.src, if we're not in "$short read" and we've read too many
|
||||
// bits.
|
||||
@@ -346,7 +346,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
||||
this.read_from_return_value = 5
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.save_code = save_code
|
||||
@@ -374,7 +374,7 @@ pri func decoder.write_to?(dst: base.io_writer) {
|
||||
}
|
||||
this.output_ri = (this.output_ri ~mod+ ((n & 0xFFFF_FFFF) as base.u32)) & 8191
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated. Use transform_io and an io_writer instead.
|
||||
|
||||
@@ -53,7 +53,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -97,14 +97,14 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
if c8 == 0x0A {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.width = ((c8 - '0') as base.u32)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) {
|
||||
@@ -117,7 +117,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return "#unsupported Netpbm file"
|
||||
}
|
||||
this.width = n
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Decode height.
|
||||
while true {
|
||||
@@ -131,14 +131,14 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
if c8 == 0x0A {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.height = ((c8 - '0') as base.u32)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) or (c8 == 0x0D) {
|
||||
@@ -153,7 +153,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return "#unsupported Netpbm file"
|
||||
}
|
||||
this.height = n
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Decode max_value.
|
||||
while true {
|
||||
@@ -167,14 +167,14 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
if c8 == 0x0A {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.max_value = ((c8 - '0') as base.u32)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) or (c8 == 0x0D) {
|
||||
@@ -189,7 +189,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return "#unsupported Netpbm file"
|
||||
}
|
||||
this.max_value = n
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.max_value <> 255 {
|
||||
return "#unsupported Netpbm file"
|
||||
@@ -219,7 +219,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -265,7 +265,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -300,7 +300,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
@@ -359,7 +359,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
}
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
@@ -367,7 +367,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
@@ -378,7 +378,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -115,7 +115,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -161,7 +161,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -196,7 +196,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
@@ -255,7 +255,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
}
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
@@ -263,7 +263,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
@@ -274,7 +274,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ pri func decoder.filter_1!(curr: slice base.u8),
|
||||
args.curr[i] = args.curr[i] ~mod+ fa
|
||||
fa = args.curr[i]
|
||||
i ~mod+= filter_distance
|
||||
} endwhile
|
||||
}
|
||||
i_start += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.filter_1_distance_3_fallback!(curr: slice base.u8) {
|
||||
@@ -91,7 +91,7 @@ pri func decoder.filter_2!(curr: slice base.u8, prev: slice base.u8) {
|
||||
assert i < args.prev.length() via "a < b: a < c; c <= b"(c: n)
|
||||
args.curr[i] = args.curr[i] ~mod+ (args.prev[i])
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Filter 3: Average.
|
||||
@@ -115,7 +115,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
|
||||
args.curr[i] = args.curr[i] ~mod+ (args.curr[i - filter_distance] / 2)
|
||||
i += 1
|
||||
assert i >= filter_distance via "a >= b: a >= (b + c); 0 <= c"(c: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
n = args.curr.length().min(no_more_than: args.prev.length())
|
||||
@@ -129,7 +129,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
|
||||
assert i < args.prev.length() via "a < b: a < c; c <= b"(c: n)
|
||||
args.curr[i] = args.curr[i] ~mod+ (args.prev[i] / 2)
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = filter_distance
|
||||
assert i >= filter_distance via "a >= b: a == b"()
|
||||
@@ -147,7 +147,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
|
||||
(args.prev[i] as base.u32)) / 2) as base.u8)
|
||||
i += 1
|
||||
assert i >= filter_distance via "a >= b: a >= (b + c); 0 <= c"(c: 1)
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ pri func decoder.filter_4!(curr: slice base.u8, prev: slice base.u8),
|
||||
assert i < args.prev.length() via "a < b: a < c; c <= b"(c: n)
|
||||
args.curr[i] = args.curr[i] ~mod+ args.prev[i]
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = filter_distance
|
||||
assert i >= filter_distance via "a >= b: a == b"()
|
||||
@@ -285,7 +285,7 @@ pri func decoder.filter_4!(curr: slice base.u8, prev: slice base.u8),
|
||||
args.curr[i] = args.curr[i] ~mod+ ((fa & 0xFF) as base.u8)
|
||||
i += 1
|
||||
assert i >= filter_distance via "a >= b: a >= (b + c); 0 <= c"(c: 1)
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.filter_4_distance_3_fallback!(curr: slice base.u8, prev: slice base.u8) {
|
||||
|
||||
@@ -174,7 +174,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -218,7 +218,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Verify CRC-32 checksum.
|
||||
checksum_want = args.src.read_u32be?()
|
||||
@@ -283,7 +283,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// If we have metadata, delay reading (skipping) the ancillary chunk's
|
||||
// CRC-32 checksum until the end of tell_me_more.
|
||||
@@ -297,7 +297,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
(checksum_have <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (this.color_type == 3) and (not this.seen_plte) {
|
||||
return "#missing palette"
|
||||
@@ -810,7 +810,7 @@ pri func decoder.decode_iccp?(src: base.io_reader) {
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Compression method.
|
||||
if this.chunk_length <= 0 {
|
||||
@@ -852,7 +852,7 @@ pri func decoder.decode_plte?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.src_palette[(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Set the remaining palette entries to opaque black.
|
||||
while i < 256 {
|
||||
@@ -861,7 +861,7 @@ pri func decoder.decode_plte?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = 0x00
|
||||
this.src_palette[(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_srgb?(src: base.io_reader) {
|
||||
@@ -945,7 +945,7 @@ pri func decoder.decode_trns?(src: base.io_reader) {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c: n)
|
||||
this.src_palette[(4 * i) + 3] = args.src.read_u8?()
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
return "#bad chunk"
|
||||
@@ -961,7 +961,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -1029,7 +1029,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
}
|
||||
args.src.skip_u32?(n: 4) // Skip the checksum.
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
@@ -1111,7 +1111,7 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
// +12 for chunk length, chunk type and checksum.
|
||||
args.src.skip?(n: (this.chunk_length as base.u64) + 12)
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
this.call_sequence = 0x20
|
||||
@@ -1126,7 +1126,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -1190,7 +1190,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
// +12 for chunk length, chunk type and checksum.
|
||||
args.src.skip?(n: (this.chunk_length as base.u64) + 12)
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.zlib_is_dirty {
|
||||
this.zlib.reset!()
|
||||
@@ -1246,7 +1246,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
status = this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
@@ -1258,7 +1258,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
break
|
||||
}
|
||||
this.interlace_pass += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
this.call_sequence = 0x20
|
||||
@@ -1354,7 +1354,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
return "#internal error: zlib decoder did not exhaust its input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.workbuf_wi <> this.pass_workbuf_length {
|
||||
return base."#not enough data"
|
||||
@@ -1430,7 +1430,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
@@ -1467,7 +1467,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
}
|
||||
this.metadata_y = this.metadata_z
|
||||
yield? base."$even more information"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
if this.metadata_is_zlib_compressed {
|
||||
@@ -1574,7 +1574,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
this.ztxt_ri += 1
|
||||
args.dst.write_u16le_fast!(a: c16)
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if zlib_status.is_ok() {
|
||||
this.metadata_is_zlib_compressed = false
|
||||
@@ -1607,7 +1607,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_u8_fast!(a: c8)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
// Other uncompressed keys and values are Latin-1.
|
||||
@@ -1648,9 +1648,9 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_u16le_fast!(a: c16)
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
} endwhile.loop
|
||||
}.loop
|
||||
|
||||
// Key-value pairs come in... pairs.
|
||||
if this.metadata_fourcc == 'KVPK'be {
|
||||
@@ -1688,8 +1688,8 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'zTXt'le {
|
||||
// Compression method.
|
||||
@@ -1708,7 +1708,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
return ok
|
||||
}
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
|
||||
@@ -97,7 +97,7 @@ pri func decoder.filter_and_swizzle!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
|
||||
prev_row = curr_row
|
||||
y += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
}
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else if this.depth < 8 {
|
||||
multiplier = 1
|
||||
@@ -210,7 +210,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
}
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
while x < this.frame_rect_x1,
|
||||
@@ -314,12 +314,12 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
src: bits_unpacked[.. 8])
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
prev_row = curr_row
|
||||
y += (1 as base.u32) << INTERLACING[this.interlace_pass][3]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ pub func hasher.update!(x: roslice base.u8) {
|
||||
this.buf_data[this.buf_len] = args.x[0]
|
||||
this.buf_len += 1
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
this.buf_len = 0
|
||||
this.up!(x: this.buf_data[..])
|
||||
}
|
||||
@@ -189,7 +189,7 @@ pri func hasher.up!(x: roslice base.u8) {
|
||||
((w15 ~mod<< 14) | (w15 >> 18))
|
||||
w[i] = ((s1 ~mod+ w[i - 7]) ~mod+ s0) ~mod+ w[i - 16]
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 64 {
|
||||
@@ -216,7 +216,7 @@ pri func hasher.up!(x: roslice base.u8) {
|
||||
a = t1 ~mod+ t2
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
a ~mod+= this.h0
|
||||
this.h0 = a
|
||||
@@ -283,7 +283,7 @@ pub func hasher.checksum_bitvec256() base.bitvec256 {
|
||||
while i < 64 {
|
||||
buf_data[i] = this.buf_data[i]
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Pad with a 1 bit and then zero or more 0 bits, until we're at 56 bytes
|
||||
// (448 bits), modulo 64 bytes (512 bits).
|
||||
@@ -294,7 +294,7 @@ pub func hasher.checksum_bitvec256() base.bitvec256 {
|
||||
while buf_len < 56 {
|
||||
buf_data[buf_len] = 0x00
|
||||
buf_len += 1
|
||||
} endwhile
|
||||
}
|
||||
final_block = true
|
||||
|
||||
} else {
|
||||
@@ -304,7 +304,7 @@ pub func hasher.checksum_bitvec256() base.bitvec256 {
|
||||
while buf_len < 64 {
|
||||
buf_data[buf_len] = 0x00
|
||||
buf_len += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
h0 = this.h0
|
||||
@@ -385,7 +385,7 @@ pub func hasher.checksum_bitvec256() base.bitvec256 {
|
||||
((w15 ~mod<< 14) | (w15 >> 18))
|
||||
w[i] = ((s1 ~mod+ w[i - 7]) ~mod+ s0) ~mod+ w[i - 16]
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 64 {
|
||||
@@ -412,7 +412,7 @@ pub func hasher.checksum_bitvec256() base.bitvec256 {
|
||||
a = t1 ~mod+ t2
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
a ~mod+= h0
|
||||
b ~mod+= h1
|
||||
@@ -441,8 +441,8 @@ pub func hasher.checksum_bitvec256() base.bitvec256 {
|
||||
while buf_len < 56 {
|
||||
buf_data[buf_len] = 0x00
|
||||
buf_len += 1
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
return this.util.make_bitvec256(
|
||||
e00: (h as base.u64) | ((g as base.u64) << 32),
|
||||
|
||||
@@ -65,7 +65,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -214,14 +214,14 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = 0xFF
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 0x100 {
|
||||
this.src_palette[(i * 4) + 0] = 0x00
|
||||
this.src_palette[(i * 4) + 1] = 0x00
|
||||
this.src_palette[(i * 4) + 2] = 0x00
|
||||
this.src_palette[(i * 4) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
@@ -248,7 +248,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -294,7 +294,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -545,7 +545,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
}
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
dst_x = 0
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
@@ -558,9 +558,9 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
// effectively literals.
|
||||
lit_length = this.width
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
break.resume
|
||||
} endwhile.resume
|
||||
}.resume
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -64,7 +64,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return "#bad header"
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Width, height.
|
||||
i = 0
|
||||
@@ -82,7 +82,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return base."#unsupported image dimension"
|
||||
}
|
||||
p <<= 7
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if i == 0 {
|
||||
this.width = p
|
||||
@@ -90,7 +90,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
this.height = p
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
@@ -116,7 +116,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -162,7 +162,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -231,7 +231,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
if dst_x_in_bytes <= dst.length() {
|
||||
dst = dst[dst_x_in_bytes ..]
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
}
|
||||
@@ -255,9 +255,9 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
|
||||
dst_x += 1
|
||||
} endwhile
|
||||
}
|
||||
dst_y += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
|
||||
@@ -21,9 +21,9 @@ pri func decoder.decode_huffman_groups?(src: base.io_reader, n_huffman_groups: b
|
||||
{
|
||||
this.decode_huffman_tree?(src: args.src, hg: hg, ht: ht)
|
||||
ht += 1
|
||||
} endwhile
|
||||
}
|
||||
hg += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_huffman_tree?(src: base.io_reader, hg: base.u32[..= 255], ht: base.u32[..= 4]) {
|
||||
@@ -170,11 +170,11 @@ pri func decoder.decode_code_length_code_lengths?(src: base.io_reader) {
|
||||
this.n_bits -= 3
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 19 {
|
||||
this.code_length_code_lengths[CODE_LENGTH_CODE_ORDER[i]] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.build_code_lengths_huffman_nodes!() base.status {
|
||||
@@ -205,7 +205,7 @@ pri func decoder.build_code_lengths_huffman_nodes!() base.status {
|
||||
last_used_symbol = symbol
|
||||
}
|
||||
symbol += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if n_used_symbols < 1 {
|
||||
return "#bad Huffman code"
|
||||
@@ -225,7 +225,7 @@ pri func decoder.build_code_lengths_huffman_nodes!() base.status {
|
||||
break
|
||||
}
|
||||
code_len += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if subscription_total > (1 << 15) {
|
||||
return "#bad Huffman code (over-subscribed)"
|
||||
@@ -262,11 +262,11 @@ pri func decoder.build_code_lengths_huffman_nodes!() base.status {
|
||||
}
|
||||
code_bits ~mod<<= 1
|
||||
code_len -= 1
|
||||
} endwhile
|
||||
}
|
||||
this.code_lengths_huffman_nodes[h] = (symbol | 0x8000) as base.u16
|
||||
}
|
||||
symbol += 1
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ pri func decoder.build_huffman_nodes!(hg: base.u32[..= 255], ht: base.u32[..= 4]
|
||||
last_used_symbol = symbol
|
||||
}
|
||||
symbol += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if n_used_symbols < 1 {
|
||||
return "#bad Huffman code"
|
||||
@@ -323,7 +323,7 @@ pri func decoder.build_huffman_nodes!(hg: base.u32[..= 255], ht: base.u32[..= 4]
|
||||
break
|
||||
}
|
||||
code_len += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if subscription_total > (1 << 15) {
|
||||
return "#bad Huffman code (over-subscribed)"
|
||||
@@ -361,11 +361,11 @@ pri func decoder.build_huffman_nodes!(hg: base.u32[..= 255], ht: base.u32[..= 4]
|
||||
}
|
||||
code_bits ~mod<<= 1
|
||||
code_len -= 1
|
||||
} endwhile
|
||||
}
|
||||
this.huffman_nodes[args.hg][h] = (symbol | 0x8000) as base.u16
|
||||
}
|
||||
symbol += 1
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ pri func decoder.build_code_lengths?(src: base.io_reader) {
|
||||
assert this.n_bits < 16 via "a < b: a < c; c <= b"(c: length_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
length = (this.bits & (((1 as base.u32) << length_n_bits) - 1)) + 2
|
||||
this.bits >>= length_n_bits
|
||||
this.n_bits -= length_n_bits
|
||||
@@ -438,7 +438,7 @@ pri func decoder.build_code_lengths?(src: base.io_reader) {
|
||||
assert s < 2328 via "a < b: a < c; c <= b"(c: this.ht_n_symbols)
|
||||
this.code_lengths[s] = 0
|
||||
s += 1
|
||||
} endwhile
|
||||
}
|
||||
break
|
||||
}
|
||||
this.ht_code_lengths_remaining -= 1
|
||||
@@ -462,7 +462,7 @@ pri func decoder.build_code_lengths?(src: base.io_reader) {
|
||||
h = (node as base.u32) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
symbol = (node & 0x7FFF) as base.u32
|
||||
if symbol == 0 {
|
||||
@@ -509,8 +509,8 @@ pri func decoder.build_code_lengths?(src: base.io_reader) {
|
||||
assert s < 2328 via "a < b: a < c; c <= b"(c: s_max)
|
||||
this.code_lengths[s] = repeat_value
|
||||
s += 1
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri const CODE_LENGTH_CODE_ORDER : roarray[19] base.u8[..= 18] = [
|
||||
|
||||
@@ -88,7 +88,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
h = (node as base.u32) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
pixel_g = (node & 0x7FFF) as base.u32
|
||||
|
||||
if pixel_g < 0x100 { // Literal pixel.
|
||||
@@ -112,7 +112,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
color |= ((node & 0xFF) as base.u32) << 16
|
||||
|
||||
// Decode the Blue symbol.
|
||||
@@ -133,7 +133,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
color |= ((node & 0xFF) as base.u32) << 0
|
||||
|
||||
// Decode the Alpha symbol.
|
||||
@@ -154,7 +154,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
color |= ((node & 0xFF) as base.u32) << 24
|
||||
|
||||
} else if pixel_g < 0x118 { // Back-ref pixel.
|
||||
@@ -177,7 +177,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
assert this.n_bits < 12 via "a < b: a < c; c <= b"(c: back_ref_len_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
back_ref_len_minus_1 += this.bits & (((1 as base.u32) << back_ref_len_n_bits) - 1)
|
||||
this.bits >>= back_ref_len_n_bits
|
||||
this.n_bits -= back_ref_len_n_bits
|
||||
@@ -202,7 +202,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
back_ref_dist_sym = (node & 0x7FFF) as base.u32
|
||||
|
||||
if back_ref_dist_sym < 4 {
|
||||
@@ -223,7 +223,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
assert this.n_bits < 24 via "a < b: a < c; c <= b"(c: back_ref_dist_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
back_ref_dist_premap_minus_1 += this.bits & (((1 as base.u32) << back_ref_dist_n_bits) - 1)
|
||||
this.bits >>= back_ref_dist_n_bits
|
||||
this.n_bits -= back_ref_dist_n_bits
|
||||
@@ -257,14 +257,14 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
args.dst[p] = args.dst[q]
|
||||
p += 1
|
||||
q += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Update (x, y).
|
||||
x ~mod+= back_ref_len_minus_1 + 1
|
||||
while x >= args.width {
|
||||
x -= args.width
|
||||
y ~mod+= 1
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
|
||||
} else { // Color cache pixel.
|
||||
@@ -281,7 +281,7 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
color = color_cache_pixels.peek_u32le()
|
||||
this.color_cache[((color ~mod* 0x1E35_A7BD) >> color_cache_shift) & 2047] = color
|
||||
color_cache_pixels = color_cache_pixels[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Look up this.color_cache.
|
||||
color = this.color_cache[(pixel_g - 0x118) & 2047]
|
||||
@@ -304,5 +304,5 @@ pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, wi
|
||||
x = 0
|
||||
y ~mod+= 1
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
|
||||
curr_row[6] ~mod+= curr_row[2]
|
||||
curr_row[7] ~mod+= curr_row[3]
|
||||
curr_row = curr_row[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
tile_size_log2 = this.transform_tile_size_log2[0] as base.u32
|
||||
tiles_per_row = (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
@@ -232,10 +232,10 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
|
||||
curr_row = curr_row[4 ..]
|
||||
prev_row = prev_row[4 ..]
|
||||
x += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
y += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.absolute_difference(a: base.u32[..= 0xFF], b: base.u32[..= 0xFF]) base.u32[..= 0xFF] {
|
||||
@@ -340,10 +340,10 @@ pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: ros
|
||||
}
|
||||
|
||||
x += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
y += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.apply_transform_subtract_green!(pix: slice base.u8) {
|
||||
@@ -421,10 +421,10 @@ pri func decoder.apply_transform_color_indexing!(pix: slice base.u8) {
|
||||
dst[3] = p3
|
||||
dst = dst[4 ..]
|
||||
x ~mod+= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
y += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: we shouldn't need a lookup table for converting i8 to i32.
|
||||
|
||||
@@ -154,7 +154,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -191,7 +191,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return "#short chunk"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
@@ -245,7 +245,7 @@ pri func decoder.do_decode_image_config_limited?(src: base.io_reader) {
|
||||
return "#short chunk"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else if c32 == 'VP8X'le {
|
||||
return "#unsupported WebP file"
|
||||
@@ -293,7 +293,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -339,7 +339,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -384,7 +384,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
break
|
||||
}
|
||||
this.decode_transform?(src: args.src, workbuf: args.workbuf)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
width = this.width
|
||||
if this.seen_transform[3] {
|
||||
@@ -421,7 +421,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (this.workbuf_offset_for_transform[0] as base.u64) > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
@@ -452,7 +452,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
this.apply_transform_color_indexing!(pix: pix)
|
||||
width = this.width
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
status = this.swizzle!(
|
||||
dst: args.dst,
|
||||
@@ -578,7 +578,7 @@ pri func decoder.decode_transform?(src: base.io_reader, workbuf: slice base.u8)
|
||||
p[6] ~mod+= p[2]
|
||||
p[7] ~mod+= p[3]
|
||||
p = p[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,7 +712,7 @@ pri func decoder.decode_hg_table?(src: base.io_reader, width: base.u32[..= 0x400
|
||||
this.overall_n_huffman_groups = hg_plus_1
|
||||
}
|
||||
p = p[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_pixels?(dst: slice base.u8, src: base.io_reader, width: base.u32[..= 0x4000], height: base.u32[..= 0x4000], tile_data: roslice base.u8, tile_size_log2: base.u32[..= 9]) {
|
||||
@@ -725,7 +725,7 @@ pri func decoder.decode_pixels?(dst: slice base.u8, src: base.io_reader, width:
|
||||
assert i < 2048 via "a < b: a < c; c <= b"(c: n)
|
||||
this.color_cache[i] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.decode_pixels_slow?(
|
||||
dst: args.dst,
|
||||
@@ -771,7 +771,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: roslice base.u8, blen
|
||||
tab = args.dst.plane(p: 0)
|
||||
src_bytes_per_row = (this.width * 4) as base.u64
|
||||
|
||||
while.outer src_bytes_per_row <= args.src.length() {
|
||||
while src_bytes_per_row <= args.src.length() {
|
||||
dst = tab.row_u32(y: y)
|
||||
if dst_bytes_per_row < dst.length() {
|
||||
dst = dst[.. dst_bytes_per_row]
|
||||
@@ -784,7 +784,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: roslice base.u8, blen
|
||||
|
||||
args.src = args.src[src_bytes_per_row ..]
|
||||
y ~mod+= 1
|
||||
} endwhile.outer
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ pub func hasher.update!(x: roslice base.u8) {
|
||||
this.up!(x: args.x)
|
||||
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
@@ -135,7 +135,7 @@ pri func hasher.up!(x: roslice base.u8) {
|
||||
this.buf_data[this.buf_len] = args.x[0]
|
||||
this.buf_len += 1
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
buf_len = (this.buf_len & 15) as base.u32
|
||||
v0 = this.v0
|
||||
@@ -249,7 +249,7 @@ pub func hasher.checksum_u32() base.u32 {
|
||||
ret ~mod*= XXH_PRIME32_1
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
ret ^= ret >> 15
|
||||
ret ~mod*= XXH_PRIME32_2
|
||||
|
||||
@@ -138,7 +138,7 @@ pri func hasher.up!(x: roslice base.u8) {
|
||||
this.buf_data[this.buf_len] = args.x[0]
|
||||
this.buf_len += 1
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
buf_len = this.buf_len & 31
|
||||
v0 = this.v0
|
||||
@@ -330,7 +330,7 @@ pub func hasher.checksum_u64() base.u64 {
|
||||
ret ~mod*= XXH_PRIME64_1
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
ret ^= ret >> 33
|
||||
ret ~mod*= XXH_PRIME64_2
|
||||
|
||||
@@ -37,7 +37,7 @@ pri func decoder.apply_non_final_filters!(dst_slice: slice base.u8) base.u8,
|
||||
delta_pos ~mod-= 1
|
||||
args.dst_slice[i] = c8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
this.filters[f] &= 0xFFFF
|
||||
this.filters[f] |= (delta_pos ~mod<< 24)
|
||||
}
|
||||
@@ -46,7 +46,7 @@ pri func decoder.apply_non_final_filters!(dst_slice: slice base.u8) base.u8,
|
||||
break
|
||||
}
|
||||
f -= 1
|
||||
} endwhile
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ pri func decoder.apply_filter_04_x86!(dst_slice: slice base.u8) base.u8 {
|
||||
break
|
||||
}
|
||||
src = dst ^ FILTER_04_X86_MASK_TO_XOR_OPERAND[prev_mask & 7]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
dst &= 0x01FF_FFFF
|
||||
dst |= 0 ~mod- (dst & 0x0100_0000)
|
||||
@@ -157,7 +157,7 @@ pri func decoder.apply_filter_04_x86!(dst_slice: slice base.u8) base.u8 {
|
||||
i ~mod+= 5
|
||||
p ~mod+= 5
|
||||
s = s[5 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
prev_pos = i ~mod- prev_pos
|
||||
if prev_pos > 3 {
|
||||
@@ -194,7 +194,7 @@ pri func decoder.apply_filter_05_powerpc!(dst_slice: slice base.u8) base.u8 {
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
@@ -250,7 +250,7 @@ pri func decoder.apply_filter_06_ia64!(dst_slice: slice base.u8) base.u8 {
|
||||
{
|
||||
x |= (s[j + byte_pos] as base.u64) << (8 * j)
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
norm = x >> bit_res
|
||||
if (((norm >> 37) & 0x0F) <> 0x05) or
|
||||
@@ -276,20 +276,20 @@ pri func decoder.apply_filter_06_ia64!(dst_slice: slice base.u8) base.u8 {
|
||||
{
|
||||
s[j + byte_pos] = ((x >> (8 * j)) & 0xFF) as base.u8
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
if slot >= 2 {
|
||||
break
|
||||
}
|
||||
slot += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
p ~mod+= 16
|
||||
s = s[16 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
@@ -318,7 +318,7 @@ pri func decoder.apply_filter_07_arm!(dst_slice: slice base.u8) base.u8 {
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bcj_pos = p ~mod- 8
|
||||
return s.length() as base.u8
|
||||
@@ -356,7 +356,7 @@ pri func decoder.apply_filter_08_armthumb!(dst_slice: slice base.u8) base.u8 {
|
||||
s[3] = (((y >> 0x08) & 0x07) | 0xF8) as base.u8
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bcj_pos = p ~mod- 4
|
||||
return s.length() as base.u8
|
||||
@@ -387,7 +387,7 @@ pri func decoder.apply_filter_09_sparc!(dst_slice: slice base.u8) base.u8 {
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
@@ -435,7 +435,7 @@ pri func decoder.apply_filter_0a_arm64!(dst_slice: slice base.u8) base.u8 {
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
@@ -537,7 +537,7 @@ pri func decoder.apply_filter_0b_riscv!(dst_slice: slice base.u8) base.u8 {
|
||||
|
||||
p ~mod+= 2
|
||||
s = s[2 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
|
||||
@@ -145,7 +145,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -222,7 +222,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
checksum32_want = args.src.read_u32le?()
|
||||
if this.ignore_checksum {
|
||||
@@ -273,7 +273,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
i8 -= 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
}
|
||||
compressed_size ~mod+= args.src.count_since(mark: smark)
|
||||
@@ -292,7 +292,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (this.block_has_compressed_size and (this.block_compressed_size <> compressed_size)) or
|
||||
(this.block_has_uncompressed_size and (this.block_uncompressed_size <> uncompressed_size)) {
|
||||
@@ -342,7 +342,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
return "#bad padding"
|
||||
}
|
||||
compressed_size ~mod+= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.lzma_needs_reset = true
|
||||
|
||||
@@ -382,7 +382,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
} endwhile.blocks
|
||||
}.blocks
|
||||
|
||||
// Verify the index.
|
||||
this.backwards_size = 0
|
||||
@@ -400,7 +400,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
if not this.ignore_checksum {
|
||||
this.crc32.update!(x: ZEROES[.. 3 & (0 ~mod- (3 & this.backwards_size))])
|
||||
}
|
||||
@@ -410,7 +410,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
return "#bad index"
|
||||
}
|
||||
this.backwards_size ~mod+= 1
|
||||
} endwhile
|
||||
}
|
||||
this.backwards_size >>= 2
|
||||
if (this.backwards_size == 0) or (this.backwards_size > 0xFFFF_FFFF) {
|
||||
return "#bad index"
|
||||
@@ -436,7 +436,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
if (not this.ignore_checksum) and (checksum32_want <> this.crc32.checksum_u32()) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
@@ -462,7 +462,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
}
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
c32 = args.src.peek_u32le()
|
||||
if c32 == '\xFD\x37\x7A\x58'le {
|
||||
@@ -471,9 +471,9 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
return "#bad header (concatenated stream)"
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
} endwhile.stream_padding
|
||||
}.stream_padding
|
||||
this.started_verify_index = false
|
||||
} endwhile.streams
|
||||
}.streams
|
||||
}
|
||||
|
||||
pri func decoder.decode_block_header_with_padding?(src: base.io_reader) {
|
||||
@@ -494,7 +494,7 @@ pri func decoder.decode_block_header_with_padding?(src: base.io_reader) {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if padded_size_have > padded_size_want {
|
||||
return "#bad block header"
|
||||
@@ -508,7 +508,7 @@ pri func decoder.decode_block_header_with_padding?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
padded_size_have += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_block_header_sans_padding?(src: base.io_reader) {
|
||||
@@ -549,7 +549,7 @@ pri func decoder.decode_block_header_sans_padding?(src: base.io_reader) {
|
||||
}
|
||||
this.block_compressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.block_has_uncompressed_size = (flags & 0x80) <> 0
|
||||
@@ -573,7 +573,7 @@ pri func decoder.decode_block_header_sans_padding?(src: base.io_reader) {
|
||||
}
|
||||
this.block_uncompressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the non-final filters.
|
||||
@@ -603,7 +603,7 @@ pri func decoder.decode_block_header_sans_padding?(src: base.io_reader) {
|
||||
{
|
||||
this.filter_data[f][k] = 0x00
|
||||
k += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else if (filter_id < 0x03) or (0x0B < filter_id) {
|
||||
return "#unsupported filter"
|
||||
@@ -650,7 +650,7 @@ pri func decoder.decode_block_header_sans_padding?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
f += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Configure the final filter (which must be LZMA2).
|
||||
|
||||
@@ -711,7 +711,7 @@ pri func decoder.verify_index?(src: base.io_reader) {
|
||||
}
|
||||
this.num_index_blocks |= (1 as base.u64) << 63
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
if this.num_index_blocks <> this.num_actual_blocks {
|
||||
return "#bad index"
|
||||
}
|
||||
@@ -738,7 +738,7 @@ pri func decoder.verify_index?(src: base.io_reader) {
|
||||
}
|
||||
this.index_block_compressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.index_block_uncompressed_size = 0
|
||||
shift = 0
|
||||
@@ -758,7 +758,7 @@ pri func decoder.verify_index?(src: base.io_reader) {
|
||||
}
|
||||
this.index_block_uncompressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Update the verification_want_etc values. The hash function is
|
||||
// loosely based on https://en.wikipedia.org/wiki/MurmurHash#Algorithm
|
||||
@@ -778,7 +778,7 @@ pri func decoder.verify_index?(src: base.io_reader) {
|
||||
hash ^= this.verification_want_hashed_sizes[1]
|
||||
hash = (hash ~mod<< 13) | (hash >> 19)
|
||||
this.verification_want_hashed_sizes[1] = (hash ~mod* 5) ~mod+ 0xE654_6B64
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (this.verification_have_hashed_sizes[0] <> this.verification_want_hashed_sizes[0]) or
|
||||
(this.verification_have_hashed_sizes[1] <> this.verification_want_hashed_sizes[1]) or
|
||||
|
||||
@@ -112,7 +112,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -165,7 +165,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
|
||||
checksum_want = args.src.read_u32be?()
|
||||
|
||||
Reference in New Issue
Block a user