mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Rename the !?? effect to ?
This commit is contained in:
1 parent
1ea32b3745
commit
093268e179
11 files changed
+172
-172
No files matched your search
@@ -265,7 +265,7 @@ func (h *resumabilityHelper) doAssign(r resumabilities, n *a.Assign, depth uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *resumabilityHelper) doExpr(r resumabilities, n *a.Expr) error {
|
func (h *resumabilityHelper) doExpr(r resumabilities, n *a.Expr) error {
|
||||||
if n.Effect()&a.EffectCoroutine == 0 {
|
if !n.Effect().Coroutine() {
|
||||||
return h.doExpr1(r, n, subExprFilterNone, 0)
|
return h.doExpr1(r, n, subExprFilterNone, 0)
|
||||||
}
|
}
|
||||||
for sef := subExprFilterBeforeCoroutine; sef <= subExprFilterAfterCoroutine; sef++ {
|
for sef := subExprFilterBeforeCoroutine; sef <= subExprFilterAfterCoroutine; sef++ {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@
|
|||||||
- Renamed `u32`, `io_reader`, etc to `base.u32`, `base.io_reader`, etc.
|
- Renamed `u32`, `io_reader`, etc to `base.u32`, `base.io_reader`, etc.
|
||||||
- Renamed `unread_u8?` to `undo_byte!`; added `can_undo_byte`.
|
- Renamed `unread_u8?` to `undo_byte!`; added `can_undo_byte`.
|
||||||
- Replaced `= try foo` with `=? foo`.
|
- Replaced `= try foo` with `=? foo`.
|
||||||
- Redesigned `!` vs `?` effects; prohibited effect-ful subexpressions.
|
- Prohibited effect-ful subexpressions.
|
||||||
- Redesigned iterate blocks.
|
- Redesigned iterate blocks.
|
||||||
- Added `{frame,image,pixel}_config` and `pixel_buffer` types.
|
- Added `{frame,image,pixel}_config` and `pixel_buffer` types.
|
||||||
- Added a `reset` method.
|
- Added a `reset` method.
|
||||||
|
|||||||
+11
-7
@@ -109,8 +109,12 @@ func (f Flags) AsEffect() Effect { return Effect(f) }
|
|||||||
type Effect uint8
|
type Effect uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EffectImpure = Effect(0x01)
|
EffectPure = Effect(0)
|
||||||
EffectCoroutine = Effect(0x02)
|
EffectImpure = Effect(effectBitImpure)
|
||||||
|
EffectImpureCoroutine = Effect(effectBitImpure | effectBitCoroutine)
|
||||||
|
|
||||||
|
effectBitImpure = 0x01
|
||||||
|
effectBitCoroutine = 0x02
|
||||||
|
|
||||||
effectMask = Effect(0xFF)
|
effectMask = Effect(0xFF)
|
||||||
)
|
)
|
||||||
@@ -118,19 +122,19 @@ const (
|
|||||||
func (e Effect) AsFlags() Flags { return Flags(e) }
|
func (e Effect) AsFlags() Flags { return Flags(e) }
|
||||||
|
|
||||||
func (e Effect) Pure() bool { return e == 0 }
|
func (e Effect) Pure() bool { return e == 0 }
|
||||||
func (e Effect) Impure() bool { return e&EffectImpure != 0 }
|
func (e Effect) Impure() bool { return e&effectBitImpure != 0 }
|
||||||
func (e Effect) Coroutine() bool { return e&EffectCoroutine != 0 }
|
func (e Effect) Coroutine() bool { return e&effectBitCoroutine != 0 }
|
||||||
|
|
||||||
func (e Effect) WeakerThan(o Effect) bool { return e < o }
|
func (e Effect) WeakerThan(o Effect) bool { return e < o }
|
||||||
|
|
||||||
func (e Effect) String() string {
|
func (e Effect) String() string {
|
||||||
switch e & effectMask {
|
switch e & effectMask {
|
||||||
case 0:
|
case EffectPure:
|
||||||
return ""
|
return ""
|
||||||
case EffectImpure:
|
case EffectImpure:
|
||||||
return "!"
|
return "!"
|
||||||
case EffectImpure | EffectCoroutine:
|
case EffectImpureCoroutine:
|
||||||
return "!??"
|
return "?"
|
||||||
}
|
}
|
||||||
return "‽INVALID_EFFECT‽"
|
return "‽INVALID_EFFECT‽"
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-41
@@ -139,34 +139,34 @@ var Funcs = []string{
|
|||||||
"io_reader.can_undo_byte() bool",
|
"io_reader.can_undo_byte() bool",
|
||||||
"io_reader.undo_byte!()",
|
"io_reader.undo_byte!()",
|
||||||
|
|
||||||
"io_reader.read_u8!??() u8",
|
"io_reader.read_u8?() u8",
|
||||||
|
|
||||||
"io_reader.read_u16be!??() u16",
|
"io_reader.read_u16be?() u16",
|
||||||
"io_reader.read_u16le!??() u16",
|
"io_reader.read_u16le?() u16",
|
||||||
|
|
||||||
"io_reader.read_u8_as_u32!??() u32[..0xFF]",
|
"io_reader.read_u8_as_u32?() u32[..0xFF]",
|
||||||
"io_reader.read_u16be_as_u32!??() u32[..0xFFFF]",
|
"io_reader.read_u16be_as_u32?() u32[..0xFFFF]",
|
||||||
"io_reader.read_u16le_as_u32!??() u32[..0xFFFF]",
|
"io_reader.read_u16le_as_u32?() u32[..0xFFFF]",
|
||||||
"io_reader.read_u24be_as_u32!??() u32[..0xFFFFFF]",
|
"io_reader.read_u24be_as_u32?() u32[..0xFFFFFF]",
|
||||||
"io_reader.read_u24le_as_u32!??() u32[..0xFFFFFF]",
|
"io_reader.read_u24le_as_u32?() u32[..0xFFFFFF]",
|
||||||
"io_reader.read_u32be!??() u32",
|
"io_reader.read_u32be?() u32",
|
||||||
"io_reader.read_u32le!??() u32",
|
"io_reader.read_u32le?() u32",
|
||||||
|
|
||||||
"io_reader.read_u8_as_u64!??() u64[..0xFF]",
|
"io_reader.read_u8_as_u64?() u64[..0xFF]",
|
||||||
"io_reader.read_u16be_as_u64!??() u64[..0xFFFF]",
|
"io_reader.read_u16be_as_u64?() u64[..0xFFFF]",
|
||||||
"io_reader.read_u16le_as_u64!??() u64[..0xFFFF]",
|
"io_reader.read_u16le_as_u64?() u64[..0xFFFF]",
|
||||||
"io_reader.read_u24be_as_u64!??() u64[..0xFFFFFF]",
|
"io_reader.read_u24be_as_u64?() u64[..0xFFFFFF]",
|
||||||
"io_reader.read_u24le_as_u64!??() u64[..0xFFFFFF]",
|
"io_reader.read_u24le_as_u64?() u64[..0xFFFFFF]",
|
||||||
"io_reader.read_u32be_as_u64!??() u64[..0xFFFFFFFF]",
|
"io_reader.read_u32be_as_u64?() u64[..0xFFFFFFFF]",
|
||||||
"io_reader.read_u32le_as_u64!??() u64[..0xFFFFFFFF]",
|
"io_reader.read_u32le_as_u64?() u64[..0xFFFFFFFF]",
|
||||||
"io_reader.read_u40be_as_u64!??() u64[..0xFFFFFFFFFF]",
|
"io_reader.read_u40be_as_u64?() u64[..0xFFFFFFFFFF]",
|
||||||
"io_reader.read_u40le_as_u64!??() u64[..0xFFFFFFFFFF]",
|
"io_reader.read_u40le_as_u64?() u64[..0xFFFFFFFFFF]",
|
||||||
"io_reader.read_u48be_as_u64!??() u64[..0xFFFFFFFFFFFF]",
|
"io_reader.read_u48be_as_u64?() u64[..0xFFFFFFFFFFFF]",
|
||||||
"io_reader.read_u48le_as_u64!??() u64[..0xFFFFFFFFFFFF]",
|
"io_reader.read_u48le_as_u64?() u64[..0xFFFFFFFFFFFF]",
|
||||||
"io_reader.read_u56be_as_u64!??() u64[..0xFFFFFFFFFFFFFF]",
|
"io_reader.read_u56be_as_u64?() u64[..0xFFFFFFFFFFFFFF]",
|
||||||
"io_reader.read_u56le_as_u64!??() u64[..0xFFFFFFFFFFFFFF]",
|
"io_reader.read_u56le_as_u64?() u64[..0xFFFFFFFFFFFFFF]",
|
||||||
"io_reader.read_u64be!??() u64",
|
"io_reader.read_u64be?() u64",
|
||||||
"io_reader.read_u64le!??() u64",
|
"io_reader.read_u64le?() u64",
|
||||||
|
|
||||||
// TODO: these should have an explicit pre-condition "available() >= N".
|
// TODO: these should have an explicit pre-condition "available() >= N".
|
||||||
// For now, that's implicitly checked (i.e. hard coded).
|
// For now, that's implicitly checked (i.e. hard coded).
|
||||||
@@ -212,7 +212,7 @@ var Funcs = []string{
|
|||||||
"io_reader.since_mark() slice u8",
|
"io_reader.since_mark() slice u8",
|
||||||
"io_reader.take!(n u64) slice u8",
|
"io_reader.take!(n u64) slice u8",
|
||||||
|
|
||||||
"io_reader.skip!??(n u32)",
|
"io_reader.skip?(n u32)",
|
||||||
|
|
||||||
// TODO: this should have explicit pre-conditions "actual <= worst_case"
|
// TODO: this should have explicit pre-conditions "actual <= worst_case"
|
||||||
// and "worst_case <= available()". As an implementation restriction, we
|
// and "worst_case <= available()". As an implementation restriction, we
|
||||||
@@ -222,21 +222,21 @@ var Funcs = []string{
|
|||||||
|
|
||||||
// ---- io_writer
|
// ---- io_writer
|
||||||
|
|
||||||
"io_writer.write_u8!??(x u8)",
|
"io_writer.write_u8?(x u8)",
|
||||||
"io_writer.write_u16be!??(x u16)",
|
"io_writer.write_u16be?(x u16)",
|
||||||
"io_writer.write_u16le!??(x u16)",
|
"io_writer.write_u16le?(x u16)",
|
||||||
"io_writer.write_u24be!??(x u32[..0xFFFFFF])",
|
"io_writer.write_u24be?(x u32[..0xFFFFFF])",
|
||||||
"io_writer.write_u24le!??(x u32[..0xFFFFFF])",
|
"io_writer.write_u24le?(x u32[..0xFFFFFF])",
|
||||||
"io_writer.write_u32be!??(x u32)",
|
"io_writer.write_u32be?(x u32)",
|
||||||
"io_writer.write_u32le!??(x u32)",
|
"io_writer.write_u32le?(x u32)",
|
||||||
"io_writer.write_u40be!??(x u64[..0xFFFFFFFFFF])",
|
"io_writer.write_u40be?(x u64[..0xFFFFFFFFFF])",
|
||||||
"io_writer.write_u40le!??(x u64[..0xFFFFFFFFFF])",
|
"io_writer.write_u40le?(x u64[..0xFFFFFFFFFF])",
|
||||||
"io_writer.write_u48be!??(x u64[..0xFFFFFFFFFFFF])",
|
"io_writer.write_u48be?(x u64[..0xFFFFFFFFFFFF])",
|
||||||
"io_writer.write_u48le!??(x u64[..0xFFFFFFFFFFFF])",
|
"io_writer.write_u48le?(x u64[..0xFFFFFFFFFFFF])",
|
||||||
"io_writer.write_u56be!??(x u64[..0xFFFFFFFFFFFFFF])",
|
"io_writer.write_u56be?(x u64[..0xFFFFFFFFFFFFFF])",
|
||||||
"io_writer.write_u56le!??(x u64[..0xFFFFFFFFFFFFFF])",
|
"io_writer.write_u56le?(x u64[..0xFFFFFFFFFFFFFF])",
|
||||||
"io_writer.write_u64be!??(x u64)",
|
"io_writer.write_u64be?(x u64)",
|
||||||
"io_writer.write_u64le!??(x u64)",
|
"io_writer.write_u64le?(x u64)",
|
||||||
|
|
||||||
// TODO: these should have an explicit pre-condition "available() >= N".
|
// TODO: these should have an explicit pre-condition "available() >= N".
|
||||||
// For now, that's implicitly checked (i.e. hard coded).
|
// For now, that's implicitly checked (i.e. hard coded).
|
||||||
|
|||||||
+7
-11
@@ -1161,17 +1161,13 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parseEffect() a.Effect {
|
func (p *parser) parseEffect() a.Effect {
|
||||||
if p.peek1() != t.IDExclam {
|
switch p.peek1() {
|
||||||
return 0
|
case t.IDExclam:
|
||||||
}
|
p.src = p.src[1:]
|
||||||
p.src = p.src[1:]
|
|
||||||
if p.peek1() != t.IDQuestion {
|
|
||||||
return a.EffectImpure
|
return a.EffectImpure
|
||||||
|
case t.IDQuestion:
|
||||||
|
p.src = p.src[1:]
|
||||||
|
return a.EffectImpureCoroutine
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
return 0
|
||||||
if p.peek1() != t.IDQuestion {
|
|
||||||
panic("TODO: delete")
|
|
||||||
}
|
|
||||||
p.src = p.src[1:]
|
|
||||||
return a.EffectImpure | a.EffectCoroutine
|
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ pub struct decoder?(
|
|||||||
end_of_block base.bool,
|
end_of_block base.bool,
|
||||||
)
|
)
|
||||||
|
|
||||||
pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||||
var status base.status
|
var status base.status
|
||||||
var written slice base.u8
|
var written slice base.u8
|
||||||
var n_copied base.u64
|
var n_copied base.u64
|
||||||
@@ -129,7 +129,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
|
|
||||||
while true {
|
while true {
|
||||||
args.dst.set_mark!()
|
args.dst.set_mark!()
|
||||||
status =? this.decode_blocks!??(dst:args.dst, src:args.src)
|
status =? this.decode_blocks?(dst:args.dst, src:args.src)
|
||||||
if not status.is_suspension() {
|
if not status.is_suspension() {
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
|
||||||
var final base.u32
|
var final base.u32
|
||||||
var b0 base.u32[..255]
|
var b0 base.u32[..255]
|
||||||
var type base.u32
|
var type base.u32
|
||||||
@@ -188,7 +188,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
|||||||
while this.n_bits < 3,
|
while this.n_bits < 3,
|
||||||
post this.n_bits >= 3,
|
post this.n_bits >= 3,
|
||||||
{
|
{
|
||||||
b0 = args.src.read_u8_as_u32!??()
|
b0 = args.src.read_u8_as_u32?()
|
||||||
this.bits |= b0 << this.n_bits
|
this.bits |= b0 << this.n_bits
|
||||||
this.n_bits += 8
|
this.n_bits += 8
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
|||||||
this.n_bits -= 3
|
this.n_bits -= 3
|
||||||
|
|
||||||
if type == 0 {
|
if type == 0 {
|
||||||
this.decode_uncompressed!??(dst:args.dst, src:args.src)
|
this.decode_uncompressed?(dst:args.dst, src:args.src)
|
||||||
continue
|
continue
|
||||||
} else if type == 1 {
|
} else if type == 1 {
|
||||||
status = this.init_fixed_huffman!()
|
status = this.init_fixed_huffman!()
|
||||||
@@ -206,7 +206,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
} else if type == 2 {
|
} else if type == 2 {
|
||||||
this.init_dynamic_huffman!??(src:args.src)
|
this.init_dynamic_huffman?(src:args.src)
|
||||||
} else {
|
} else {
|
||||||
return "?bad block"
|
return "?bad block"
|
||||||
}
|
}
|
||||||
@@ -219,7 +219,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
|||||||
if this.end_of_block {
|
if this.end_of_block {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
this.decode_huffman_slow!??(dst:args.dst, src:args.src)
|
this.decode_huffman_slow?(dst:args.dst, src:args.src)
|
||||||
if this.end_of_block {
|
if this.end_of_block {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
|||||||
|
|
||||||
// decode_uncompressed decodes an uncompresed block as per the RFC section
|
// decode_uncompressed decodes an uncompresed block as per the RFC section
|
||||||
// 3.2.4.
|
// 3.2.4.
|
||||||
pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader) {
|
pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
|
||||||
var length base.u32
|
var length base.u32
|
||||||
var n_copied base.u32
|
var n_copied base.u32
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader)
|
|||||||
this.n_bits = 0
|
this.n_bits = 0
|
||||||
this.bits = 0
|
this.bits = 0
|
||||||
|
|
||||||
length = args.src.read_u32le!??()
|
length = args.src.read_u32le?()
|
||||||
if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
|
if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
|
||||||
return "?inconsistent stored block length"
|
return "?inconsistent stored block length"
|
||||||
}
|
}
|
||||||
@@ -299,7 +299,7 @@ pri func decoder.init_fixed_huffman!() base.status {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7.
|
// init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7.
|
||||||
pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||||
var bits base.u32
|
var bits base.u32
|
||||||
var n_bits base.u32
|
var n_bits base.u32
|
||||||
var b0 base.u32[..255]
|
var b0 base.u32[..255]
|
||||||
@@ -323,7 +323,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
|||||||
while n_bits < 14,
|
while n_bits < 14,
|
||||||
post n_bits >= 14,
|
post n_bits >= 14,
|
||||||
{
|
{
|
||||||
b0 = args.src.read_u8_as_u32!??()
|
b0 = args.src.read_u8_as_u32?()
|
||||||
bits |= b0 << n_bits
|
bits |= b0 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
|||||||
inv i < n_clen,
|
inv i < n_clen,
|
||||||
post n_bits >= 3,
|
post n_bits >= 3,
|
||||||
{
|
{
|
||||||
b1 = args.src.read_u8_as_u32!??()
|
b1 = args.src.read_u8_as_u32?()
|
||||||
bits |= b1 << n_bits
|
bits |= b1 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
@@ -385,7 +385,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||||
b2 = args.src.read_u8_as_u32!??()
|
b2 = args.src.read_u8_as_u32?()
|
||||||
bits |= b2 << n_bits
|
bits |= b2 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
@@ -434,7 +434,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
|||||||
post n_bits >= n_extra_bits,
|
post n_bits >= n_extra_bits,
|
||||||
{
|
{
|
||||||
assert n_bits < 7 via "a < b: a < c; c <= b"(c:n_extra_bits)
|
assert n_bits < 7 via "a < b: a < c; c <= b"(c:n_extra_bits)
|
||||||
b3 = args.src.read_u8_as_u32!??()
|
b3 = args.src.read_u8_as_u32?()
|
||||||
bits |= b3 << n_bits
|
bits |= b3 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader) {
|
pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||||
var bits base.u32
|
var bits base.u32
|
||||||
var n_bits base.u32
|
var n_bits base.u32
|
||||||
var table_entry base.u32
|
var table_entry base.u32
|
||||||
@@ -59,14 +59,14 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||||
b0 = args.src.read_u8_as_u32!??()
|
b0 = args.src.read_u8_as_u32?()
|
||||||
bits |= b0 << n_bits
|
bits |= b0 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table_entry >> 31) != 0 {
|
if (table_entry >> 31) != 0 {
|
||||||
// Literal.
|
// Literal.
|
||||||
args.dst.write_u8!??(x:((table_entry >> 8) & 0xFF) as base.u8)
|
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||||
continue:loop
|
continue:loop
|
||||||
} else if (table_entry >> 30) != 0 {
|
} else if (table_entry >> 30) != 0 {
|
||||||
// No-op; code continues past the if-else chain.
|
// No-op; code continues past the if-else chain.
|
||||||
@@ -90,14 +90,14 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||||
b1 = args.src.read_u8_as_u32!??()
|
b1 = args.src.read_u8_as_u32?()
|
||||||
bits |= b1 << n_bits
|
bits |= b1 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table_entry >> 31) != 0 {
|
if (table_entry >> 31) != 0 {
|
||||||
// Literal.
|
// Literal.
|
||||||
args.dst.write_u8!??(x:((table_entry >> 8) & 0xFF) as base.u8)
|
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
|
||||||
continue:loop
|
continue:loop
|
||||||
} else if (table_entry >> 30) != 0 {
|
} else if (table_entry >> 30) != 0 {
|
||||||
// No-op; code continues past the if-else chain.
|
// No-op; code continues past the if-else chain.
|
||||||
@@ -130,7 +130,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
post n_bits >= table_entry_n_bits,
|
post n_bits >= table_entry_n_bits,
|
||||||
{
|
{
|
||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||||
b2 = args.src.read_u8_as_u32!??()
|
b2 = args.src.read_u8_as_u32?()
|
||||||
bits |= b2 << n_bits
|
bits |= b2 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||||
b3 = args.src.read_u8_as_u32!??()
|
b3 = args.src.read_u8_as_u32?()
|
||||||
bits |= b3 << n_bits
|
bits |= b3 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||||
b4 = args.src.read_u8_as_u32!??()
|
b4 = args.src.read_u8_as_u32?()
|
||||||
bits |= b4 << n_bits
|
bits |= b4 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
|||||||
post n_bits >= table_entry_n_bits,
|
post n_bits >= table_entry_n_bits,
|
||||||
{
|
{
|
||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||||
b5 = args.src.read_u8_as_u32!??()
|
b5 = args.src.read_u8_as_u32?()
|
||||||
bits |= b5 << n_bits
|
bits |= b5 << n_bits
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-67
@@ -121,7 +121,7 @@ pub struct decoder?(
|
|||||||
lzw lzw.decoder,
|
lzw lzw.decoder,
|
||||||
)
|
)
|
||||||
|
|
||||||
pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_reader) {
|
pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_reader) {
|
||||||
var ffio base.bool
|
var ffio base.bool
|
||||||
|
|
||||||
if this.call_sequence >= 1 {
|
if this.call_sequence >= 1 {
|
||||||
@@ -129,9 +129,9 @@ pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_
|
|||||||
}
|
}
|
||||||
this.dirty_y.reset!()
|
this.dirty_y.reset!()
|
||||||
|
|
||||||
this.decode_header!??(src:args.src)
|
this.decode_header?(src:args.src)
|
||||||
this.decode_lsd!??(src:args.src)
|
this.decode_lsd?(src:args.src)
|
||||||
this.decode_up_to_id_part1!??(src:args.src)
|
this.decode_up_to_id_part1?(src:args.src)
|
||||||
|
|
||||||
// TODO: if this.end_of_data, return an error and/or set dst to zero?
|
// TODO: if this.end_of_data, return an error and/or set dst to zero?
|
||||||
|
|
||||||
@@ -201,17 +201,17 @@ pub func decoder.restart_frame!(index base.u64, io_position base.u64) base.statu
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_reader) {
|
pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_reader) {
|
||||||
var blend base.u8
|
var blend base.u8
|
||||||
|
|
||||||
if not this.end_of_data {
|
if not this.end_of_data {
|
||||||
if this.call_sequence == 0 {
|
if this.call_sequence == 0 {
|
||||||
this.decode_image_config!??(dst:nullptr, src:args.src)
|
this.decode_image_config?(dst:nullptr, src:args.src)
|
||||||
} else if this.call_sequence != 1 {
|
} else if this.call_sequence != 1 {
|
||||||
if this.call_sequence == 2 {
|
if this.call_sequence == 2 {
|
||||||
this.skip_frame!??(src:args.src)
|
this.skip_frame?(src:args.src)
|
||||||
}
|
}
|
||||||
this.decode_up_to_id_part1!??(src:args.src)
|
this.decode_up_to_id_part1?(src:args.src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,30 +243,30 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_
|
|||||||
this.call_sequence = 2
|
this.call_sequence = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.skip_frame!??(src base.io_reader) {
|
pri func decoder.skip_frame?(src base.io_reader) {
|
||||||
var flags base.u8
|
var flags base.u8
|
||||||
|
|
||||||
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
|
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
|
||||||
flags = args.src.read_u8!??()
|
flags = args.src.read_u8?()
|
||||||
if (flags & 0x80) != 0 {
|
if (flags & 0x80) != 0 {
|
||||||
args.src.skip!??(n:(3 as base.u32) << (1 + (flags & 0x07)))
|
args.src.skip?(n:(3 as base.u32) << (1 + (flags & 0x07)))
|
||||||
}
|
}
|
||||||
// Skip the literal width.
|
// Skip the literal width.
|
||||||
args.src.skip!??(n:1)
|
args.src.skip?(n:1)
|
||||||
// Skip the blocks of LZW-compressed data.
|
// Skip the blocks of LZW-compressed data.
|
||||||
this.skip_blocks!??(src:args.src)
|
this.skip_blocks?(src:args.src)
|
||||||
|
|
||||||
this.num_decoded_frames_value ~sat+= 1
|
this.num_decoded_frames_value ~sat+= 1
|
||||||
this.reset_gc!()
|
this.reset_gc!()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: honor args.opts.
|
// TODO: honor args.opts.
|
||||||
pub func decoder.decode_frame!??(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) {
|
pub func decoder.decode_frame?(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) {
|
||||||
if this.call_sequence != 2 {
|
if this.call_sequence != 2 {
|
||||||
this.decode_frame_config!??(dst:nullptr, src:args.src)
|
this.decode_frame_config?(dst:nullptr, src:args.src)
|
||||||
}
|
}
|
||||||
this.decode_id_part1!??(dst:args.dst, src:args.src)
|
this.decode_id_part1?(dst:args.dst, src:args.src)
|
||||||
this.decode_id_part2!??(dst:args.dst, src:args.src, workbuf:args.workbuf)
|
this.decode_id_part2?(dst:args.dst, src:args.src, workbuf:args.workbuf)
|
||||||
|
|
||||||
this.num_decoded_frames_value ~sat+= 1
|
this.num_decoded_frames_value ~sat+= 1
|
||||||
this.reset_gc!()
|
this.reset_gc!()
|
||||||
@@ -283,7 +283,7 @@ pri func decoder.reset_gc!() {
|
|||||||
this.gc_duration = 0
|
this.gc_duration = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.decode_up_to_id_part1!??(src base.io_reader) {
|
pri func decoder.decode_up_to_id_part1?(src base.io_reader) {
|
||||||
var block_type base.u8
|
var block_type base.u8
|
||||||
|
|
||||||
if not this.restarted {
|
if not this.restarted {
|
||||||
@@ -295,11 +295,11 @@ pri func decoder.decode_up_to_id_part1!??(src base.io_reader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while true {
|
while true {
|
||||||
block_type = args.src.read_u8!??()
|
block_type = args.src.read_u8?()
|
||||||
if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer".
|
if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer".
|
||||||
this.decode_extension!??(src:args.src)
|
this.decode_extension?(src:args.src)
|
||||||
} else if block_type == 0x2C { // The spec calls 0x2C the "Image Separator".
|
} else if block_type == 0x2C { // The spec calls 0x2C the "Image Separator".
|
||||||
this.decode_id_part0!??(src:args.src)
|
this.decode_id_part0?(src:args.src)
|
||||||
break
|
break
|
||||||
} else if block_type == 0x3B { // The spec calls 0x3B the "Trailer".
|
} else if block_type == 0x3B { // The spec calls 0x3B the "Trailer".
|
||||||
this.end_of_data = true
|
this.end_of_data = true
|
||||||
@@ -313,12 +313,12 @@ pri func decoder.decode_up_to_id_part1!??(src base.io_reader) {
|
|||||||
// decode_header reads either "GIF87a" or "GIF89a".
|
// decode_header reads either "GIF87a" or "GIF89a".
|
||||||
//
|
//
|
||||||
// See the spec section 17 "Header" on page 7.
|
// See the spec section 17 "Header" on page 7.
|
||||||
pri func decoder.decode_header!??(src base.io_reader) {
|
pri func decoder.decode_header?(src base.io_reader) {
|
||||||
var c array[6] base.u8
|
var c array[6] base.u8
|
||||||
var i base.u32
|
var i base.u32
|
||||||
|
|
||||||
while i < 6 {
|
while i < 6 {
|
||||||
c[i] = args.src.read_u8!??()
|
c[i] = args.src.read_u8?()
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
if (c[0] != 0x47) or (c[1] != 0x49) or (c[2] != 0x46) or (c[3] != 0x38) or
|
if (c[0] != 0x47) or (c[1] != 0x49) or (c[2] != 0x46) or (c[3] != 0x38) or
|
||||||
@@ -330,17 +330,17 @@ pri func decoder.decode_header!??(src base.io_reader) {
|
|||||||
// decode_lsd reads the Logical Screen Descriptor.
|
// decode_lsd reads the Logical Screen Descriptor.
|
||||||
//
|
//
|
||||||
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
||||||
pri func decoder.decode_lsd!??(src base.io_reader) {
|
pri func decoder.decode_lsd?(src base.io_reader) {
|
||||||
var flags base.u8
|
var flags base.u8
|
||||||
var num_palette_entries base.u32[..256]
|
var num_palette_entries base.u32[..256]
|
||||||
var i base.u32
|
var i base.u32
|
||||||
var argb base.u32
|
var argb base.u32
|
||||||
|
|
||||||
this.width = args.src.read_u16le_as_u32!??()
|
this.width = args.src.read_u16le_as_u32?()
|
||||||
this.height = args.src.read_u16le_as_u32!??()
|
this.height = args.src.read_u16le_as_u32?()
|
||||||
flags = args.src.read_u8!??()
|
flags = args.src.read_u8?()
|
||||||
// Ignore the Background Color Index and Pixel Aspect Ratio bytes.
|
// Ignore the Background Color Index and Pixel Aspect Ratio bytes.
|
||||||
args.src.skip!??(n:2)
|
args.src.skip?(n:2)
|
||||||
|
|
||||||
// Read the optional Global Color Table.
|
// Read the optional Global Color Table.
|
||||||
if (flags & 0x80) != 0 {
|
if (flags & 0x80) != 0 {
|
||||||
@@ -350,7 +350,7 @@ pri func decoder.decode_lsd!??(src base.io_reader) {
|
|||||||
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
|
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
|
||||||
// Convert from RGB (in memory order) to ARGB (in native u32 order)
|
// Convert from RGB (in memory order) to ARGB (in native u32 order)
|
||||||
// to BGRA (in memory order).
|
// to BGRA (in memory order).
|
||||||
argb = args.src.read_u24be_as_u32!??()
|
argb = args.src.read_u24be_as_u32?()
|
||||||
argb |= 0xFF000000
|
argb |= 0xFF000000
|
||||||
this.palettes[0][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
|
this.palettes[0][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
|
||||||
this.palettes[0][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
|
this.palettes[0][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
|
||||||
@@ -377,31 +377,31 @@ pri func decoder.decode_lsd!??(src base.io_reader) {
|
|||||||
// - section 24 "Comment Extension" on page 17.
|
// - section 24 "Comment Extension" on page 17.
|
||||||
// - section 25 "Plain Text Extension" on page 18.
|
// - section 25 "Plain Text Extension" on page 18.
|
||||||
// - section 26 "Application Extension" on page 21.
|
// - section 26 "Application Extension" on page 21.
|
||||||
pri func decoder.decode_extension!??(src base.io_reader) {
|
pri func decoder.decode_extension?(src base.io_reader) {
|
||||||
var label base.u8
|
var label base.u8
|
||||||
|
|
||||||
label = args.src.read_u8!??()
|
label = args.src.read_u8?()
|
||||||
if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label".
|
if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label".
|
||||||
this.decode_gc!??(src:args.src)
|
this.decode_gc?(src:args.src)
|
||||||
return ok
|
return ok
|
||||||
} else if label == 0xFF { // The spec calls 0xFF the "Application Extension Label".
|
} else if label == 0xFF { // The spec calls 0xFF the "Application Extension Label".
|
||||||
this.decode_ae!??(src:args.src)
|
this.decode_ae?(src:args.src)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
// We skip over all other extensions, including 0x01 "Plain Text Label" and
|
// We skip over all other extensions, including 0x01 "Plain Text Label" and
|
||||||
// 0xFE "Comment Label".
|
// 0xFE "Comment Label".
|
||||||
this.skip_blocks!??(src:args.src)
|
this.skip_blocks?(src:args.src)
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.skip_blocks!??(src base.io_reader) {
|
pri func decoder.skip_blocks?(src base.io_reader) {
|
||||||
var block_size base.u8
|
var block_size base.u8
|
||||||
|
|
||||||
while true {
|
while true {
|
||||||
block_size = args.src.read_u8!??()
|
block_size = args.src.read_u8?()
|
||||||
if block_size == 0 {
|
if block_size == 0 {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
args.src.skip!??(n:block_size as base.u32)
|
args.src.skip?(n:block_size as base.u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,7 +416,7 @@ pri const netscape2dot0 array[11] base.u8 = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// decode_ae reads an Application Extension.
|
// decode_ae reads an Application Extension.
|
||||||
pri func decoder.decode_ae!??(src base.io_reader) {
|
pri func decoder.decode_ae?(src base.io_reader) {
|
||||||
var c base.u8
|
var c base.u8
|
||||||
var block_size base.u8
|
var block_size base.u8
|
||||||
var not_animexts base.bool
|
var not_animexts base.bool
|
||||||
@@ -425,7 +425,7 @@ pri func decoder.decode_ae!??(src base.io_reader) {
|
|||||||
// This "while true" always executes exactly once, as it ends with a
|
// This "while true" always executes exactly once, as it ends with a
|
||||||
// "break", but using "break"s throughout simplifies the control flow.
|
// "break", but using "break"s throughout simplifies the control flow.
|
||||||
while true {
|
while true {
|
||||||
block_size = args.src.read_u8!??()
|
block_size = args.src.read_u8?()
|
||||||
if block_size == 0 {
|
if block_size == 0 {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
@@ -435,14 +435,14 @@ pri func decoder.decode_ae!??(src base.io_reader) {
|
|||||||
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
|
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
|
||||||
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
|
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
|
||||||
if block_size != 11 {
|
if block_size != 11 {
|
||||||
args.src.skip!??(n:block_size as base.u32)
|
args.src.skip?(n:block_size as base.u32)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
not_animexts = false
|
not_animexts = false
|
||||||
not_netscape = false
|
not_netscape = false
|
||||||
block_size = 0 // Re-purpose the block_size variable as a counter.
|
block_size = 0 // Re-purpose the block_size variable as a counter.
|
||||||
while block_size < 11 {
|
while block_size < 11 {
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
not_animexts = not_animexts or (c != animexts1dot0[block_size])
|
not_animexts = not_animexts or (c != animexts1dot0[block_size])
|
||||||
not_netscape = not_netscape or (c != netscape2dot0[block_size])
|
not_netscape = not_netscape or (c != netscape2dot0[block_size])
|
||||||
block_size += 1
|
block_size += 1
|
||||||
@@ -453,17 +453,17 @@ pri func decoder.decode_ae!??(src base.io_reader) {
|
|||||||
|
|
||||||
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
|
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
|
||||||
// count.
|
// count.
|
||||||
block_size = args.src.read_u8!??()
|
block_size = args.src.read_u8?()
|
||||||
if block_size != 3 {
|
if block_size != 3 {
|
||||||
args.src.skip!??(n:block_size as base.u32)
|
args.src.skip?(n:block_size as base.u32)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c != 0x01 {
|
if c != 0x01 {
|
||||||
args.src.skip!??(n:2)
|
args.src.skip?(n:2)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
this.num_loops = args.src.read_u16le_as_u32!??()
|
this.num_loops = args.src.read_u16le_as_u32?()
|
||||||
this.seen_num_loops = true
|
this.seen_num_loops = true
|
||||||
|
|
||||||
// A loop count of N, in the wire format, actually means "repeat N
|
// A loop count of N, in the wire format, actually means "repeat N
|
||||||
@@ -482,11 +482,11 @@ pri func decoder.decode_ae!??(src base.io_reader) {
|
|||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
this.skip_blocks!??(src:args.src)
|
this.skip_blocks?(src:args.src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode_gc reads a Graphic Control.
|
// decode_gc reads a Graphic Control.
|
||||||
pri func decoder.decode_gc!??(src base.io_reader) {
|
pri func decoder.decode_gc?(src base.io_reader) {
|
||||||
var c base.u8
|
var c base.u8
|
||||||
var flags base.u8
|
var flags base.u8
|
||||||
var gc_duration_centiseconds base.u16
|
var gc_duration_centiseconds base.u16
|
||||||
@@ -494,12 +494,12 @@ pri func decoder.decode_gc!??(src base.io_reader) {
|
|||||||
if this.seen_graphic_control {
|
if this.seen_graphic_control {
|
||||||
return "?bad graphic control"
|
return "?bad graphic control"
|
||||||
}
|
}
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c != 4 {
|
if c != 4 {
|
||||||
return "?bad graphic control"
|
return "?bad graphic control"
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = args.src.read_u8!??()
|
flags = args.src.read_u8?()
|
||||||
this.gc_has_transparent_index = (flags & 0x01) != 0
|
this.gc_has_transparent_index = (flags & 0x01) != 0
|
||||||
|
|
||||||
// Convert the disposal method from GIF's wire format to Wuffs constants.
|
// Convert the disposal method from GIF's wire format to Wuffs constants.
|
||||||
@@ -521,11 +521,11 @@ pri func decoder.decode_gc!??(src base.io_reader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// There are 7056000 flicks per centisecond.
|
// There are 7056000 flicks per centisecond.
|
||||||
gc_duration_centiseconds = args.src.read_u16le!??()
|
gc_duration_centiseconds = args.src.read_u16le?()
|
||||||
this.gc_duration = (gc_duration_centiseconds as base.u64) * 7056000
|
this.gc_duration = (gc_duration_centiseconds as base.u64) * 7056000
|
||||||
this.gc_transparent_index = args.src.read_u8!??()
|
this.gc_transparent_index = args.src.read_u8?()
|
||||||
|
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c != 0 {
|
if c != 0 {
|
||||||
return "?bad graphic control"
|
return "?bad graphic control"
|
||||||
}
|
}
|
||||||
@@ -544,12 +544,12 @@ pri func decoder.decode_gc!??(src base.io_reader) {
|
|||||||
// (part1 and part2) not out of necessity, just for the general programming
|
// (part1 and part2) not out of necessity, just for the general programming
|
||||||
// principle that smaller functions are easier to understand.
|
// principle that smaller functions are easier to understand.
|
||||||
|
|
||||||
pri func decoder.decode_id_part0!??(src base.io_reader) {
|
pri func decoder.decode_id_part0?(src base.io_reader) {
|
||||||
this.frame_rect_x0 = args.src.read_u16le_as_u32!??()
|
this.frame_rect_x0 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_y0 = args.src.read_u16le_as_u32!??()
|
this.frame_rect_y0 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_x1 = args.src.read_u16le_as_u32!??()
|
this.frame_rect_x1 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_x1 ~mod+= this.frame_rect_x0
|
this.frame_rect_x1 ~mod+= this.frame_rect_x0
|
||||||
this.frame_rect_y1 = args.src.read_u16le_as_u32!??()
|
this.frame_rect_y1 = args.src.read_u16le_as_u32?()
|
||||||
this.frame_rect_y1 ~mod+= this.frame_rect_y0
|
this.frame_rect_y1 ~mod+= this.frame_rect_y0
|
||||||
this.dst_x = this.frame_rect_x0
|
this.dst_x = this.frame_rect_x0
|
||||||
this.dst_y = this.frame_rect_y0
|
this.dst_y = this.frame_rect_y0
|
||||||
@@ -565,7 +565,7 @@ pri func decoder.decode_id_part0!??(src base.io_reader) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reader) {
|
pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader) {
|
||||||
var flags base.u8
|
var flags base.u8
|
||||||
var num_palette_entries base.u32[..256]
|
var num_palette_entries base.u32[..256]
|
||||||
var i base.u32
|
var i base.u32
|
||||||
@@ -573,7 +573,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
var dst_palette slice base.u8
|
var dst_palette slice base.u8
|
||||||
var lw base.u8
|
var lw base.u8
|
||||||
|
|
||||||
flags = args.src.read_u8!??()
|
flags = args.src.read_u8?()
|
||||||
if (flags & 0x40) != 0 {
|
if (flags & 0x40) != 0 {
|
||||||
this.interlace = 4
|
this.interlace = 4
|
||||||
} else {
|
} else {
|
||||||
@@ -589,7 +589,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
|
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
|
||||||
// Convert from RGB (in memory order) to ARGB (in native u32 order)
|
// Convert from RGB (in memory order) to ARGB (in native u32 order)
|
||||||
// to BGRA (in memory order).
|
// to BGRA (in memory order).
|
||||||
argb = args.src.read_u24be_as_u32!??()
|
argb = args.src.read_u24be_as_u32?()
|
||||||
argb |= 0xFF000000
|
argb |= 0xFF000000
|
||||||
this.palettes[1][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
|
this.palettes[1][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
|
||||||
this.palettes[1][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
|
this.palettes[1][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
|
||||||
@@ -651,7 +651,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
this.lzw.reset!()
|
this.lzw.reset!()
|
||||||
}
|
}
|
||||||
|
|
||||||
lw = args.src.read_u8!??()
|
lw = args.src.read_u8?()
|
||||||
if (lw < 2) or (8 < lw) {
|
if (lw < 2) or (8 < lw) {
|
||||||
return "?bad literal width"
|
return "?bad literal width"
|
||||||
}
|
}
|
||||||
@@ -660,7 +660,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
this.previous_lzw_decode_ended_abruptly = true
|
this.previous_lzw_decode_ended_abruptly = true
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.decode_id_part2!??(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8) {
|
pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8) {
|
||||||
var block_size base.u64[..255]
|
var block_size base.u64[..255]
|
||||||
var need_block_size base.bool
|
var need_block_size base.bool
|
||||||
var n_compressed base.u64
|
var n_compressed base.u64
|
||||||
@@ -674,7 +674,7 @@ pri func decoder.decode_id_part2!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
while:outer true {
|
while:outer true {
|
||||||
if need_block_size {
|
if need_block_size {
|
||||||
need_block_size = false
|
need_block_size = false
|
||||||
block_size = args.src.read_u8_as_u64!??()
|
block_size = args.src.read_u8_as_u64?()
|
||||||
}
|
}
|
||||||
if block_size == 0 {
|
if block_size == 0 {
|
||||||
break
|
break
|
||||||
@@ -718,7 +718,7 @@ pri func decoder.decode_id_part2!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
return "?internal error: inconsistent ri/wi"
|
return "?internal error: inconsistent ri/wi"
|
||||||
}
|
}
|
||||||
io_bind (io:r, data:this.compressed[this.compressed_ri:this.compressed_wi]) {
|
io_bind (io:r, data:this.compressed[this.compressed_ri:this.compressed_wi]) {
|
||||||
lzw_status =? this.lzw.decode!??(dst:this.util.null_io_writer(), src:r)
|
lzw_status =? this.lzw.decode?(dst:this.util.null_io_writer(), src:r)
|
||||||
this.compressed_ri ~sat+= r.since_mark().length()
|
this.compressed_ri ~sat+= r.since_mark().length()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -735,8 +735,8 @@ pri func decoder.decode_id_part2!??(dst ptr base.pixel_buffer, src base.io_reade
|
|||||||
|
|
||||||
// Skip any trailing blocks.
|
// Skip any trailing blocks.
|
||||||
if need_block_size or (block_size > 0) {
|
if need_block_size or (block_size > 0) {
|
||||||
args.src.skip!??(n:block_size as base.u32)
|
args.src.skip?(n:block_size as base.u32)
|
||||||
this.skip_blocks!??(src:args.src)
|
this.skip_blocks?(src:args.src)
|
||||||
}
|
}
|
||||||
|
|
||||||
break:outer
|
break:outer
|
||||||
|
|||||||
+14
-14
@@ -30,7 +30,7 @@ pub func decoder.set_ignore_checksum!(ic base.bool) {
|
|||||||
this.ignore_checksum = args.ic
|
this.ignore_checksum = args.ic
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||||
var c base.u8
|
var c base.u8
|
||||||
var flags base.u8
|
var flags base.u8
|
||||||
var xlen base.u16
|
var xlen base.u16
|
||||||
@@ -41,26 +41,26 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
var decoded_length_want base.u32
|
var decoded_length_want base.u32
|
||||||
|
|
||||||
// Read the header.
|
// Read the header.
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c != 0x1F {
|
if c != 0x1F {
|
||||||
return "?bad header"
|
return "?bad header"
|
||||||
}
|
}
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c != 0x8B {
|
if c != 0x8B {
|
||||||
return "?bad header"
|
return "?bad header"
|
||||||
}
|
}
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c != 0x08 {
|
if c != 0x08 {
|
||||||
return "?bad compression method"
|
return "?bad compression method"
|
||||||
}
|
}
|
||||||
flags = args.src.read_u8!??()
|
flags = args.src.read_u8?()
|
||||||
// TODO: API for returning the header's MTIME field.
|
// TODO: API for returning the header's MTIME field.
|
||||||
args.src.skip!??(n:6)
|
args.src.skip?(n:6)
|
||||||
|
|
||||||
// Handle FEXTRA.
|
// Handle FEXTRA.
|
||||||
if (flags & 0x04) != 0 {
|
if (flags & 0x04) != 0 {
|
||||||
xlen = args.src.read_u16le!??()
|
xlen = args.src.read_u16le?()
|
||||||
args.src.skip!??(n:xlen as base.u32)
|
args.src.skip?(n:xlen as base.u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle FNAME.
|
// Handle FNAME.
|
||||||
@@ -70,7 +70,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
// filename length to NAME_MAX, which is 255.
|
// filename length to NAME_MAX, which is 255.
|
||||||
if (flags & 0x08) != 0 {
|
if (flags & 0x08) != 0 {
|
||||||
while true {
|
while true {
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
// Handle FCOMMENT.
|
// Handle FCOMMENT.
|
||||||
if (flags & 0x10) != 0 {
|
if (flags & 0x10) != 0 {
|
||||||
while true {
|
while true {
|
||||||
c = args.src.read_u8!??()
|
c = args.src.read_u8?()
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
|
|
||||||
// Handle FHCRC.
|
// Handle FHCRC.
|
||||||
if (flags & 0x02) != 0 {
|
if (flags & 0x02) != 0 {
|
||||||
args.src.skip!??(n:2)
|
args.src.skip?(n:2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserved flags bits must be zero.
|
// Reserved flags bits must be zero.
|
||||||
@@ -100,7 +100,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
// Decode and checksum the DEFLATE-encoded payload.
|
// Decode and checksum the DEFLATE-encoded payload.
|
||||||
while true {
|
while true {
|
||||||
args.dst.set_mark!()
|
args.dst.set_mark!()
|
||||||
status =? this.flate.decode!??(dst:args.dst, src:args.src)
|
status =? this.flate.decode?(dst:args.dst, src:args.src)
|
||||||
if not this.ignore_checksum {
|
if not this.ignore_checksum {
|
||||||
checksum_got = this.checksum.update!(x:args.dst.since_mark())
|
checksum_got = this.checksum.update!(x:args.dst.since_mark())
|
||||||
decoded_length_got ~mod+= ((args.dst.since_mark().length() & 0xFFFFFFFF) as base.u32)
|
decoded_length_got ~mod+= ((args.dst.since_mark().length() & 0xFFFFFFFF) as base.u32)
|
||||||
@@ -110,8 +110,8 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
}
|
}
|
||||||
yield status
|
yield status
|
||||||
}
|
}
|
||||||
checksum_want = args.src.read_u32le!??()
|
checksum_want = args.src.read_u32le?()
|
||||||
decoded_length_want = args.src.read_u32le!??()
|
decoded_length_want = args.src.read_u32le?()
|
||||||
if (not this.ignore_checksum) and
|
if (not this.ignore_checksum) and
|
||||||
((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) {
|
((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) {
|
||||||
return "?bad checksum"
|
return "?bad checksum"
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ pub func decoder.set_literal_width!(lw base.u32[2..8]) {
|
|||||||
this.lw = args.lw
|
this.lw = args.lw
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||||
var i base.u32[..8191]
|
var i base.u32[..8191]
|
||||||
|
|
||||||
// Initialize read_from state.
|
// Initialize read_from state.
|
||||||
@@ -85,7 +85,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
this.read_from!(src:args.src)
|
this.read_from!(src:args.src)
|
||||||
|
|
||||||
if this.output_wi > 0 {
|
if this.output_wi > 0 {
|
||||||
this.write_to!??(dst:args.dst)
|
this.write_to?(dst:args.dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.read_from_return_value == 0 {
|
if this.read_from_return_value == 0 {
|
||||||
@@ -309,7 +309,7 @@ pri func decoder.read_from!(src base.io_reader) {
|
|||||||
this.output_wi = output_wi
|
this.output_wi = output_wi
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.write_to!??(dst base.io_writer) {
|
pri func decoder.write_to?(dst base.io_writer) {
|
||||||
var i base.u32[..8191]
|
var i base.u32[..8191]
|
||||||
var s slice base.u8
|
var s slice base.u8
|
||||||
var n base.u64
|
var n base.u64
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ pub func decoder.set_ignore_checksum!(ic base.bool) {
|
|||||||
this.ignore_checksum = args.ic
|
this.ignore_checksum = args.ic
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||||
var x base.u16
|
var x base.u16
|
||||||
var checksum_got base.u32
|
var checksum_got base.u32
|
||||||
var status base.status
|
var status base.status
|
||||||
var checksum_want base.u32
|
var checksum_want base.u32
|
||||||
|
|
||||||
x = args.src.read_u16be!??()
|
x = args.src.read_u16be?()
|
||||||
if ((x >> 8) & 0x0F) != 0x08 {
|
if ((x >> 8) & 0x0F) != 0x08 {
|
||||||
return "?bad compression method"
|
return "?bad compression method"
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
// Decode and checksum the DEFLATE-encoded payload.
|
// Decode and checksum the DEFLATE-encoded payload.
|
||||||
while true {
|
while true {
|
||||||
args.dst.set_mark!()
|
args.dst.set_mark!()
|
||||||
status =? this.flate.decode!??(dst:args.dst, src:args.src)
|
status =? this.flate.decode?(dst:args.dst, src:args.src)
|
||||||
if not this.ignore_checksum {
|
if not this.ignore_checksum {
|
||||||
checksum_got = this.checksum.update!(x:args.dst.since_mark())
|
checksum_got = this.checksum.update!(x:args.dst.since_mark())
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
|||||||
}
|
}
|
||||||
yield status
|
yield status
|
||||||
}
|
}
|
||||||
checksum_want = args.src.read_u32be!??()
|
checksum_want = args.src.read_u32be?()
|
||||||
if (not this.ignore_checksum) and (checksum_got != checksum_want) {
|
if (not this.ignore_checksum) and (checksum_got != checksum_want) {
|
||||||
return "?bad checksum"
|
return "?bad checksum"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user