Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5ccd9e8e7 | ||
|
|
b0e9efff3f | ||
|
|
8b7f82142c | ||
|
|
b245252e1e | ||
|
|
bad2693efb | ||
|
|
be1f605108 | ||
|
|
315b2e5262 | ||
|
|
fac934b272 | ||
|
|
b8d44be783 | ||
|
|
d0f0591f64 | ||
|
|
c1283e4989 | ||
|
|
c226ed60f5 | ||
|
|
45a79923e6 | ||
|
|
67aa63297c | ||
|
|
8c33dd503b | ||
|
|
5d7b113172 | ||
|
|
886e7f3e8f | ||
|
|
fbc686f9b7 | ||
|
|
9256fe5e54 | ||
|
|
e1b43cd767 | ||
|
|
d90dde4049 | ||
|
|
5392d503e3 | ||
|
|
3ff4bf4674 | ||
|
|
ebe080c9ec | ||
|
|
8feb2709fa | ||
|
|
65afe919b5 | ||
|
|
21acc78c24 | ||
|
|
c5e41f0e65 | ||
|
|
4c5d313120 | ||
|
|
89411bc91d | ||
|
|
8d03a67e6e | ||
|
|
a2e3a5a272 | ||
|
|
f700e00df8 | ||
|
|
a56dbb3e3b | ||
|
|
0f98004914 | ||
|
|
f55274aaa7 | ||
|
|
3e93ffe175 | ||
|
|
e6793fc501 | ||
|
|
09102fb1e8 | ||
|
|
6a3e43f495 | ||
|
|
bed155bd6f | ||
|
|
66f194f7e0 | ||
|
|
29eec43287 | ||
|
|
ae1e075401 | ||
|
|
fc0c5e465b | ||
|
|
99b8c1cb9e | ||
|
|
623290ef87 | ||
|
|
fdad12d59f | ||
|
|
94a2c704d4 | ||
|
|
27e9b81588 | ||
|
|
be047533e1 | ||
|
|
fff55bee66 | ||
|
|
cda8b1950a | ||
|
|
53c0dd20ed | ||
|
|
2422997ee5 | ||
|
|
84ef91dda8 | ||
|
|
f1350825cc | ||
|
|
68b76a8a56 | ||
|
|
787ff21cc7 | ||
|
|
fc635d76f7 | ||
|
|
ce8d08598d | ||
|
|
4c56f5bdb2 | ||
|
|
b5f12153db | ||
|
|
d6cece7e32 | ||
|
|
9c6db2673d | ||
|
|
e0afb3dad3 | ||
|
|
e9cb3c8b34 | ||
|
|
7eaf488bae | ||
|
|
03fd43cfcc | ||
|
|
a55e0a02a2 | ||
|
|
23c9de18c6 | ||
|
|
9719073707 | ||
|
|
94736e2eae | ||
|
|
e4d237df89 | ||
|
|
dd9679b56e | ||
|
|
7b51266642 | ||
|
|
5a93c63f0a | ||
|
|
656c0bdf92 | ||
|
|
b374b2b34f | ||
|
|
ad46513ded | ||
|
|
97eb1290f5 | ||
|
|
14f5859311 | ||
|
|
79ce1a7b0e | ||
|
|
5ecd84e0ed | ||
|
|
a4b14a0f17 | ||
|
|
63d8564b3c | ||
|
|
84d0576419 | ||
|
|
6614ed0e90 | ||
|
|
54646d826d | ||
|
|
d53f37997f | ||
|
|
985a756a48 | ||
|
|
fa1bf3415e | ||
|
|
48e457204f | ||
|
|
418847fe94 | ||
|
|
adfd2965cc | ||
|
|
3fa3928c68 | ||
|
|
03e6188bea | ||
|
|
2f61d7dbd4 | ||
|
|
c203818556 | ||
|
|
6d35660651 | ||
|
|
c82793a984 | ||
|
|
ed4d556721 | ||
|
|
fd69133c5d | ||
|
|
f4002c5b21 | ||
|
|
fc77dc35ff | ||
|
|
c997066a2a | ||
|
|
2c10bc32b0 | ||
|
|
5aa7a9339f | ||
|
|
d17fc6e6eb | ||
|
|
4c09c77bb9 | ||
|
|
db0a5a4f3a | ||
|
|
15c174634e | ||
|
|
510f4581c6 | ||
|
|
792d05bd9c | ||
|
|
e5ead0218e | ||
|
|
f0412122be | ||
|
|
546af5a7c3 | ||
|
|
b64b2ff09a | ||
|
|
c104ae296c | ||
|
|
42de49a938 | ||
|
|
92ea631055 |
No files matched your search
@@ -0,0 +1,6 @@
|
||||
# Allstar (https://github.com/ossf/allstar/) is a GitHub App to set and enforce
|
||||
# security policies.
|
||||
|
||||
# test/data/archive.iso is test data, not a binary to be executed.
|
||||
ignorePaths:
|
||||
- test/data/archive.iso
|
||||
@@ -0,0 +1 @@
|
||||
BasedOnStyle: Chromium
|
||||
@@ -14,6 +14,7 @@ Andrew Dassonville <dassonville.andrew@gmail.com>
|
||||
Google Inc.
|
||||
Jimmy Casey <casey.jimmy@gmail.com>
|
||||
Magnus Anderson <magnus@iastate.edu>
|
||||
Michael Mc Donnell <michael@mcdonnell.dk>
|
||||
Mike Kaufman <mkaufman@microsoft.com>
|
||||
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
|
||||
Přemysl Eric Janouch <p@janouch.name>
|
||||
@@ -37,6 +37,7 @@ Chris Palmer <chris@noncombatant.org>
|
||||
Jimmy Casey <casey.jimmy@gmail.com>
|
||||
Leo Neat <lneat@google.com>
|
||||
Magnus Anderson <magnus@iastate.edu>
|
||||
Michael Mc Donnell <michael@mcdonnell.dk>
|
||||
Mike Kaufman <mkaufman@microsoft.com>
|
||||
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
|
||||
Nigel Tao <nigeltao@golang.org>
|
||||
|
||||
@@ -53,13 +53,13 @@ wuffs gen
|
||||
# http://fastcompression.blogspot.com/2019/01/compiler-warnings.html
|
||||
WARNING_FLAGS="-Wall -Werror -Wpedantic -Wcast-qual -Wcast-align -Wpointer-arith -Wfloat-equal -Wundef -Wvla -Wconversion -Wshadow"
|
||||
|
||||
echo "Checking snapshot compiles cleanly (as C)"
|
||||
echo "Checking snapshot compiles cleanly (as C99)"
|
||||
$CC -c $WARNING_FLAGS -std=c99 -Wc++-compat \
|
||||
release/c/wuffs-unsupported-snapshot.c -o /dev/null
|
||||
$CC -c $WARNING_FLAGS -DWUFFS_IMPLEMENTATION -std=c99 -Wc++-compat \
|
||||
release/c/wuffs-unsupported-snapshot.c -o /dev/null
|
||||
|
||||
echo "Checking snapshot compiles cleanly (as C++)"
|
||||
echo "Checking snapshot compiles cleanly (as C++11)"
|
||||
$CXX -c $WARNING_FLAGS -std=c++11 -x c++ \
|
||||
release/c/wuffs-unsupported-snapshot.c -o /dev/null
|
||||
$CXX -c $WARNING_FLAGS -DWUFFS_IMPLEMENTATION -std=c++11 -x c++ \
|
||||
|
||||
@@ -35,20 +35,20 @@
|
||||
// To quantify "much faster", on this one C file, this program was 80 times
|
||||
// faster than `clang-format`, even without a column limit:
|
||||
//
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
//
|
||||
// More commentary is at:
|
||||
// https://godoc.org/github.com/google/wuffs/lib/dumbindent
|
||||
|
||||
@@ -33,7 +33,7 @@ https://github.com/google/wuffs/blob/main/doc/spec/rac-spec.md
|
||||
|
||||
Usage:
|
||||
|
||||
ractool [flags] [input_filename]
|
||||
ractool [flags] [input_filename]
|
||||
|
||||
If no input_filename is given, stdin is used. Either way, output is written to
|
||||
stdout.
|
||||
@@ -63,10 +63,10 @@ or temporary disk space.
|
||||
|
||||
Examples:
|
||||
|
||||
ractool -decode foo.rac | sha256sum
|
||||
ractool -decode -drange=400..500 foo.rac
|
||||
ractool -encode foo.dat > foo.rac
|
||||
ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac
|
||||
ractool -decode foo.rac | sha256sum
|
||||
ractool -decode -drange=400..500 foo.rac
|
||||
ractool -encode foo.dat > foo.rac
|
||||
ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac
|
||||
|
||||
The "400..500" flag value means the 100 bytes ranging from a DSpace offset
|
||||
(offset in terms of decompressed bytes, not compressed bytes) of 400
|
||||
@@ -79,42 +79,42 @@ Similarly, "1m" and "1M" both mean 1 mebibyte (1048576 bytes).
|
||||
|
||||
General Flags:
|
||||
|
||||
-decode
|
||||
whether to decode the input
|
||||
-encode
|
||||
whether to encode the input
|
||||
-quiet
|
||||
whether to suppress messages
|
||||
-decode
|
||||
whether to decode the input
|
||||
-encode
|
||||
whether to encode the input
|
||||
-quiet
|
||||
whether to suppress messages
|
||||
|
||||
Decode-Related Flags:
|
||||
|
||||
-drange
|
||||
the "i..j" range to decompress, "..8" means the first 8 bytes
|
||||
-singlethreaded
|
||||
whether to decode on a single execution thread
|
||||
-drange
|
||||
the "i..j" range to decompress, "..8" means the first 8 bytes
|
||||
-singlethreaded
|
||||
whether to decode on a single execution thread
|
||||
|
||||
Encode-Related Flags:
|
||||
|
||||
-cchunksize
|
||||
the chunk size (in CSpace)
|
||||
-codec
|
||||
the compression codec (default "zstd")
|
||||
-cpagesize
|
||||
the page size (in CSpace)
|
||||
-dchunksize
|
||||
the chunk size (in DSpace)
|
||||
-indexlocation
|
||||
the index location, "start" or "end" (default "start")
|
||||
-resources
|
||||
comma-separated list of resource files, such as shared dictionaries
|
||||
-tmpdir
|
||||
directory (e.g. $TMPDIR) for intermediate work; empty means in-memory
|
||||
-cchunksize
|
||||
the chunk size (in CSpace)
|
||||
-codec
|
||||
the compression codec (default "zstd")
|
||||
-cpagesize
|
||||
the page size (in CSpace)
|
||||
-dchunksize
|
||||
the chunk size (in DSpace)
|
||||
-indexlocation
|
||||
the index location, "start" or "end" (default "start")
|
||||
-resources
|
||||
comma-separated list of resource files, such as shared dictionaries
|
||||
-tmpdir
|
||||
directory (e.g. $TMPDIR) for intermediate work; empty means in-memory
|
||||
|
||||
Codecs:
|
||||
|
||||
lz4
|
||||
zlib
|
||||
zstd
|
||||
lz4
|
||||
zlib
|
||||
zstd
|
||||
|
||||
Only zlib is fully supported. The others will work for the flags' default
|
||||
values, but they (1) don't support -cchunksize, only -dchunksize, and (2) don't
|
||||
@@ -125,123 +125,123 @@ Installation:
|
||||
|
||||
Like any other implemented-in-Go program, to install the ractool program:
|
||||
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
|
||||
Extended Example:
|
||||
|
||||
--------
|
||||
$ # Fetch and unzip the enwik8 test file, a sample of Wikipedia.
|
||||
$ wget http://mattmahoney.net/dc/enwik8.zip
|
||||
$ unzip enwik8.zip
|
||||
--------
|
||||
$ # Fetch and unzip the enwik8 test file, a sample of Wikipedia.
|
||||
$ wget http://mattmahoney.net/dc/enwik8.zip
|
||||
$ unzip enwik8.zip
|
||||
|
||||
$ # Also zstd-encode it, as a reference point. Using compression level 15,
|
||||
$ # instead of the default of 3, matches what ractool uses.
|
||||
$ zstd -15 enwik8
|
||||
$ # Also zstd-encode it, as a reference point. Using compression level 15,
|
||||
$ # instead of the default of 3, matches what ractool uses.
|
||||
$ zstd -15 enwik8
|
||||
|
||||
$ # Create a shared dictionary. Using zstd-the-program produces a
|
||||
$ # dictionary that is especially useful for zstd-the-format, but it can
|
||||
$ # also be used by other formats as a 'raw' prefix dictionary.
|
||||
$ zstd -15 --train -B64K --maxdict=32K -o dict.dat enwik8
|
||||
$ # Create a shared dictionary. Using zstd-the-program produces a
|
||||
$ # dictionary that is especially useful for zstd-the-format, but it can
|
||||
$ # also be used by other formats as a 'raw' prefix dictionary.
|
||||
$ zstd -15 --train -B64K --maxdict=32K -o dict.dat enwik8
|
||||
|
||||
$ # RAC-encode it with various codecs, with and without that dictionary.
|
||||
$ ractool -encode -codec=zlib -resources=dict.dat enwik8 > zlib.withdict.rac
|
||||
$ ractool -encode -codec=zlib enwik8 > zlib.sansdict.rac
|
||||
$ ractool -encode -codec=zstd -resources=dict.dat enwik8 > zstd.withdict.rac
|
||||
$ ractool -encode -codec=zstd enwik8 > zstd.sansdict.rac
|
||||
$ ractool -encode -codec=lz4 enwik8 > lz4.sansdict.rac
|
||||
$ # RAC-encode it with various codecs, with and without that dictionary.
|
||||
$ ractool -encode -codec=zlib -resources=dict.dat enwik8 > zlib.withdict.rac
|
||||
$ ractool -encode -codec=zlib enwik8 > zlib.sansdict.rac
|
||||
$ ractool -encode -codec=zstd -resources=dict.dat enwik8 > zstd.withdict.rac
|
||||
$ ractool -encode -codec=zstd enwik8 > zstd.sansdict.rac
|
||||
$ ractool -encode -codec=lz4 enwik8 > lz4.sansdict.rac
|
||||
|
||||
$ # The size overhead (comparing RAC+Xxx to Xxx) is about 0.2% (with) or
|
||||
$ # 4.8% (sans) for zlib/zip and about 13% (with) or 28% (sans) for zstd,
|
||||
$ # depending on whether we used a shared dictionary (with or sans).
|
||||
$ ls -l
|
||||
total 362080
|
||||
-rw-r----- 1 tao tao 32768 Oct 25 10:10 dict.dat
|
||||
-rw-r----- 1 tao tao 100000000 Jun 2 2011 enwik8
|
||||
-rw-r----- 1 tao tao 36445475 Sep 2 2011 enwik8.zip
|
||||
-rw-r----- 1 tao tao 29563109 Jun 2 2011 enwik8.zst
|
||||
-rw-r----- 1 tao tao 58813316 Oct 25 10:17 lz4.sansdict.rac
|
||||
-rw-r----- 1 tao tao 38185178 Oct 25 10:16 zlib.sansdict.rac
|
||||
-rw-r----- 1 tao tao 36505786 Oct 25 10:16 zlib.withdict.rac
|
||||
-rw-r----- 1 tao tao 37820491 Oct 25 10:17 zstd.sansdict.rac
|
||||
-rw-r----- 1 tao tao 33386395 Oct 25 10:17 zstd.withdict.rac
|
||||
$ # The size overhead (comparing RAC+Xxx to Xxx) is about 0.2% (with) or
|
||||
$ # 4.8% (sans) for zlib/zip and about 13% (with) or 28% (sans) for zstd,
|
||||
$ # depending on whether we used a shared dictionary (with or sans).
|
||||
$ ls -l
|
||||
total 362080
|
||||
-rw-r----- 1 tao tao 32768 Oct 25 10:10 dict.dat
|
||||
-rw-r----- 1 tao tao 100000000 Jun 2 2011 enwik8
|
||||
-rw-r----- 1 tao tao 36445475 Sep 2 2011 enwik8.zip
|
||||
-rw-r----- 1 tao tao 29563109 Jun 2 2011 enwik8.zst
|
||||
-rw-r----- 1 tao tao 58813316 Oct 25 10:17 lz4.sansdict.rac
|
||||
-rw-r----- 1 tao tao 38185178 Oct 25 10:16 zlib.sansdict.rac
|
||||
-rw-r----- 1 tao tao 36505786 Oct 25 10:16 zlib.withdict.rac
|
||||
-rw-r----- 1 tao tao 37820491 Oct 25 10:17 zstd.sansdict.rac
|
||||
-rw-r----- 1 tao tao 33386395 Oct 25 10:17 zstd.withdict.rac
|
||||
|
||||
$ # Check that the decompressed forms all match.
|
||||
$ cat enwik8 | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzip -p enwik8.zip | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzstd --stdout enwik8.zst | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ for f in *.rac; do ractool -decode $f | sha256sum; done
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ # Check that the decompressed forms all match.
|
||||
$ cat enwik8 | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzip -p enwik8.zip | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzstd --stdout enwik8.zst | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ for f in *.rac; do ractool -decode $f | sha256sum; done
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
|
||||
$ # Compare how long it takes to produce 8 bytes from the middle of
|
||||
$ # the decompressed file, which happens to be the word "Business".
|
||||
$ time unzip -p enwik8.zip | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.379s
|
||||
user 0m0.410s
|
||||
sys 0m0.080s
|
||||
$ time unzstd --stdout enwik8.zst | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.172s
|
||||
user 0m0.141s
|
||||
sys 0m0.103s
|
||||
$ time ractool -decode -drange=50000000..50000008 zstd.withdict.rac
|
||||
Business
|
||||
real 0m0.004s
|
||||
user 0m0.005s
|
||||
sys 0m0.001s
|
||||
$ # Compare how long it takes to produce 8 bytes from the middle of
|
||||
$ # the decompressed file, which happens to be the word "Business".
|
||||
$ time unzip -p enwik8.zip | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.379s
|
||||
user 0m0.410s
|
||||
sys 0m0.080s
|
||||
$ time unzstd --stdout enwik8.zst | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.172s
|
||||
user 0m0.141s
|
||||
sys 0m0.103s
|
||||
$ time ractool -decode -drange=50000000..50000008 zstd.withdict.rac
|
||||
Business
|
||||
real 0m0.004s
|
||||
user 0m0.005s
|
||||
sys 0m0.001s
|
||||
|
||||
$ # A RAC file's chunks can be decoded in parallel, unlike ZIP,
|
||||
$ # substantially reducing the real (wall clock) time taken even
|
||||
$ # though both of these files use DEFLATE (RFC 1951) compression.
|
||||
$ #
|
||||
$ # Comparing the -singlethreaded time suggests that zlib-the-library's
|
||||
$ # DEFLATE implementation is faster than unzip's.
|
||||
$ time unzip -p enwik8.zip > /dev/null
|
||||
real 0m0.711s
|
||||
user 0m0.690s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode -singlethreaded zlib.withdict.rac > /dev/null
|
||||
real 0m0.519s
|
||||
user 0m0.513s
|
||||
sys 0m0.017s
|
||||
$ time ractool -decode zlib.withdict.rac > /dev/null
|
||||
real 0m0.052s
|
||||
user 0m0.678s
|
||||
sys 0m0.036s
|
||||
$ # A RAC file's chunks can be decoded in parallel, unlike ZIP,
|
||||
$ # substantially reducing the real (wall clock) time taken even
|
||||
$ # though both of these files use DEFLATE (RFC 1951) compression.
|
||||
$ #
|
||||
$ # Comparing the -singlethreaded time suggests that zlib-the-library's
|
||||
$ # DEFLATE implementation is faster than unzip's.
|
||||
$ time unzip -p enwik8.zip > /dev/null
|
||||
real 0m0.711s
|
||||
user 0m0.690s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode -singlethreaded zlib.withdict.rac > /dev/null
|
||||
real 0m0.519s
|
||||
user 0m0.513s
|
||||
sys 0m0.017s
|
||||
$ time ractool -decode zlib.withdict.rac > /dev/null
|
||||
real 0m0.052s
|
||||
user 0m0.678s
|
||||
sys 0m0.036s
|
||||
|
||||
$ # A similar comparison can be made for Zstandard.
|
||||
$ time unzstd --stdout enwik8.zst > /dev/null
|
||||
real 0m0.203s
|
||||
user 0m0.187s
|
||||
sys 0m0.016s
|
||||
$ time ractool -decode -singlethreaded zstd.withdict.rac > /dev/null
|
||||
real 0m0.235s
|
||||
user 0m0.206s
|
||||
sys 0m0.033s
|
||||
$ time ractool -decode zstd.withdict.rac > /dev/null
|
||||
real 0m0.037s
|
||||
user 0m0.374s
|
||||
sys 0m0.080s
|
||||
$ # A similar comparison can be made for Zstandard.
|
||||
$ time unzstd --stdout enwik8.zst > /dev/null
|
||||
real 0m0.203s
|
||||
user 0m0.187s
|
||||
sys 0m0.016s
|
||||
$ time ractool -decode -singlethreaded zstd.withdict.rac > /dev/null
|
||||
real 0m0.235s
|
||||
user 0m0.206s
|
||||
sys 0m0.033s
|
||||
$ time ractool -decode zstd.withdict.rac > /dev/null
|
||||
real 0m0.037s
|
||||
user 0m0.374s
|
||||
sys 0m0.080s
|
||||
|
||||
$ # For reference, LZ4 numbers.
|
||||
$ time ractool -decode -singlethreaded lz4.sansdict.rac > /dev/null
|
||||
real 0m0.072s
|
||||
user 0m0.053s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode lz4.sansdict.rac > /dev/null
|
||||
real 0m0.024s
|
||||
user 0m0.097s
|
||||
sys 0m0.034s
|
||||
--------
|
||||
$ # For reference, LZ4 numbers.
|
||||
$ time ractool -decode -singlethreaded lz4.sansdict.rac > /dev/null
|
||||
real 0m0.072s
|
||||
user 0m0.053s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode lz4.sansdict.rac > /dev/null
|
||||
real 0m0.024s
|
||||
user 0m0.097s
|
||||
sys 0m0.034s
|
||||
--------
|
||||
*/
|
||||
package main
|
||||
|
||||
|
||||
@@ -5,20 +5,34 @@ below. Higher is better.
|
||||
|
||||
"Mimic" tests check that Wuffs' output mimics (i.e. exactly matches) other
|
||||
libraries' output. "Mimic" benchmarks give the numbers for those other
|
||||
libraries, as shipped with Debian. These were measured on a Debian Testing
|
||||
system as of October 2019, which meant these compiler versions:
|
||||
libraries, as shipped with Debian. These were measured on a Debian Bullseye
|
||||
system as of September 2022, which meant these compiler versions:
|
||||
|
||||
- clang/llvm 8.0.1
|
||||
- gcc 9.2.1
|
||||
- clang/llvm 11.0.1
|
||||
- gcc 10.2.1
|
||||
|
||||
and these "mimic" library versions, all written in C:
|
||||
and these popular "mimic" library versions, all written in C:
|
||||
|
||||
- libgif 5.1.4
|
||||
- zlib 1.2.11
|
||||
- libbz2 1.0.8
|
||||
- libgif 5.1.9
|
||||
- libpng 1.6.37
|
||||
- zlib 1.2.11 (we'll call this "ztl" or "zlib the library", as opposed to "zlib
|
||||
the format")
|
||||
|
||||
Unless otherwise stated, the numbers below were measured on an Intel x86\_64
|
||||
Broadwell, and were taken as of Wuffs git commit ffdce5ef "Have bench-rust-gif
|
||||
process animated / RGBA images".
|
||||
and these alternative "mimic" library versions, again all written in C:
|
||||
|
||||
- [libdeflate](https://github.com/ebiggers/libdeflate) 1.7.1
|
||||
- [libspng](https://github.com/randy408/libspng) 0.7.3
|
||||
- [lodepng](https://github.com/lvandeve/lodepng) 20220717
|
||||
- [miniz](https://github.com/richgel999/miniz) 2.2.0
|
||||
- [stb](https://github.com/nothings/stb) 2.27
|
||||
|
||||
Unless otherwise stated, the numbers below were taken as of Wuffs git commit
|
||||
315b2e52 "wuffs gen -version=0.3.0-rc.1", the first Wuffs v0.3 release
|
||||
candidate. As for the CPU model:
|
||||
|
||||
$ cat /proc/cpuinfo | grep model.name | uniq
|
||||
model name: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
|
||||
|
||||
|
||||
## Reproducing
|
||||
@@ -89,65 +103,110 @@ power management can be controlled with:
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes are hashed.
|
||||
|
||||
name speed vs_mimic
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_adler32_10k/clang8 2.41GB/s 0.84x
|
||||
wuffs_adler32_100k/clang8 2.42GB/s 0.84x
|
||||
wuffs_adler32_10k/clang11 22.3 GB/s 6.4x
|
||||
wuffs_adler32_100k/clang11 26.4 GB/s 7.5x
|
||||
|
||||
wuffs_adler32_10k/gcc9 3.24GB/s 1.13x
|
||||
wuffs_adler32_100k/gcc9 3.24GB/s 1.12x
|
||||
wuffs_adler32_10k/gcc10 21.9 GB/s 6.3x
|
||||
wuffs_adler32_100k/gcc10 22.4 GB/s 6.4x
|
||||
|
||||
mimic_adler32_10k 2.87GB/s 1.00x
|
||||
mimic_adler32_100k 2.90GB/s 1.00x
|
||||
mimicztl_adler32_10k 3.50 GB/s 1.0x
|
||||
mimicztl_adler32_100k 3.52 GB/s 1.0x
|
||||
|
||||
mimiclibdeflate_adler32_10k 50.4 GB/s 14.4x
|
||||
mimiclibdeflate_adler32_100k 49.4 GB/s 14.0x
|
||||
|
||||
|
||||
# Bzip2
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
|
||||
decoded output.
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_bzip2_decode_10k/clang11 63.0 MB/s 1.86x
|
||||
wuffs_bzip2_decode_100k/clang11 48.9 MB/s 1.62x
|
||||
|
||||
wuffs_bzip2_decode_10k/gcc10 61.1 MB/s 1.81x
|
||||
wuffs_bzip2_decode_100k/gcc10 49.1 MB/s 1.62x
|
||||
|
||||
mimic_bzip2_decode_10k 33.8 MB/s 1.00x
|
||||
mimic_bzip2_decode_100k 30.2 MB/s 1.00x
|
||||
|
||||
|
||||
# CRC-32
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes are hashed.
|
||||
|
||||
name speed vs_mimic
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_crc32_ieee_10k/clang8 2.85GB/s 2.11x
|
||||
wuffs_crc32_ieee_100k/clang8 2.87GB/s 2.13x
|
||||
wuffs_crc32_ieee_10k/clang11 14.7 GB/s 9.1x
|
||||
wuffs_crc32_ieee_100k/clang11 21.6 GB/s 13.3x
|
||||
|
||||
wuffs_crc32_ieee_10k/gcc9 3.38GB/s 2.50x
|
||||
wuffs_crc32_ieee_100k/gcc9 3.40GB/s 2.52x
|
||||
wuffs_crc32_ieee_10k/gcc10 14.9 GB/s 9.2x
|
||||
wuffs_crc32_ieee_100k/gcc10 23.8 GB/s 14.7x
|
||||
|
||||
mimic_crc32_ieee_10k 1.35GB/s 1.00x
|
||||
mimic_crc32_ieee_100k 1.35GB/s 1.00x
|
||||
mimicztl_crc32_ieee_10k 1.62 GB/s 1.0x
|
||||
mimicztl_crc32_ieee_100k 1.62 GB/s 1.0x
|
||||
|
||||
mimiclibdeflate_crc32_ieee_10k 24.6 GB/s 15.2x
|
||||
mimiclibdeflate_crc32_ieee_100k 25.4 GB/s 15.7x
|
||||
|
||||
|
||||
# Deflate
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
|
||||
decoded output.
|
||||
|
||||
The `full_init` vs `part_init` suffixes are whether
|
||||
[`WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED`](/doc/note/initialization.md#partial-zero-initialization)
|
||||
is unset or set.
|
||||
|
||||
name speed vs_mimic
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_deflate_decode_1k_full_init/clang8 160MB/s 0.74x
|
||||
wuffs_deflate_decode_1k_part_init/clang8 199MB/s 0.92x
|
||||
wuffs_deflate_decode_10k_full_init/clang8 255MB/s 0.94x
|
||||
wuffs_deflate_decode_10k_part_init/clang8 263MB/s 0.97x
|
||||
wuffs_deflate_decode_100k_just_one_read/clang8 306MB/s 0.93x
|
||||
wuffs_deflate_decode_100k_many_big_reads/clang8 250MB/s 0.98x
|
||||
wuffs_deflate_decode_1k_full_init/clang11 195 MB/s 0.81x
|
||||
wuffs_deflate_decode_1k_part_init/clang11 226 MB/s 0.93x
|
||||
wuffs_deflate_decode_10k_full_init/clang11 409 MB/s 1.41x
|
||||
wuffs_deflate_decode_10k_part_init/clang11 418 MB/s 1.47x
|
||||
wuffs_deflate_decode_100k_just_one_read/clang11 521 MB/s 1.48x
|
||||
wuffs_deflate_decode_100k_many_big_reads/clang11 330 MB/s 1.19x
|
||||
|
||||
wuffs_deflate_decode_1k_full_init/gcc9 164MB/s 0.76x
|
||||
wuffs_deflate_decode_1k_part_init/gcc9 207MB/s 0.95x
|
||||
wuffs_deflate_decode_10k_full_init/gcc9 247MB/s 0.91x
|
||||
wuffs_deflate_decode_10k_part_init/gcc9 254MB/s 0.94x
|
||||
wuffs_deflate_decode_100k_just_one_read/gcc9 333MB/s 1.01x
|
||||
wuffs_deflate_decode_100k_many_big_reads/gcc9 261MB/s 1.02x
|
||||
wuffs_deflate_decode_1k_full_init/gcc10 183 MB/s 0.76x
|
||||
wuffs_deflate_decode_1k_part_init/gcc10 217 MB/s 0.90x
|
||||
wuffs_deflate_decode_10k_full_init/gcc10 402 MB/s 1.39x
|
||||
wuffs_deflate_decode_10k_part_init/gcc10 414 MB/s 1.43x
|
||||
wuffs_deflate_decode_100k_just_one_read/gcc10 522 MB/s 1.48x
|
||||
wuffs_deflate_decode_100k_many_big_reads/gcc10 330 MB/s 1.19x
|
||||
|
||||
mimic_deflate_decode_1k 217MB/s 1.00x
|
||||
mimic_deflate_decode_10k 270MB/s 1.00x
|
||||
mimic_deflate_decode_100k_just_one_read 329MB/s 1.00x
|
||||
mimic_deflate_decode_100k_many_big_reads 256MB/s 1.00x
|
||||
mimicztl_deflate_decode_1k_full_init 241 MB/s 1.00x
|
||||
mimicztl_deflate_decode_10k_full_init 289 MB/s 1.00x
|
||||
mimicztl_deflate_decode_100k_just_one_read 352 MB/s 1.00x
|
||||
mimicztl_deflate_decode_100k_many_big_reads 277 MB/s 1.00x
|
||||
|
||||
32-bit ARMv7 (2012 era Samsung Exynos 5 Chromebook), Debian Stretch (2017):
|
||||
mimiclibdeflate_deflate_decode_1k_full_init 326 MB/s 1.35x
|
||||
mimiclibdeflate_deflate_decode_10k_full_init 503 MB/s 1.74x
|
||||
mimiclibdeflate_deflate_decode_100k_just_one_read 507 MB/s 1.44x
|
||||
|
||||
mimicminiz_deflate_decode_1k_full_init 204 MB/s 0.85x
|
||||
mimicminiz_deflate_decode_10k_full_init 252 MB/s 0.87x
|
||||
mimicminiz_deflate_decode_100k_just_one_read 287 MB/s 0.82x
|
||||
|
||||
go_deflate_decode_1k_full_init 71 MB/s 0.29x
|
||||
go_deflate_decode_10k_full_init 120 MB/s 0.42x
|
||||
go_deflate_decode_100k_just_one_read 135 MB/s 0.38x
|
||||
|
||||
rust_deflate_decode_1k_full_init 165 MB/s 0.68x
|
||||
rust_deflate_decode_10k_full_init 259 MB/s 0.90x
|
||||
rust_deflate_decode_100k_just_one_read 272 MB/s 0.77x
|
||||
|
||||
To reproduce the libdeflate or miniz numbers, look in
|
||||
`test/c/mimiclib/deflate-gzip-zlib.c`. For Go 1.19, run `go run main.go` in
|
||||
`script/bench-go-deflate`. For Rust 1.48 / flate2 1.0.24 / miniz\_oxide 0.5.3,
|
||||
run `cargo run --release` in `script/bench-rust-deflate`.
|
||||
|
||||
Historical (Wuffs v0.2; 2019) numbers for 32-bit ARMv7 (2012 era Samsung Exynos
|
||||
5 Chromebook), Debian Stretch (2017):
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
@@ -171,63 +230,6 @@ is unset or set.
|
||||
mimic_deflate_decode_100k_many_big_reads 90.0MB/s 1.00x
|
||||
|
||||
|
||||
## Deflate (C, miniz)
|
||||
|
||||
For comparison, here are [miniz](https://github.com/richgel999/miniz) 2.1.0's
|
||||
numbers.
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
miniz_deflate_decode_1k/clang8 174MB/s 0.80x
|
||||
miniz_deflate_decode_10k/clang8 245MB/s 0.91x
|
||||
miniz_deflate_decode_100k_just_one_read/clang8 309MB/s 0.94x
|
||||
|
||||
miniz_deflate_decode_1k/gcc9 158MB/s 0.73x
|
||||
miniz_deflate_decode_10k/gcc9 221MB/s 0.82x
|
||||
miniz_deflate_decode_100k_just_one_read/gcc9 250MB/s 0.76x
|
||||
|
||||
To reproduce these numbers, look in `test/c/mimiclib/deflate-gzip-zlib.c`.
|
||||
|
||||
|
||||
## Deflate (Go)
|
||||
|
||||
For comparison, here are Go 1.12.10's numbers, using Go's standard library's
|
||||
`compress/flate` package.
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
go_deflate_decode_1k 45.4MB/s 0.21x
|
||||
go_deflate_decode_10k 82.5MB/s 0.31x
|
||||
go_deflate_decode_100k 94.0MB/s 0.29x
|
||||
|
||||
To reproduce these numbers:
|
||||
|
||||
git clone https://github.com/google/wuffs.git
|
||||
cd wuffs/script/bench-go-deflate/
|
||||
go run main.go
|
||||
|
||||
|
||||
## Deflate (Rust)
|
||||
|
||||
For comparison, here are Rust 1.37.0's numbers, using the
|
||||
[alexcrichton/flate2-rs](https://github.com/alexcrichton/flate2-rs) and
|
||||
[Frommi/miniz_oxide](https://github.com/Frommi/miniz_oxide) crates, which [this
|
||||
file](https://github.com/sile/libflate/blob/77a1004edf6518a0badab7ce8837bc5338ff9bc3/README.md#an-informal-benchmark)
|
||||
suggests is the fastest pure-Rust Deflate decoder.
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
rust_deflate_decode_1k 104MB/s 0.48x
|
||||
rust_deflate_decode_10k 202MB/s 0.75x
|
||||
rust_deflate_decode_100k 218MB/s 0.66x
|
||||
|
||||
To reproduce these numbers:
|
||||
|
||||
git clone https://github.com/google/wuffs.git
|
||||
cd wuffs/script/bench-rust-deflate/
|
||||
cargo run --release
|
||||
|
||||
|
||||
# GIF
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many pixels there are in
|
||||
@@ -245,42 +247,67 @@ is unset or set.
|
||||
The libgif library doesn't export any API for decode-to-BGRA or decode-to-RGBA,
|
||||
so there are no mimic numbers to compare to for the `bgra` suffix.
|
||||
|
||||
name speed vs_mimic
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_gif_decode_1k_bw/clang8 461MB/s 3.18x
|
||||
wuffs_gif_decode_1k_color_full_init/clang8 141MB/s 1.85x
|
||||
wuffs_gif_decode_1k_color_part_init/clang8 189MB/s 2.48x
|
||||
wuffs_gif_decode_10k_bgra/clang8 743MB/s n/a
|
||||
wuffs_gif_decode_10k_indexed/clang8 200MB/s 2.11x
|
||||
wuffs_gif_decode_20k/clang8 245MB/s 2.50x
|
||||
wuffs_gif_decode_100k_artificial/clang8 531MB/s 3.43x
|
||||
wuffs_gif_decode_100k_realistic/clang8 218MB/s 2.27x
|
||||
wuffs_gif_decode_1000k_full_init/clang8 221MB/s 2.25x
|
||||
wuffs_gif_decode_1000k_part_init/clang8 221MB/s 2.25x
|
||||
wuffs_gif_decode_anim_screencap/clang8 1.07GB/s 6.01x
|
||||
wuffs_gif_decode_1k_bw/clang11 758 MB/s 4.38x
|
||||
wuffs_gif_decode_1k_color_full_init/clang11 176 MB/s 1.96x
|
||||
wuffs_gif_decode_1k_color_part_init/clang11 213 MB/s 2.37x
|
||||
wuffs_gif_decode_10k_bgra/clang11 786 MB/s n/a
|
||||
wuffs_gif_decode_10k_indexed/clang11 208 MB/s 1.98x
|
||||
wuffs_gif_decode_20k/clang11 262 MB/s 2.47x
|
||||
wuffs_gif_decode_100k_artificial/clang11 580 MB/s 3.52x
|
||||
wuffs_gif_decode_100k_realistic/clang11 225 MB/s 2.18x
|
||||
wuffs_gif_decode_1000k_full_init/clang11 229 MB/s 2.16x
|
||||
wuffs_gif_decode_1000k_part_init/clang11 229 MB/s 2.16x
|
||||
wuffs_gif_decode_anim_screencap/clang11 1.31 GB/s 6.58x
|
||||
|
||||
wuffs_gif_decode_1k_bw/gcc9 478MB/s 3.30x
|
||||
wuffs_gif_decode_1k_color_full_init/gcc9 148MB/s 1.94x
|
||||
wuffs_gif_decode_1k_color_part_init/gcc9 194MB/s 2.54x
|
||||
wuffs_gif_decode_10k_bgra/gcc9 645MB/s n/a
|
||||
wuffs_gif_decode_10k_indexed/gcc9 203MB/s 2.14x
|
||||
wuffs_gif_decode_20k/gcc9 244MB/s 2.49x
|
||||
wuffs_gif_decode_100k_artificial/gcc9 532MB/s 3.43x
|
||||
wuffs_gif_decode_100k_realistic/gcc9 214MB/s 2.23x
|
||||
wuffs_gif_decode_1000k_full_init/gcc9 217MB/s 2.21x
|
||||
wuffs_gif_decode_1000k_part_init/gcc9 218MB/s 2.22x
|
||||
wuffs_gif_decode_anim_screencap/gcc9 1.11GB/s 6.24x
|
||||
wuffs_gif_decode_1k_bw/gcc10 659 MB/s 3.80x
|
||||
wuffs_gif_decode_1k_color_full_init/gcc10 175 MB/s 1.94x
|
||||
wuffs_gif_decode_1k_color_part_init/gcc10 202 MB/s 2.24x
|
||||
wuffs_gif_decode_10k_bgra/gcc10 768 MB/s n/a
|
||||
wuffs_gif_decode_10k_indexed/gcc10 202 MB/s 1.92x
|
||||
wuffs_gif_decode_20k/gcc10 250 MB/s 2.36x
|
||||
wuffs_gif_decode_100k_artificial/gcc10 564 MB/s 3.42x
|
||||
wuffs_gif_decode_100k_realistic/gcc10 217 MB/s 2.11x
|
||||
wuffs_gif_decode_1000k_full_init/gcc10 221 MB/s 2.08x
|
||||
wuffs_gif_decode_1000k_part_init/gcc10 221 MB/s 2.08x
|
||||
wuffs_gif_decode_anim_screencap/gcc10 1.31 GB/s 6.58x
|
||||
|
||||
mimic_gif_decode_1k_bw 145MB/s 1.00x
|
||||
mimic_gif_decode_1k_color 76.3MB/s 1.00x
|
||||
mimic_gif_decode_10k_indexed 94.9MB/s 1.00x
|
||||
mimic_gif_decode_20k 98.1MB/s 1.00x
|
||||
mimic_gif_decode_100k_artificial 155MB/s 1.00x
|
||||
mimic_gif_decode_100k_realistic 96.1MB/s 1.00x
|
||||
mimic_gif_decode_1000k 98.4MB/s 1.00x
|
||||
mimic_gif_decode_anim_screencap 178MB/s 1.00x
|
||||
mimic_gif_decode_1k_bw 173 MB/s 1.00x
|
||||
mimic_gif_decode_1k_color_full_init 90 MB/s 1.00x
|
||||
mimic_gif_decode_10k_indexed 105 MB/s 1.00x
|
||||
mimic_gif_decode_20k 106 MB/s 1.00x
|
||||
mimic_gif_decode_100k_artificial 165 MB/s 1.00x
|
||||
mimic_gif_decode_100k_realistic 103 MB/s 1.00x
|
||||
mimic_gif_decode_1000k_full_init 106 MB/s 1.00x
|
||||
mimic_gif_decode_anim_screencap 199 MB/s 1.00x
|
||||
|
||||
32-bit ARMv7 (2012 era Samsung Exynos 5 Chromebook), Debian Stretch (2017):
|
||||
go_gif_decode_1k_bw 167 MB/s 0.97x
|
||||
go_gif_decode_1k_color_full_init 63 MB/s 0.70x
|
||||
go_gif_decode_10k_bgra 216 MB/s n/a
|
||||
go_gif_decode_10k_indexed 92 MB/s 0.88x
|
||||
go_gif_decode_20k 102 MB/s 0.96x
|
||||
go_gif_decode_100k_artificial 202 MB/s 1.22x
|
||||
go_gif_decode_100k_realistic 102 MB/s 0.99x
|
||||
go_gif_decode_1000k_full_init 103 MB/s 0.97x
|
||||
go_gif_decode_anim_screencap 237 MB/s 1.19x
|
||||
|
||||
rust_gif_decode_1k_bw 362 MB/s 2.09x
|
||||
rust_gif_decode_1k_color_full_init 113 MB/s 1.26x
|
||||
rust_gif_decode_10k_bgra 333 MB/s n/a
|
||||
rust_gif_decode_10k_indexed 101 MB/s 0.96x
|
||||
rust_gif_decode_20k 119 MB/s 1.12x
|
||||
rust_gif_decode_100k_artificial 248 MB/s 1.50x
|
||||
rust_gif_decode_100k_realistic 113 MB/s 1.10x
|
||||
rust_gif_decode_1000k_full_init 115 MB/s 1.08x
|
||||
rust_gif_decode_anim_screencap 513 MB/s 2.58x
|
||||
|
||||
To reproduce the Go 1.19 numbers, run `go run main.go` in
|
||||
`script/bench-go-gif`. For Rust 1.48 / gif 0.11.4, run `cargo run --release` in
|
||||
`script/bench-rust-gif`.
|
||||
|
||||
Historical (Wuffs v0.2; 2019) numbers for 32-bit ARMv7 (2012 era Samsung Exynos
|
||||
5 Chromebook), Debian Stretch (2017):
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
@@ -318,106 +345,137 @@ so there are no mimic numbers to compare to for the `bgra` suffix.
|
||||
mimic_gif_decode_anim_screencap 60.3MB/s 1.00x
|
||||
|
||||
|
||||
## GIF (Go)
|
||||
|
||||
For comparison, here are Go 1.12.10's numbers, using Go's standard library's
|
||||
`image/gif` package.
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
go_gif_decode_1k_bw 107MB/s 0.74x
|
||||
go_gif_decode_1k_color 39.2MB/s 0.51x
|
||||
go_gif_decode_10k_bgra 117MB/s n/a
|
||||
go_gif_decode_10k_indexed 57.8MB/s 0.61x
|
||||
go_gif_decode_20k 67.2MB/s 0.69x
|
||||
go_gif_decode_100k_artificial 151MB/s 0.97x
|
||||
go_gif_decode_100k_realistic 67.2MB/s 0.70x
|
||||
go_gif_decode_1000k 68.1MB/s 0.69x
|
||||
go_gif_decode_anim_screencap 206MB/s 1.16x
|
||||
|
||||
To reproduce these numbers:
|
||||
|
||||
git clone https://github.com/google/wuffs.git
|
||||
cd wuffs/script/bench-go-gif/
|
||||
go run main.go
|
||||
|
||||
|
||||
## GIF (Rust)
|
||||
|
||||
For comparison, here are Rust 1.37.0's numbers, using the
|
||||
[image-rs/image-gif](https://github.com/image-rs/image-gif) crate, easily the
|
||||
top `crates.io` result for ["gif"](https://crates.io/search?q=gif).
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
rust_gif_decode_1k_bw 89.2MB/s 0.62x
|
||||
rust_gif_decode_1k_color 20.7MB/s 0.27x
|
||||
rust_gif_decode_10k_bgra 74.5MB/s n/a
|
||||
rust_gif_decode_10k_indexed 20.4MB/s 0.21x
|
||||
rust_gif_decode_20k 28.9MB/s 0.29x
|
||||
rust_gif_decode_100k_artificial 79.1MB/s 0.51x
|
||||
rust_gif_decode_100k_realistic 27.9MB/s 0.29x
|
||||
rust_gif_decode_1000k 27.9MB/s 0.28x
|
||||
rust_gif_decode_anim_screencap 144MB/s 0.81x
|
||||
|
||||
To reproduce these numbers:
|
||||
|
||||
git clone https://github.com/google/wuffs.git
|
||||
cd wuffs/script/bench-rust-gif/
|
||||
cargo run --release
|
||||
|
||||
|
||||
# Gzip (Deflate + CRC-32)
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
|
||||
decoded output.
|
||||
|
||||
name speed vs_mimic
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_gzip_decode_10k/clang8 238MB/s 1.05x
|
||||
wuffs_gzip_decode_100k/clang8 273MB/s 1.03x
|
||||
wuffs_gzip_decode_10k/clang11 420 MB/s 1.71x
|
||||
wuffs_gzip_decode_100k/clang11 527 MB/s 1.81x
|
||||
|
||||
wuffs_gzip_decode_10k/gcc9 239MB/s 1.06x
|
||||
wuffs_gzip_decode_100k/gcc9 297MB/s 1.12x
|
||||
wuffs_gzip_decode_10k/gcc10 427 MB/s 1.74x
|
||||
wuffs_gzip_decode_100k/gcc10 550 MB/s 1.89x
|
||||
|
||||
mimic_gzip_decode_10k 226MB/s 1.00x
|
||||
mimic_gzip_decode_100k 265MB/s 1.00x
|
||||
mimicztl_gzip_decode_10k 246 MB/s 1.00x
|
||||
mimicztl_gzip_decode_100k 291 MB/s 1.00x
|
||||
|
||||
mimiclibdeflate_gzip_decode_10k 494 MB/s 2.01x
|
||||
mimiclibdeflate_gzip_decode_100k 496 MB/s 1.70x
|
||||
|
||||
|
||||
# LZW
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
|
||||
decoded output.
|
||||
|
||||
The libgif library doesn't export its LZW decoder in its API, so there are no
|
||||
mimic numbers to compare to.
|
||||
|
||||
name speed vs_mimic
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_lzw_decode_20k/clang8 263MB/s n/a
|
||||
wuffs_lzw_decode_100k/clang8 438MB/s n/a
|
||||
wuffs_lzw_decode_20k/clang11 293 MB/s n/a
|
||||
wuffs_lzw_decode_100k/clang11 489 MB/s n/a
|
||||
|
||||
wuffs_lzw_decode_20k/gcc9 266MB/s n/a
|
||||
wuffs_lzw_decode_100k/gcc9 450MB/s n/a
|
||||
wuffs_lzw_decode_20k/gcc10 259 MB/s n/a
|
||||
wuffs_lzw_decode_100k/gcc10 516 MB/s n/a
|
||||
|
||||
|
||||
# PNG
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
|
||||
decoded image. For example, the `test/data/harvesters.*` images are 1165 × 859,
|
||||
approximately 1000k pixels and hence 4000k bytes at 4 bytes per pixel.
|
||||
|
||||
The `full_init` vs `part_init` suffixes are whether
|
||||
[`WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED`](/doc/note/initialization.md#partial-zero-initialization)
|
||||
is unset or set.
|
||||
|
||||
libpng's "simplified API" doesn't provide a way to ignore the checksum. We copy
|
||||
the `verify_checksum` numbers for a 1.00x baseline.
|
||||
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_png_decode_image_19k_8bpp/clang11 279 MB/s 2.29x
|
||||
wuffs_png_decode_image_40k_24bpp/clang11 323 MB/s 2.20x
|
||||
wuffs_png_decode_image_77k_8bpp/clang11 984 MB/s 2.66x
|
||||
wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang11 871 MB/s 3.01x
|
||||
wuffs_png_decode_image_552k_32bpp_verify_checksum/clang11 837 MB/s 2.90x
|
||||
wuffs_png_decode_image_4002k_24bpp/clang11 331 MB/s 1.55x
|
||||
|
||||
wuffs_png_decode_image_19k_8bpp/gcc10 277 MB/s 2.27x
|
||||
wuffs_png_decode_image_40k_24bpp/gcc10 343 MB/s 2.33x
|
||||
wuffs_png_decode_image_77k_8bpp/gcc10 1.00 GB/s 2.70x
|
||||
wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10 914 MB/s 3.16x
|
||||
wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10 870 MB/s 3.01x
|
||||
wuffs_png_decode_image_4002k_24bpp/gcc10 353 MB/s 1.65x
|
||||
|
||||
mimiclibpng_png_decode_image_19k_8bpp 122 MB/s 1.00x
|
||||
mimiclibpng_png_decode_image_40k_24bpp 147 MB/s 1.00x
|
||||
mimiclibpng_png_decode_image_77k_8bpp 370 MB/s 1.00x
|
||||
mimiclibpng_png_decode_image_552k_32bpp_verify_checksum 289 MB/s 1.00x
|
||||
mimiclibpng_png_decode_image_4002k_24bpp 214 MB/s 1.00x
|
||||
|
||||
mimiclibspng_png_decode_image_19k_8bpp 125 MB/s 1.02x
|
||||
mimiclibspng_png_decode_image_40k_24bpp 155 MB/s 1.05x
|
||||
mimiclibspng_png_decode_image_77k_8bpp 384 MB/s 1.04x
|
||||
mimiclibspng_png_decode_image_552k_32bpp_ignore_checksum 461 MB/s 1.60x
|
||||
mimiclibspng_png_decode_image_552k_32bpp_verify_checksum 392 MB/s 1.36x
|
||||
mimiclibspng_png_decode_image_4002k_24bpp 225 MB/s 1.05x
|
||||
|
||||
mimiclodepng_png_decode_image_19k_8bpp 138 MB/s 1.13x
|
||||
mimiclodepng_png_decode_image_40k_24bpp 166 MB/s 1.13x
|
||||
mimiclodepng_png_decode_image_77k_8bpp 404 MB/s 1.09x
|
||||
mimiclodepng_png_decode_image_552k_32bpp_verify_checksum 258 MB/s 0.89x
|
||||
mimiclodepng_png_decode_image_4002k_24bpp 165 MB/s 0.77x
|
||||
|
||||
mimicstb_png_decode_image_19k_8bpp 150 MB/s 1.23x
|
||||
mimicstb_png_decode_image_40k_24bpp 166 MB/s 1.13x
|
||||
mimicstb_png_decode_image_77k_8bpp 443 MB/s 1.20x
|
||||
mimicstb_png_decode_image_552k_32bpp_ignore_checksum 288 MB/s 1.00x
|
||||
mimicstb_png_decode_image_4002k_24bpp 163 MB/s 0.76x
|
||||
|
||||
go_png_decode_image_19k_8bpp 92 MB/s 0.75x
|
||||
go_png_decode_image_40k_24bpp 107 MB/s 0.73x
|
||||
go_png_decode_image_77k_8bpp 207 MB/s 0.56x
|
||||
go_png_decode_image_552k_32bpp_verify_checksum 246 MB/s 0.85x
|
||||
go_png_decode_image_4002k_24bpp 116 MB/s 0.54x
|
||||
|
||||
rust_png_decode_image_19k_8bpp 187 MB/s 1.53x
|
||||
rust_png_decode_image_40k_24bpp 260 MB/s 1.77x
|
||||
rust_png_decode_image_77k_8bpp 330 MB/s 0.89x
|
||||
rust_png_decode_image_552k_32bpp_verify_checksum 299 MB/s 1.03x
|
||||
rust_png_decode_image_4002k_24bpp 264 MB/s 1.23x
|
||||
|
||||
To reproduce the Go 1.19 numbers, run `go run main.go` in
|
||||
`script/bench-go-png`. For Rust 1.48 / png 0.17.5 / deflate 1.0.0 /
|
||||
miniz\_oxide 0.5.3, run `cargo run --release` in `script/bench-rust-png`.
|
||||
|
||||
|
||||
# Zlib (Deflate + Adler-32)
|
||||
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
|
||||
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
|
||||
decoded output.
|
||||
|
||||
name speed vs_mimic
|
||||
name speed vs_mimic
|
||||
|
||||
wuffs_zlib_decode_10k/clang8 237MB/s 0.96x
|
||||
wuffs_zlib_decode_100k/clang8 272MB/s 0.92x
|
||||
wuffs_zlib_decode_10k/clang11 410 MB/s 1.53x
|
||||
wuffs_zlib_decode_100k/clang11 505 MB/s 1.56x
|
||||
|
||||
wuffs_zlib_decode_10k/gcc9 242MB/s 0.98x
|
||||
wuffs_zlib_decode_100k/gcc9 294MB/s 0.99x
|
||||
wuffs_zlib_decode_10k/gcc10 431 MB/s 1.61x
|
||||
wuffs_zlib_decode_100k/gcc10 548 MB/s 1.70x
|
||||
|
||||
mimic_zlib_decode_10k 247MB/s 1.00x
|
||||
mimic_zlib_decode_100k 296MB/s 1.00x
|
||||
mimicztl_zlib_decode_10k 268 MB/s 1.00x
|
||||
mimicztl_zlib_decode_100k 323 MB/s 1.00x
|
||||
|
||||
mimiclibdeflate_zlib_decode_10k 497 MB/s 1.85x
|
||||
mimiclibdeflate_zlib_decode_100k 499 MB/s 1.54x
|
||||
|
||||
mimicminiz_zlib_decode_10k 237 MB/s 0.88x
|
||||
mimicminiz_zlib_decode_100k 272 MB/s 0.84x
|
||||
|
||||
|
||||
---
|
||||
|
||||
Updated on December 2019.
|
||||
Updated on September 2022.
|
||||
@@ -23,10 +23,12 @@
|
||||
- Added `example/sdl-imageviewer`.
|
||||
- Added `slice base.u8 peek/poke` methods.
|
||||
- Added `std/bmp`.
|
||||
- Added `std/bzip2`.
|
||||
- Added `std/cbor`.
|
||||
- Added `std/json`.
|
||||
- Added `std/nie`.
|
||||
- Added `std/png`.
|
||||
- Added `std/tga`.
|
||||
- Added `std/wbmp`.
|
||||
- Added `tell_me_more?` mechanism.
|
||||
- Added SIMD.
|
||||
@@ -46,6 +48,7 @@
|
||||
- Made `wuffs_base__pixel_format` a struct.
|
||||
- Made `wuffs_base__pixel_subsampling` a struct.
|
||||
- Made `wuffs_base__status` a struct.
|
||||
- Prohibited iterate loops inside coroutines.
|
||||
- Removed `ack_metadata_chunk?`.
|
||||
- Removed `wuffs_base__frame_config__blend`.
|
||||
- Renamed I/O `available` methods to `length`.
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
|
||||
Short term:
|
||||
|
||||
- [Image decode API for color spaces and gamma
|
||||
correction.](https://github.com/google/wuffs/issues/39)
|
||||
- [Image decode API for Region of
|
||||
Interest.](https://github.com/google/wuffs/issues/40)
|
||||
- [Decode APNG.](https://github.com/google/wuffs/issues/41)
|
||||
- [Decode JPEG.](https://github.com/google/wuffs/issues/42)
|
||||
- [Decode LZ4.](https://github.com/google/wuffs/issues/43)
|
||||
- [Decode RAC.](https://github.com/google/wuffs/issues/22)
|
||||
@@ -41,4 +38,4 @@ Long term:
|
||||
|
||||
---
|
||||
|
||||
Updated on March 2021.
|
||||
Updated on October 2022.
|
||||
@@ -353,7 +353,7 @@ synonymous with `octet` and `uint8`.
|
||||
|
||||
The recommended filename extensions are `.nie`, `.nii` and `.nia`.
|
||||
|
||||
The recommended MIME types are `image/nie`, `image/nii` and `image/nia`.
|
||||
The recommended MIME types are `image/x-nie`, `image/x-nii` and `image/x-nia`.
|
||||
|
||||
|
||||
## Why NIE and not NIF (for Naïve Image Format)?
|
||||
@@ -370,4 +370,4 @@ in a long "E", "I" or "A" sound. It's definitely a hard "N", not a soft one.
|
||||
|
||||
---
|
||||
|
||||
Updated on November 2021.
|
||||
Updated on January 2022.
|
||||
@@ -56,6 +56,7 @@ to enable.
|
||||
- `LZW: BASE`
|
||||
- `NIE: BASE`
|
||||
- `PNG: BASE, ADLER32, CRC32, DEFLATE, ZLIB`
|
||||
- `TGA: BASE`
|
||||
- `WBMP: BASE`
|
||||
- `ZLIB: BASE, ADLER32, DEFLATE`
|
||||
|
||||
|
||||
@@ -17,11 +17,22 @@ long decompressed output to stdout.
|
||||
|
||||
## Dictionaries
|
||||
|
||||
TODO: standardize the various dictionary APIs, after Wuffs v0.2 is released.
|
||||
TODO: standardize the [various dictionary
|
||||
APIs](https://github.com/google/wuffs/issues/73), after Wuffs v0.2 is released.
|
||||
|
||||
|
||||
## API Listing
|
||||
|
||||
In Wuffs syntax, the `base.io_transformer` methods are:
|
||||
|
||||
- `set_quirk_enabled!(quirk: u32, enabled: bool)`
|
||||
- `transform_io?(dst: io_writer, src: io_reader, workbuf: slice u8)`
|
||||
- `workbuf_len() range_ii_u64`
|
||||
|
||||
|
||||
## Implementations
|
||||
|
||||
- [std/bzip2](/std/bzip2)
|
||||
- [std/deflate](/std/deflate)
|
||||
- [std/gzip](/std/gzip)
|
||||
- [std/lzw](/std/lzw)
|
||||
@@ -30,10 +41,16 @@ TODO: standardize the various dictionary APIs, after Wuffs v0.2 is released.
|
||||
|
||||
## Examples
|
||||
|
||||
- [example/bzcat](/example/bzcat)
|
||||
- [example/toy-genlib](/example/toy-genlib)
|
||||
- [example/zcat](/example/zcat)
|
||||
|
||||
|
||||
## [Quirks](/doc/note/quirks.md)
|
||||
|
||||
- [Zlib decoder quirks](/std/zlib/decode_quirks.wuffs)
|
||||
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- [I/O (Input / Output)](/doc/note/io-input-output.md)
|
||||
|
||||
@@ -19,6 +19,14 @@ Wuffs' hasher implementations are not cryptographic. They make no attempt to
|
||||
resist timing attacks.
|
||||
|
||||
|
||||
## API Listing
|
||||
|
||||
In Wuffs syntax, the `base.hasher_u32` methods are:
|
||||
|
||||
- `set_quirk_enabled!(quirk: u32, enabled: bool)`
|
||||
- `update_u32!(x: slice u8) u32`
|
||||
|
||||
|
||||
## Implementations
|
||||
|
||||
- [std/adler32](/std/adler32)
|
||||
|
||||
|
After Width: | Height: | Size: 48 KiB |
@@ -0,0 +1,96 @@
|
||||
<svg version="1.1" viewBox="0.0 0.0 1280.0 960.0" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">
|
||||
<clipPath id="p.0">
|
||||
<path d="m0 0l1280.0 0l0 960.0l-1280.0 0l0 -960.0z" clip-rule="nonzero"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#p.0)">
|
||||
<path fill="#000000" fill-opacity="0.0" d="m0 0l1280.0 0l0 960.0l-1280.0 0z" fill-rule="evenodd"/>
|
||||
<path fill="#f4cccc" d="m232.11023 113.00525l0 0c0 -24.744095 20.059067 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.720314 31.680603 13.122536c8.402222 8.402222 13.122528 19.79808 13.122528 31.68061l0 0c0 24.744095 -20.059052 44.803146 -44.80313 44.803146l0 0c-24.744095 0 -44.80316 -20.059052 -44.80316 -44.803146z" fill-rule="evenodd"/>
|
||||
<path stroke="#000000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m232.11023 113.00525l0 0c0 -24.744095 20.059067 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.720314 31.680603 13.122536c8.402222 8.402222 13.122528 19.79808 13.122528 31.68061l0 0c0 24.744095 -20.059052 44.803146 -44.80313 44.803146l0 0c-24.744095 0 -44.80316 -20.059052 -44.80316 -44.803146z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" d="m267.51105 114.162125q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125zm7.1015625 1.0625l1.421875 -2.515625l2.40625 0l-2.40625 4.140625l2.515625 4.3125l-2.421875 0l-1.515625 -2.65625l-1.5 2.65625l-2.421875 0l2.5 -4.3125l-2.390625 -4.140625l2.421875 0l1.390625 2.515625zm12.484375 1.234375q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125zm11.4453125 2.296875q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125z" fill-rule="nonzero"/>
|
||||
<path fill="#d9d9d9" d="m395.7257 113.00525l0 0c0 -24.744095 20.059082 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.720314 31.680603 13.122536c8.402222 8.402222 13.122559 19.79808 13.122559 31.68061l0 0c0 24.744095 -20.059052 44.803146 -44.80316 44.803146l0 0c-24.74408 0 -44.80316 -20.059052 -44.80316 -44.803146z" fill-rule="evenodd"/>
|
||||
<path stroke="#000000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m395.7257 113.00525l0 0c0 -24.744095 20.059082 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.720314 31.680603 13.122536c8.402222 8.402222 13.122559 19.79808 13.122559 31.68061l0 0c0 24.744095 -20.059052 44.803146 -44.80316 44.803146l0 0c-24.74408 0 -44.80316 -20.059052 -44.80316 -44.803146z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" d="m427.13434 119.0215q-1.4375 -0.03125 -2.15625 -1.015625q-0.71875 -1.0 -0.65625 -2.859375q0.015625 -0.578125 0.09375 -1.140625l0.28125 -1.890625q0.375 -2.4375 1.421875 -3.625q1.0625 -1.203125 2.78125 -1.15625q1.453125 0.03125 2.171875 1.0q0.71875 0.953125 0.65625 2.796875q-0.015625 0.578125 -0.09375 1.140625l-0.265625 1.84375q-0.421875 2.5625 -1.46875 3.765625q-1.046875 1.1875 -2.765625 1.140625zm3.140625 -7.0q0.109375 -0.953125 0.09375 -1.46875q-0.03125 -1.984375 -1.53125 -2.046875q-1.09375 -0.03125 -1.78125 0.8125q-0.671875 0.84375 -0.9375 2.65625l-0.328125 2.265625q-0.109375 0.90625 -0.109375 1.484375q0.046875 2.0625 1.53125 2.125q1.046875 0.046875 1.71875 -0.765625q0.671875 -0.8125 0.96875 -2.578125l0.375 -2.484375zm5.84375 1.46875l2.296875 -3.078125l1.734375 0l-3.390625 4.25l2.0625 4.203125l-1.53125 0l-1.40625 -3.15625l-2.375 3.15625l-1.734375 0l3.5 -4.34375l-2.0 -4.109375l1.546875 0l1.296875 3.078125zm8.6171875 5.375l-1.421875 0l1.671875 -9.59375l-3.015625 1.0625l0.234375 -1.375l4.21875 -1.53125l0.25 0l-1.9375 11.4375zm7.765625 0.15625q-1.4375 -0.03125 -2.15625 -1.015625q-0.71875 -1.0 -0.65625 -2.859375q0.015625 -0.578125 0.09375 -1.140625l0.28125 -1.890625q0.375 -2.4375 1.421875 -3.625q1.0625 -1.203125 2.78125 -1.15625q1.453125 0.03125 2.171875 1.0q0.71875 0.953125 0.65625 2.796875q-0.015625 0.578125 -0.09375 1.140625l-0.265625 1.84375q-0.421875 2.5625 -1.46875 3.765625q-1.046875 1.1875 -2.765625 1.140625zm3.140625 -7.0q0.109375 -0.953125 0.09375 -1.46875q-0.03125 -1.984375 -1.53125 -2.046875q-1.09375 -0.03125 -1.78125 0.8125q-0.671875 0.84375 -0.9375 2.65625l-0.328125 2.265625q-0.109375 0.90625 -0.109375 1.484375q0.046875 2.0625 1.53125 2.125q1.046875 0.046875 1.71875 -0.765625q0.671875 -0.8125 0.96875 -2.578125l0.375 -2.484375z" fill-rule="nonzero"/>
|
||||
<path fill="#d9ead3" d="m232.11154 281.12686l0 0c0 -24.74411 20.059067 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.7203064 31.680603 13.122528c8.402222 8.402237 13.122528 19.79808 13.122528 31.680618l0 0c0 24.74408 -20.059052 44.80316 -44.80313 44.80316l0 0c-24.744095 0 -44.80316 -20.059082 -44.80316 -44.80316z" fill-rule="evenodd"/>
|
||||
<path stroke="#000000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m232.11154 281.12686l0 0c0 -24.74411 20.059067 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.7203064 31.680603 13.122528c8.402222 8.402237 13.122528 19.79808 13.122528 31.680618l0 0c0 24.74408 -20.059052 44.80316 -44.80313 44.80316l0 0c-24.744095 0 -44.80316 -20.059082 -44.80316 -44.80316z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" d="m267.51236 282.28372q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125zm7.1015625 1.0625l1.421875 -2.515625l2.40625 0l-2.40625 4.140625l2.515625 4.3125l-2.421875 0l-1.515625 -2.65625l-1.5 2.65625l-2.421875 0l2.5 -4.3125l-2.390625 -4.140625l2.421875 0l1.390625 2.515625zm12.625 5.9375l-7.796875 0l0 -1.546875l3.671875 -3.921875q0.765625 -0.828125 1.125 -1.4375q0.359375 -0.625 0.359375 -1.1875q0 -0.75 -0.390625 -1.1875q-0.375 -0.4375 -1.078125 -0.4375q-0.765625 0 -1.21875 0.53125q-0.4375 0.53125 -0.4375 1.390625l-2.265625 0q0 -1.046875 0.5 -1.90625q0.5 -0.859375 1.40625 -1.34375q0.90625 -0.484375 2.046875 -0.484375q1.765625 0 2.734375 0.84375q0.96875 0.84375 0.96875 2.375q0 0.84375 -0.4375 1.71875q-0.4375 0.875 -1.5 2.046875l-2.578125 2.71875l4.890625 0l0 1.828125zm9.0390625 -4.703125q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125z" fill-rule="nonzero"/>
|
||||
<path fill="#d9d9d9" d="m395.72702 281.12686l0 0c0 -24.74411 20.059082 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.7203064 31.680603 13.122528c8.402222 8.402237 13.122559 19.79808 13.122559 31.680618l0 0c0 24.74408 -20.059052 44.80316 -44.80316 44.80316l0 0c-24.74408 0 -44.80316 -20.059082 -44.80316 -44.80316z" fill-rule="evenodd"/>
|
||||
<path stroke="#000000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m395.72702 281.12686l0 0c0 -24.74411 20.059082 -44.803146 44.80316 -44.803146l0 0c11.882538 0 23.278381 4.7203064 31.680603 13.122528c8.402222 8.402237 13.122559 19.79808 13.122559 31.680618l0 0c0 24.74408 -20.059052 44.80316 -44.80316 44.80316l0 0c-24.74408 0 -44.80316 -20.059082 -44.80316 -44.80316z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" d="m427.13565 287.1431q-1.4375 -0.03125 -2.15625 -1.015625q-0.71875 -1.0 -0.65625 -2.859375q0.015625 -0.578125 0.09375 -1.140625l0.28125 -1.890625q0.375 -2.4375 1.421875 -3.625q1.0625 -1.203125 2.78125 -1.15625q1.453125 0.03125 2.171875 1.0q0.71875 0.953125 0.65625 2.796875q-0.015625 0.578125 -0.09375 1.140625l-0.265625 1.84375q-0.421875 2.5625 -1.46875 3.765625q-1.046875 1.1875 -2.765625 1.140625zm3.140625 -7.0q0.109375 -0.953125 0.09375 -1.46875q-0.03125 -1.984375 -1.53125 -2.046875q-1.09375 -0.03125 -1.78125 0.8125q-0.671875 0.84375 -0.9375 2.65625l-0.328125 2.265625q-0.109375 0.90625 -0.109375 1.484375q0.046875 2.0625 1.53125 2.125q1.046875 0.046875 1.71875 -0.765625q0.671875 -0.8125 0.96875 -2.578125l0.375 -2.484375zm5.84375 1.46875l2.296875 -3.078125l1.734375 0l-3.390625 4.25l2.0625 4.203125l-1.53125 0l-1.40625 -3.15625l-2.375 3.15625l-1.734375 0l3.5 -4.34375l-2.0 -4.109375l1.546875 0l1.296875 3.078125zm7.1484375 -1.015625l0.9375 0q1.03125 0 1.734375 -0.53125q0.71875 -0.546875 0.8125 -1.484375q0.109375 -0.90625 -0.328125 -1.421875q-0.4375 -0.515625 -1.28125 -0.53125q-0.890625 -0.015625 -1.515625 0.515625q-0.609375 0.53125 -0.75 1.4375l-1.40625 0.015625q0.140625 -1.40625 1.203125 -2.28125q1.0625 -0.890625 2.546875 -0.875q1.421875 0.03125 2.234375 0.90625q0.828125 0.859375 0.71875 2.265625q-0.078125 0.8125 -0.625 1.484375q-0.546875 0.65625 -1.515625 1.09375q0.78125 0.3125 1.15625 0.984375q0.390625 0.671875 0.328125 1.578125q-0.125 1.546875 -1.234375 2.484375q-1.09375 0.9375 -2.65625 0.90625q-1.46875 -0.03125 -2.34375 -0.90625q-0.859375 -0.875 -0.796875 -2.265625l1.421875 0.015625q-0.046875 0.875 0.421875 1.40625q0.46875 0.53125 1.359375 0.5625q1.0 0.03125 1.65625 -0.5625q0.671875 -0.609375 0.765625 -1.609375q0.078125 -0.9375 -0.4375 -1.453125q-0.5 -0.515625 -1.5 -0.546875l-1.09375 -0.015625l0.1875 -1.171875zm9.234375 6.546875q-1.4375 -0.03125 -2.15625 -1.015625q-0.71875 -1.0 -0.65625 -2.859375q0.015625 -0.578125 0.09375 -1.140625l0.28125 -1.890625q0.375 -2.4375 1.421875 -3.625q1.0625 -1.203125 2.78125 -1.15625q1.453125 0.03125 2.171875 1.0q0.71875 0.953125 0.65625 2.796875q-0.015625 0.578125 -0.09375 1.140625l-0.265625 1.84375q-0.421875 2.5625 -1.46875 3.765625q-1.046875 1.1875 -2.765625 1.140625zm3.140625 -7.0q0.109375 -0.953125 0.09375 -1.46875q-0.03125 -1.984375 -1.53125 -2.046875q-1.09375 -0.03125 -1.78125 0.8125q-0.671875 0.84375 -0.9375 2.65625l-0.328125 2.265625q-0.109375 0.90625 -0.109375 1.484375q0.046875 2.0625 1.53125 2.125q1.046875 0.046875 1.71875 -0.765625q0.671875 -0.8125 0.96875 -2.578125l0.375 -2.484375z" fill-rule="nonzero"/>
|
||||
<path fill="#c9daf8" d="m232.11023 449.24847l0 0c0 -24.74411 20.059067 -44.80316 44.80316 -44.80316l0 0c11.882538 0 23.278381 4.720337 31.680603 13.122559c8.402222 8.402222 13.122528 19.798065 13.122528 31.680603l0 0c0 24.74408 -20.059052 44.80313 -44.80313 44.80313l0 0c-24.744095 0 -44.80316 -20.059052 -44.80316 -44.80313z" fill-rule="evenodd"/>
|
||||
<path stroke="#000000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m232.11023 449.24847l0 0c0 -24.74411 20.059067 -44.80316 44.80316 -44.80316l0 0c11.882538 0 23.278381 4.720337 31.680603 13.122559c8.402222 8.402222 13.122528 19.798065 13.122528 31.680603l0 0c0 24.74408 -20.059052 44.80313 -44.80313 44.80313l0 0c-24.744095 0 -44.80316 -20.059052 -44.80316 -44.80313z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" d="m267.51105 450.40533q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125zm7.1015625 1.0625l1.421875 -2.515625l2.40625 0l-2.40625 4.140625l2.515625 4.3125l-2.421875 0l-1.515625 -2.65625l-1.5 2.65625l-2.421875 0l2.5 -4.3125l-2.390625 -4.140625l2.421875 0l1.390625 2.515625zm11.5 1.65625l1.296875 0l0 1.8125l-1.296875 0l0 2.46875l-2.25 0l0 -2.46875l-4.671875 0l-0.09375 -1.421875l4.734375 -7.484375l2.28125 0l0 7.09375zm-4.765625 0l2.515625 0l0 -4.015625l-0.15625 0.25l-2.359375 3.765625zm14.9296875 -0.421875q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125z" fill-rule="nonzero"/>
|
||||
<path fill="#d9d9d9" d="m395.7257 449.24847l0 0c0 -24.74411 20.059082 -44.80316 44.80316 -44.80316l0 0c11.882538 0 23.278381 4.720337 31.680603 13.122559c8.402222 8.402222 13.122559 19.798065 13.122559 31.680603l0 0c0 24.74408 -20.059052 44.80313 -44.80316 44.80313l0 0c-24.74408 0 -44.80316 -20.059052 -44.80316 -44.80313z" fill-rule="evenodd"/>
|
||||
<path stroke="#000000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m395.7257 449.24847l0 0c0 -24.74411 20.059082 -44.80316 44.80316 -44.80316l0 0c11.882538 0 23.278381 4.720337 31.680603 13.122559c8.402222 8.402222 13.122559 19.798065 13.122559 31.680603l0 0c0 24.74408 -20.059052 44.80313 -44.80316 44.80313l0 0c-24.74408 0 -44.80316 -20.059052 -44.80316 -44.80313z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" d="m427.13434 455.2647q-1.4375 -0.03125 -2.15625 -1.015625q-0.71875 -1.0 -0.65625 -2.859375q0.015625 -0.578125 0.09375 -1.140625l0.28125 -1.890625q0.375 -2.4375 1.421875 -3.625q1.0625 -1.203125 2.78125 -1.15625q1.453125 0.03125 2.171875 1.0q0.71875 0.953125 0.65625 2.796875q-0.015625 0.578125 -0.09375 1.140625l-0.265625 1.84375q-0.421875 2.5625 -1.46875 3.765625q-1.046875 1.1875 -2.765625 1.140625zm3.140625 -7.0q0.109375 -0.953125 0.09375 -1.46875q-0.03125 -1.984375 -1.53125 -2.046875q-1.09375 -0.03125 -1.78125 0.8125q-0.671875 0.84375 -0.9375 2.65625l-0.328125 2.265625q-0.109375 0.90625 -0.109375 1.484375q0.046875 2.0625 1.53125 2.125q1.046875 0.046875 1.71875 -0.765625q0.671875 -0.8125 0.96875 -2.578125l0.375 -2.484375zm5.84375 1.46875l2.296875 -3.078125l1.734375 0l-3.390625 4.25l2.0625 4.203125l-1.53125 0l-1.40625 -3.15625l-2.375 3.15625l-1.734375 0l3.5 -4.34375l-2.0 -4.109375l1.546875 0l1.296875 3.078125zm5.6171875 -0.359375l1.4375 -5.640625l5.671875 0l-0.203125 1.328125l-4.453125 0l-0.875 3.109375q0.859375 -0.5 1.859375 -0.484375q1.40625 0.015625 2.15625 1.0625q0.765625 1.046875 0.625 2.671875q-0.140625 1.75 -1.234375 2.828125q-1.09375 1.0625 -2.734375 1.03125q-1.359375 -0.015625 -2.203125 -0.875q-0.828125 -0.875 -0.875 -2.296875l1.328125 0q0.046875 0.9375 0.515625 1.453125q0.484375 0.515625 1.296875 0.53125q1.0 0.03125 1.6875 -0.703125q0.6875 -0.75 0.8125 -1.953125q0.109375 -1.0625 -0.375 -1.734375q-0.46875 -0.6875 -1.390625 -0.71875q-0.578125 -0.015625 -1.015625 0.171875q-0.4375 0.1875 -0.875 0.53125l-1.15625 -0.3125zm10.765625 5.890625q-1.4375 -0.03125 -2.15625 -1.015625q-0.71875 -1.0 -0.65625 -2.859375q0.015625 -0.578125 0.09375 -1.140625l0.28125 -1.890625q0.375 -2.4375 1.421875 -3.625q1.0625 -1.203125 2.78125 -1.15625q1.453125 0.03125 2.171875 1.0q0.71875 0.953125 0.65625 2.796875q-0.015625 0.578125 -0.09375 1.140625l-0.265625 1.84375q-0.421875 2.5625 -1.46875 3.765625q-1.046875 1.1875 -2.765625 1.140625zm3.140625 -7.0q0.109375 -0.953125 0.09375 -1.46875q-0.03125 -1.984375 -1.53125 -2.046875q-1.09375 -0.03125 -1.78125 0.8125q-0.671875 0.84375 -0.9375 2.65625l-0.328125 2.265625q-0.109375 0.90625 -0.109375 1.484375q0.046875 2.0625 1.53125 2.125q1.046875 0.046875 1.71875 -0.765625q0.671875 -0.8125 0.96875 -2.578125l0.375 -2.484375z" fill-rule="nonzero"/>
|
||||
<path fill="#fff2cc" d="m232.11154 617.37006l0 0c0 -24.74408 20.059067 -44.8031 44.80316 -44.8031l0 0c11.882538 0 23.278381 4.720276 31.680603 13.122498c8.402222 8.402222 13.122528 19.798096 13.122528 31.680603l0 0c0 24.74414 -20.059052 44.80316 -44.80313 44.80316l0 0c-24.744095 0 -44.80316 -20.059021 -44.80316 -44.80316z" fill-rule="evenodd"/>
|
||||
<path stroke="#000000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m232.11154 617.37006l0 0c0 -24.74408 20.059067 -44.8031 44.80316 -44.8031l0 0c11.882538 0 23.278381 4.720276 31.680603 13.122498c8.402222 8.402222 13.122528 19.798096 13.122528 31.680603l0 0c0 24.74414 -20.059052 44.80316 -44.80313 44.80316l0 0c-24.744095 0 -44.80316 -20.059021 -44.80316 -44.80316z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" d="m267.51236 618.527q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125zm7.1015625 1.0625l1.421875 -2.515625l2.40625 0l-2.40625 4.140625l2.515625 4.3125l-2.421875 0l-1.515625 -2.65625l-1.5 2.65625l-2.421875 0l2.5 -4.3125l-2.390625 -4.140625l2.421875 0l1.390625 2.515625zm10.953125 -5.5625l0 1.859375l-0.21875 0q-1.53125 0.03125 -2.46875 0.8125q-0.9375 0.765625 -1.125 2.140625q0.90625 -0.921875 2.296875 -0.921875q1.484375 0 2.359375 1.0625q0.875 1.0625 0.875 2.796875q0 1.109375 -0.484375 2.015625q-0.484375 0.890625 -1.359375 1.390625q-0.875 0.5 -1.984375 0.5q-1.796875 0 -2.90625 -1.25q-1.109375 -1.25 -1.109375 -3.34375l0 -0.8125q0 -1.84375 0.703125 -3.265625q0.703125 -1.421875 2.0 -2.1875q1.3125 -0.78125 3.046875 -0.796875l0.375 0zm-2.203125 5.703125q-0.546875 0 -1.0 0.28125q-0.4375 0.28125 -0.65625 0.75l0 0.6875q0 1.140625 0.4375 1.78125q0.453125 0.625 1.265625 0.625q0.71875 0 1.171875 -0.5625q0.453125 -0.578125 0.453125 -1.5q0 -0.921875 -0.453125 -1.484375q-0.453125 -0.578125 -1.21875 -0.578125zm12.9140625 1.09375q0 2.359375 -0.984375 3.609375q-0.96875 1.25 -2.859375 1.25q-1.859375 0 -2.84375 -1.21875q-0.984375 -1.234375 -1.0 -3.53125l0 -2.09375q0 -2.375 0.984375 -3.609375q0.984375 -1.234375 2.84375 -1.234375q1.859375 0 2.84375 1.21875q0.984375 1.21875 1.015625 3.515625l0 2.09375zm-2.265625 -2.296875q0 -1.421875 -0.390625 -2.0625q-0.375 -0.640625 -1.203125 -0.640625q-0.796875 0 -1.171875 0.609375q-0.375 0.609375 -0.40625 1.921875l0 2.765625q0 1.390625 0.375 2.0625q0.390625 0.671875 1.21875 0.671875q0.828125 0 1.1875 -0.640625q0.375 -0.65625 0.390625 -1.984375l0 -2.703125z" fill-rule="nonzero"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m321.71652 113.00525l74.01575 0" fill-rule="evenodd"/>
|
||||
<path stroke="#990000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m321.71652 113.00525l62.015747 0" fill-rule="evenodd"/>
|
||||
<path fill="#990000" stroke="#990000" stroke-width="2.0" stroke-linecap="butt" d="m383.73227 116.308716l9.076202 -3.3034668l-9.076202 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m408.84827 144.68587l-100.25198 0" fill-rule="evenodd"/>
|
||||
<path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m408.84827 144.68585l-88.25198 0" fill-rule="evenodd"/>
|
||||
<path fill="#666666" stroke="#666666" stroke-width="2.0" stroke-linecap="butt" d="m320.59628 141.3824l-9.076172 3.3034515l9.076172 3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m276.9134 157.8084l0 78.519684" fill-rule="evenodd"/>
|
||||
<path stroke="#990000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m276.9134 157.8084l0 66.519684" fill-rule="evenodd"/>
|
||||
<path fill="#990000" stroke="#990000" stroke-width="2.0" stroke-linecap="butt" d="m273.60992 224.32808l3.3034668 9.076202l3.3034668 -9.076202z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m321.71783 281.12686l74.01575 0" fill-rule="evenodd"/>
|
||||
<path stroke="#38761d" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m321.71783 281.12686l62.015747 0" fill-rule="evenodd"/>
|
||||
<path fill="#38761d" stroke="#38761d" stroke-width="2.0" stroke-linecap="butt" d="m383.73358 284.43033l9.076202 -3.3034668l-9.076202 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m408.84958 312.80746l-100.25198 0" fill-rule="evenodd"/>
|
||||
<path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m408.84958 312.80746l-88.25198 0" fill-rule="evenodd"/>
|
||||
<path fill="#666666" stroke="#666666" stroke-width="2.0" stroke-linecap="butt" d="m320.5976 309.504l-9.076172 3.3034668l9.076172 3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m276.9147 325.93002l0 78.519684" fill-rule="evenodd"/>
|
||||
<path stroke="#38761d" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m276.9147 325.93002l0 66.51965" fill-rule="evenodd"/>
|
||||
<path fill="#38761d" stroke="#38761d" stroke-width="2.0" stroke-linecap="butt" d="m273.61124 392.44968l3.3034668 9.076202l3.3034668 -9.076202z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m321.71652 449.24847l74.01575 0" fill-rule="evenodd"/>
|
||||
<path stroke="#1155cc" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m321.71652 449.24847l62.015747 0" fill-rule="evenodd"/>
|
||||
<path fill="#1155cc" stroke="#1155cc" stroke-width="2.0" stroke-linecap="butt" d="m383.73227 452.55194l9.076202 -3.3034668l-9.076202 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m408.84827 480.92908l-100.25198 0" fill-rule="evenodd"/>
|
||||
<path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m408.84827 480.9291l-88.25198 0" fill-rule="evenodd"/>
|
||||
<path fill="#666666" stroke="#666666" stroke-width="2.0" stroke-linecap="butt" d="m320.59628 477.62564l-9.076172 3.3034668l9.076172 3.3034363z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m424.24933 602.3884l74.01578 0" fill-rule="evenodd"/>
|
||||
<path stroke="#990000" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m424.24933 602.3884l62.015778 0" fill-rule="evenodd"/>
|
||||
<path fill="#990000" stroke="#990000" stroke-width="2.0" stroke-linecap="butt" d="m486.2651 605.6919l9.076172 -3.3034668l-9.076172 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m509.0105 583.0026l179.18109 0l0 38.771667l-179.18109 0z" fill-rule="evenodd"/>
|
||||
<path fill="#990000" d="m518.7605 603.06573q0 -1.953125 0.921875 -3.125q0.921875 -1.1875 2.40625 -1.1875q1.484375 0 2.359375 1.015625l0 -4.40625l1.4375 0l0 12.0l-1.328125 0l-0.0625 -0.90625q-0.875 1.0625 -2.421875 1.0625q-1.46875 0 -2.390625 -1.203125q-0.921875 -1.203125 -0.921875 -3.140625l0 -0.109375zm1.4375 0.15625q0 1.4375 0.59375 2.25q0.59375 0.8125 1.640625 0.8125q1.375 0 2.015625 -1.234375l0 -3.875q-0.65625 -1.203125 -2.0 -1.203125q-1.0625 0 -1.65625 0.828125q-0.59375 0.8125 -0.59375 2.421875zm11.4453125 4.296875q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm8.5390625 6.390625q0.78125 0 1.359375 -0.46875q0.578125 -0.46875 0.640625 -1.171875l1.359375 0q-0.03125 0.734375 -0.5 1.390625q-0.453125 0.65625 -1.234375 1.046875q-0.765625 0.390625 -1.625 0.390625q-1.71875 0 -2.75 -1.15625q-1.015625 -1.15625 -1.015625 -3.15625l0 -0.234375q0 -1.234375 0.453125 -2.1875q0.453125 -0.96875 1.296875 -1.5q0.859375 -0.53125 2.015625 -0.53125q1.421875 0 2.359375 0.859375q0.9375 0.84375 1.0 2.203125l-1.359375 0q-0.0625 -0.828125 -0.625 -1.34375q-0.5625 -0.53125 -1.375 -0.53125q-1.109375 0 -1.71875 0.796875q-0.59375 0.78125 -0.59375 2.28125l0 0.28125q0 1.453125 0.59375 2.25q0.609375 0.78125 1.71875 0.78125zm4.609375 -3.28125q0 -1.234375 0.484375 -2.21875q0.484375 -1.0 1.359375 -1.53125q0.875 -0.546875 1.984375 -0.546875q1.734375 0 2.796875 1.203125q1.0625 1.1875 1.0625 3.171875l0 0.09375q0 1.234375 -0.46875 2.21875q-0.46875 0.984375 -1.359375 1.53125q-0.875 0.546875 -2.015625 0.546875q-1.71875 0 -2.78125 -1.1875q-1.0625 -1.203125 -1.0625 -3.171875l0 -0.109375zm1.453125 0.171875q0 1.40625 0.640625 2.265625q0.65625 0.84375 1.75 0.84375q1.109375 0 1.75 -0.859375q0.65625 -0.859375 0.65625 -2.421875q0 -1.390625 -0.671875 -2.25q-0.65625 -0.859375 -1.75 -0.859375q-1.0625 0 -1.71875 0.859375q-0.65625 0.84375 -0.65625 2.421875zm7.703125 -0.15625q0 -1.953125 0.921875 -3.125q0.921875 -1.1875 2.40625 -1.1875q1.484375 0 2.359375 1.015625l0 -4.40625l1.4375 0l0 12.0l-1.328125 0l-0.0625 -0.90625q-0.875 1.0625 -2.421875 1.0625q-1.46875 0 -2.390625 -1.203125q-0.921875 -1.203125 -0.921875 -3.140625l0 -0.109375zm1.4375 0.15625q0 1.4375 0.59375 2.25q0.59375 0.8125 1.640625 0.8125q1.375 0 2.015625 -1.234375l0 -3.875q-0.65625 -1.203125 -2.0 -1.203125q-1.0625 0 -1.65625 0.828125q-0.59375 0.8125 -0.59375 2.421875zm11.4453125 4.296875q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm11.2421875 8.609375l-7.15625 0l0 -1.1875l7.15625 0l0 1.1875zm2.703125 -1.1875l-1.453125 0l0 -8.453125l1.453125 0l0 8.453125zm-1.5625 -10.703125q0 -0.34375 0.203125 -0.578125q0.21875 -0.25 0.640625 -0.25q0.421875 0 0.640625 0.25q0.21875 0.234375 0.21875 0.59375q0 0.34375 -0.21875 0.578125q-0.21875 0.234375 -0.640625 0.234375q-0.421875 0 -0.640625 -0.234375q-0.203125 -0.234375 -0.203125 -0.59375zm5.2265625 2.25l0.046875 0.9375q0.921875 -1.09375 2.5 -1.09375q1.78125 0 2.421875 1.359375q0.421875 -0.609375 1.09375 -0.984375q0.671875 -0.375 1.59375 -0.375q2.78125 0 2.828125 2.9375l0 5.671875l-1.4375 0l0 -5.578125q0 -0.90625 -0.421875 -1.359375q-0.40625 -0.453125 -1.390625 -0.453125q-0.796875 0 -1.328125 0.484375q-0.53125 0.484375 -0.625 1.296875l0 5.609375l-1.453125 0l0 -5.546875q0 -1.84375 -1.796875 -1.84375q-1.421875 0 -1.953125 1.21875l0 6.171875l-1.4375 0l0 -8.453125l1.359375 0zm17.882812 8.453125q-0.125 -0.25 -0.203125 -0.890625q-1.0 1.046875 -2.40625 1.046875q-1.25 0 -2.046875 -0.703125q-0.796875 -0.71875 -0.796875 -1.796875q0 -1.328125 1.0 -2.046875q1.0 -0.734375 2.828125 -0.734375l1.40625 0l0 -0.671875q0 -0.75 -0.453125 -1.203125q-0.453125 -0.453125 -1.34375 -0.453125q-0.765625 0 -1.296875 0.390625q-0.515625 0.390625 -0.515625 0.953125l-1.453125 0q0 -0.640625 0.4375 -1.21875q0.453125 -0.59375 1.21875 -0.9375q0.78125 -0.34375 1.703125 -0.34375q1.453125 0 2.28125 0.734375q0.828125 0.71875 0.859375 2.0l0 3.890625q0 1.171875 0.296875 1.859375l0 0.125l-1.515625 0zm-2.3906Line truncated
|
||||
<path fill="#000000" fill-opacity="0.0" d="m424.24933 640.0623l74.01578 0" fill-rule="evenodd"/>
|
||||
<path stroke="#38761d" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m424.24933 640.0623l62.015778 0" fill-rule="evenodd"/>
|
||||
<path fill="#38761d" stroke="#38761d" stroke-width="2.0" stroke-linecap="butt" d="m486.2651 643.3658l9.076172 -3.3034668l-9.076172 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m509.0105 620.6765l179.18109 0l0 38.771667l-179.18109 0z" fill-rule="evenodd"/>
|
||||
<path fill="#38761d" d="m518.7605 640.7396q0 -1.953125 0.921875 -3.125q0.921875 -1.1875 2.40625 -1.1875q1.484375 0 2.359375 1.015625l0 -4.40625l1.4375 0l0 12.0l-1.328125 0l-0.0625 -0.90625q-0.875 1.0625 -2.421875 1.0625q-1.46875 0 -2.390625 -1.203125q-0.921875 -1.203125 -0.921875 -3.140625l0 -0.109375zm1.4375 0.15625q0 1.4375 0.59375 2.25q0.59375 0.8125 1.640625 0.8125q1.375 0 2.015625 -1.234375l0 -3.875q-0.65625 -1.203125 -2.0 -1.203125q-1.0625 0 -1.65625 0.828125q-0.59375 0.8125 -0.59375 2.421875zm11.4453125 4.296875q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm8.5390625 6.390625q0.78125 0 1.359375 -0.46875q0.578125 -0.46875 0.640625 -1.171875l1.359375 0q-0.03125 0.734375 -0.5 1.390625q-0.453125 0.65625 -1.234375 1.046875q-0.765625 0.390625 -1.625 0.390625q-1.71875 0 -2.75 -1.15625q-1.015625 -1.15625 -1.015625 -3.15625l0 -0.234375q0 -1.234375 0.453125 -2.1875q0.453125 -0.96875 1.296875 -1.5q0.859375 -0.53125 2.015625 -0.53125q1.421875 0 2.359375 0.859375q0.9375 0.84375 1.0 2.203125l-1.359375 0q-0.0625 -0.828125 -0.625 -1.34375q-0.5625 -0.53125 -1.375 -0.53125q-1.109375 0 -1.71875 0.796875q-0.59375 0.78125 -0.59375 2.28125l0 0.28125q0 1.453125 0.59375 2.25q0.609375 0.78125 1.71875 0.78125zm4.609375 -3.28125q0 -1.234375 0.484375 -2.21875q0.484375 -1.0 1.359375 -1.53125q0.875 -0.546875 1.984375 -0.546875q1.734375 0 2.796875 1.203125q1.0625 1.1875 1.0625 3.171875l0 0.09375q0 1.234375 -0.46875 2.21875q-0.46875 0.984375 -1.359375 1.53125q-0.875 0.546875 -2.015625 0.546875q-1.71875 0 -2.78125 -1.1875q-1.0625 -1.203125 -1.0625 -3.171875l0 -0.109375zm1.453125 0.171875q0 1.40625 0.640625 2.265625q0.65625 0.84375 1.75 0.84375q1.109375 0 1.75 -0.859375q0.65625 -0.859375 0.65625 -2.421875q0 -1.390625 -0.671875 -2.25q-0.65625 -0.859375 -1.75 -0.859375q-1.0625 0 -1.71875 0.859375q-0.65625 0.84375 -0.65625 2.421875zm7.703125 -0.15625q0 -1.953125 0.921875 -3.125q0.921875 -1.1875 2.40625 -1.1875q1.484375 0 2.359375 1.015625l0 -4.40625l1.4375 0l0 12.0l-1.328125 0l-0.0625 -0.90625q-0.875 1.0625 -2.421875 1.0625q-1.46875 0 -2.390625 -1.203125q-0.921875 -1.203125 -0.921875 -3.140625l0 -0.109375zm1.4375 0.15625q0 1.4375 0.59375 2.25q0.59375 0.8125 1.640625 0.8125q1.375 0 2.015625 -1.234375l0 -3.875q-0.65625 -1.203125 -2.0 -1.203125q-1.0625 0 -1.65625 0.828125q-0.59375 0.8125 -0.59375 2.421875zm11.4453125 4.296875q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm11.2421875 8.609375l-7.15625 0l0 -1.1875l7.15625 0l0 1.1875zm1.84375 -1.1875l0 -7.34375l-1.34375 0l0 -1.109375l1.34375 0l0 -0.875q0 -1.359375 0.71875 -2.09375q0.734375 -0.75 2.0625 -0.75q0.5 0 0.984375 0.140625l-0.078125 1.171875q-0.359375 -0.078125 -0.78125 -0.078125q-0.703125 0 -1.09375 0.421875q-0.375 0.40625 -0.375 1.171875l0 0.890625l1.8125 0l0 1.109375l-1.8125 0l0 7.34375l-1.4375 0zm8.9296875 -7.15625q-0.328125 -0.0625 -0.71875 -0.0625q-1.421875 0 -1.921875 1.21875l0 6.0l-1.453125 0l0 -8.453125l1.40625 0l0.03125 0.96875q0.703125 -1.125 2.015625 -1.125q0.421875 0 0.640625 0.109375l0 1.34375zm6.2265625 7.15625q-0.125 -0.25 -0.203125 -0.890625q-1.0 1.046875 -2.40625 1.046875q-1.25 0 -2.046875 -0.703125q-0.796875 -0.71875 -0.796875 -1.796875q0 -1.328125 1.0 -2.046875q1.0 -0.734375 2.828125 -0.734375l1.40625 0l0 -0.671875q0 -0.75 -0.453125 -1.203125q-0.453125 -0.453125 -1.34375 -0.453125q-0.765625 0 -1.296875 0.390625q-0.515625 0.390625 -0.515625 0.953125l-1.453125 0q0 -0.640625 0.4375 -1.21875q0.453125 -0.59375 1.21875 -0.9375q0.78125 -0.34375 1.703125 -0.34375q1.453125 0 2.28125 0.734375q0.828125 0.71875 0.859375 2.0l0 3.890625q0 1.171875 0.296875 1.859375l0 0.125l-1.515625 0zm-2.390625 -1.109375q0.671875 0 1.28125 -0.34375q0.609375 -0.359375 0.890625 -0.921875l0 -1.734375l-1.140625 0q-2.65625 0 -2.65625 1.5625q0 0.671875 0.453125 1.0625q0.453125 0.375 1.171875 0.375zm7.234375 -7.34375l0.046875 0.9375q0.921875 -1.09375 2.5 -1.09375q1.78125 0 2.421875 1.359375q0.42187Line truncated
|
||||
<path fill="#000000" fill-opacity="0.0" d="m424.24933 677.7362l74.01578 0" fill-rule="evenodd"/>
|
||||
<path stroke="#1155cc" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m424.24933 677.7362l62.015778 0" fill-rule="evenodd"/>
|
||||
<path fill="#1155cc" stroke="#1155cc" stroke-width="2.0" stroke-linecap="butt" d="m486.2651 681.0397l9.076172 -3.3034668l-9.076172 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m509.0105 658.3504l179.18109 0l0 38.771667l-179.18109 0z" fill-rule="evenodd"/>
|
||||
<path fill="#1155cc" d="m518.7605 678.4135q0 -1.953125 0.921875 -3.125q0.921875 -1.1875 2.40625 -1.1875q1.484375 0 2.359375 1.015625l0 -4.40625l1.4375 0l0 12.0l-1.328125 0l-0.0625 -0.90625q-0.875 1.0625 -2.421875 1.0625q-1.46875 0 -2.390625 -1.203125q-0.921875 -1.203125 -0.921875 -3.140625l0 -0.109375zm1.4375 0.15625q0 1.4375 0.59375 2.25q0.59375 0.8125 1.640625 0.8125q1.375 0 2.015625 -1.234375l0 -3.875q-0.65625 -1.203125 -2.0 -1.203125q-1.0625 0 -1.65625 0.828125q-0.59375 0.8125 -0.59375 2.421875zm11.4453125 4.296875q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm8.5390625 6.390625q0.78125 0 1.359375 -0.46875q0.578125 -0.46875 0.640625 -1.171875l1.359375 0q-0.03125 0.734375 -0.5 1.390625q-0.453125 0.65625 -1.234375 1.046875q-0.765625 0.390625 -1.625 0.390625q-1.71875 0 -2.75 -1.15625q-1.015625 -1.15625 -1.015625 -3.15625l0 -0.234375q0 -1.234375 0.453125 -2.1875q0.453125 -0.96875 1.296875 -1.5q0.859375 -0.53125 2.015625 -0.53125q1.421875 0 2.359375 0.859375q0.9375 0.84375 1.0 2.203125l-1.359375 0q-0.0625 -0.828125 -0.625 -1.34375q-0.5625 -0.53125 -1.375 -0.53125q-1.109375 0 -1.71875 0.796875q-0.59375 0.78125 -0.59375 2.28125l0 0.28125q0 1.453125 0.59375 2.25q0.609375 0.78125 1.71875 0.78125zm4.609375 -3.28125q0 -1.234375 0.484375 -2.21875q0.484375 -1.0 1.359375 -1.53125q0.875 -0.546875 1.984375 -0.546875q1.734375 0 2.796875 1.203125q1.0625 1.1875 1.0625 3.171875l0 0.09375q0 1.234375 -0.46875 2.21875q-0.46875 0.984375 -1.359375 1.53125q-0.875 0.546875 -2.015625 0.546875q-1.71875 0 -2.78125 -1.1875q-1.0625 -1.203125 -1.0625 -3.171875l0 -0.109375zm1.453125 0.171875q0 1.40625 0.640625 2.265625q0.65625 0.84375 1.75 0.84375q1.109375 0 1.75 -0.859375q0.65625 -0.859375 0.65625 -2.421875q0 -1.390625 -0.671875 -2.25q-0.65625 -0.859375 -1.75 -0.859375q-1.0625 0 -1.71875 0.859375q-0.65625 0.84375 -0.65625 2.421875zm7.703125 -0.15625q0 -1.953125 0.921875 -3.125q0.921875 -1.1875 2.40625 -1.1875q1.484375 0 2.359375 1.015625l0 -4.40625l1.4375 0l0 12.0l-1.328125 0l-0.0625 -0.90625q-0.875 1.0625 -2.421875 1.0625q-1.46875 0 -2.390625 -1.203125q-0.921875 -1.203125 -0.921875 -3.140625l0 -0.109375zm1.4375 0.15625q0 1.4375 0.59375 2.25q0.59375 0.8125 1.640625 0.8125q1.375 0 2.015625 -1.234375l0 -3.875q-0.65625 -1.203125 -2.0 -1.203125q-1.0625 0 -1.65625 0.828125q-0.59375 0.8125 -0.59375 2.421875zm11.4453125 4.296875q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm11.2421875 8.609375l-7.15625 0l0 -1.1875l7.15625 0l0 1.1875zm1.84375 -1.1875l0 -7.34375l-1.34375 0l0 -1.109375l1.34375 0l0 -0.875q0 -1.359375 0.71875 -2.09375q0.734375 -0.75 2.0625 -0.75q0.5 0 0.984375 0.140625l-0.078125 1.171875q-0.359375 -0.078125 -0.78125 -0.078125q-0.703125 0 -1.09375 0.421875q-0.375 0.40625 -0.375 1.171875l0 0.890625l1.8125 0l0 1.109375l-1.8125 0l0 7.34375l-1.4375 0zm8.9296875 -7.15625q-0.328125 -0.0625 -0.71875 -0.0625q-1.421875 0 -1.921875 1.21875l0 6.0l-1.453125 0l0 -8.453125l1.40625 0l0.03125 0.96875q0.703125 -1.125 2.015625 -1.125q0.421875 0 0.640625 0.109375l0 1.34375zm6.2265625 7.15625q-0.125 -0.25 -0.203125 -0.890625q-1.0 1.046875 -2.40625 1.046875q-1.25 0 -2.046875 -0.703125q-0.796875 -0.71875 -0.796875 -1.796875q0 -1.328125 1.0 -2.046875q1.0 -0.734375 2.828125 -0.734375l1.40625 0l0 -0.671875q0 -0.75 -0.453125 -1.203125q-0.453125 -0.453125 -1.34375 -0.453125q-0.765625 0 -1.296875 0.390625q-0.515625 0.390625 -0.515625 0.953125l-1.453125 0q0 -0.640625 0.4375 -1.21875q0.453125 -0.59375 1.21875 -0.9375q0.78125 -0.34375 1.703125 -0.34375q1.453125 0 2.28125 0.734375q0.828125 0.71875 0.859375 2.0l0 3.890625q0 1.171875 0.296875 1.859375l0 0.125l-1.515625 0zm-2.390625 -1.109375q0.671875 0 1.28125 -0.34375q0.609375 -0.359375 0.890625 -0.921875l0 -1.734375l-1.140625 0q-2.65625 0 -2.65625 1.5625q0 0.671875 0.453125 1.0625q0.453125 0.375 1.171875 0.375zm7.234375 -7.34375l0.046875 0.9375q0.921875 -1.09375 2.5 -1.09375q1.78125 0 2.421875 1.359375q0.42187Line truncated
|
||||
<path fill="#000000" fill-opacity="0.0" d="m424.24933 715.4101l74.01578 0" fill-rule="evenodd"/>
|
||||
<path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m424.24933 715.4101l62.015778 0" fill-rule="evenodd"/>
|
||||
<path fill="#666666" stroke="#666666" stroke-width="2.0" stroke-linecap="butt" d="m486.2651 718.71356l9.076172 -3.3034668l-9.076172 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m509.0105 696.0243l179.18109 0l0 38.771667l-179.18109 0z" fill-rule="evenodd"/>
|
||||
<path fill="#666666" d="m521.073 709.8843l0 2.046875l1.578125 0l0 1.109375l-1.578125 0l0 5.25q0 0.5 0.203125 0.765625q0.21875 0.25 0.71875 0.25q0.25 0 0.6875 -0.09375l0 1.171875q-0.5625 0.15625 -1.109375 0.15625q-0.96875 0 -1.46875 -0.578125q-0.484375 -0.59375 -0.484375 -1.671875l0 -5.25l-1.53125 0l0 -1.109375l1.53125 0l0 -2.046875l1.453125 0zm6.7734375 10.65625q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm6.7265625 7.421875l-1.453125 0l0 -12.0l1.453125 0l0 12.0zm3.8828125 0l-1.453125 0l0 -12.0l1.453125 0l0 12.0zm8.3984375 1.1875l-7.15625 0l0 -1.1875l7.15625 0l0 1.1875zm2.484375 -9.640625l0.046875 0.9375q0.921875 -1.09375 2.5 -1.09375q1.78125 0 2.421875 1.359375q0.421875 -0.609375 1.09375 -0.984375q0.671875 -0.375 1.59375 -0.375q2.78125 0 2.828125 2.9375l0 5.671875l-1.4375 0l0 -5.578125q0 -0.90625 -0.421875 -1.359375q-0.40625 -0.453125 -1.390625 -0.453125q-0.796875 0 -1.328125 0.484375q-0.53125 0.484375 -0.625 1.296875l0 5.609375l-1.453125 0l0 -5.546875q0 -1.84375 -1.796875 -1.84375q-1.421875 0 -1.953125 1.21875l0 6.171875l-1.4375 0l0 -8.453125l1.359375 0zm16.179688 8.609375q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm11.2421875 8.609375l-7.15625 0l0 -1.1875l7.15625 0l0 1.1875zm2.484375 -9.640625l0.046875 0.9375q0.921875 -1.09375 2.5 -1.09375q1.78125 0 2.421875 1.359375q0.421875 -0.609375 1.09375 -0.984375q0.671875 -0.375 1.59375 -0.375q2.78125 0 2.828125 2.9375l0 5.671875l-1.4375 0l0 -5.578125q0 -0.90625 -0.421875 -1.359375q-0.40625 -0.453125 -1.390625 -0.453125q-0.796875 0 -1.328125 0.484375q-0.53125 0.484375 -0.625 1.296875l0 5.609375l-1.453125 0l0 -5.546875q0 -1.84375 -1.796875 -1.84375q-1.421875 0 -1.953125 1.21875l0 6.171875l-1.4375 0l0 -8.453125l1.359375 0zm12.2890625 4.140625q0 -1.234375 0.484375 -2.21875q0.484375 -1.0 1.359375 -1.53125q0.875 -0.546875 1.984375 -0.546875q1.734375 0 2.796875 1.203125q1.0625 1.1875 1.0625 3.171875l0 0.09375q0 1.234375 -0.46875 2.21875q-0.46875 0.984375 -1.359375 1.53125q-0.875 0.546875 -2.015625 0.546875q-1.71875 0 -2.78125 -1.1875q-1.0625 -1.203125 -1.0625 -3.171875l0 -0.109375zm1.453125 0.171875q0 1.40625 0.640625 2.265625q0.65625 0.84375 1.75 0.84375q1.109375 0 1.75 -0.859375q0.65625 -0.859375 0.65625 -2.421875q0 -1.390625 -0.671875 -2.25q-0.65625 -0.859375 -1.75 -0.859375q-1.0625 0 -1.71875 0.859375q-0.65625 0.84375 -0.65625 2.421875zm12.140625 -3.015625q-0.328125 -0.0625 -0.71875 -0.0625q-1.421875 0 -1.921875 1.21875l0 6.0l-1.453125 0l0 -8.453125l1.40625 0l0.03125 0.96875q0.703125 -1.125 2.015625 -1.125q0.421875 0 0.640625 0.109375l0 1.34375zm4.6875 7.3125q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375z" fill-rule="nonzero"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m232.11154 281.12686c-37.158127 0 -74.32414 84.06299 -74.31627 168.12598c0.007873535 84.06302 37.189636 168.126 74.37927 168.126" fill-rule="evenodd"/>
|
||||
<path stroke="#38761d" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m232.11154 281.12686c-37.158127 0 -74.32414 84.06299 -74.31627 168.12598c0.0039367676 42.031494 9.301346 84.06296 23.246475 115.58658c6.9725647 15.761841 15.107056 28.896667 23.822754 38.091064c4.3578644 4.597229 8.861008 8.20929 13.43689 10.672058c0.57199097 0.30786133 1.1450958 0.5977783 1.719223 0.86938477c0.14350891 0.067871094 0.28710938 0.13464355 0.43077087 0.20025635l0.029342651 0.013122559" fill-rule="evenodd"/>
|
||||
<path fill="#38761d" stroke="#38761d" stroke-width="2.0" stroke-linecap="butt" d="m219.73924 617.90454l9.58609 -1.1820068l-8.103119 -5.2563477z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m188.76164 192.9738l56.472443 56.472443" fill-rule="evenodd"/>
|
||||
<path stroke="#351c75" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m188.76164 192.97382l47.987167 47.987167" fill-rule="evenodd"/>
|
||||
<path fill="#351c75" stroke="#351c75" stroke-width="2.0" stroke-linecap="butt" d="m234.4129 243.29688l8.753738 4.0819397l-4.0819244 -8.753738z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m424.24933 753.084l74.01578 0" fill-rule="evenodd"/>
|
||||
<path stroke="#351c75" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m424.24933 753.084l62.015778 0" fill-rule="evenodd"/>
|
||||
<path fill="#351c75" stroke="#351c75" stroke-width="2.0" stroke-linecap="butt" d="m486.2651 756.38745l9.076172 -3.3034668l-9.076172 -3.3034668z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m509.0105 733.6982l179.18109 0l0 38.771606l-179.18109 0z" fill-rule="evenodd"/>
|
||||
<path fill="#351c75" d="m523.198 750.9019q-0.328125 -0.0625 -0.71875 -0.0625q-1.421875 0 -1.921875 1.21875l0 6.0l-1.453125 0l0 -8.453125l1.40625 0l0.03125 0.96875q0.703125 -1.125 2.015625 -1.125q0.421875 0 0.640625 0.109375l0 1.34375zm4.6875 7.3125q-1.71875 0 -2.796875 -1.125q-1.078125 -1.140625 -1.078125 -3.03125l0 -0.265625q0 -1.25 0.46875 -2.234375q0.484375 -1.0 1.34375 -1.546875q0.875 -0.5625 1.875 -0.5625q1.65625 0 2.5625 1.09375q0.921875 1.078125 0.921875 3.09375l0 0.609375l-5.734375 0q0.03125 1.25 0.734375 2.015625q0.703125 0.765625 1.78125 0.765625q0.765625 0 1.296875 -0.3125q0.53125 -0.3125 0.921875 -0.828125l0.890625 0.6875q-1.0625 1.640625 -3.1875 1.640625zm-0.1875 -7.578125q-0.875 0 -1.46875 0.640625q-0.59375 0.625 -0.734375 1.78125l4.234375 0l0 -0.109375q-0.0625 -1.109375 -0.59375 -1.703125q-0.53125 -0.609375 -1.4375 -0.609375zm10.0703125 5.171875q0 -0.578125 -0.4375 -0.90625q-0.4375 -0.328125 -1.546875 -0.5625q-1.09375 -0.234375 -1.734375 -0.5625q-0.640625 -0.328125 -0.953125 -0.78125q-0.3125 -0.453125 -0.3125 -1.078125q0 -1.03125 0.875 -1.75q0.890625 -0.71875 2.25 -0.71875q1.4375 0 2.328125 0.75q0.90625 0.734375 0.90625 1.890625l-1.453125 0q0 -0.59375 -0.515625 -1.015625q-0.5 -0.4375 -1.265625 -0.4375q-0.78125 0 -1.234375 0.34375q-0.4375 0.34375 -0.4375 0.890625q0 0.53125 0.40625 0.796875q0.421875 0.265625 1.5 0.515625q1.078125 0.234375 1.75 0.578125q0.671875 0.328125 1.0 0.796875q0.328125 0.46875 0.328125 1.15625q0 1.125 -0.90625 1.8125q-0.90625 0.6875 -2.359375 0.6875q-1.015625 0 -1.796875 -0.359375q-0.78125 -0.359375 -1.21875 -1.0q-0.4375 -0.65625 -0.4375 -1.40625l1.4375 0q0.046875 0.734375 0.578125 1.15625q0.546875 0.421875 1.4375 0.421875q0.828125 0 1.3125 -0.328125q0.5 -0.328125 0.5 -0.890625zm5.296875 -8.25l0 2.046875l1.578125 0l0 1.109375l-1.578125 0l0 5.25q0 0.5 0.203125 0.765625q0.21875 0.25 0.71875 0.25q0.25 0 0.6875 -0.09375l0 1.171875q-0.5625 0.15625 -1.109375 0.15625q-0.96875 0 -1.46875 -0.578125q-0.484375 -0.59375 -0.484375 -1.671875l0 -5.25l-1.53125 0l0 -1.109375l1.53125 0l0 -2.046875l1.453125 0zm8.4765625 10.5q-0.125 -0.25 -0.203125 -0.890625q-1.0 1.046875 -2.40625 1.046875q-1.25 0 -2.046875 -0.703125q-0.796875 -0.71875 -0.796875 -1.796875q0 -1.328125 1.0 -2.046875q1.0 -0.734375 2.828125 -0.734375l1.40625 0l0 -0.671875q0 -0.75 -0.453125 -1.203125q-0.453125 -0.453125 -1.34375 -0.453125q-0.765625 0 -1.296875 0.390625q-0.515625 0.390625 -0.515625 0.953125l-1.453125 0q0 -0.640625 0.4375 -1.21875q0.453125 -0.59375 1.21875 -0.9375q0.78125 -0.34375 1.703125 -0.34375q1.453125 0 2.28125 0.734375q0.828125 0.71875 0.859375 2.0l0 3.890625q0 1.171875 0.296875 1.859375l0 0.125l-1.515625 0zm-2.390625 -1.109375q0.671875 0 1.28125 -0.34375q0.609375 -0.359375 0.890625 -0.921875l0 -1.734375l-1.140625 0q-2.65625 0 -2.65625 1.5625q0 0.671875 0.453125 1.0625q0.453125 0.375 1.171875 0.375zm9.96875 -6.046875q-0.328125 -0.0625 -0.71875 -0.0625q-1.421875 0 -1.921875 1.21875l0 6.0l-1.453125 0l0 -8.453125l1.40625 0l0.03125 0.96875q0.703125 -1.125 2.015625 -1.125q0.421875 0 0.640625 0.109375l0 1.34375zm3.6796875 -3.34375l0 2.046875l1.578125 0l0 1.109375l-1.578125 0l0 5.25q0 0.5 0.203125 0.765625q0.21875 0.25 0.71875 0.25q0.25 0 0.6875 -0.09375l0 1.171875q-0.5625 0.15625 -1.109375 0.15625q-0.96875 0 -1.46875 -0.578125q-0.484375 -0.59375 -0.484375 -1.671875l0 -5.25l-1.53125 0l0 -1.109375l1.53125 0l0 -2.046875l1.453125 0zm9.3515625 11.6875l-7.15625 0l0 -1.1875l7.15625 0l0 1.1875zm1.84375 -1.1875l0 -7.34375l-1.34375 0l0 -1.109375l1.34375 0l0 -0.875q0 -1.359375 0.71875 -2.09375q0.734375 -0.75 2.0625 -0.75q0.5 0 0.984375 0.140625l-0.078125 1.171875q-0.359375 -0.078125 -0.78125 -0.078125q-0.703125 0 -1.09375 0.421875q-0.375 0.40625 -0.375 1.171875l0 0.890625l1.8125 0l0 1.109375l-1.8125 0l0 7.34375l-1.4375 0zm8.9296875 -7.15625q-0.328125 -0.0625 -0.71875 -0.0625q-1.421875 0 -1.921875 1.21875l0 6.0l-1.453125 0l0 -8.453125l1.40625 0l0.03125 0.96875q0.703125 -1.125 2.015625 -1.125q0.421875 0 0.640625 0.109375l0 1.34375zm6.2265625 7.15625q-0.125 -0.25 -0.203125 -0.890625q-1.0 1.046875 -2.40625 1.046875q-1.25 0 -2.046875 -0.703125q-0.796875 -0.71875 -0.796875 -1.796875q0 -1.328125 1.0 -2.046875q1.0 -0.734375 2.828125 -0.734375l1.40625 0l0 -0.671875q0 -0.75 -0.453125 -1.203125q-0.453125 -0.453125 -1.34375 -0.453125q-0.765625 0 -1.296875 0.390625q-0.515625 0.390625 -0.515625 0.953125l-1.453125 0q0 -0.640625 0.4375 -1.21875q0.453125 -0.59375 1.21875 -0.9375q0.78125 -0.34375 1.703125 -0.34375q1.453125 0 2.28125 0.734375q0.828125 0.71875 0.859375 2.0l0 3.890625q0 1.171875 0.296875 1.859375l0 0.125l-1.515625 0zm-2.390625 -1.109375q0.671875 0 1.28125 -0.34375q0.609375 -0.359375 0.890625 -0.921875l0 -1.734375l-1.140625 0q-2.65625 0 -2.65625 1.5625q0 0.671875 0.453125 1.0625q0.453125 0.375 1.171875 0.375zm7.234375 -7.34375l0.046875 0.9375q0.921875 -1.09375 2.5 -1.09375q1.78125 0 2.421875 1.359375q0.421875 -0.609375 1.09375 -0.984375q0.671875 -0.375 1.59375 -0.375q2.78125 0 2.828125 2.9375l0 5.671875l-1.4375 0l0 -5.57Line truncated
|
||||
<path fill="#000000" fill-opacity="0.0" d="m276.9134 494.0516c0 24.788177 -19.656372 58.359528 -38.181107 49.576385c-18.52475 -8.783142 -35.917892 -59.920746 -38.181107 -106.89435c-2.263214 -46.973633 10.603485 -89.783264 22.338577 -106.89438c11.735107 -17.111115 22.338593 -8.523743 22.338593 -17.047485" fill-rule="evenodd"/>
|
||||
<path stroke="#1155cc" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m276.9134 494.05164c0 24.788147 -19.656372 58.359497 -38.181107 49.576355c-18.52475 -8.783142 -35.917892 -59.920715 -38.181107 -106.89435c-2.2632294 -46.973633 10.6035 -89.783264 22.338593 -106.89438c2.9337616 -4.2778015 5.796814 -6.9494324 8.441147 -8.683777c0.6610718 -0.43359375 1.3084717 -0.80859375 1.9399109 -1.135498c0.3157196 -0.16345215 0.62742615 -0.31484985 0.9348602 -0.4555359c0.1537323 -0.07034302 0.30636597 -0.13800049 0.457901 -0.20315552l0.4124298 -0.17184448" fill-rule="evenodd"/>
|
||||
<path fill="#1155cc" stroke="#1155cc" stroke-width="2.0" stroke-linecap="butt" d="m236.83723 321.98425l5.9174957 -7.6336975l-9.439911 2.0440674z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m472.20947 144.68587c0 2.4825134 9.531769 9.491394 19.06128 4.965042c9.5295105 -4.526352 19.056763 -20.587952 19.06128 -36.649452c0.004486084 -16.061508 -9.513763 -32.12294 -19.029785 -36.649452c-9.516022 -4.526512 -19.029785 2.4818878 -19.029785 4.9637756" fill-rule="evenodd"/>
|
||||
<path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m472.20947 144.68585c0 2.4825287 9.531738 9.491409 19.06128 4.9650574c9.529541 -4.526367 19.056763 -20.587952 19.06128 -36.649452c0.004486084 -16.061508 -9.513794 -32.12294 -19.029785 -36.649452c-2.3790283 -1.13163 -4.7578735 -1.5423279 -6.9879456 -1.4830475c-0.55752563 0.014816284 -1.1057739 0.059005737 -1.642395 0.12865448l-0.18148804 0.025817871" fill-rule="evenodd"/>
|
||||
<path fill="#666666" stroke="#666666" stroke-width="2.0" stroke-linecap="butt" d="m480.7582 72.21055l-5.9961243 7.572098l9.460541 -1.9463272z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m472.20947 312.81186c0 2.4825134 9.531769 9.491394 19.06128 4.965027c9.5295105 -4.5263367 19.056763 -20.587952 19.06128 -36.649445c0.004486084 -16.061523 -9.513763 -32.12294 -19.029785 -36.64946c-9.516022 -4.5265045 -19.029785 2.4818878 -19.029785 4.963791" fill-rule="evenodd"/>
|
||||
<path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m472.20947 312.81183c0 2.482544 9.531738 9.491425 19.06128 4.9650574c9.529541 -4.526367 19.056763 -20.587921 19.06128 -36.649445c0.004486084 -16.061523 -9.513794 -32.122925 -19.029785 -36.64946c-2.3790283 -1.1316223 -4.7578735 -1.5423279 -6.9879456 -1.4830475c-0.55752563 0.014801025 -1.1057739 0.059020996 -1.642395 0.12864685l-0.18148804 0.025817871" fill-rule="evenodd"/>
|
||||
<path fill="#666666" stroke="#666666" stroke-width="2.0" stroke-linecap="butt" d="m480.7582 240.33653l-5.9961243 7.572098l9.460541 -1.9463348z" fill-rule="evenodd"/>
|
||||
<path fill="#000000" fill-opacity="0.0" d="m472.20947 482.81842c0 2.4825134 9.531769 9.491394 19.06128 4.965027c9.5295105 -4.5263367 19.056763 -20.587952 19.06128 -36.649445c0.004486084 -16.061523 -9.513763 -32.122925 -19.029785 -36.649445c-9.516022 -4.52652 -19.029785 2.4818726 -19.029785 4.9637756" fill-rule="evenodd"/>
|
||||
<path stroke="#666666" stroke-width="2.0" stroke-linejoin="round" stroke-linecap="butt" d="m472.20947 482.81842c0 2.4825134 9.531738 9.491364 19.06128 4.9650574c9.529541 -4.5263977 19.056763 -20.587982 19.06128 -36.649506c0.004486084 -16.061462 -9.513794 -32.122894 -19.029785 -36.649445c-2.3790283 -1.1315918 -4.7578735 -1.5422974 -6.9879456 -1.4830017c-0.55752563 0.014801025 -1.1057739 0.05899048 -1.642395 0.12863159l-0.18148804 0.025848389" fill-rule="evenodd"/>
|
||||
<path fill="#666666" stroke="#666666" stroke-width="2.0" stroke-linecap="butt" d="m480.7582 410.3431l-5.9961243 7.5720825l9.460541 -1.9463196z" fill-rule="evenodd"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 67 KiB |
@@ -0,0 +1,118 @@
|
||||
# Image Decoders Call Sequence
|
||||
|
||||
As discussed in the [Image Decoders](./image-decoders.md) document, here's the
|
||||
canonical sequence of API calls to decode an animated image (with N frames):
|
||||
|
||||
1. DIC (`decode_image_config`)
|
||||
1. DFC (`decode_frame_config`) #0
|
||||
1. DF (`decode_frame`) #0
|
||||
1. DFC (`decode_frame_config`) #1
|
||||
1. DF (`decode_frame`) #1
|
||||
1. ...
|
||||
1. DFC (`decode_frame_config`) #N-1
|
||||
1. DF (`decode_frame`) #N-1
|
||||
1. DFC (`decode_frame_config`) #N returning an `"@end of data"` status value.
|
||||
|
||||
The final DFC call returns `"@end of data"` even if the animation loops.
|
||||
|
||||
Decoding a still (non-animated) image is equivalent to N being 1.
|
||||
|
||||
These three methods (DIC, DFC, DF) are all
|
||||
[coroutines](/doc/note/coroutines.md) and may return I/O related suspension
|
||||
status values. Those coroutines should be resumed by calling the same method
|
||||
again, before moving to the next one in the sequence.
|
||||
|
||||
Encountering an error (such as the input not being valid in that image file
|
||||
format) is sticky (any further calls will return that same error).
|
||||
|
||||
|
||||
## Implicit Calls
|
||||
|
||||
These three methods (DIC, DFC, DF) are all also optional in some sense.
|
||||
Referring to the ordered list at the top of this page, any `decode_etc` call
|
||||
jumps forward to the next matching method in that canonical sequence,
|
||||
implicitly calling any jumped over method with the same `io_reader` but null
|
||||
values for other arguments.
|
||||
|
||||
For example, starting with a freshly initialized image decoder, if it's a first
|
||||
party image and you already know its width, height and pixel format (so you can
|
||||
prepare a perfectly sized pixel buffer without having to call DIC or DFC), it
|
||||
is valid to call DF, going straight to the DF #0 stage. This implicitly calls
|
||||
DIC and DFC #0.
|
||||
|
||||
Even if you didn't know the width, height and pixel format, it is still valid
|
||||
to call DF with a smaller-dimensioned pixel buffer (which just means the
|
||||
decoded image will be clipped) or with a different pixel format (the decoder
|
||||
will convert).
|
||||
|
||||
After that, it is valid to call DFC, going to the DFC #1 stage (or get "@end of
|
||||
data" for still images), which would not make any implicit calls.
|
||||
|
||||
After that, it is valid to call DFC, going to the DFC #2 stage, implicitly
|
||||
calling DF #1.
|
||||
|
||||
And so on.
|
||||
|
||||
For example, starting at the DF #N-1 stage, it is valid to call DF again, which
|
||||
will return "@end of data" because it first implicitly calls DF #N, which
|
||||
returns "@end of data".
|
||||
|
||||
Implicitly calling DF (skipping over the pixel data) is typically much faster
|
||||
than explicitly calling DF (decompressing the pixel data). For example,
|
||||
starting with a freshly initialized image decoder, if you just want to *count*
|
||||
the number of animation frames, without needing each frame's decoded pixels,
|
||||
just call DFC (and not DF) in a loop until "#end of data".
|
||||
|
||||
|
||||
## State Machine
|
||||
|
||||
It's not part of Wuffs' public API, but Wuffs' standard library's image decoder
|
||||
implementations all have a private `call_sequence` field to track this state
|
||||
machine. Broadly speaking, an image decoder starts in an initial state (labeled
|
||||
`0x00`). The DIC call moves to state `0x20`. Subsequent DFC and DF calls bounce
|
||||
between states `0x40` and `0x20` until the last DFC moves the final state
|
||||
`0x60`. These are the bold-labeled states in the left hand column of the
|
||||
diagram below:
|
||||
|
||||

|
||||
|
||||
The original Google Docs document for that diagram [is
|
||||
here](https://docs.google.com/document/d/1bbH9cpgxsMP8M5U4NsTotr-wSlyH85tiDKSJSF1HVXc/edit?usp=sharing).
|
||||
|
||||
The italic-labeled states (whose numeric labels all have the `0x10` bit set) in
|
||||
the right hand column are side-track states when [metadata](./metadata.md) is
|
||||
encountered, and are discussed below. If the caller never opts in to seeing
|
||||
metadata (opting in by calling `set_report_metadata`) then the decoder never
|
||||
enters these `(base_value | 0x10)` states.
|
||||
|
||||
The `0x08` bit is used when calling `restart_frame`, discussed below. The low
|
||||
three bits are reserved but currently unused.
|
||||
|
||||
The primary purposes of the `call_sequence` field is track when we've reached
|
||||
"@end of data" and to reject method calls that occur out of sequence. Such
|
||||
method calls result in the `"#bad call sequence"` error status value. For
|
||||
example, a DIC call is illegal after a DIC, DFC or DF call. Similarly, a TMM
|
||||
(`tell_me_more`) call is illegal unless the decoder is in a right hand column
|
||||
state.
|
||||
|
||||
|
||||
## Restarts
|
||||
|
||||
Image decoding typically runs sequentially: the first frame (#0) is decoded,
|
||||
then the second (#1), then the third (#2), etc. However, decoding can sometimes
|
||||
happen in random access instead of sequential order. Playing a looping
|
||||
animation may require rewinding back to the first frame. Replaying an animation
|
||||
may be able to re-use previousy cached frames at times, so a decoder may be
|
||||
asked to jump ahead. While Wuffs is designed for sequential decoding (as it
|
||||
does not assume that its input byte stream is rewindable or seekable), using
|
||||
Wuffs to implement other graphics APIs can involve [random access to animation
|
||||
frames](https://github.com/google/skia/blob/ee6f41262b2ef86b5f06b33473379ac887401451/include/codec/SkCodec.h#L314-L319).
|
||||
|
||||
The RF `restart_frame` method supports these usage patterns, setting up the
|
||||
decoder so that it's just about to decode the I'th frame configuration (when
|
||||
the `io_reader` is also placed at `io_position` previously returned by the I'th
|
||||
DFC).
|
||||
|
||||
The RF method can only be called when the image configuration has already been
|
||||
decoded. Equivalently, only when the `call_sequence` is at least `0x20`.
|
||||
@@ -61,7 +61,9 @@ will implicitly parse and verify the image header, before parsing the first
|
||||
frame's header. Similarly, you can call only `decode_frame` N times, without
|
||||
calling `decode_image_config` or `decode_frame_config`, if you already know
|
||||
metadata like N and each frame's rectangle bounds by some other means (e.g.
|
||||
this is a first party, statically known image).
|
||||
this is a first party, statically known image). The [Image Decoders Call
|
||||
Sequence](./image-decoders-call-sequence.md) document has more implementation
|
||||
information.
|
||||
|
||||
Specifically, starting with an unknown (but re-windable) animated image, if you
|
||||
want to just find N (i.e. count the number of frames), you can loop calling
|
||||
@@ -89,26 +91,26 @@ associated stream will also need to be rewound.
|
||||
|
||||
## Metadata
|
||||
|
||||
Images can also contain metadata (e.g. color profiles, time stamps). By
|
||||
default, Wuffs' image decoders skip over metadata, but calling
|
||||
`set_report_metadata` will opt in to having `decode_image_config` return early
|
||||
when encountering metadata in the file. Calling `set_report_metadata` can be
|
||||
done multiple times, each with a different
|
||||
[FourCC](/doc/note/base38-and-fourcc.md) code such as `0x49434350` "ICCP" or
|
||||
`0x584D5020` "XMP ", to indicate what sorts of metadata the caller is
|
||||
interested in. Conversely, when the parser encounters metadata (and returns a
|
||||
"@metadata reported" [status](/doc/note/statuses.md)), call `metadata_fourcc`
|
||||
to see what sort of metadata it is.
|
||||
The [Metadata](./metadata.md) document has more API information, applicable to
|
||||
Wuffs' decoders but not specific to Wuffs' image decoders.
|
||||
|
||||
Embedded metadata needs to be processed by a separate parser. For example,
|
||||
processing XMP metadata usually involves some sort of XML parser, regardless of
|
||||
what particular image format that XMP metadata was embedded in. That metadata
|
||||
might also be in multiple (non-contiguous) chunks. The caller needs to loop,
|
||||
repeatedly calling `metadata_chunk_length`, advancing the `io_buffer` by that
|
||||
many bytes (after diverting those bytes to the separate parser) and calling
|
||||
`ack_metadata_chunk`. If the latter returns "@metadata reported", then repeat
|
||||
the loop. If it returns ok, then the metadata was completely consumed, and the
|
||||
caller can go back to the `decode_image_config` method.
|
||||
|
||||
## API Listing
|
||||
|
||||
In Wuffs syntax, the `base.image_decoder` methods are:
|
||||
|
||||
- `decode_frame?(dst: ptr pixel_buffer, src: io_reader, blend: pixel_blend, workbuf: slice u8, opts: nptr decode_frame_options)`
|
||||
- `decode_frame_config?(dst: nptr frame_config, src: io_reader)`
|
||||
- `decode_image_config?(dst: nptr image_config, src: io_reader)`
|
||||
- `frame_dirty_rect() rect_ie_u32`
|
||||
- `num_animation_loops() u32`
|
||||
- `num_decoded_frame_configs() u64`
|
||||
- `num_decoded_frames() u64`
|
||||
- `restart_frame!(index: u64, io_position: u64) status`
|
||||
- `set_quirk_enabled!(quirk: u32, enabled: bool)`
|
||||
- `set_report_metadata!(fourcc: u32, report: bool)`
|
||||
- `tell_me_more?(dst: io_writer, minfo: nptr more_information, src: io_reader)`
|
||||
- `workbuf_len() range_ii_u64`
|
||||
|
||||
|
||||
## Implementations
|
||||
@@ -117,6 +119,7 @@ caller can go back to the `decode_image_config` method.
|
||||
- [std/gif](/std/gif)
|
||||
- [std/nie](/std/nie)
|
||||
- [std/png](/std/png)
|
||||
- [std/tga](/std/tga)
|
||||
- [std/wbmp](/std/wbmp)
|
||||
|
||||
|
||||
@@ -125,6 +128,9 @@ caller can go back to the `decode_image_config` method.
|
||||
- [example/convert-to-nia](/example/convert-to-nia)
|
||||
- [example/gifplayer](/example/gifplayer)
|
||||
- [example/imageviewer](/example/imageviewer)
|
||||
- [example/sdl-imageviewer](/example/sdl-imageviewer)
|
||||
- [script/print-average-pixel](/script/print-average-pixel.cc)
|
||||
- [script/print-image-metadata](/script/print-image-metadata.cc)
|
||||
|
||||
Examples in other repositories:
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# Metadata
|
||||
|
||||
Files can also contain metadata (e.g. for image files, EXIF information, color
|
||||
profiles and time stamps). By default, Wuffs' decoders skip over metadata, but
|
||||
calling `set_report_metadata` will opt in to having `decode_etc` methods return
|
||||
early when encountering metadata in the file. Calling `set_report_metadata` can
|
||||
be done multiple times, each with a different
|
||||
[FourCC](/doc/note/base38-and-fourcc.md) code such as `0x49434350` "ICCP" or
|
||||
`0x584D5020` "XMP ", to indicate what sorts of metadata the caller is
|
||||
interested in. Conversely, when the parser encounters metadata (and returns a
|
||||
"@metadata reported" [status](/doc/note/statuses.md)), call `tell_me_more` to
|
||||
see what sort of metadata it is.
|
||||
|
||||
Some metadata is short and `tell_me_more` will also fill in its `minfo: nptr
|
||||
more_information` out parameter with "parsed metadata". For example, Gamma
|
||||
Correction metadata is a single numerical value and Primary Chromaticities
|
||||
metadata is only eight numbers. From C++ code, call the `metadata_parsed__gama`
|
||||
or `metadata_parsed__chrm` methods to retrieve these value.
|
||||
|
||||
Some metadata is long (or at least variable length) and needs processing by a
|
||||
separate parser. For example, processing XMP metadata usually involves some
|
||||
sort of XML parser, regardless of what particular image format that XMP
|
||||
metadata was embedded in. Wuffs decoders will return "raw metadata" instead of
|
||||
parsing it themselves. Raw metadata is further sub-divided into two categories:
|
||||
"raw passthrough" and "raw transform". Either way, note that raw metadata might
|
||||
also be arranged in multiple (non-contiguous) chunks of the source data.
|
||||
|
||||
"Raw passthrough" means that the bytes in the wire format can be sent "as is"
|
||||
to the separate parser. Call `tell_me_more` in a loop (the `dst: io_writer`
|
||||
argument will be ignored) and `metadata_raw_passthrough__range` to identify a
|
||||
range (a chunk) of the input stream. Divert the bytes in that range to the
|
||||
separate parser (which should advance the `io_buffer` to the end of that range)
|
||||
and repeat the loop as long as `tell_me_more` returned a "$even more
|
||||
information" status.
|
||||
|
||||
"Raw transform" means that the bytes in the wire format have to be further
|
||||
processed (e.g. decompressed) before sending them on to the separate parser.
|
||||
That processing is done by the decoder callee, not the caller. Pass a writable
|
||||
`dst io_buffer` to `tell_me_more` (where writable means that it has a positive
|
||||
`writer_length`) and implementations should fill in that buffer with
|
||||
post-transformed (e.g. decompressed) data to send onwards. Like any
|
||||
`io_transformer`-like coroutine, this should be in a loop, as it may suspend
|
||||
with "$short read" and "$short write" statuses.
|
||||
|
||||
Either way, break the loop (after handling the `dst` and `minfo` out
|
||||
parameters) when `tell_me_more` returns a NULL status, meaning ok, when the
|
||||
metadata is complete. Afterwards, call the original action (e.g. `decode_etc`)
|
||||
again to resume after the "@metadata reported" detour.
|
||||
|
||||
`tell_me_more` both returns a status and fills in the `dst` and `minfo` out
|
||||
parameters. Subtly, the caller should process the out parameters before
|
||||
considering the status. It is valid for the callee to fill in the out
|
||||
parameters with partial results when returning an error status or with full
|
||||
results when returning an ok status. 'No partial results' is represented by an
|
||||
unchanged `dst` or `minfo`. For example, if `minfo` was reset to zero before
|
||||
each `tell_me_more` call then `minfo.flavor` remaining zero means that the
|
||||
`minfo` was unchanged, as valid flavor values are non-zero.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
- [script/print-image-metadata](/script/print-image-metadata.cc)
|
||||
@@ -1,3 +1,5 @@
|
||||
# Wuffs' Example Programs
|
||||
|
||||
This directory contains example programs that use [Wuffs the
|
||||
Library](/doc/wuffs-the-library.md). See [Hello `wuffs-c`](/hello-wuffs-c) for
|
||||
an example program that uses [Wuffs the Language](/doc/wuffs-the-language.md)
|
||||
@@ -8,3 +10,17 @@ not just programming language toys at the "calculate the Fibonacci sequence"
|
||||
level of triviality. For example, the [example/crc32](/example/crc32/crc32.cc)
|
||||
and [example/zcat](/example/zcat/zcat.c) programs are roughly equivalent to
|
||||
Debian Linux's `/usr/bin/crc32` and `/bin/zcat` programs.
|
||||
|
||||
|
||||
## Building
|
||||
|
||||
Running `build-example.sh` from the top level directory will build all of the
|
||||
examples. To check out and build just one, such as `jsonptr`:
|
||||
|
||||
git clone https://github.com/google/wuffs.git
|
||||
cd wuffs
|
||||
./build-example.sh example/jsonptr
|
||||
|
||||
When re-building, you only need the last of those three lines. To run it:
|
||||
|
||||
gen/bin/example-jsonptr test/data/json-things.unformatted.json
|
||||
@@ -0,0 +1,266 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
bzcat decodes bzip2'ed data to stdout. It is similar to the standard /bin/bzcat
|
||||
program, except that this example program only reads from stdin. On Linux, it
|
||||
also self-imposes a SECCOMP_MODE_STRICT sandbox. To run:
|
||||
|
||||
$CC bzcat.c && ./a.out < ../../test/data/romeo.txt.bz2; rm -f a.out
|
||||
|
||||
for a C compiler $CC, such as clang or gcc.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||
// functions have static storage.
|
||||
//
|
||||
// This can help the compiler ignore or discard unused code, which can produce
|
||||
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__BZIP2
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../release/c/wuffs-unsupported-snapshot.c"
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <linux/prctl.h>
|
||||
#include <linux/seccomp.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#define WUFFS_EXAMPLE_USE_SECCOMP
|
||||
#endif
|
||||
|
||||
#ifndef DST_BUFFER_ARRAY_SIZE
|
||||
#define DST_BUFFER_ARRAY_SIZE (128 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef SRC_BUFFER_ARRAY_SIZE
|
||||
#define SRC_BUFFER_ARRAY_SIZE (128 * 1024)
|
||||
#endif
|
||||
|
||||
#define WORK_BUFFER_ARRAY_SIZE \
|
||||
WUFFS_GZIP__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
|
||||
|
||||
uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE];
|
||||
uint8_t g_src_buffer_array[SRC_BUFFER_ARRAY_SIZE];
|
||||
#if WORK_BUFFER_ARRAY_SIZE > 0
|
||||
uint8_t g_work_buffer_array[WORK_BUFFER_ARRAY_SIZE];
|
||||
#else
|
||||
// Not all C/C++ compilers support 0-length arrays.
|
||||
uint8_t g_work_buffer_array[1];
|
||||
#endif
|
||||
|
||||
// ----
|
||||
|
||||
static bool g_sandboxed = false;
|
||||
|
||||
struct {
|
||||
int remaining_argc;
|
||||
char** remaining_argv;
|
||||
|
||||
bool fail_if_unsandboxed;
|
||||
} g_flags = {0};
|
||||
|
||||
const char* //
|
||||
parse_flags(int argc, char** argv) {
|
||||
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
|
||||
for (; c < argc; c++) {
|
||||
char* arg = argv[c];
|
||||
if (*arg++ != '-') {
|
||||
break;
|
||||
}
|
||||
|
||||
// A double-dash "--foo" is equivalent to a single-dash "-foo". As special
|
||||
// cases, a bare "-" is not a flag (some programs may interpret it as
|
||||
// stdin) and a bare "--" means to stop parsing flags.
|
||||
if (*arg == '\x00') {
|
||||
break;
|
||||
} else if (*arg == '-') {
|
||||
arg++;
|
||||
if (*arg == '\x00') {
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(arg, "fail-if-unsandboxed")) {
|
||||
g_flags.fail_if_unsandboxed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
return "main: unrecognized flag argument";
|
||||
}
|
||||
|
||||
g_flags.remaining_argc = argc - c;
|
||||
g_flags.remaining_argv = argv + c;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
// ignore_return_value suppresses errors from -Wall -Werror.
|
||||
static void //
|
||||
ignore_return_value(int ignored) {}
|
||||
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
const char* z = parse_flags(argc, argv);
|
||||
if (z) {
|
||||
return z;
|
||||
} else if (g_flags.remaining_argc > 0) {
|
||||
return "main: bad argument: use \"program < input\", not \"program input\"";
|
||||
} else if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
wuffs_bzip2__decoder dec;
|
||||
wuffs_base__status status =
|
||||
wuffs_bzip2__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer dst;
|
||||
dst.data.ptr = g_dst_buffer_array;
|
||||
dst.data.len = DST_BUFFER_ARRAY_SIZE;
|
||||
dst.meta.wi = 0;
|
||||
dst.meta.ri = 0;
|
||||
dst.meta.pos = 0;
|
||||
dst.meta.closed = false;
|
||||
|
||||
wuffs_base__io_buffer src;
|
||||
src.data.ptr = g_src_buffer_array;
|
||||
src.data.len = SRC_BUFFER_ARRAY_SIZE;
|
||||
src.meta.wi = 0;
|
||||
src.meta.ri = 0;
|
||||
src.meta.pos = 0;
|
||||
src.meta.closed = false;
|
||||
|
||||
while (true) {
|
||||
const int stdin_fd = 0;
|
||||
ssize_t n =
|
||||
read(stdin_fd, src.data.ptr + src.meta.wi, src.data.len - src.meta.wi);
|
||||
if (n < 0) {
|
||||
if (errno != EINTR) {
|
||||
return strerror(errno);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
src.meta.wi += n;
|
||||
if (n == 0) {
|
||||
src.meta.closed = true;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
status = wuffs_bzip2__decoder__transform_io(
|
||||
&dec, &dst, &src,
|
||||
wuffs_base__make_slice_u8(g_work_buffer_array,
|
||||
WORK_BUFFER_ARRAY_SIZE));
|
||||
|
||||
if (dst.meta.wi) {
|
||||
// TODO: handle EINTR and other write errors; see "man 2 write".
|
||||
const int stdout_fd = 1;
|
||||
ignore_return_value(write(stdout_fd, g_dst_buffer_array, dst.meta.wi));
|
||||
dst.meta.ri = dst.meta.wi;
|
||||
wuffs_base__io_buffer__compact(&dst);
|
||||
}
|
||||
|
||||
if (status.repr == wuffs_base__suspension__short_read) {
|
||||
break;
|
||||
}
|
||||
if (status.repr == wuffs_base__suspension__short_write) {
|
||||
continue;
|
||||
}
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer__compact(&src);
|
||||
if (src.meta.wi == src.data.len) {
|
||||
return "main: internal error: no I/O progress possible";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int //
|
||||
compute_exit_code(const char* status_msg) {
|
||||
if (!status_msg) {
|
||||
return 0;
|
||||
}
|
||||
size_t n = strnlen(status_msg, 2047);
|
||||
if (n >= 2047) {
|
||||
status_msg = "main: internal error: error message is too long";
|
||||
n = strnlen(status_msg, 2047);
|
||||
}
|
||||
const int stderr_fd = 2;
|
||||
ignore_return_value(write(stderr_fd, status_msg, n));
|
||||
ignore_return_value(write(stderr_fd, "\n", 1));
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
// run-time checks found that an internal invariant did not hold.
|
||||
//
|
||||
// Automated testing, including badly formatted inputs, can therefore
|
||||
// discriminate between expected failure (exit code 1) and unexpected failure
|
||||
// (other non-zero exit codes). Specifically, exit code 2 for internal
|
||||
// invariant violation, exit code 139 (which is 128 + SIGSEGV on x86_64
|
||||
// linux) for a segmentation fault (e.g. null pointer dereference).
|
||||
return strstr(status_msg, "internal error:") ? 2 : 1;
|
||||
}
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
|
||||
prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT);
|
||||
g_sandboxed = true;
|
||||
#endif
|
||||
|
||||
int exit_code = compute_exit_code(main1(argc, argv));
|
||||
|
||||
#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
|
||||
// Call SYS_exit explicitly, instead of calling SYS_exit_group implicitly by
|
||||
// either calling _exit or returning from main. SECCOMP_MODE_STRICT allows
|
||||
// only SYS_exit.
|
||||
syscall(SYS_exit, exit_code);
|
||||
#endif
|
||||
return exit_code;
|
||||
}
|
||||
@@ -66,6 +66,7 @@ https://skia-review.googlesource.com/c/skia/+/290618
|
||||
#define WUFFS_CONFIG__MODULE__LZW
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
@@ -138,6 +139,7 @@ union {
|
||||
wuffs_gif__decoder gif;
|
||||
wuffs_nie__decoder nie;
|
||||
wuffs_png__decoder png;
|
||||
wuffs_tga__decoder tga;
|
||||
wuffs_wbmp__decoder wbmp;
|
||||
} g_potential_decoders;
|
||||
|
||||
@@ -246,7 +248,7 @@ load_image_type() {
|
||||
g_fourcc = 0;
|
||||
while (true) {
|
||||
g_fourcc = wuffs_base__magic_number_guess_fourcc(
|
||||
wuffs_base__io_buffer__reader_slice(&g_src));
|
||||
wuffs_base__io_buffer__reader_slice(&g_src), g_src.meta.closed);
|
||||
if ((g_fourcc >= 0) ||
|
||||
(wuffs_base__io_buffer__reader_length(&g_src) == g_src.data.len)) {
|
||||
break;
|
||||
@@ -300,6 +302,16 @@ initialize_image_decoder() {
|
||||
&g_potential_decoders.png);
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
status = wuffs_tga__decoder__initialize(
|
||||
&g_potential_decoders.tga, sizeof g_potential_decoders.tga,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
TRY(wuffs_base__status__message(&status));
|
||||
g_image_decoder =
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
&g_potential_decoders.tga);
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
status = wuffs_wbmp__decoder__initialize(
|
||||
&g_potential_decoders.wbmp, sizeof g_potential_decoders.wbmp,
|
||||
@@ -646,7 +658,9 @@ convert_frames() {
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
if (g_flags.remaining_argc > 0) {
|
||||
return "main: bad argument: use \"program < input\", not \"program input\"";
|
||||
} else if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ wuffs_base__slice_u8 g_workbuf = {0};
|
||||
wuffs_base__slice_u8 g_printbuf = {0};
|
||||
|
||||
bool g_first_play = true;
|
||||
bool g_still_image = false;
|
||||
uint32_t g_num_loops_remaining = 0;
|
||||
wuffs_base__image_config g_ic = {0};
|
||||
wuffs_base__pixel_buffer g_pb = {0};
|
||||
@@ -494,6 +495,7 @@ play() {
|
||||
|
||||
if (g_first_play) {
|
||||
g_first_play = false;
|
||||
g_still_image = wuffs_gif__decoder__num_decoded_frame_configs(&dec) <= 1;
|
||||
g_num_loops_remaining = wuffs_gif__decoder__num_animation_loops(&dec);
|
||||
}
|
||||
|
||||
@@ -509,7 +511,9 @@ main1(int argc, char** argv) {
|
||||
TRY(read_stdin());
|
||||
while (true) {
|
||||
TRY(play());
|
||||
if (g_num_loops_remaining == 0) {
|
||||
if (g_still_image) {
|
||||
break;
|
||||
} else if (g_num_loops_remaining == 0) {
|
||||
continue;
|
||||
}
|
||||
g_num_loops_remaining--;
|
||||
|
||||
@@ -35,6 +35,8 @@ matters if the image has fully or partially transparent pixels.
|
||||
The '1' to '8' keys change the magnification zoom (or minification zoom with
|
||||
the shift key). The '0' key toggles nearest neighbor and bilinear filtering.
|
||||
|
||||
The arrow keys (or hjkl keys) scroll the image. The '`' key resets.
|
||||
|
||||
The Escape key quits.
|
||||
*/
|
||||
|
||||
@@ -80,6 +82,7 @@ The Escape key quits.
|
||||
#define WUFFS_CONFIG__MODULE__LZW
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
@@ -107,6 +110,8 @@ wuffs_aux::MemOwner g_pixbuf_mem_owner(nullptr, &free);
|
||||
wuffs_base__pixel_buffer g_pixbuf = {0};
|
||||
uint32_t g_background_color_index = 0;
|
||||
int32_t g_zoom = 0;
|
||||
int32_t g_pos_x = 0;
|
||||
int32_t g_pos_y = 0;
|
||||
bool g_filter = false;
|
||||
|
||||
struct {
|
||||
@@ -307,6 +312,10 @@ load_image(const char* filename) {
|
||||
#define XK_BackSpace 0xFF08
|
||||
#define XK_Escape 0xFF1B
|
||||
#define XK_Return 0xFF0D
|
||||
#define XK_Left 0xFF51
|
||||
#define XK_Up 0xFF52
|
||||
#define XK_Right 0xFF53
|
||||
#define XK_Down 0xFF54
|
||||
|
||||
uint32_t g_maximum_request_length = 0; // Measured in 4-byte units.
|
||||
xcb_atom_t g_atom_net_wm_name = XCB_NONE;
|
||||
@@ -334,7 +343,10 @@ make_window(xcb_connection_t* c, xcb_screen_t* s) {
|
||||
uint32_t value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||
uint32_t value_list[2];
|
||||
value_list[0] = s->black_pixel;
|
||||
value_list[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
|
||||
value_list[1] = XCB_EVENT_MASK_KEY_PRESS | //
|
||||
XCB_EVENT_MASK_BUTTON_PRESS | //
|
||||
XCB_EVENT_MASK_BUTTON_1_MOTION | //
|
||||
XCB_EVENT_MASK_EXPOSURE;
|
||||
xcb_create_window(c, 0, w, s->root, 0, 0, 1024, 768, 0,
|
||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, s->root_visual, value_mask,
|
||||
value_list);
|
||||
@@ -406,6 +418,16 @@ zoom_shift(uint32_t a) {
|
||||
return (b < M) ? b : M;
|
||||
}
|
||||
|
||||
int32_t //
|
||||
calculate_delta(uint16_t state) {
|
||||
if (state & XCB_MOD_MASK_SHIFT) {
|
||||
return 256;
|
||||
} else if (state & XCB_MOD_MASK_CONTROL) {
|
||||
return 1;
|
||||
}
|
||||
return 16;
|
||||
}
|
||||
|
||||
bool //
|
||||
load(xcb_connection_t* c, xcb_window_t w, const char* filename) {
|
||||
if (g_pixmap != XCB_NONE) {
|
||||
@@ -468,6 +490,75 @@ load(xcb_connection_t* c, xcb_window_t w, const char* filename) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool //
|
||||
intersects(int32_t old_x,
|
||||
int32_t old_y,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
int32_t new_x,
|
||||
int32_t new_y) {
|
||||
if ((width <= 0) || (height <= 0)) {
|
||||
return false;
|
||||
} else if ((old_x > new_x) && ((old_x - new_x) >= width)) {
|
||||
return false;
|
||||
} else if ((new_x > old_x) && ((new_x - old_x) >= width)) {
|
||||
return false;
|
||||
} else if ((old_y > new_y) && ((old_y - new_y) >= height)) {
|
||||
return false;
|
||||
} else if ((new_y > old_y) && ((new_y - old_y) >= height)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// clear_area clears the L-shaped difference between old and new rectangles (of
|
||||
// equal width and height). It does this in up to two xcb_clear_area calls,
|
||||
// labeled A and B in the example below (with old_x=0, old_y=0, width=5,
|
||||
// height=4, new_x=2, new_y=2).
|
||||
//
|
||||
// If the old and new rectangles do not intersect then the old rectangle (not
|
||||
// an L-shape) will be cleared.
|
||||
//
|
||||
// AAAAA
|
||||
// AAAAA
|
||||
// BB+---+
|
||||
// BB| |
|
||||
// | |
|
||||
// +---+
|
||||
void //
|
||||
clear_area(xcb_connection_t* c,
|
||||
xcb_window_t w,
|
||||
int32_t old_x,
|
||||
int32_t old_y,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
int32_t new_x,
|
||||
int32_t new_y) {
|
||||
if ((width <= 0) || (height <= 0)) {
|
||||
return;
|
||||
} else if (!intersects(old_x, old_y, width, height, new_x, new_y)) {
|
||||
xcb_clear_area(c, 1, w, old_x, old_y, width, height);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t dy = new_y - old_y;
|
||||
if (dy < 0) {
|
||||
xcb_clear_area(c, 1, w, old_x, old_y + height + dy, width, -dy);
|
||||
} else if (dy > 0) {
|
||||
xcb_clear_area(c, 1, w, old_x, old_y, width, dy);
|
||||
}
|
||||
|
||||
int32_t y0 = wuffs_base__i32__max(old_y, new_y);
|
||||
int32_t y1 = wuffs_base__i32__min(old_y + height, new_y + height);
|
||||
|
||||
int32_t dx = new_x - old_x;
|
||||
if (dx < 0) {
|
||||
xcb_clear_area(c, 1, w, old_x + width + dx, y0, -dx, y1 - y0);
|
||||
} else if (dx > 0) {
|
||||
xcb_clear_area(c, 1, w, old_x, y0, dx, y1 - y0);
|
||||
}
|
||||
}
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
const char* status = parse_flags(argc, argv);
|
||||
@@ -531,6 +622,9 @@ main(int argc, char** argv) {
|
||||
g_pixmap_gc = xcb_generate_id(c);
|
||||
g_pixmap_picture = xcb_generate_id(c);
|
||||
|
||||
int32_t button_x = 0;
|
||||
int32_t button_y = 0;
|
||||
|
||||
bool loaded = load(
|
||||
c, w, (g_flags.remaining_argc > 0) ? g_flags.remaining_argv[0] : NULL);
|
||||
int arg = 0;
|
||||
@@ -543,12 +637,14 @@ main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
bool reload = false;
|
||||
int32_t old_pos_x = g_pos_x;
|
||||
int32_t old_pos_y = g_pos_y;
|
||||
switch (event->response_type & 0x7F) {
|
||||
case XCB_EXPOSE: {
|
||||
xcb_expose_event_t* e = (xcb_expose_event_t*)event;
|
||||
if (loaded && (e->count == 0)) {
|
||||
xcb_render_composite(c, XCB_RENDER_PICT_OP_SRC, g_pixmap_picture,
|
||||
XCB_NONE, p, 0, 0, 0, 0, 0, 0,
|
||||
XCB_NONE, p, 0, 0, 0, 0, g_pos_x, g_pos_y,
|
||||
zoom_shift(g_width), zoom_shift(g_height));
|
||||
xcb_flush(c);
|
||||
}
|
||||
@@ -588,6 +684,31 @@ main(int argc, char** argv) {
|
||||
reload = true;
|
||||
break;
|
||||
|
||||
case '`':
|
||||
g_pos_x = 0;
|
||||
g_pos_y = 0;
|
||||
break;
|
||||
|
||||
case XK_Left:
|
||||
case 'h':
|
||||
g_pos_x += calculate_delta(e->state);
|
||||
break;
|
||||
|
||||
case XK_Down:
|
||||
case 'j':
|
||||
g_pos_y -= calculate_delta(e->state);
|
||||
break;
|
||||
|
||||
case XK_Up:
|
||||
case 'k':
|
||||
g_pos_y += calculate_delta(e->state);
|
||||
break;
|
||||
|
||||
case XK_Right:
|
||||
case 'l':
|
||||
g_pos_x -= calculate_delta(e->state);
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
@@ -618,6 +739,38 @@ main(int argc, char** argv) {
|
||||
break;
|
||||
}
|
||||
|
||||
case XCB_BUTTON_PRESS: {
|
||||
xcb_button_press_event_t* e = (xcb_button_press_event_t*)event;
|
||||
switch (e->detail) {
|
||||
case 1:
|
||||
button_x = e->event_x;
|
||||
button_y = e->event_y;
|
||||
break;
|
||||
case 4:
|
||||
g_pos_y += calculate_delta(e->state);
|
||||
break;
|
||||
case 5:
|
||||
g_pos_y -= calculate_delta(e->state);
|
||||
break;
|
||||
case 6:
|
||||
g_pos_x += calculate_delta(e->state);
|
||||
break;
|
||||
case 7:
|
||||
g_pos_x -= calculate_delta(e->state);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case XCB_MOTION_NOTIFY: {
|
||||
xcb_motion_notify_event_t* e = (xcb_motion_notify_event_t*)event;
|
||||
g_pos_x += e->event_x - button_x;
|
||||
g_pos_y += e->event_y - button_y;
|
||||
button_x = e->event_x;
|
||||
button_y = e->event_y;
|
||||
break;
|
||||
}
|
||||
|
||||
case XCB_CLIENT_MESSAGE: {
|
||||
xcb_client_message_event_t* e = (xcb_client_message_event_t*)event;
|
||||
if (e->data.data32[0] == g_atom_wm_delete_window) {
|
||||
@@ -633,6 +786,14 @@ main(int argc, char** argv) {
|
||||
loaded = load(c, w, g_flags.remaining_argv[arg]);
|
||||
xcb_clear_area(c, 1, w, 0, 0, 0xFFFF, 0xFFFF);
|
||||
xcb_flush(c);
|
||||
} else if (loaded && //
|
||||
((old_pos_x != g_pos_x) || (old_pos_y != g_pos_y))) {
|
||||
clear_area(c, w, old_pos_x, old_pos_y, zoom_shift(g_width),
|
||||
zoom_shift(g_height), g_pos_x, g_pos_y);
|
||||
xcb_render_composite(c, XCB_RENDER_PICT_OP_SRC, g_pixmap_picture,
|
||||
XCB_NONE, p, 0, 0, 0, 0, g_pos_x, g_pos_y,
|
||||
zoom_shift(g_width), zoom_shift(g_height));
|
||||
xcb_flush(c);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -51,10 +51,11 @@ uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE];
|
||||
|
||||
// src_ptr and src_len hold a gzip-encoded "Hello Wuffs."
|
||||
//
|
||||
// $ echo "Hello Wuffs." | gzip --no-name | xxd
|
||||
// 00000000: 1f8b 0800 0000 0000 0003 f348 cdc9 c957 ...........H...W
|
||||
// 00000010: 082f 4d4b 2bd6 e302 003c 8475 bb0d 0000 ./MK+....<.u....
|
||||
// 00000020: 00 .
|
||||
// $ echo "Hello Wuffs." | gzip --no-name | hd
|
||||
// 00000000 1f 8b 08 00 00 00 00 00 00 03 f3 48 cd c9 c9 57 |...........H...W|
|
||||
// 00000010 08 2f 4d 4b 2b d6 e3 02 00 3c 84 75 bb 0d 00 00 |./MK+....<.u....|
|
||||
// 00000020 00 |.|
|
||||
// 00000021
|
||||
//
|
||||
// Passing --no-name to the gzip command line also means to skip the timestamp,
|
||||
// which means that its output is deterministic.
|
||||
|
||||
@@ -148,8 +148,9 @@ main1(int argc, char** argv) {
|
||||
const char* z = parse_flags(argc, argv);
|
||||
if (z) {
|
||||
return z;
|
||||
}
|
||||
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
} else if (g_flags.remaining_argc > 0) {
|
||||
return "main: bad argument: use \"program < input\", not \"program input\"";
|
||||
} else if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,19 @@ jenkins_hash_u32(const uint8_t* data, size_t size) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
// memrandomize is like memcpy or memset but it writes pseudo-random values.
|
||||
static void* //
|
||||
memrandomize(void* dest, uint64_t seed, size_t n) {
|
||||
unsigned short xsubi[3]; // See "man 3 nrand48".
|
||||
xsubi[0] = (seed >> 0) ^ (seed >> 48);
|
||||
xsubi[1] = (seed >> 16);
|
||||
xsubi[2] = (seed >> 32);
|
||||
for (uint8_t* ptr = (uint8_t*)dest; n--;) {
|
||||
*ptr++ = nrand48(xsubi);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
const char* //
|
||||
fuzz(wuffs_base__io_buffer* src, uint64_t hash);
|
||||
|
||||
@@ -55,18 +68,8 @@ llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
|
||||
uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
|
||||
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = ((wuffs_base__slice_u8){
|
||||
.ptr = (uint8_t*)(data),
|
||||
.len = size,
|
||||
}),
|
||||
.meta = ((wuffs_base__io_buffer_meta){
|
||||
.wi = size,
|
||||
.ri = 0,
|
||||
.pos = 0,
|
||||
.closed = true,
|
||||
}),
|
||||
});
|
||||
wuffs_base__io_buffer src =
|
||||
wuffs_base__ptr_u8__reader((uint8_t*)data, size, true);
|
||||
|
||||
const char* msg = fuzz(&src, hash);
|
||||
if (msg) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Wuffs' Fuzzer Programs
|
||||
|
||||
This directory contains multiple programs to fuzz Wuffs' implementations of
|
||||
various codecs. For example, `gif_fuzzer.c` is a program to fuzz Wuffs' GIF
|
||||
implementation.
|
||||
@@ -11,3 +13,17 @@ When working on these files, it is possible to run them directly on an explicit
|
||||
test suite, in order to speed up the edit-compile-run cycle. Look for
|
||||
`WUFFS_CONFIG__FUZZLIB_MAIN` for more details, and in `seed_corpora.txt` for
|
||||
suggested test data.
|
||||
|
||||
|
||||
## Building
|
||||
|
||||
Running `build-fuzz.sh` from the top level directory will build all of the
|
||||
fuzzers. To check out and build just one, such as `json_fuzzer`:
|
||||
|
||||
git clone https://github.com/google/wuffs.git
|
||||
cd wuffs
|
||||
./build-fuzz.sh fuzz/c/std/json_fuzzer.cc
|
||||
|
||||
When re-building, you only need the last of those three lines. To run it:
|
||||
|
||||
gen/bin/fuzz-json test/data/json-things.*
|
||||
@@ -0,0 +1,121 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
// Silence the nested slash-star warning for the next comment's command line.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcomment"
|
||||
|
||||
/*
|
||||
This fuzzer (the fuzz function) is typically run indirectly, by a framework
|
||||
such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput.
|
||||
|
||||
When working on the fuzz implementation, or as a coherence check, defining
|
||||
WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files:
|
||||
|
||||
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN bzip2_fuzzer.c
|
||||
./a.out ../../../test/data/*.bzip2
|
||||
rm -f ./a.out
|
||||
|
||||
It should print "PASS", amongst other information, and exit(0).
|
||||
*/
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||
// functions have static storage.
|
||||
//
|
||||
// This can help the compiler ignore or discard unused code, which can produce
|
||||
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__BZIP2
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
|
||||
#define DST_BUFFER_ARRAY_SIZE 65536
|
||||
|
||||
// Wuffs allows either statically or dynamically allocated work buffers. This
|
||||
// program exercises static allocation.
|
||||
#define WORK_BUFFER_ARRAY_SIZE \
|
||||
WUFFS_BZIP2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
|
||||
#if WORK_BUFFER_ARRAY_SIZE > 0
|
||||
uint8_t g_work_buffer_array[WORK_BUFFER_ARRAY_SIZE];
|
||||
#else
|
||||
// Not all C/C++ compilers support 0-length arrays.
|
||||
uint8_t g_work_buffer_array[1];
|
||||
#endif
|
||||
|
||||
const char* //
|
||||
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_bzip2__decoder dec;
|
||||
wuffs_base__status status = wuffs_bzip2__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
// Ignore the checksum for 99.99%-ish of all input. When fuzzers generate
|
||||
// random input, the checkum is very unlikely to match. Still, it's useful to
|
||||
// verify that checksumming does not lead to e.g. buffer overflows.
|
||||
wuffs_bzip2__decoder__set_quirk_enabled(
|
||||
&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, hash & 0xFFFE);
|
||||
|
||||
uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__io_buffer dst =
|
||||
wuffs_base__ptr_u8__writer(&dst_buffer[0], DST_BUFFER_ARRAY_SIZE);
|
||||
|
||||
while (true) {
|
||||
dst.meta.wi = 0;
|
||||
status = wuffs_bzip2__decoder__transform_io(
|
||||
&dec, &dst, src,
|
||||
wuffs_base__make_slice_u8(g_work_buffer_array, WORK_BUFFER_ARRAY_SIZE));
|
||||
if (status.repr != wuffs_base__suspension__short_write) {
|
||||
break;
|
||||
}
|
||||
if (dst.meta.wi == 0) {
|
||||
fprintf(stderr, "wuffs_bzip2__decoder__transform_io made no progress\n");
|
||||
intentional_segfault();
|
||||
}
|
||||
}
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
@@ -15,11 +15,13 @@
|
||||
# https://github.com/google/oss-fuzz/blob/master/projects/wuffs/Dockerfile
|
||||
|
||||
bmp: test/data/*.bmp ../bmpsuite_corpus/*.bmp
|
||||
bzip2: test/data/*.bz2
|
||||
cbor: test/data/*.cbor
|
||||
gif: test/data/*.gif test/data/artificial-gif/*.gif
|
||||
gzip: test/data/*.gz
|
||||
json: test/data/*.json ../rapidjson_corpus/* ../simdjson_corpus/* ../JSONTestSuite/test_*/*.json
|
||||
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
|
||||
tga: test/data/*.tga
|
||||
wbmp: test/data/*.wbmp
|
||||
zlib: test/data/*.zlib
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// Copyright 2020 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
// Silence the nested slash-star warning for the next comment's command line.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcomment"
|
||||
|
||||
/*
|
||||
This fuzzer (the fuzz function) is typically run indirectly, by a framework
|
||||
such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput.
|
||||
|
||||
When working on the fuzz implementation, or as a coherence check, defining
|
||||
WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files:
|
||||
|
||||
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN tga_fuzzer.c
|
||||
./a.out ../../../test/data/*.tga
|
||||
rm -f ./a.out
|
||||
|
||||
It should print "PASS", amongst other information, and exit(0).
|
||||
*/
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||
// functions have static storage.
|
||||
//
|
||||
// This can help the compiler ignore or discard unused code, which can produce
|
||||
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
#include "../fuzzlib/fuzzlib_image_decoder.c"
|
||||
|
||||
const char* //
|
||||
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_tga__decoder dec;
|
||||
wuffs_base__status status = wuffs_tga__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
return fuzz_image_decoder(
|
||||
src, hash,
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec));
|
||||
}
|
||||
@@ -103,12 +103,8 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, hash & 0xFFFE);
|
||||
|
||||
uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){
|
||||
.data = ((wuffs_base__slice_u8){
|
||||
.ptr = dst_buffer,
|
||||
.len = DST_BUFFER_ARRAY_SIZE,
|
||||
}),
|
||||
});
|
||||
wuffs_base__io_buffer dst =
|
||||
wuffs_base__ptr_u8__writer(&dst_buffer[0], DST_BUFFER_ARRAY_SIZE);
|
||||
|
||||
while (true) {
|
||||
dst.meta.wi = 0;
|
||||
|
||||
@@ -58,7 +58,8 @@ DecodeImageCallbacks::AllocWorkbufResult::AllocWorkbufResult(
|
||||
|
||||
wuffs_base__image_decoder::unique_ptr //
|
||||
DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
switch (fourcc) {
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
@@ -84,6 +85,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
@@ -304,6 +310,7 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
|
||||
wuffs_base__image_config image_config = wuffs_base__null_image_config();
|
||||
sync_io::DynIOBuffer raw_metadata_buf(max_incl_metadata_length);
|
||||
uint64_t start_pos = io_buf.reader_position();
|
||||
bool interested_in_metadata_after_the_frame = false;
|
||||
bool redirected = false;
|
||||
int32_t fourcc = 0;
|
||||
redirect:
|
||||
@@ -311,10 +318,17 @@ redirect:
|
||||
// Determine the image format.
|
||||
if (!redirected) {
|
||||
while (true) {
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice());
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice(),
|
||||
io_buf.meta.closed);
|
||||
if (fourcc > 0) {
|
||||
break;
|
||||
} else if ((fourcc == 0) && (io_buf.reader_length() >= 64)) {
|
||||
// Having (fourcc == 0) means that Wuffs' built in MIME sniffer
|
||||
// didn't recognize the image format. Nonetheless, custom callbacks
|
||||
// may still be able to do their own MIME sniffing, for exotic image
|
||||
// types. We try to give them at least 64 bytes of prefix data when
|
||||
// one-shot-calling callbacks.SelectDecoder. There is no mechanism
|
||||
// for the callbacks to request a longer prefix.
|
||||
break;
|
||||
} else if (io_buf.meta.closed || (io_buf.writer_length() == 0)) {
|
||||
fourcc = 0;
|
||||
@@ -355,8 +369,7 @@ redirect:
|
||||
|
||||
// Select the image decoder.
|
||||
image_decoder = callbacks.SelectDecoder(
|
||||
(uint32_t)fourcc,
|
||||
fourcc ? wuffs_base__empty_slice_u8() : io_buf.reader_slice());
|
||||
(uint32_t)fourcc, io_buf.reader_slice(), io_buf.meta.closed);
|
||||
if (!image_decoder) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
@@ -372,6 +385,7 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
@@ -381,12 +395,14 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_XMP) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__XMP, true);
|
||||
}
|
||||
}
|
||||
@@ -421,7 +437,9 @@ redirect:
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
raw_metadata_buf.drop();
|
||||
if (!interested_in_metadata_after_the_frame) {
|
||||
raw_metadata_buf.drop();
|
||||
}
|
||||
|
||||
// Select the pixel format.
|
||||
uint32_t w = image_config.pixcfg.width();
|
||||
@@ -482,6 +500,12 @@ redirect:
|
||||
image_decoder->decode_frame_config(&frame_config, &io_buf);
|
||||
if (id_dfc_status.repr == nullptr) {
|
||||
break;
|
||||
} else if (id_dfc_status.repr == wuffs_base__note__metadata_reported) {
|
||||
std::string error_message = DecodeImageHandleMetadata(
|
||||
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
} else if (id_dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return DecodeImageResult(id_dfc_status.message());
|
||||
} else if (io_buf.meta.closed) {
|
||||
@@ -523,6 +547,35 @@ redirect:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decode any metadata after the frame.
|
||||
if (interested_in_metadata_after_the_frame) {
|
||||
while (true) {
|
||||
wuffs_base__status id_dfc_status =
|
||||
image_decoder->decode_frame_config(NULL, &io_buf);
|
||||
if (id_dfc_status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else if (id_dfc_status.repr == nullptr) {
|
||||
continue;
|
||||
} else if (id_dfc_status.repr == wuffs_base__note__metadata_reported) {
|
||||
std::string error_message = DecodeImageHandleMetadata(
|
||||
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
} else if (id_dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return DecodeImageResult(id_dfc_status.message());
|
||||
} else if (io_buf.meta.closed) {
|
||||
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
|
||||
} else {
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DecodeImageResult(std::move(alloc_pixbuf_result.mem_owner),
|
||||
pixel_buffer, std::move(message));
|
||||
}
|
||||
|
||||
@@ -70,9 +70,13 @@ class DecodeImageCallbacks {
|
||||
// Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).
|
||||
//
|
||||
// Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the
|
||||
// caller is responsible for examining the opening bytes (a prefix) of the
|
||||
// input data. SelectDecoder implementations should not modify those bytes.
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that Wuffs'
|
||||
// standard library did not recognize the image format but if SelectDecoder
|
||||
// was overridden, it may examine the input data's starting bytes and still
|
||||
// provide its own image decoder, e.g. for an exotic image file format that's
|
||||
// not in Wuffs' standard library. The prefix_etc fields have the same
|
||||
// meaning as wuffs_base__magic_number_guess_fourcc arguments. SelectDecoder
|
||||
// implementations should not modify prefix_data's contents.
|
||||
//
|
||||
// SelectDecoder might be called more than once, since some image file
|
||||
// formats can wrap others. For example, a nominal BMP file can actually
|
||||
@@ -87,9 +91,12 @@ class DecodeImageCallbacks {
|
||||
// - WUFFS_BASE__FOURCC__GIF
|
||||
// - WUFFS_BASE__FOURCC__NIE
|
||||
// - WUFFS_BASE__FOURCC__PNG
|
||||
// - WUFFS_BASE__FOURCC__TGA
|
||||
// - WUFFS_BASE__FOURCC__WBMP
|
||||
virtual wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
|
||||
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
|
||||
@@ -797,6 +797,22 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
|
||||
|
||||
// --------
|
||||
|
||||
// Normally, the wuffs_base__peek_etc and wuffs_base__poke_etc implementations
|
||||
// are both (1) correct regardless of CPU endianness and (2) very fast (e.g. an
|
||||
// inlined wuffs_base__peek_u32le__no_bounds_check call, in an optimized clang
|
||||
// or gcc build, is a single MOV instruction on x86_64).
|
||||
//
|
||||
// However, the endian-agnostic implementations are slow on Microsoft's C
|
||||
// compiler (MSC). Alternative memcpy-based implementations restore speed, but
|
||||
// they are only correct on little-endian CPU architectures. Defining
|
||||
// WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE opts in to these implementations.
|
||||
//
|
||||
// https://godbolt.org/z/q4MfjzTPh
|
||||
#if defined(_MSC_VER) && !defined(__clang__) && \
|
||||
(defined(_M_ARM64) || defined(_M_X64))
|
||||
#define WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE
|
||||
#endif
|
||||
|
||||
#define wuffs_base__peek_u8be__no_bounds_check \
|
||||
wuffs_base__peek_u8__no_bounds_check
|
||||
#define wuffs_base__peek_u8le__no_bounds_check \
|
||||
@@ -809,12 +825,24 @@ wuffs_base__peek_u8__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__peek_u16be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint16_t x;
|
||||
memcpy(&x, p, 2);
|
||||
return _byteswap_ushort(x);
|
||||
#else
|
||||
return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__peek_u16le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint16_t x;
|
||||
memcpy(&x, p, 2);
|
||||
return x;
|
||||
#else
|
||||
return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
@@ -831,14 +859,26 @@ wuffs_base__peek_u24le__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__peek_u32be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint32_t x;
|
||||
memcpy(&x, p, 4);
|
||||
return _byteswap_ulong(x);
|
||||
#else
|
||||
return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |
|
||||
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__peek_u32le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint32_t x;
|
||||
memcpy(&x, p, 4);
|
||||
return x;
|
||||
#else
|
||||
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
|
||||
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
@@ -887,18 +927,30 @@ wuffs_base__peek_u56le__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__peek_u64be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint64_t x;
|
||||
memcpy(&x, p, 8);
|
||||
return _byteswap_uint64(x);
|
||||
#else
|
||||
return ((uint64_t)(p[0]) << 56) | ((uint64_t)(p[1]) << 48) |
|
||||
((uint64_t)(p[2]) << 40) | ((uint64_t)(p[3]) << 32) |
|
||||
((uint64_t)(p[4]) << 24) | ((uint64_t)(p[5]) << 16) |
|
||||
((uint64_t)(p[6]) << 8) | ((uint64_t)(p[7]) << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__peek_u64le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint64_t x;
|
||||
memcpy(&x, p, 8);
|
||||
return x;
|
||||
#else
|
||||
return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |
|
||||
((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |
|
||||
((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |
|
||||
((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------
|
||||
@@ -921,7 +973,8 @@ wuffs_base__poke_u16be__no_bounds_check(uint8_t* p, uint16_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u16le__no_bounds_check(uint8_t* p, uint16_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 2);
|
||||
@@ -955,7 +1008,8 @@ wuffs_base__poke_u32be__no_bounds_check(uint8_t* p, uint32_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u32le__no_bounds_check(uint8_t* p, uint32_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 4);
|
||||
@@ -1041,7 +1095,8 @@ wuffs_base__poke_u64be__no_bounds_check(uint8_t* p, uint64_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u64le__no_bounds_check(uint8_t* p, uint64_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 8);
|
||||
@@ -1192,6 +1247,38 @@ wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u8 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u16 //
|
||||
wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u16 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u32 //
|
||||
wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u32 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u64 //
|
||||
wuffs_base__make_slice_u64_ij(uint64_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u64 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__empty_slice_u8() {
|
||||
wuffs_base__slice_u8 ret;
|
||||
@@ -1418,13 +1505,19 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// wuffs_base__magic_number_guess_fourcc guesses the file format of some data,
|
||||
// given its opening bytes. It returns a positive FourCC value on success.
|
||||
// given its starting bytes (the prefix_data argument) and whether or not there
|
||||
// may be further bytes (the prefix_closed argument; true means that
|
||||
// prefix_data is the entire data).
|
||||
//
|
||||
// It returns a positive FourCC value on success.
|
||||
//
|
||||
// It returns zero if nothing matches its hard-coded list of 'magic numbers'.
|
||||
//
|
||||
// It returns a negative value if a longer prefix is required for a conclusive
|
||||
// result. For example, seeing a single 'B' byte is not enough to discriminate
|
||||
// the BMP and BPG image file formats.
|
||||
// It returns a negative value if prefix_closed is false and a longer prefix is
|
||||
// required for a conclusive result. For example, a single 'B' byte (without
|
||||
// further data) is not enough to discriminate the BMP and BPG image file
|
||||
// formats. Similarly, a single '\xFF' byte might be the start of JPEG data or
|
||||
// it might be the start of some other binary data.
|
||||
//
|
||||
// It does not do a full validity check. Like any guess made from a short
|
||||
// prefix of the data, it may return false positives. Data that starts with 99
|
||||
@@ -1439,4 +1532,5 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__MAGIC sub-module, not just
|
||||
// WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix);
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
@@ -14,14 +14,134 @@
|
||||
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// ICO doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly ICO.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// first two bytes are 0x00.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/ico/
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[3] != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01: // ICO
|
||||
case 0x02: // CUR
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The Number Of Images should be positive.
|
||||
if (prefix_data.len < 6) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[4] == 0) && (prefix_data.ptr[5] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The first ICONDIRENTRY's fourth byte should be zero.
|
||||
if (prefix_data.len < 10) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[9] != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: have a separate FourCC for CUR?
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
|
||||
// TGA doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly TGA.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// second byte (prefix_data.ptr[1], the Color Map Type byte), is either 0x00 or
|
||||
// 0x01.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/tga/
|
||||
// - https://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 3) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0x09:
|
||||
case 0x0A:
|
||||
case 0x0B:
|
||||
break;
|
||||
default:
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Color Map Entry Size field (if the Color Map Type field
|
||||
// is non-zero) or else all the Color Map fields should be zero.
|
||||
if (prefix_data.len < 8) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[1] != 0x00) {
|
||||
switch (prefix_data.ptr[7]) {
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
|
||||
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Pixel Depth field.
|
||||
if (prefix_data.len < 17) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[16]) {
|
||||
case 0x01:
|
||||
case 0x08:
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0x54474120; // 'TGA 'be
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// This is similar to (but different from):
|
||||
// - the magic/Magdir tables under https://github.com/file/file
|
||||
// - the MIME Sniffing algorithm at https://mimesniff.spec.whatwg.org/
|
||||
|
||||
// table holds the 'magic numbers' (which are actually variable length
|
||||
// strings). The strings may contain NUL bytes, so the "const char* magic"
|
||||
// value starts with the length-minus-1 of the 'magic number'.
|
||||
//
|
||||
// Keep it sorted by magic[1], then magic[0] descending and finally by
|
||||
// magic[2:]. When multiple entries match, the longest one wins.
|
||||
// Keep it sorted by magic[1], then magic[0] descending (prioritizing longer
|
||||
// matches) and finally by magic[2:]. When multiple entries match, the
|
||||
// longest one wins.
|
||||
//
|
||||
// The fourcc field might be negated, in which case there's further
|
||||
// specialization (see § below).
|
||||
@@ -30,6 +150,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
const char* magic;
|
||||
} table[] = {
|
||||
{-0x30302020, "\x01\x00\x00"}, // '00 'be
|
||||
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
|
||||
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
|
||||
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
|
||||
{+0x424D5020, "\x01\x42\x4D"}, // BMP
|
||||
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
||||
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
||||
@@ -37,15 +160,16 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
|
||||
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
|
||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||
};
|
||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||
|
||||
if (prefix.len == 0) {
|
||||
return -1;
|
||||
if (prefix_data.len == 0) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint8_t pre_first_byte = prefix.ptr[0];
|
||||
uint8_t pre_first_byte = prefix_data.ptr[0];
|
||||
|
||||
int32_t fourcc = 0;
|
||||
size_t i;
|
||||
@@ -64,11 +188,11 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
|
||||
const char* mag_remaining_ptr = table[i].magic + 2;
|
||||
uint8_t* pre_remaining_ptr = prefix.ptr + 1;
|
||||
size_t pre_remaining_len = prefix.len - 1;
|
||||
uint8_t* pre_remaining_ptr = prefix_data.ptr + 1;
|
||||
size_t pre_remaining_len = prefix_data.len - 1;
|
||||
if (pre_remaining_len < mag_remaining_len) {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, pre_remaining_len)) {
|
||||
return -1;
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
} else {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, mag_remaining_len)) {
|
||||
@@ -76,6 +200,14 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix_data.len < 2) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[1] == 0x00) || (prefix_data.ptr[1] == 0x01)) {
|
||||
return wuffs_base__magic_number_guess_fourcc__maybe_tga(prefix_data,
|
||||
prefix_closed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
match:
|
||||
@@ -84,26 +216,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 12) {
|
||||
return -1;
|
||||
if (prefix_data.len < 12) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix_data.ptr + 8);
|
||||
if (x == 0x57454250) { // 'WEBP'be
|
||||
return 0x57454250; // 'WEBP'be
|
||||
}
|
||||
|
||||
} else if (fourcc == 0x30302020) { // '00 'be
|
||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||
if (prefix.len < 4) {
|
||||
return -1;
|
||||
} else if ((prefix.ptr[2] != 0x00) &&
|
||||
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
|
||||
// Unfortunately, some file formats also don't start with a magic
|
||||
// identifier, so we have to use heuristics (where the order matters, the
|
||||
// same as /usr/bin/file's magic/Magdir tables) as best we can. Maybe
|
||||
// it's TGA, ICO/CUR, etc. Maybe it's something else.
|
||||
int32_t tga = wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
prefix_data, prefix_closed);
|
||||
if (tga != 0) {
|
||||
return tga;
|
||||
}
|
||||
int32_t ico = wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
prefix_data, prefix_closed);
|
||||
if (ico != 0) {
|
||||
return ico;
|
||||
}
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[2] != 0x00) &&
|
||||
((prefix_data.ptr[2] >= 0x80) ||
|
||||
(prefix_data.ptr[3] != 0x00))) {
|
||||
// Roughly speaking, this could be a non-degenerate (non-0-width and
|
||||
// non-0-height) WBMP image.
|
||||
return 0x57424D50; // 'WBMP'be
|
||||
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
|
||||
(prefix.ptr[3] == 0x00)) {
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package cgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
@@ -153,22 +152,47 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
|
||||
|
||||
case t.IDDotDot:
|
||||
// n is a slice.
|
||||
//
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
lhs := n.LHS().AsExpr()
|
||||
mhs := n.MHS().AsExpr()
|
||||
rhs := n.RHS().AsExpr()
|
||||
|
||||
mcv := (*big.Int)(nil)
|
||||
rcv := (*big.Int)(nil)
|
||||
lhsIsArray := lhs.MType().IsArrayType()
|
||||
if lhsIsArray {
|
||||
if (mhs != nil) && (mhs.ConstValue() != nil) {
|
||||
mcv = mhs.ConstValue()
|
||||
mhs = nil
|
||||
comma := ", "
|
||||
if (mhs != nil) && (mhs.Operator() != 0) &&
|
||||
(rhs != nil) && (rhs.Operator() != 0) {
|
||||
comma = ",\n"
|
||||
}
|
||||
|
||||
if lhs.MType().IsArrayType() {
|
||||
if mhs == nil {
|
||||
b.writes("wuffs_base__make_slice_u8(")
|
||||
} else {
|
||||
b.writes("wuffs_base__make_slice_u8_ij(")
|
||||
}
|
||||
if (rhs != nil) && (rhs.ConstValue() != nil) {
|
||||
rcv = rhs.ConstValue()
|
||||
rhs = nil
|
||||
if err := g.writeExpr(b, lhs, false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
if mhs == nil {
|
||||
// No-op.
|
||||
} else {
|
||||
b.writes(comma)
|
||||
if mcv := mhs.ConstValue(); mcv != nil {
|
||||
b.writes(mcv.String())
|
||||
} else if err := g.writeExpr(b, mhs, false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
b.writes(comma)
|
||||
if rhs == nil {
|
||||
b.writes(lhs.MType().ArrayLength().ConstValue().String())
|
||||
} else if rcv := rhs.ConstValue(); rcv != nil {
|
||||
b.writes(rcv.String())
|
||||
} else if err := g.writeExpr(b, rhs, false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(")")
|
||||
return nil
|
||||
}
|
||||
|
||||
switch {
|
||||
@@ -180,40 +204,9 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
|
||||
b.writes("wuffs_base__slice_u8__subslice_ij(")
|
||||
}
|
||||
|
||||
comma := ", "
|
||||
if (mhs != nil) && (mhs.Operator() != 0) &&
|
||||
(rhs != nil) && (rhs.Operator() != 0) {
|
||||
comma = ",\n"
|
||||
}
|
||||
|
||||
if lhsIsArray {
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
b.writes("wuffs_base__make_slice_u8(")
|
||||
if mcv != nil {
|
||||
b.writeb('(')
|
||||
}
|
||||
}
|
||||
if err := g.writeExpr(b, lhs, false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
if lhsIsArray {
|
||||
if mcv != nil {
|
||||
b.writes(") + ")
|
||||
b.writes(mcv.String())
|
||||
}
|
||||
b.writes(comma)
|
||||
|
||||
length := lhs.MType().ArrayLength().ConstValue()
|
||||
if rcv != nil {
|
||||
length = rcv
|
||||
}
|
||||
if mcv != nil {
|
||||
length = big.NewInt(0).Sub(length, mcv)
|
||||
}
|
||||
b.writes(length.String())
|
||||
b.writeb(')')
|
||||
}
|
||||
|
||||
if mhs != nil {
|
||||
b.writes(comma)
|
||||
if err := g.writeExpr(b, mhs, false, depth); err != nil {
|
||||
|
||||
@@ -82,6 +82,12 @@ const (
|
||||
// livenesses is a slice of liveness values, one per local variable.
|
||||
type livenesses []liveness
|
||||
|
||||
func (r livenesses) clear() {
|
||||
for i := range r {
|
||||
r[i] = livenessNone
|
||||
}
|
||||
}
|
||||
|
||||
func (r livenesses) clone() livenesses {
|
||||
return append(livenesses(nil), r...)
|
||||
}
|
||||
@@ -133,6 +139,7 @@ type livenessHelper struct {
|
||||
tm *t.Map
|
||||
vars map[t.ID]int // Maps from local variable name to livenesses index.
|
||||
loops map[a.Loop]*loopLivenesses
|
||||
final livenesses
|
||||
}
|
||||
|
||||
func (g *gen) findVars() error {
|
||||
@@ -152,14 +159,16 @@ func (g *gen) findVars() error {
|
||||
}
|
||||
|
||||
if f.Effect().Coroutine() {
|
||||
h.final = make(livenesses, len(h.vars))
|
||||
r := make(livenesses, len(h.vars))
|
||||
if err := h.doBlock(r, f.Body(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
h.final.reconcile(r)
|
||||
|
||||
g.currFunk.varResumables = map[t.ID]bool{}
|
||||
for i, v := range g.currFunk.varList {
|
||||
g.currFunk.varResumables[v.Name()] = r[i] == livenessStrong
|
||||
g.currFunk.varResumables[v.Name()] = h.final[i] == livenessStrong
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,9 +205,7 @@ loop:
|
||||
}
|
||||
|
||||
case a.KIterate:
|
||||
if err := h.doIterate(r, o.AsIterate(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("iterate loop is inside a coroutine")
|
||||
|
||||
case a.KJump:
|
||||
if err := h.doJump(r, o.AsJump(), depth); err != nil {
|
||||
@@ -342,7 +349,7 @@ func (h *livenessHelper) doIOManip(r livenesses, n *a.IOManip, depth uint32) err
|
||||
func (h *livenessHelper) doIf(r livenesses, n *a.If, depth uint32) error {
|
||||
scratch := make(livenesses, len(r))
|
||||
result := make(livenesses, len(r))
|
||||
for ; n != nil; n = n.ElseIf() {
|
||||
for {
|
||||
if err := h.doExpr(r, n.Condition()); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -353,44 +360,33 @@ func (h *livenessHelper) doIf(r livenesses, n *a.If, depth uint32) error {
|
||||
}
|
||||
result.reconcile(scratch)
|
||||
|
||||
if ei := n.ElseIf(); ei != nil {
|
||||
n = ei
|
||||
continue
|
||||
}
|
||||
|
||||
copy(scratch, r)
|
||||
if err := h.doBlock(scratch, n.BodyIfFalse(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
result.reconcile(scratch)
|
||||
break
|
||||
}
|
||||
copy(r, result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *livenessHelper) doIterate(r livenesses, n *a.Iterate, depth uint32) error {
|
||||
// TODO: ban jumps, rets and coroutine calls inside an iterate. Also ensure
|
||||
// that the iterate variable values are all pure expressions.
|
||||
for _, o := range n.Assigns() {
|
||||
o := o.AsAssign()
|
||||
if err := h.doExpr(r, o.RHS()); err != nil {
|
||||
return err
|
||||
}
|
||||
name := o.LHS().Ident()
|
||||
if i, ok := h.vars[name]; !ok {
|
||||
return fmt.Errorf("unrecognized variable %q", name.Str(h.tm))
|
||||
} else {
|
||||
r.lowerWeakToNone(i)
|
||||
}
|
||||
}
|
||||
return h.doBlock(r, n.Body(), depth)
|
||||
}
|
||||
|
||||
func (h *livenessHelper) doJump(r livenesses, n *a.Jump, depth uint32) error {
|
||||
l := h.loops[n.JumpTarget()]
|
||||
switch n.Keyword() {
|
||||
case t.IDBreak:
|
||||
l.changed = l.before.reconcile(r) || l.changed
|
||||
case t.IDContinue:
|
||||
l.changed = l.after.reconcile(r) || l.changed
|
||||
case t.IDContinue:
|
||||
l.changed = l.before.reconcile(r) || l.changed
|
||||
default:
|
||||
return fmt.Errorf("unrecognized ast.Jump keyword")
|
||||
}
|
||||
r.clear()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -401,7 +397,8 @@ func (h *livenessHelper) doRet(r livenesses, n *a.Ret, depth uint32) error {
|
||||
|
||||
switch n.Keyword() {
|
||||
case t.IDReturn:
|
||||
// No-op.
|
||||
h.final.reconcile(r)
|
||||
r.clear()
|
||||
case t.IDYield:
|
||||
r.raiseNoneToWeak()
|
||||
default:
|
||||
@@ -429,28 +426,22 @@ func (h *livenessHelper) doWhile(r livenesses, n *a.While, depth uint32) error {
|
||||
h.loops[n] = l
|
||||
|
||||
copy(l.before, r)
|
||||
if err := h.doExpr(r, n.Condition()); err != nil {
|
||||
return err
|
||||
}
|
||||
copy(l.after, r)
|
||||
|
||||
for {
|
||||
copy(r, l.after)
|
||||
if err := h.doBlock(r, n.Body(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
l.changed = l.before.reconcile(r) || l.changed
|
||||
|
||||
for l.changed = true; l.changed; {
|
||||
l.changed = false
|
||||
copy(r, l.before)
|
||||
|
||||
if err := h.doExpr(r, n.Condition()); err != nil {
|
||||
return err
|
||||
} else if !n.IsWhileTrue() {
|
||||
l.changed = l.after.reconcile(r) || l.changed
|
||||
}
|
||||
l.changed = l.after.reconcile(r) || l.changed
|
||||
|
||||
if !l.changed {
|
||||
break
|
||||
if err := h.doBlock(r, n.Body(), depth); err != nil {
|
||||
return err
|
||||
} else {
|
||||
l.changed = l.before.reconcile(r) || l.changed
|
||||
}
|
||||
l.changed = false
|
||||
}
|
||||
|
||||
copy(r, l.after)
|
||||
|
||||
@@ -125,7 +125,7 @@ func (g *gen) writeInitialLoadDerivedVar(b *buffer, n *a.Field) error {
|
||||
b.printf("%s%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", c, elem, io1Prefix, preName)
|
||||
b.printf("%s%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", c, elem, io2Prefix, preName)
|
||||
|
||||
b.printf("if (%s) {\n", preName)
|
||||
b.printf("if (%s && %s->data.ptr) {\n", preName, preName)
|
||||
|
||||
b.printf("%s%s = %s->data.ptr;\n", io0Prefix, preName, preName)
|
||||
b.printf("%s%s = %s%s + %s->%s;\n", io1Prefix, preName, io0Prefix, preName, preName, i1)
|
||||
@@ -149,8 +149,8 @@ func (g *gen) writeFinalSaveDerivedVar(b *buffer, n *a.Field) error {
|
||||
}
|
||||
preName := aPrefix + n.Name().Str(g.tm)
|
||||
|
||||
b.printf("if (%s) {\n%s->%s = ((size_t)(%s%s - %s->data.ptr));\n}\n",
|
||||
preName, preName, i1, iopPrefix, preName, preName)
|
||||
b.printf("if (%s && %s->data.ptr) {\n%s->%s = ((size_t)(%s%s - %s->data.ptr));\n}\n",
|
||||
preName, preName, preName, i1, iopPrefix, preName, preName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -328,12 +328,12 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
const MaxExprDepth = 255
|
||||
|
||||
// Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
|
||||
// - ID2: <0|literal|ident>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|Expr|TypeExpr>
|
||||
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
|
||||
// - ID2: <0|literal|ident>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|Expr|TypeExpr>
|
||||
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
|
||||
//
|
||||
// A zero ID0 means an identifier or literal in ID2, like `foo`, `42` or a
|
||||
// status literal like `"#foo"`.
|
||||
@@ -468,10 +468,10 @@ func NewExpr(flags Flags, operator t.ID, ident t.ID, lhs *Node, mhs *Node, rhs *
|
||||
|
||||
// Assert is "assert RHS via ID2(args)", "choose etc", "pre etc", "inv etc" or
|
||||
// "post etc":
|
||||
// - ID0: <IDAssert|IDChoose|IDPre|IDInv|IDPost>
|
||||
// - ID2: <"-string literal> reason
|
||||
// - RHS: <Expr>
|
||||
// - List0: <Arg> reason arguments
|
||||
// - ID0: <IDAssert|IDChoose|IDPre|IDInv|IDPost>
|
||||
// - ID2: <"-string literal> reason
|
||||
// - RHS: <Expr>
|
||||
// - List0: <Arg> reason arguments
|
||||
type Assert Node
|
||||
|
||||
func (n *Assert) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -513,8 +513,8 @@ func NewAssert(keyword t.ID, condition *Expr, reason t.ID, args []*Node) *Assert
|
||||
}
|
||||
|
||||
// Arg is "name:value".
|
||||
// - ID2: <ident> name
|
||||
// - RHS: <Expr> value
|
||||
// - ID2: <ident> name
|
||||
// - RHS: <Expr> value
|
||||
type Arg Node
|
||||
|
||||
func (n *Arg) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -530,9 +530,9 @@ func NewArg(name t.ID, value *Expr) *Arg {
|
||||
}
|
||||
|
||||
// Assign is "LHS = RHS" or "LHS op= RHS" or "RHS":
|
||||
// - ID0: operator
|
||||
// - LHS: <nil|Expr>
|
||||
// - RHS: <Expr>
|
||||
// - ID0: operator
|
||||
// - LHS: <nil|Expr>
|
||||
// - RHS: <Expr>
|
||||
type Assign Node
|
||||
|
||||
func (n *Assign) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -550,8 +550,8 @@ func NewAssign(operator t.ID, lhs *Expr, rhs *Expr) *Assign {
|
||||
}
|
||||
|
||||
// Var is "var ID2 LHS":
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
type Var Node
|
||||
|
||||
func (n *Var) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -569,9 +569,9 @@ func NewVar(name t.ID, xType *TypeExpr) *Var {
|
||||
}
|
||||
|
||||
// Field is a "name : type" struct field:
|
||||
// - FlagsPrivateData is the initializer need not explicitly memset to zero.
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - FlagsPrivateData is the initializer need not explicitly memset to zero.
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
type Field Node
|
||||
|
||||
func (n *Field) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -590,11 +590,11 @@ func NewField(flags Flags, name t.ID, xType *TypeExpr) *Field {
|
||||
|
||||
// IOManip is "io_bind (io:LHS, data:MHS, history_position:RHS) { List2 }" or
|
||||
// "io_limit (io:LHS, limit:MHS) { List2 }":
|
||||
// - ID0: <IDIOBind|IDIOLimit>
|
||||
// - LHS: <Expr>
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <Expr>
|
||||
// - List2: <Statement> body
|
||||
// - ID0: <IDIOBind|IDIOLimit>
|
||||
// - LHS: <Expr>
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <Expr>
|
||||
// - List2: <Statement> body
|
||||
type IOManip Node
|
||||
|
||||
func (n *IOManip) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -617,16 +617,16 @@ func NewIOManip(keyword t.ID, io *Expr, arg1 *Expr, historyPosition *Expr, body
|
||||
|
||||
// Iterate is
|
||||
// "iterate.ID1 (assigns)(length:ID2, advance:ID0, unroll:LHS), List1 { List2 } else RHS":
|
||||
// - FlagsHasBreak is the iterate has an explicit break
|
||||
// - FlagsHasContinue is the iterate has an explicit continue
|
||||
// - ID0: advance
|
||||
// - ID1: <0|label>
|
||||
// - ID2: length
|
||||
// - LHS: <Expr> unroll
|
||||
// - RHS: <nil|Iterate>
|
||||
// - List0: <Assign> assigns
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
// - FlagsHasBreak is the iterate has an explicit break
|
||||
// - FlagsHasContinue is the iterate has an explicit continue
|
||||
// - ID0: advance
|
||||
// - ID1: <0|label>
|
||||
// - ID2: length
|
||||
// - LHS: <Expr> unroll
|
||||
// - RHS: <nil|Iterate>
|
||||
// - List0: <Assign> assigns
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
type Iterate Node
|
||||
|
||||
func (n *Iterate) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -661,12 +661,12 @@ func NewIterate(label t.ID, assigns []*Node, length t.ID, advance t.ID, unroll t
|
||||
}
|
||||
|
||||
// While is "while.ID1 MHS, List1 { List2 } endwhile.ID1":
|
||||
// - FlagsHasBreak is the while has an explicit break
|
||||
// - FlagsHasContinue is the while has an explicit continue
|
||||
// - ID1: <0|label>
|
||||
// - MHS: <Expr>
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
// - FlagsHasBreak is the while has an explicit break
|
||||
// - FlagsHasContinue is the while has an explicit continue
|
||||
// - ID1: <0|label>
|
||||
// - MHS: <Expr>
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
//
|
||||
// TODO: should we be able to unroll while loops too?
|
||||
type While Node
|
||||
@@ -699,10 +699,10 @@ func NewWhile(label t.ID, condition *Expr, asserts []*Node) *While {
|
||||
}
|
||||
|
||||
// If is "if MHS { List2 } else RHS" or "if MHS { List2 } else { List1 }":
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <nil|If>
|
||||
// - List1: <Statement> if-false body
|
||||
// - List2: <Statement> if-true body
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <nil|If>
|
||||
// - List1: <Statement> if-false body
|
||||
// - List2: <Statement> if-true body
|
||||
type If Node
|
||||
|
||||
func (n *If) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -722,8 +722,8 @@ func NewIf(condition *Expr, bodyIfTrue []*Node, bodyIfFalse []*Node, elseIf *If)
|
||||
}
|
||||
|
||||
// Choose is "choose ID2: List0":
|
||||
// - ID2: name
|
||||
// - List0: <Expr> method names.
|
||||
// - ID2: name
|
||||
// - List0: <Expr> method names.
|
||||
type Choose Node
|
||||
|
||||
func (n *Choose) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -739,9 +739,9 @@ func NewChoose(name t.ID, args []*Node) *Choose {
|
||||
}
|
||||
|
||||
// Ret is "return LHS" or "yield LHS":
|
||||
// - FlagsReturnsError LHS is an error status
|
||||
// - ID0: <IDReturn|IDYield>
|
||||
// - LHS: <Expr>
|
||||
// - FlagsReturnsError LHS is an error status
|
||||
// - ID0: <IDReturn|IDYield>
|
||||
// - LHS: <Expr>
|
||||
type Ret Node
|
||||
|
||||
func (n *Ret) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -760,8 +760,8 @@ func NewRet(keyword t.ID, value *Expr) *Ret {
|
||||
}
|
||||
|
||||
// Jump is "break" or "continue", with an optional label, "break.label":
|
||||
// - ID0: <IDBreak|IDContinue>
|
||||
// - ID1: <0|label>
|
||||
// - ID0: <IDBreak|IDContinue>
|
||||
// - ID1: <0|label>
|
||||
type Jump Node
|
||||
|
||||
func (n *Jump) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -784,12 +784,12 @@ const MaxTypeExprDepth = 63
|
||||
|
||||
// TypeExpr is a type expression, such as "base.u32", "base.u32[..= 8]", "foo",
|
||||
// "pkg.bar", "ptr T", "array[8] T", "slice T" or "table T":
|
||||
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
|
||||
// - ID1: <0|pkg>
|
||||
// - ID2: <0|type name>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|TypeExpr>
|
||||
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
|
||||
// - ID1: <0|pkg>
|
||||
// - ID2: <0|type name>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|TypeExpr>
|
||||
//
|
||||
// An IDNptr or IDPtr ID0 means "nptr RHS" or "ptr RHS". RHS is the inner type.
|
||||
//
|
||||
@@ -958,14 +958,14 @@ func NewTypeExpr(decorator t.ID, pkg t.ID, name t.ID, alenRecvMin *Node, max *Ex
|
||||
const MaxBodyDepth = 255
|
||||
|
||||
// Func is "func ID2.ID0(LHS)(RHS) { List2 }":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID0: funcName
|
||||
// - ID1: <0|receiverPkg> (set by calling SetPackage)
|
||||
// - ID2: <0|receiverName>
|
||||
// - LHS: <Struct> in-parameters
|
||||
// - RHS: <Struct> out-parameters
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID0: funcName
|
||||
// - ID1: <0|receiverPkg> (set by calling SetPackage)
|
||||
// - ID2: <0|receiverName>
|
||||
// - LHS: <Struct> in-parameters
|
||||
// - RHS: <Struct> out-parameters
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
type Func Node
|
||||
|
||||
func (n *Func) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1033,9 +1033,9 @@ func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcN
|
||||
}
|
||||
|
||||
// Status is "error (RHS) ID2" or "suspension (RHS) ID2":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: message
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: message
|
||||
type Status Node
|
||||
|
||||
func (n *Status) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1055,11 +1055,11 @@ func NewStatus(flags Flags, filename string, line uint32, message t.ID) *Status
|
||||
}
|
||||
|
||||
// Const is "const ID2 LHS = RHS":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - RHS: <Expr>
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - RHS: <Expr>
|
||||
type Const Node
|
||||
|
||||
func (n *Const) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1087,12 +1087,12 @@ func NewConst(flags Flags, filename string, line uint32, name t.ID, xType *TypeE
|
||||
const MaxImplements = 63
|
||||
|
||||
// Struct is "struct ID2? implements List0 (List1)":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - FlagsClassy is "ID2" vs "ID2?"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - List0: <TypeExpr> implements
|
||||
// - List1: <Field> fields
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - FlagsClassy is "ID2" vs "ID2?"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - List0: <TypeExpr> implements
|
||||
// - List1: <Field> fields
|
||||
//
|
||||
// The question mark indicates a classy struct - one that supports methods,
|
||||
// especially coroutines.
|
||||
@@ -1120,7 +1120,7 @@ func NewStruct(flags Flags, filename string, line uint32, name t.ID, implements
|
||||
}
|
||||
|
||||
// Use is "use ID2":
|
||||
// - ID2: <"-string literal> package path
|
||||
// - ID2: <"-string literal> package path
|
||||
type Use Node
|
||||
|
||||
func (n *Use) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1138,7 +1138,7 @@ func NewUse(filename string, line uint32, path t.ID) *Use {
|
||||
}
|
||||
|
||||
// File is a file of source code:
|
||||
// - List0: <Const|Func|Status|Struct|Use> top-level declarations
|
||||
// - List0: <Const|Func|Status|Struct|Use> top-level declarations
|
||||
type File Node
|
||||
|
||||
func (n *File) AsNode() *Node { return (*Node)(n) }
|
||||
|
||||
@@ -76,6 +76,7 @@ var FourCCs = [...][2]string{
|
||||
{"SVG ", "Scalable Vector Graphics"},
|
||||
{"TAR ", "Tape Archive"},
|
||||
{"TEXT", "Text"},
|
||||
{"TGA ", "Truevision Advanced Raster Graphics Adapter"},
|
||||
{"TIFF", "Tagged Image File Format"},
|
||||
{"TOML", "Tom's Obvious Minimal Language"},
|
||||
{"WAVE", "Waveform"},
|
||||
|
||||
@@ -19,6 +19,7 @@ package check
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
@@ -373,33 +374,42 @@ func (c *Checker) checkConst(node *a.Node) error {
|
||||
}
|
||||
|
||||
nLists := 0
|
||||
for typ.IsArrayType() {
|
||||
if nLists == a.MaxTypeExprDepth {
|
||||
return fmt.Errorf("check: type expression recursion depth too large")
|
||||
for elemTyp := typ; ; {
|
||||
if elemTyp.IsArrayType() {
|
||||
if nLists == a.MaxTypeExprDepth {
|
||||
return fmt.Errorf("check: type expression recursion depth too large")
|
||||
}
|
||||
nLists++
|
||||
elemTyp = elemTyp.Inner()
|
||||
continue
|
||||
} else if elemTyp.Decorator() != 0 {
|
||||
return fmt.Errorf("check: invalid const type %q for %s", n.XType().Str(c.tm), qid.Str(c.tm))
|
||||
}
|
||||
nLists++
|
||||
typ = typ.Inner()
|
||||
}
|
||||
if typ.Decorator() != 0 {
|
||||
return fmt.Errorf("check: invalid const type %q for %s", n.XType().Str(c.tm), qid.Str(c.tm))
|
||||
break
|
||||
}
|
||||
|
||||
nb := typ.Innermost().AsNode().MBounds()
|
||||
if err := c.checkConstElement(n.Value(), nb, nLists); err != nil {
|
||||
if err := c.checkConstElement(typ, n.Value(), nb, nLists); err != nil {
|
||||
return fmt.Errorf("check: %v for %s", err, qid.Str(c.tm))
|
||||
}
|
||||
setPlaceholderMBoundsMType(n.AsNode())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Checker) checkConstElement(n *a.Expr, nb bounds, nLists int) error {
|
||||
func (c *Checker) checkConstElement(typ *a.TypeExpr, n *a.Expr, nb bounds, nLists int) error {
|
||||
if nLists > 0 {
|
||||
nLists--
|
||||
if !typ.IsArrayType() {
|
||||
return fmt.Errorf("internal error: inconsistent element type %q", typ.Str(c.tm))
|
||||
}
|
||||
cv := typ.ArrayLength().ConstValue()
|
||||
if args, ok := n.IsList(); !ok {
|
||||
return fmt.Errorf("invalid const value %q", n.Str(c.tm))
|
||||
} else if cv.Cmp(big.NewInt(int64(len(args)))) != 0 {
|
||||
return fmt.Errorf("inconsistent array length (%d) and element count (%d)", cv, len(args))
|
||||
} else {
|
||||
for _, o := range args {
|
||||
if err := c.checkConstElement(o.AsExpr(), nb, nLists); err != nil {
|
||||
if err := c.checkConstElement(typ.Inner(), o.AsExpr(), nb, nLists); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,11 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
}
|
||||
|
||||
case a.KIf:
|
||||
for n := n.AsIf(); n != nil; n = n.ElseIf() {
|
||||
if (n.ElseIf() != nil) && (len(n.BodyIfFalse()) > 0) {
|
||||
return fmt.Errorf("check: if has an else-if and an else-not-if")
|
||||
}
|
||||
}
|
||||
for n := n.AsIf(); n != nil; n = n.ElseIf() {
|
||||
cond := n.Condition()
|
||||
if cond.Effect() != 0 {
|
||||
|
||||
@@ -1204,7 +1204,9 @@ func (p *parser) parseIf() (*a.If, error) {
|
||||
}
|
||||
|
||||
func (p *parser) parseIterateNode() (*a.Node, error) {
|
||||
if x := p.peek1(); x != t.IDIterate {
|
||||
if p.funcEffect.Coroutine() {
|
||||
return nil, fmt.Errorf(`parse: "iterate" inside coroutine at %s:%d`, p.filename, p.line())
|
||||
} else if x := p.peek1(); x != t.IDIterate {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "iterate", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
|
||||
@@ -201,16 +201,16 @@ type Token struct {
|
||||
}
|
||||
|
||||
// nBuiltInIDs is the number of built-in IDs. The packing is:
|
||||
// - 0x00 is invalid.
|
||||
// - 0x01 ..= 0x0F are squiggly punctuation, such as ";", "." and "?".
|
||||
// - 0x10 ..= 0x1F are squiggly bookends, such as "(", ")" and "]".
|
||||
// - 0x20 ..= 0x3F are squiggly assignments, such as "=" and "+=".
|
||||
// - 0x40 ..= 0x6F are operators, such as "+", "==" and "not".
|
||||
// - 0x70 ..= 0xAF are x-ops (disambiguation forms): unary vs binary "+".
|
||||
// - 0xB0 ..= 0xCF are keywords, such as "if" and "return".
|
||||
// - 0xD0 ..= 0xDF are type modifiers, such as "ptr" and "slice".
|
||||
// - 0xE0 ..= 0xFF are literals, such as "ok" and "true".
|
||||
// - 0x100 ..= 0x3FF are identifiers, such as "bool", "u32" and "read_u8".
|
||||
// - 0x00 is invalid.
|
||||
// - 0x01 ..= 0x0F are squiggly punctuation, such as ";", "." and "?".
|
||||
// - 0x10 ..= 0x1F are squiggly bookends, such as "(", ")" and "]".
|
||||
// - 0x20 ..= 0x3F are squiggly assignments, such as "=" and "+=".
|
||||
// - 0x40 ..= 0x6F are operators, such as "+", "==" and "not".
|
||||
// - 0x70 ..= 0xAF are x-ops (disambiguation forms): unary vs binary "+".
|
||||
// - 0xB0 ..= 0xCF are keywords, such as "if" and "return".
|
||||
// - 0xD0 ..= 0xDF are type modifiers, such as "ptr" and "slice".
|
||||
// - 0xE0 ..= 0xFF are literals, such as "ok" and "true".
|
||||
// - 0x100 ..= 0x3FF are identifiers, such as "bool", "u32" and "read_u8".
|
||||
//
|
||||
// Squiggly means a sequence of non-alpha-numeric bytes, such as "+" and "&=".
|
||||
const (
|
||||
@@ -1299,9 +1299,12 @@ func init() {
|
||||
// addXForms modifies table so that, if table[x] == y, then table[y] = y.
|
||||
//
|
||||
// For example, for the unaryForms table, the explicit entries are like:
|
||||
// IDPlus: IDXUnaryPlus,
|
||||
//
|
||||
// IDPlus: IDXUnaryPlus,
|
||||
//
|
||||
// and this function implicitly addes entries like:
|
||||
// IDXUnaryPlus: IDXUnaryPlus,
|
||||
//
|
||||
// IDXUnaryPlus: IDXUnaryPlus,
|
||||
func addXForms(table *[nBuiltInSymbolicIDs]ID) {
|
||||
implicitEntries := [nBuiltInSymbolicIDs]bool{}
|
||||
for _, y := range table {
|
||||
|
||||
@@ -27,57 +27,57 @@
|
||||
// repository was 80 times faster than `clang-format`, even without a column
|
||||
// limit:
|
||||
//
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
//
|
||||
// Apart from some rare and largely uninteresting exceptions, the dumbindent
|
||||
// algorithm only considers:
|
||||
//
|
||||
// ∙ '{' and '}' curly braces,
|
||||
// ∙ '(' and ')' round parentheses,
|
||||
// ∙ '\n' line breaks,
|
||||
// ∙ ' ' spaces and '\t' tabs that start or end a line, and
|
||||
// ∙ strings, comments and preprocessor directives (in order to ignore any of
|
||||
// the above special characters within them),
|
||||
// ∙ '{' and '}' curly braces,
|
||||
// ∙ '(' and ')' round parentheses,
|
||||
// ∙ '\n' line breaks,
|
||||
// ∙ ' ' spaces and '\t' tabs that start or end a line, and
|
||||
// ∙ strings, comments and preprocessor directives (in order to ignore any of
|
||||
// the above special characters within them),
|
||||
//
|
||||
// Everything else is an opaque byte. Consider this input:
|
||||
//
|
||||
// for (i = 0; i < 3; i++) {
|
||||
// j = 0; // Ignore { in a comment.
|
||||
// if (i < j) { foo(); }
|
||||
// u = (v +
|
||||
// w);
|
||||
// }
|
||||
// for (i = 0; i < 3; i++) {
|
||||
// j = 0; // Ignore { in a comment.
|
||||
// if (i < j) { foo(); }
|
||||
// u = (v +
|
||||
// w);
|
||||
// }
|
||||
//
|
||||
// From the algorithm's point of view, this input is equivalent to:
|
||||
//
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
//
|
||||
// The formatted output (using the default of 2 spaces per indent level) is:
|
||||
//
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
//
|
||||
// Dumbindent adjusts lines horizontally (indenting) but not vertically (it
|
||||
// does not break or un-break lines, or collapse consecutive blank lines),
|
||||
@@ -103,9 +103,9 @@
|
||||
//
|
||||
// Similarly, dumbindent will not correct this mis-indentation:
|
||||
//
|
||||
// if (condition)
|
||||
// goto fail;
|
||||
// goto fail;
|
||||
// if (condition)
|
||||
// goto fail;
|
||||
// goto fail;
|
||||
//
|
||||
// Instead, when automatically or manually generating the input for dumbindent,
|
||||
// it is recommended to always emit curly braces (again, similar to `gofmt`
|
||||
|
||||
@@ -130,23 +130,23 @@ func (b *bitstream) take(nBits uint32) int32 {
|
||||
// 4, 4)" example from RFC 1951 section 3.2.2, the huffman struct is
|
||||
// initialized by calling:
|
||||
//
|
||||
// h.construct([]uint32{
|
||||
// 'A': 3, 'B': 3, 'C': 3, 'D': 3, 'E': 3, 'F': 2, 'G': 4, 'H': 4,
|
||||
// })
|
||||
// h.construct([]uint32{
|
||||
// 'A': 3, 'B': 3, 'C': 3, 'D': 3, 'E': 3, 'F': 2, 'G': 4, 'H': 4,
|
||||
// })
|
||||
//
|
||||
// which results in:
|
||||
//
|
||||
// huffman{
|
||||
// counts: [maxCodeBits + 1]uint32{
|
||||
// 2: 1, 3: 5, 4: 2,
|
||||
// },
|
||||
// symbols: [maxNumCodes]int32{
|
||||
// 0: 'F', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'G', 7: 'H',
|
||||
// },
|
||||
// lookUpTable: [256]uint32{
|
||||
// etc,
|
||||
// },
|
||||
// }
|
||||
// huffman{
|
||||
// counts: [maxCodeBits + 1]uint32{
|
||||
// 2: 1, 3: 5, 4: 2,
|
||||
// },
|
||||
// symbols: [maxNumCodes]int32{
|
||||
// 0: 'F', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'G', 7: 'H',
|
||||
// },
|
||||
// lookUpTable: [256]uint32{
|
||||
// etc,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// Continuing the example from the RFC, decoding "1110" from the bitstream will
|
||||
// produce the 'G' symbol.
|
||||
|
||||
@@ -1057,18 +1057,19 @@ func orOneNegOneNonNeg(neg IntRange, non IntRange) (z IntRange) {
|
||||
// possible xx in x and yy in y.
|
||||
//
|
||||
// Algorithm:
|
||||
// // If the two intervals overlap, the result is the minimum of the two
|
||||
// // intervals' maxima.
|
||||
// //
|
||||
// // This overlaps code path is just an optimization.
|
||||
// if overlaps(x, y) {
|
||||
// return min(xMax, yMax)
|
||||
// }
|
||||
// xFlip = bitFillRight(bitFillRight(xMax & ~xMin) & xMax & ~yMax)
|
||||
// xResult = yMax & ((xMax & ~xFlip) | (xFlip >> 1))
|
||||
// yFlip = bitFillRight(bitFillRight(yMax & ~yMin) & yMax & ~xMax)
|
||||
// yResult = xMax & ((yMax & ~yFlip) | (yFlip >> 1))
|
||||
// return max(xResult, yResult)
|
||||
//
|
||||
// // If the two intervals overlap, the result is the minimum of the two
|
||||
// // intervals' maxima.
|
||||
// //
|
||||
// // This overlaps code path is just an optimization.
|
||||
// if overlaps(x, y) {
|
||||
// return min(xMax, yMax)
|
||||
// }
|
||||
// xFlip = bitFillRight(bitFillRight(xMax & ~xMin) & xMax & ~yMax)
|
||||
// xResult = yMax & ((xMax & ~xFlip) | (xFlip >> 1))
|
||||
// yFlip = bitFillRight(bitFillRight(yMax & ~yMin) & yMax & ~xMax)
|
||||
// yResult = xMax & ((yMax & ~yFlip) | (yFlip >> 1))
|
||||
// return max(xResult, yResult)
|
||||
//
|
||||
// If xMin and yMin are both zero, the overlaps branch is taken.
|
||||
//
|
||||
@@ -1189,13 +1190,15 @@ func (x IntRange) andMax(y IntRange) *big.Int {
|
||||
// possible xx in x and yy in y.
|
||||
//
|
||||
// Algorithm:
|
||||
// droppable = bitFillRight((xMax & ~xMin) | (yMax & ~yMin))
|
||||
// available = xMax & yMax & droppable
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
//
|
||||
// droppable = bitFillRight((xMax & ~xMin) | (yMax & ~yMin))
|
||||
// available = xMax & yMax & droppable
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
//
|
||||
// If xMin and yMin are both zero, this simplifies to:
|
||||
// available = xMax & yMax
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
//
|
||||
// available = xMax & yMax
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
func (x IntRange) orMax(y IntRange) *big.Int {
|
||||
if x[0].Sign() == 0 && y[0].Sign() == 0 {
|
||||
i := big.NewInt(0)
|
||||
@@ -1257,17 +1260,17 @@ func (x IntRange) orMax(y IntRange) *big.Int {
|
||||
}
|
||||
|
||||
// bitFillRight modifies i to round up to the next power of 2 minus 1:
|
||||
// - If i is +0 then bitFillRight(i) sets i to 0.
|
||||
// - If i is +1 then bitFillRight(i) sets i to 1.
|
||||
// - If i is +2 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +3 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +4 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +5 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +6 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +7 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +8 then bitFillRight(i) sets i to 15.
|
||||
// - If i is +9 then bitFillRight(i) sets i to 15.
|
||||
// - Etc.
|
||||
// - If i is +0 then bitFillRight(i) sets i to 0.
|
||||
// - If i is +1 then bitFillRight(i) sets i to 1.
|
||||
// - If i is +2 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +3 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +4 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +5 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +6 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +7 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +8 then bitFillRight(i) sets i to 15.
|
||||
// - If i is +9 then bitFillRight(i) sets i to 15.
|
||||
// - Etc.
|
||||
func bitFillRight(i *big.Int) {
|
||||
if s := i.Sign(); s < 0 {
|
||||
panic("pre-condition failure")
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package litonlylzma_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/google/wuffs/lib/litonlylzma"
|
||||
)
|
||||
|
||||
func ExampleRoundTripLZMA() {
|
||||
original := []byte("Hello world.\n")
|
||||
compressed, err := litonlylzma.FileFormatLZMA.Encode(nil, original)
|
||||
if err != nil {
|
||||
log.Fatalf("Encode: %v", err)
|
||||
}
|
||||
recovered, _, err := litonlylzma.FileFormatLZMA.Decode(nil, compressed)
|
||||
if err != nil {
|
||||
log.Fatalf("Decode: %v", err)
|
||||
}
|
||||
|
||||
for i, c := range compressed {
|
||||
if (i & 15) > 0 {
|
||||
fmt.Printf(" ")
|
||||
}
|
||||
fmt.Printf("%02X", c)
|
||||
if ((i & 15) == 15) || ((i + 1) == len(compressed)) {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
fmt.Printf("%s", recovered)
|
||||
|
||||
// Output:
|
||||
// 5D 00 10 00 00 0D 00 00 00 00 00 00 00 00 24 19
|
||||
// 49 86 E7 D5 E5 E2 56 ED 6A E6 0E 81 FE B8 00 00
|
||||
// Hello world.
|
||||
}
|
||||
|
||||
func ExampleRoundTripXz() {
|
||||
original := []byte("Hello world.\n")
|
||||
compressed, err := litonlylzma.FileFormatXz.Encode(nil, original)
|
||||
if err != nil {
|
||||
log.Fatalf("Encode: %v", err)
|
||||
}
|
||||
recovered, _, err := litonlylzma.FileFormatXz.Decode(nil, compressed)
|
||||
if err != nil {
|
||||
log.Fatalf("Decode: %v", err)
|
||||
}
|
||||
|
||||
for i, c := range compressed {
|
||||
if (i & 15) > 0 {
|
||||
fmt.Printf(" ")
|
||||
}
|
||||
fmt.Printf("%02X", c)
|
||||
if ((i & 15) == 15) || ((i + 1) == len(compressed)) {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
fmt.Printf("%s", recovered)
|
||||
|
||||
// Output:
|
||||
// FD 37 7A 58 5A 00 00 01 69 22 DE 36 02 00 21 01
|
||||
// 00 00 00 00 37 27 97 D6 01 00 0C 48 65 6C 6C 6F
|
||||
// 20 77 6F 72 6C 64 2E 0A 00 00 00 00 8E F8 31 35
|
||||
// 00 01 21 0D 75 DC A8 D2 90 42 99 0D 01 00 00 00
|
||||
// 00 01 59 5A
|
||||
// Hello world.
|
||||
}
|
||||
@@ -0,0 +1,779 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
// Package litonlylzma provides a decoder and encoder for Literal Only LZMA (or
|
||||
// Literal Only Xz), a subset of the LZMA (or Xz) compressed file formats.
|
||||
//
|
||||
// Subset means that:
|
||||
// - the Encode methods' output is a valid LZMA/Xz file and can be
|
||||
// decompressed by the tools available at https://www.7-zip.org/sdk.html or
|
||||
// https://tukaani.org/xz/ (and available as /usr/bin/lzma or /usr/bin/xz
|
||||
// on a Debian system).
|
||||
// - the Decode methods supports the Encode methods' output but they do not
|
||||
// support the full set of valid LZMA/Xz files.
|
||||
// - this codec's compression ratios are not as good as full LZMA/Xz
|
||||
// (although compression times are much faster). Moderate compression is
|
||||
// still achieved, through range coding, but there are no Lempel Ziv
|
||||
// back-references.
|
||||
//
|
||||
// The main benefit, compared to full LZMA/Xz, is that this implementation is
|
||||
// much simpler and hence easier to study. It is around 800 lines of code.
|
||||
//
|
||||
// Example compression numbers on a small English text file (at
|
||||
// https://github.com/google/wuffs/blob/main/test/data/romeo.txt):
|
||||
// - romeo.txt is 942 bytes (100%).
|
||||
// - romeo.txt.litonlyxz is 708 bytes (75%).
|
||||
// - romeo.txt.litonlylzma is 659 bytes (70%).
|
||||
// - romeo.txt.xz is 644 bytes (68%).
|
||||
// - romeo.txt.lzma is 598 bytes (63%).
|
||||
// - romeo.txt.bz2 is 568 bytes (60%).
|
||||
// - romeo.txt.zst is 559 bytes (59%).
|
||||
// - romeo.txt.gz is 558 bytes (59%).
|
||||
//
|
||||
// Example compression numbers on a large archive of source code (at
|
||||
// https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.1.tar.xz):
|
||||
// - linux-5.0.1.tar is 863313920 bytes (100%).
|
||||
// - linux-5.0.1.tar.litonlyxz is 454480932 bytes (53%).
|
||||
// - linux-5.0.1.tar.litonlylzma is 449726070 bytes (52%).
|
||||
// - linux-5.0.1.tar.gz is 164575959 bytes (19%).
|
||||
// - linux-5.0.1.tar.zst is 156959897 bytes (18%).
|
||||
// - linux-5.0.1.tar.bz2 is 125873134 bytes (15%).
|
||||
// - linux-5.0.1.tar.xz is 108233572 bytes (13%).
|
||||
// - linux-5.0.1.tar.lzma is 108216601 bytes (13%).
|
||||
//
|
||||
// The various tools (/usr/bin/gzip, /usr/bin/xz, etc) were all ran with their
|
||||
// default settings, not their "maximum compression" settings. This is why the
|
||||
// linux-5.0.1.tar.xz file size above differs from what cdn.kernel.org served.
|
||||
package litonlylzma
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"hash/crc32"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnsupportedXxxData is potentially returned by Decode.
|
||||
ErrUnsupportedLZMAData = errors.New("litonlylzma: unsupported LZMA data")
|
||||
ErrUnsupportedXzData = errors.New("litonlylzma: unsupported Xz data")
|
||||
|
||||
errInvalidLZMAData = errors.New("litonlylzma: invalid LZMA data")
|
||||
errInvalidXzData = errors.New("litonlylzma: invalid Xz data")
|
||||
errUnexpectedEOF = errors.New("litonlylzma: unexpected EOF")
|
||||
errUnsupportedFileFormat = errors.New("litonlylzma: unsupported FileFormat")
|
||||
)
|
||||
|
||||
const (
|
||||
// LZMA has a few configuration knobs but our subset-of-LZMA hard codes
|
||||
// these to LZMA's default values:
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/781863cdf592da3e97420f50de5dac056ad352a5/C/LzmaEnc.h#L19-L21
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/781863cdf592da3e97420f50de5dac056ad352a5/DOC/lzma-specification.txt#L43-L45
|
||||
lc = 3 // The number of Literal Context bits.
|
||||
lp = 0 // The number of Literal Position bits.
|
||||
pb = 2 // The number of Position Bits.
|
||||
|
||||
lpMask = (1 << lp) - 1
|
||||
pbMask = (1 << pb) - 1
|
||||
)
|
||||
|
||||
// lzmaHeader5 is the first 5 bytes of an LZMA file using the hard-coded
|
||||
// configuration for the subset-of-LZMA that this package supports.
|
||||
//
|
||||
// 0x5D encodes the (lc, lp, pb) triple and the next four bytes hold the u32le
|
||||
// dictionary size. 0x00001000 is LZMA's minimum dictionary size, although our
|
||||
// subset-of-LZMA does not use a dictionary (also called a "sliding window").
|
||||
const lzmaHeader5 = "\x5D\x00\x10\x00\x00"
|
||||
|
||||
// xzHeader24 is the first 24 bytes of an Xz file using the hard-coded
|
||||
// configuration for the subset-of-Xz that this package supports.
|
||||
const xzHeader24 = "" +
|
||||
"\xFD\x37\x7A\x58\x5A\x00" + // Stream Header Magic Bytes.
|
||||
// ----
|
||||
"\x00\x01" + // Stream Flags (0x01 means CRC-32).
|
||||
"\x69\x22\xDE\x36" + // CRC-32 of the previous 2 bytes.
|
||||
// ----
|
||||
"\x02" + // Block Header Size (0x02 * 4 = 8 bytes).
|
||||
"\x00" + // Block Flags.
|
||||
"\x21" + // Filter ID (0x21 means LZMA2).
|
||||
"\x01" + // Size of Filter Properties (size of the next line).
|
||||
"\x00" + // Filter Properties (0x00 means an 0x1000 dictionary size).
|
||||
"\x00\x00\x00" + // Padding to 4-byte alignment.
|
||||
"\x37\x27\x97\xD6" // CRC-32 of the previous 8 bytes.
|
||||
|
||||
// rangeDecoder and rangeEncoder hold the state for range coding (also known as
|
||||
// arithmetic coding, roughly speaking). "range" is a keyword in Go, so in this
|
||||
// implementation, what's traditionally called the "range" fields are called
|
||||
// "width" instead.
|
||||
//
|
||||
// Conceptually, the encoded bitstream holds a high precision number (a binary
|
||||
// fraction) in the range from zero to one. High precision could mean thousands
|
||||
// or millions of bits, but when decoding, only 32 of these are 'paged in' at a
|
||||
// time - this is the rangeDecoder.bits field. The encoder similarly works on
|
||||
// only a small, fixed number of bits.
|
||||
//
|
||||
// When encoding, that high precision *number* isn't fully known until the end
|
||||
// of the input is reached. *During* the encoding process, what's known is a
|
||||
// high precision *interval* that gets narrowed down as the input bytes are
|
||||
// consumed. That interval is represented by the rangeEncoder.low and
|
||||
// rangeEncoder.width fields (the width is the difference between the
|
||||
// interval's upper and lower bound). Both low and width are, conceptually,
|
||||
// 32-bit values - they operate at the same scale - but low is an uint64
|
||||
// because of potential overflow. We'll revisit that below.
|
||||
//
|
||||
// Width is initialized to 0xFFFF_FFFF and shrinks every time a bit is decoded
|
||||
// or encoded. Similarly, low can only increase or stay the same on each bit
|
||||
// step. When width drops below (1 << 24), the rangeDecoder or rangeEncoder
|
||||
// 'zooms in', left-shifting (with truncation) by 8 the bits, low and width
|
||||
// fields and reading a src byte or writing a dst byte of compressed data.
|
||||
//
|
||||
// Writing a byte may be delayed because the encoding interval could span
|
||||
// multiple possible digits. To use a decimal fraction analogy, suppose that
|
||||
// our interval is [0.7138872, 0.7146055] and the low field nominally holds 4
|
||||
// digits. We could emit '7' and '1' but we have to hold back on emitting
|
||||
// either '3' or '4' until we can narrow down the interval further. That '3'
|
||||
// digit is stashed as the pendingHead field. low is set to 8872, width is set
|
||||
// to (46055 - 38872) = 7183 and we progress until the width drops below 1000,
|
||||
// causing a 'zoom in' event. There are three cases:
|
||||
// - if low is less than 9000 (but starts with an '8'), we can emit the '3'
|
||||
// with confidence (and then stash '8' in the pendingHead field).
|
||||
// - if low overflows 9999, we can emit the '4' with confidence (and then
|
||||
// stash low's 'thousands digit' in the pendingHead field).
|
||||
// - if low is in 9000 ..= 9999 then we could still be unsure. Keep the '3'
|
||||
// pending but extend it so that there are two pending digits: '39'. If
|
||||
// this occurs again: '399', and so on.
|
||||
//
|
||||
// In all three cases, 'zooming in' causes us to shift out the most significant
|
||||
// digit of the low field. This method is therefore named shiftLow here, the
|
||||
// same name used in other range coding implementations, such as
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/781863cdf592da3e97420f50de5dac056ad352a5/C/LzmaEnc.c#L572-L602
|
||||
//
|
||||
// The pendingEtc fields combine to hold one or more digits ('0' ..= '9'
|
||||
// decimal digits in our analogy, 0x00 ..= 0xFF bytes in our actual
|
||||
// implementation). There are (1 + pendingExtra) digits in total and while the
|
||||
// head digit might be any value, the extra digits must be all '9' (in the
|
||||
// decimal analogy) or 0xFF (in our actual implementation).
|
||||
//
|
||||
// Some other implementations use the name "cache" instead of "pending", and
|
||||
// store a "cacheSize" field equivalent to our (1 + pendingExtra).
|
||||
//
|
||||
// As above, the low field is conceptually a uint32, but it is a uint64 because
|
||||
// of this potential overflow. Its high 32 bits are usually zero, rarely one
|
||||
// and never anything higher. The high 32 bits essentially hold an overflow
|
||||
// carry bit. If set, it flips "3999etc" to "4000etc".
|
||||
//
|
||||
// "Low is conceptually 4 bytes; pendingHead holds another byte" is why the
|
||||
// shortest LZMA payload is 5 bytes even though the first byte is always 0x00
|
||||
// and seems redundant.
|
||||
|
||||
type rangeDecoder struct {
|
||||
src []byte
|
||||
bits uint32
|
||||
width uint32
|
||||
}
|
||||
|
||||
type rangeEncoder struct {
|
||||
dst []byte
|
||||
low uint64
|
||||
width uint32
|
||||
pendingHead uint8
|
||||
pendingExtra uint64
|
||||
}
|
||||
|
||||
// Precondition: (rEnc.width < (1 << 24)) or we are at the end of our input
|
||||
// (and are flushing the rangeEncoder).
|
||||
func (rEnc *rangeEncoder) shiftLow() {
|
||||
if rEnc.low < 0x0_FF00_0000 {
|
||||
rEnc.dst = append(rEnc.dst, rEnc.pendingHead+0x00)
|
||||
for ; rEnc.pendingExtra > 0; rEnc.pendingExtra-- {
|
||||
rEnc.dst = append(rEnc.dst, 0xFF)
|
||||
}
|
||||
rEnc.pendingHead = uint8(rEnc.low >> 24)
|
||||
rEnc.pendingExtra = 0
|
||||
rEnc.low = (rEnc.low << 8) & 0xFFFF_FFFF
|
||||
|
||||
} else if rEnc.low < 0x1_0000_0000 {
|
||||
rEnc.pendingExtra++
|
||||
rEnc.low = (rEnc.low << 8) & 0xFFFF_FFFF
|
||||
|
||||
} else {
|
||||
rEnc.dst = append(rEnc.dst, rEnc.pendingHead+0x01)
|
||||
for ; rEnc.pendingExtra > 0; rEnc.pendingExtra-- {
|
||||
rEnc.dst = append(rEnc.dst, 0x00)
|
||||
}
|
||||
rEnc.pendingHead = uint8(rEnc.low >> 24)
|
||||
rEnc.pendingExtra = 0
|
||||
rEnc.low = (rEnc.low << 8) & 0xFFFF_FFFF
|
||||
}
|
||||
}
|
||||
|
||||
// prob is a probability (out of 100%) whose uint16 value ranges from 0 to
|
||||
// (1 << 11) = 2048 inclusive. For example, prob(1024) means a 50% probability
|
||||
// and prob(384) means a (384 / 2048) = 18.75% probability.
|
||||
//
|
||||
// Specifically, it is the probability that the next bit is 0 (instead of 1).
|
||||
type prob uint16
|
||||
|
||||
const (
|
||||
// probBits is such that prob(1 << probBits) means a 100% probability.
|
||||
probBits = 11
|
||||
minProb = 0
|
||||
maxProb = 1 << probBits
|
||||
)
|
||||
|
||||
func setProbsToOneHalf(p []prob) {
|
||||
for i := range p {
|
||||
p[i] = 1 << (probBits - 1)
|
||||
}
|
||||
}
|
||||
|
||||
// adaptShift scales how much to adjust "the probability that the next bit is
|
||||
// 0" after seeing the current bit. The probability is adaptive in that the
|
||||
// current bit being 0 (or 1) increases (or decreases) the probability that the
|
||||
// next bit is 0. The larger adaptShift is, the slower the adaptation.
|
||||
const adaptShift = 5
|
||||
|
||||
func (p *prob) decodeBit(rDec *rangeDecoder) (bitValue uint32, retErr error) {
|
||||
threshold := (rDec.width >> probBits) * uint32(*p)
|
||||
if rDec.bits < threshold {
|
||||
bitValue = 0
|
||||
rDec.width = threshold
|
||||
*p += (maxProb - *p) >> adaptShift
|
||||
} else {
|
||||
bitValue = 1
|
||||
rDec.bits -= threshold
|
||||
rDec.width -= threshold
|
||||
*p -= (*p - minProb) >> adaptShift
|
||||
}
|
||||
|
||||
if rDec.width < (1 << 24) {
|
||||
if len(rDec.src) <= 0 {
|
||||
return 0, errUnexpectedEOF
|
||||
}
|
||||
rDec.bits = rDec.bits<<8 | uint32(rDec.src[0])
|
||||
rDec.width <<= 8
|
||||
rDec.src = rDec.src[1:]
|
||||
}
|
||||
return bitValue, retErr
|
||||
}
|
||||
|
||||
func (p *prob) encodeBit(rEnc *rangeEncoder, bitValue uint32) {
|
||||
threshold := (rEnc.width >> probBits) * uint32(*p)
|
||||
if bitValue == 0 {
|
||||
rEnc.width = threshold
|
||||
*p += (maxProb - *p) >> adaptShift
|
||||
} else {
|
||||
rEnc.low += uint64(threshold)
|
||||
rEnc.width -= threshold
|
||||
*p -= (*p - minProb) >> adaptShift
|
||||
}
|
||||
if rEnc.width < (1 << 24) {
|
||||
rEnc.width <<= 8
|
||||
rEnc.shiftLow()
|
||||
}
|
||||
}
|
||||
|
||||
// byteProbs hold probabilities for coding 8 bits (1 byte) of data. It is a 256
|
||||
// element array such that:
|
||||
// - The 0th element is unused.
|
||||
// - The 1st element holds the probability that the 7th bit (the highest, most
|
||||
// significant bit) is 0.
|
||||
// - The 2nd element holds the probability that the 6th bit is 0, conditional
|
||||
// on the high bit being 0.
|
||||
// - The 3rd element holds the probability that the 6th bit is 0, conditional
|
||||
// on the high bit being 1.
|
||||
// - The 4th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 00.
|
||||
// - The 5th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 01.
|
||||
// - The 6th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 10.
|
||||
// - The 7th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 11.
|
||||
// - The 8th element holds the probability that the 4th bit is 0, conditional
|
||||
// on the high three bits being 000.
|
||||
// - etc
|
||||
// - The 255th element holds the probability that the 0th bit (the lowest,
|
||||
// least significant bit) is 0, conditional on the high seven bits being
|
||||
// 1111111.
|
||||
//
|
||||
// Put another way, the 256 elements' value of N, as in "it's a probability for
|
||||
// the Nth bit", looks like this (when arranged in 8 rows of 32 elements):
|
||||
//
|
||||
// u7665555444444443333333333333333
|
||||
// 22222222222222222222222222222222
|
||||
// 11111111111111111111111111111111
|
||||
// 11111111111111111111111111111111
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
//
|
||||
// The 'u' means that the 0th element is unused.
|
||||
type byteProbs [0x100]prob
|
||||
|
||||
func (p *byteProbs) decodeByte(rDec *rangeDecoder) (byteValue byte, retErr error) {
|
||||
index := uint32(1)
|
||||
for index < 0x100 {
|
||||
if bitValue, err := p[index].decodeBit(rDec); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
index = index<<1 | bitValue
|
||||
}
|
||||
}
|
||||
return byte(index), nil
|
||||
}
|
||||
|
||||
func (p *byteProbs) encodeByte(rEnc *rangeEncoder, byteValue byte) {
|
||||
b := uint32(byteValue)
|
||||
index := uint32(1)
|
||||
for i := 7; i >= 0; i-- {
|
||||
bitValue := (b >> uint(i)) & 1
|
||||
p[index].encodeBit(rEnc, bitValue)
|
||||
index = index<<1 | bitValue
|
||||
}
|
||||
}
|
||||
|
||||
// FileFormat is a compressed file format, either the original LZMA format
|
||||
// itself or something like Xz that builds on or varies that.
|
||||
//
|
||||
// Each valid FileFormatXxx value does not distinguish between the full file
|
||||
// format (as spoken by numerous Xxx software tools) and the subset-of-Xxx
|
||||
// implemented by this package. Specifically, FileFormatLZMA.Encode will
|
||||
// produce compressed data that is valid full-LZMA (and is also valid
|
||||
// subset-of-LZMA). FileFormatLZMA.Decode can decode subset-of-LZMA (but not
|
||||
// full-LZMA).
|
||||
type FileFormat uint32
|
||||
|
||||
const (
|
||||
FileFormatInvalid = FileFormat(0)
|
||||
FileFormatLZMA = FileFormat(1)
|
||||
FileFormatXz = FileFormat(2)
|
||||
)
|
||||
|
||||
func (f FileFormat) String() string {
|
||||
switch f {
|
||||
case FileFormatLZMA:
|
||||
return "FileFormatLZMA"
|
||||
case FileFormatXz:
|
||||
return "FileFormatXz"
|
||||
}
|
||||
return "FileFormatInvalid"
|
||||
}
|
||||
|
||||
// Decode converts src from the Literal Only LZMA/Xz compressed file format,
|
||||
// appending the decoding to dst.
|
||||
//
|
||||
// It is valid to pass a nil dst, like the way it's valid to pass nil to the
|
||||
// built-in append function.
|
||||
//
|
||||
// Decode also returns the suffix of src that was not used during decoding.
|
||||
//
|
||||
// It can also return partial results. The appendedDst and remainingSrc return
|
||||
// values may be non-zero even if retErr is non-zero.
|
||||
//
|
||||
// It returns ErrUnsupportedXxxData if the source bytes look like Xxx formatted
|
||||
// data that is outside the subset-of-Xxx that this package implements.
|
||||
func (f FileFormat) Decode(dst []byte, src []byte) (appendedDst []byte, remainingSrc []byte, retErr error) {
|
||||
switch f {
|
||||
case FileFormatLZMA:
|
||||
return decodeLZMA(dst, src)
|
||||
case FileFormatXz:
|
||||
return decodeXz(dst, src)
|
||||
}
|
||||
return nil, nil, errUnsupportedFileFormat
|
||||
}
|
||||
|
||||
func decodeLZMA(dst []byte, src []byte) (appendedDst []byte, remainingSrc []byte, retErr error) {
|
||||
// LZMA consists of a 13 byte header and then at least a 5 byte payload
|
||||
// (range coded data). The 13 byte header is:
|
||||
// - 1 byte for the (lc, lp, pb) triple with max values (8, 4, 4),
|
||||
// - 4 bytes u32le dictionary size and
|
||||
// - 8 bytes i64le uncompressed size.
|
||||
if (len(src) < 18) || (src[0] >= (9 * 5 * 5)) {
|
||||
return dst, nil, errInvalidLZMAData
|
||||
} else if string(src[:5]) != lzmaHeader5 {
|
||||
return dst, nil, ErrUnsupportedLZMAData
|
||||
}
|
||||
|
||||
size := uint64(0)
|
||||
for i := 0; i < 8; i++ {
|
||||
size |= uint64(src[5+i]) << uint(8*i)
|
||||
}
|
||||
if int64(size) < -1 {
|
||||
return dst, nil, errInvalidLZMAData
|
||||
} else if int64(size) == -1 {
|
||||
return dst, nil, ErrUnsupportedLZMAData
|
||||
}
|
||||
|
||||
return decodeRaw(dst, src[13:], size, ErrUnsupportedLZMAData)
|
||||
}
|
||||
|
||||
func decodeXz(dst []byte, src []byte) (appendedDst []byte, remainingSrc []byte, retErr error) {
|
||||
originalDstLen := len(dst)
|
||||
originalSrcLen := len(src)
|
||||
|
||||
// Decode the headers.
|
||||
if (len(src) < 24) || (string(src[:6]) != xzHeader24[:6]) {
|
||||
return dst, src, errInvalidXzData
|
||||
} else if string(src[6:24]) != xzHeader24[6:24] {
|
||||
return dst, src, ErrUnsupportedXzData
|
||||
}
|
||||
src = src[24:]
|
||||
|
||||
// Decode the payload as multiple chunks.
|
||||
for {
|
||||
if len(src) == 0 {
|
||||
return dst, src, errInvalidXzData
|
||||
|
||||
} else if src[0] == 0x00 { // No more chunks.
|
||||
src = src[1:]
|
||||
break
|
||||
|
||||
} else if src[0] == 0x01 { // Independent uncompressed chunk.
|
||||
if len(src) < 3 {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
uncompressedSize := (uint32(src[1]) << 8) + (uint32(src[2]) << 0) + 1
|
||||
src = src[3:]
|
||||
if uint64(uncompressedSize) > uint64(len(src)) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
dst = append(dst, src[:uncompressedSize]...)
|
||||
src = src[uncompressedSize:]
|
||||
|
||||
} else if src[0] == 0xE0 { // Independent LZMA chunk.
|
||||
if len(src) < 6 {
|
||||
return dst, src, errInvalidXzData
|
||||
} else if src[5] != 0x5D { // Like lzmaHeader5[0], this encodes lc=3, lp=0, pb=2.
|
||||
return dst, src, ErrUnsupportedXzData
|
||||
}
|
||||
uncompressedSize := (uint32(src[1]) << 8) + (uint32(src[2]) << 0) + 1
|
||||
compressedSize := (uint32(src[3]) << 8) + (uint32(src[4]) << 0) + 1
|
||||
src = src[6:]
|
||||
if uint64(compressedSize) > uint64(len(src)) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
lenSrc := len(src)
|
||||
dst, src, retErr = decodeRaw(dst, src, uint64(uncompressedSize), ErrUnsupportedXzData)
|
||||
if retErr != nil {
|
||||
return dst, src, retErr
|
||||
} else if lenSrc != (len(src) + int(compressedSize)) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
|
||||
} else {
|
||||
return dst, src, ErrUnsupportedXzData
|
||||
}
|
||||
}
|
||||
unpaddedSizeWant := uint64((originalSrcLen - 12) - len(src) + 4)
|
||||
for i := unpaddedSizeWant & 3; (i & 3) != 0; i++ {
|
||||
if (len(src) == 0) || (src[0] != 0x00) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
src = src[1:]
|
||||
}
|
||||
if len(src) < 4 {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
checksum := crc32.ChecksumIEEE(dst[originalDstLen:])
|
||||
if (src[0] != uint8(checksum>>0)) ||
|
||||
(src[1] != uint8(checksum>>8)) ||
|
||||
(src[2] != uint8(checksum>>16)) ||
|
||||
(src[3] != uint8(checksum>>24)) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
src = src[4:]
|
||||
|
||||
// Decode the index.
|
||||
srcCheckpoint1 := src
|
||||
if (len(src) < 2) || (src[0] != 0x00) || (src[1] != 0x01) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
src = src[2:]
|
||||
src, unpaddedSizeHave, ok := decodeUvarint(src)
|
||||
if !ok || (unpaddedSizeHave != unpaddedSizeWant) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
src, uncompressedSize, ok := decodeUvarint(src)
|
||||
if !ok || (uncompressedSize != uint64(len(dst)-originalDstLen)) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
for i := (len(srcCheckpoint1) - len(src)) & 3; (i & 3) != 0; i++ {
|
||||
if (len(src) == 0) || (src[0] != 0x00) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
src = src[1:]
|
||||
}
|
||||
backwardSize := (len(srcCheckpoint1) - len(src)) >> 2
|
||||
if len(src) < 4 {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
checksum = crc32.ChecksumIEEE(srcCheckpoint1[:len(srcCheckpoint1)-len(src)])
|
||||
if (src[0] != uint8(checksum>>0)) ||
|
||||
(src[1] != uint8(checksum>>8)) ||
|
||||
(src[2] != uint8(checksum>>16)) ||
|
||||
(src[3] != uint8(checksum>>24)) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
src = src[4:]
|
||||
|
||||
// Decode the footer.
|
||||
if len(src) < 12 {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
checksum = crc32.ChecksumIEEE(src[4:10])
|
||||
if (src[0] != uint8(checksum>>0)) || // Checksum.
|
||||
(src[1] != uint8(checksum>>8)) ||
|
||||
(src[2] != uint8(checksum>>16)) ||
|
||||
(src[3] != uint8(checksum>>24)) ||
|
||||
(src[4] != uint8(backwardSize>>0)) || // Backward Size.
|
||||
(src[5] != uint8(backwardSize>>8)) ||
|
||||
(src[6] != uint8(backwardSize>>16)) ||
|
||||
(src[7] != uint8(backwardSize>>24)) ||
|
||||
(src[8] != xzHeader24[6]) || // Stream Flags again.
|
||||
(src[9] != xzHeader24[7]) ||
|
||||
(src[10] != 0x59) || // Stream Footer Magic Bytes.
|
||||
(src[11] != 0x5A) {
|
||||
return dst, src, errInvalidXzData
|
||||
}
|
||||
return dst, src[12:], nil
|
||||
}
|
||||
|
||||
func decodeRaw(dst []byte, src []byte, size uint64, errUnsupported error) (appendedDst []byte, remainingSrc []byte, retErr error) {
|
||||
if (len(src) < 5) || (src[0] != 0x00) {
|
||||
return dst, src, errUnsupported
|
||||
}
|
||||
|
||||
rDec := rangeDecoder{
|
||||
src: src[5:],
|
||||
bits: (uint32(src[1]) << 24) |
|
||||
(uint32(src[2]) << 16) |
|
||||
(uint32(src[3]) << 8) |
|
||||
(uint32(src[4]) << 0),
|
||||
width: 0xFFFF_FFFF,
|
||||
}
|
||||
|
||||
posProbs := [1 << pb]prob{}
|
||||
setProbsToOneHalf(posProbs[:])
|
||||
|
||||
litProbs := [1 << (lc + lp)]byteProbs{}
|
||||
for ij := range litProbs {
|
||||
setProbsToOneHalf(litProbs[ij][:])
|
||||
}
|
||||
|
||||
pos := uint32(0)
|
||||
prev := byte(0)
|
||||
curr := byte(0)
|
||||
for ; size > 0; size-- {
|
||||
if bitValue, err := posProbs[pos&pbMask].decodeBit(&rDec); err != nil {
|
||||
return dst, rDec.src, err
|
||||
} else if bitValue != 0 {
|
||||
// A full-LZMA decoder would implement Lempel Ziv matches (or the
|
||||
// End of Stream marker) here. Our simpler subset-of-LZMA decoder
|
||||
// only uses literals.
|
||||
return dst, rDec.src, errUnsupported
|
||||
}
|
||||
|
||||
i := (pos & lpMask) << lc
|
||||
j := uint32(prev) >> (8 - lc)
|
||||
if curr, retErr = litProbs[i|j].decodeByte(&rDec); retErr != nil {
|
||||
return dst, rDec.src, retErr
|
||||
}
|
||||
dst = append(dst, curr)
|
||||
pos++
|
||||
prev = curr
|
||||
}
|
||||
|
||||
return dst, rDec.src, nil
|
||||
}
|
||||
|
||||
func decodeUvarint(src []byte) (remainingSrc []byte, x uint64, ok bool) {
|
||||
for i := uint32(0); (i < 63) && (len(src) > 0); i += 7 {
|
||||
s := src[0]
|
||||
src = src[1:]
|
||||
x |= uint64(s&0x7F) << i
|
||||
if (s & 0x80) == 0 {
|
||||
return src, x, true
|
||||
}
|
||||
}
|
||||
return src, 0, false
|
||||
}
|
||||
|
||||
// Encode converts src to the Literal Only LZMA compressed file format,
|
||||
// appending the encoding to dst.
|
||||
//
|
||||
// It is valid to pass a nil dst, like the way it's valid to pass nil to the
|
||||
// built-in append function.
|
||||
func (f FileFormat) Encode(dst []byte, src []byte) (appendedDst []byte, retErr error) {
|
||||
switch f {
|
||||
case FileFormatLZMA:
|
||||
return encodeLZMA(dst, src)
|
||||
case FileFormatXz:
|
||||
return encodeXz(dst, src)
|
||||
}
|
||||
return nil, errUnsupportedFileFormat
|
||||
}
|
||||
|
||||
func encodeLZMA(dst []byte, src []byte) (appendedDst []byte, retErr error) {
|
||||
dst = append(dst, lzmaHeader5...)
|
||||
size := len(src)
|
||||
for i := 0; i < 8; i++ {
|
||||
dst = append(dst, byte(size))
|
||||
size >>= 8
|
||||
}
|
||||
return encodeRaw(dst, src), nil
|
||||
}
|
||||
|
||||
func encodeXz(dst []byte, src []byte) (appendedDst []byte, retErr error) {
|
||||
// Encode the headers (12 byte stream header then 12 byte block header).
|
||||
// The block's unpaddedSize calculation ignores the stream header.
|
||||
dstLen0 := len(dst) + 12
|
||||
dst = append(dst, xzHeader24...)
|
||||
|
||||
// Encode the payload as multiple chunks.
|
||||
//
|
||||
// Later XZ chunks can depend on earlier ones (and doing so can help
|
||||
// compression ratios) but for simplicity, this encoder emits independent
|
||||
// chunks. Each chunk's maximum compressed and uncompressed size are both
|
||||
// equal to 0x10000 = 65536 bytes, roughly speaking. The encoder partitions
|
||||
// the src into 65536 byte sub-slices. If a sub-slice's LZMA-compressed
|
||||
// form would be longer, the encoder emits an uncompressed chunk instead.
|
||||
rawLZMA := []byte(nil)
|
||||
for remaining := src; len(remaining) > 0; {
|
||||
srcChunk := []byte(nil)
|
||||
if len(remaining) > 0x10000 {
|
||||
srcChunk, remaining = remaining[:0x10000], remaining[0x10000:]
|
||||
} else {
|
||||
srcChunk, remaining = remaining, nil
|
||||
}
|
||||
|
||||
rawLZMA = encodeRaw(rawLZMA[:0], srcChunk)
|
||||
if (len(srcChunk) + 3) <= (len(rawLZMA) + 6) {
|
||||
dst = append(dst,
|
||||
0x01, // Independent uncompressed chunk.
|
||||
uint8((len(srcChunk)-1)>>8),
|
||||
uint8((len(srcChunk)-1)>>0),
|
||||
)
|
||||
dst = append(dst, srcChunk...)
|
||||
} else {
|
||||
dst = append(dst,
|
||||
0xE0, // Independent LZMA chunk.
|
||||
uint8((len(srcChunk)-1)>>8),
|
||||
uint8((len(srcChunk)-1)>>0),
|
||||
uint8((len(rawLZMA)-1)>>8),
|
||||
uint8((len(rawLZMA)-1)>>0),
|
||||
0x5D, // Like lzmaHeader5[0], this encodes lc=3, lp=0, pb=2.
|
||||
)
|
||||
dst = append(dst, rawLZMA...)
|
||||
}
|
||||
}
|
||||
dst = append(dst, 0x00) // No more chunks.
|
||||
unpaddedSize := uint64(len(dst)-dstLen0) + 4 // +4 for the upcoming checksum.
|
||||
for 0 != 3&(len(dst)-dstLen0) {
|
||||
dst = append(dst, 0x00) // Padding
|
||||
}
|
||||
checksum := crc32.ChecksumIEEE(src)
|
||||
dst = append(dst,
|
||||
uint8(checksum>>0),
|
||||
uint8(checksum>>8),
|
||||
uint8(checksum>>16),
|
||||
uint8(checksum>>24),
|
||||
)
|
||||
|
||||
// Encode the index.
|
||||
dstLen1 := len(dst)
|
||||
dst = append(dst,
|
||||
0x00, // Index Indicator.
|
||||
0x01, // Number of Records.
|
||||
)
|
||||
dst = encodeUvarint(dst, unpaddedSize)
|
||||
dst = encodeUvarint(dst, uint64(len(src)))
|
||||
for 0 != 3&(len(dst)-dstLen1) {
|
||||
dst = append(dst, 0x00) // Padding
|
||||
}
|
||||
backwardSize := (len(dst) - dstLen1) >> 2
|
||||
checksum = crc32.ChecksumIEEE(dst[dstLen1:])
|
||||
dst = append(dst,
|
||||
uint8(checksum>>0),
|
||||
uint8(checksum>>8),
|
||||
uint8(checksum>>16),
|
||||
uint8(checksum>>24),
|
||||
)
|
||||
|
||||
// Encode the footer.
|
||||
dstLen2 := len(dst)
|
||||
dst = append(dst,
|
||||
0, 0, 0, 0, // Space for the checksum.
|
||||
uint8(backwardSize>>0), // Backward Size.
|
||||
uint8(backwardSize>>8),
|
||||
uint8(backwardSize>>16),
|
||||
uint8(backwardSize>>24),
|
||||
xzHeader24[6], // Stream Flags again.
|
||||
xzHeader24[7],
|
||||
0x59, // Stream Footer Magic Bytes.
|
||||
0x5A,
|
||||
)
|
||||
checksum = crc32.ChecksumIEEE(dst[dstLen2+4 : dstLen2+10])
|
||||
dst[dstLen2+0] = uint8(checksum >> 0)
|
||||
dst[dstLen2+1] = uint8(checksum >> 8)
|
||||
dst[dstLen2+2] = uint8(checksum >> 16)
|
||||
dst[dstLen2+3] = uint8(checksum >> 24)
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func encodeRaw(dst []byte, src []byte) (appendedDst []byte) {
|
||||
rEnc := rangeEncoder{
|
||||
dst: dst,
|
||||
width: 0xFFFF_FFFF,
|
||||
}
|
||||
|
||||
posProbs := [1 << pb]prob{}
|
||||
setProbsToOneHalf(posProbs[:])
|
||||
|
||||
litProbs := [1 << (lc + lp)]byteProbs{}
|
||||
for ij := range litProbs {
|
||||
setProbsToOneHalf(litProbs[ij][:])
|
||||
}
|
||||
|
||||
pos := uint32(0)
|
||||
prev := byte(0)
|
||||
for _, curr := range src {
|
||||
// A full-LZMA encoder would choose between Lempel Ziv literals and
|
||||
// matches. Our simpler subset-of-LZMA encoder only uses literals, and
|
||||
// it is not a streaming encoder (it does not need to emit an End of
|
||||
// Stream marker), so we always encode a 0 bit here.
|
||||
posProbs[pos&pbMask].encodeBit(&rEnc, 0)
|
||||
|
||||
i := (pos & lpMask) << lc
|
||||
j := uint32(prev) >> (8 - lc)
|
||||
litProbs[i|j].encodeByte(&rEnc, curr)
|
||||
pos++
|
||||
prev = curr
|
||||
}
|
||||
|
||||
// Flush the rangeEncoder.
|
||||
for i := 0; i < 5; i++ {
|
||||
rEnc.shiftLow()
|
||||
}
|
||||
|
||||
return rEnc.dst
|
||||
}
|
||||
|
||||
func encodeUvarint(dst []byte, x uint64) []byte {
|
||||
for ; x >= 0x80; x >>= 7 {
|
||||
dst = append(dst, byte(x)|0x80)
|
||||
}
|
||||
return append(dst, byte(x))
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package litonlylzma
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
oneThousand0x00s = "oneThousand0x00s"
|
||||
oneThousand0xFFs = "oneThousand0xFFs"
|
||||
)
|
||||
|
||||
func testRoundTrip(tt *testing.T, filename string) {
|
||||
original := []byte(nil)
|
||||
switch filename {
|
||||
case oneThousand0x00s:
|
||||
original = make([]byte, 1000)
|
||||
case oneThousand0xFFs:
|
||||
original = make([]byte, 1000)
|
||||
for i := range original {
|
||||
original[i] = 0xFF
|
||||
}
|
||||
default:
|
||||
o, err := os.ReadFile("../../test/data/" + filename)
|
||||
if err != nil {
|
||||
tt.Fatalf("ReadFile: %v", err)
|
||||
}
|
||||
original = o
|
||||
}
|
||||
|
||||
fileFormats := [...]FileFormat{
|
||||
FileFormatLZMA,
|
||||
FileFormatXz,
|
||||
}
|
||||
|
||||
for _, f := range fileFormats {
|
||||
compressed, err := f.Encode(nil, original)
|
||||
if err != nil {
|
||||
tt.Fatalf("%v.Encode: %v", f, err)
|
||||
}
|
||||
recovered, _, err := f.Decode(nil, compressed)
|
||||
if err != nil {
|
||||
tt.Fatalf("%v.Decode: %v", f, err)
|
||||
}
|
||||
if !bytes.Equal(original, recovered) {
|
||||
tt.Fatalf("%v: round trip produced different bytes", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoundTrip0Bytes(tt *testing.T) { testRoundTrip(tt, "0.bytes") }
|
||||
func TestRoundTripArchiveTar(tt *testing.T) { testRoundTrip(tt, "archive.tar") }
|
||||
func TestRoundTripOneThousand0x00s(tt *testing.T) { testRoundTrip(tt, oneThousand0x00s) }
|
||||
func TestRoundTripOneThousand0xFFs(tt *testing.T) { testRoundTrip(tt, oneThousand0xFFs) }
|
||||
func TestRoundTripPiTxt(tt *testing.T) { testRoundTrip(tt, "pi.txt") }
|
||||
func TestRoundTripRomeoTxt(tt *testing.T) { testRoundTrip(tt, "romeo.txt") }
|
||||
@@ -0,0 +1,146 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
// Package nie provides access to NIE (Naïve Image Format) files.
|
||||
//
|
||||
// The NIE specification is at
|
||||
// https://github.com/google/wuffs/blob/main/doc/spec/nie-spec.md
|
||||
package nie
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image"
|
||||
"image/color"
|
||||
"io"
|
||||
)
|
||||
|
||||
func u32le(b []byte) uint32 {
|
||||
return (uint32(b[0]) << 0) |
|
||||
(uint32(b[1]) << 8) |
|
||||
(uint32(b[2]) << 16) |
|
||||
(uint32(b[3]) << 24)
|
||||
}
|
||||
|
||||
func init() {
|
||||
image.RegisterFormat("nie", "nïE", Decode, DecodeConfig)
|
||||
}
|
||||
|
||||
var (
|
||||
errImageIsTooLarge = errors.New("nie: image is too large")
|
||||
errInvalidHeader = errors.New("nie: invalid header")
|
||||
)
|
||||
|
||||
func decodeConfig(r io.Reader) (image.Config, byte, byte, error) {
|
||||
b := [16]byte{}
|
||||
_, err := io.ReadFull(r, b[:])
|
||||
if err != nil {
|
||||
return image.Config{}, 0, 0, err
|
||||
}
|
||||
if (u32le(b[:]) != 0x45afc36e) ||
|
||||
(b[4] != 0xff) ||
|
||||
(b[5] != 'b') ||
|
||||
((b[6] != 'n') && (b[6] != 'p')) ||
|
||||
((b[7] != '4') && (b[7] != '8')) {
|
||||
return image.Config{}, 0, 0, errInvalidHeader
|
||||
}
|
||||
|
||||
cm := color.Model(nil)
|
||||
switch {
|
||||
case (b[6] == 'n') && (b[7] == '4'):
|
||||
cm = color.NRGBAModel
|
||||
case (b[6] == 'n') && (b[7] == '8'):
|
||||
cm = color.NRGBA64Model
|
||||
case (b[6] == 'p') && (b[7] == '4'):
|
||||
cm = color.RGBAModel
|
||||
case (b[6] == 'p') && (b[7] == '8'):
|
||||
cm = color.RGBA64Model
|
||||
default:
|
||||
return image.Config{}, 0, 0, errInvalidHeader
|
||||
}
|
||||
|
||||
w := u32le(b[8:])
|
||||
h := u32le(b[12:])
|
||||
if (w > 0x7fffffff) || (h > 0x7fffffff) {
|
||||
return image.Config{}, 0, 0, errInvalidHeader
|
||||
}
|
||||
return image.Config{
|
||||
ColorModel: cm,
|
||||
Width: int(w),
|
||||
Height: int(h),
|
||||
}, b[6], b[7], nil
|
||||
}
|
||||
|
||||
// DecodeConfig returns the color model and dimensions of a NIE image without
|
||||
// decoding the entire image.
|
||||
func DecodeConfig(r io.Reader) (image.Config, error) {
|
||||
cfg, _, _, err := decodeConfig(r)
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
// Decode reads a NIE image from r.
|
||||
func Decode(r io.Reader) (image.Image, error) {
|
||||
cfg, b6, b7, err := decodeConfig(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
const u64max = 0xffffffffffffffff
|
||||
tooBig := false
|
||||
wh := uint64(cfg.Width) * uint64(cfg.Height)
|
||||
if b7 == '4' {
|
||||
tooBig = (wh > (u64max / 4)) ||
|
||||
((wh * 4) != uint64(int((wh * 4))))
|
||||
} else {
|
||||
tooBig = (wh > (u64max / 8)) ||
|
||||
((wh * 8) != uint64(int((wh * 8))))
|
||||
}
|
||||
if tooBig {
|
||||
return nil, errImageIsTooLarge
|
||||
}
|
||||
|
||||
img, pix := image.Image(nil), []byte(nil)
|
||||
switch {
|
||||
case (b6 == 'n') && (b7 == '4'):
|
||||
m := image.NewNRGBA(image.Rect(0, 0, int(cfg.Width), int(cfg.Height)))
|
||||
img, pix = m, m.Pix
|
||||
case (b6 == 'n') && (b7 == '8'):
|
||||
m := image.NewNRGBA64(image.Rect(0, 0, int(cfg.Width), int(cfg.Height)))
|
||||
img, pix = m, m.Pix
|
||||
case (b6 == 'p') && (b7 == '4'):
|
||||
m := image.NewRGBA(image.Rect(0, 0, int(cfg.Width), int(cfg.Height)))
|
||||
img, pix = m, m.Pix
|
||||
case (b6 == 'p') && (b7 == '8'):
|
||||
m := image.NewRGBA64(image.Rect(0, 0, int(cfg.Width), int(cfg.Height)))
|
||||
img, pix = m, m.Pix
|
||||
}
|
||||
if _, err := io.ReadFull(r, pix); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// NIE is little-endian BGRA. Go is big-endian RGBA.
|
||||
if b7 == '4' {
|
||||
for i := 0; i < len(pix); i += 4 {
|
||||
pix[i+0], pix[i+2] = pix[i+2], pix[i+0]
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < len(pix); i += 8 {
|
||||
pix[i+0], pix[i+1], pix[i+2], pix[i+3], pix[i+4], pix[i+5], pix[i+6], pix[i+7] =
|
||||
pix[i+5], pix[i+4], pix[i+3], pix[i+2], pix[i+1], pix[i+0], pix[i+7], pix[i+6]
|
||||
}
|
||||
}
|
||||
|
||||
return img, err
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func (r *ReadSeeker) Seek(offset int64, whence int) (int64, error) {
|
||||
return 0, errSeekToInvalidWhence
|
||||
}
|
||||
|
||||
if r.offset < 0 {
|
||||
if offset < 0 {
|
||||
return 0, errSeekToNegativePosition
|
||||
}
|
||||
r.offset = offset
|
||||
|
||||
@@ -716,6 +716,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Text.
|
||||
#define WUFFS_BASE__FOURCC__TEXT 0x54455854
|
||||
|
||||
// Truevision Advanced Raster Graphics Adapter.
|
||||
#define WUFFS_BASE__FOURCC__TGA 0x54474120
|
||||
|
||||
// Tagged Image File Format.
|
||||
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
|
||||
|
||||
@@ -1061,6 +1064,22 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
|
||||
|
||||
// --------
|
||||
|
||||
// Normally, the wuffs_base__peek_etc and wuffs_base__poke_etc implementations
|
||||
// are both (1) correct regardless of CPU endianness and (2) very fast (e.g. an
|
||||
// inlined wuffs_base__peek_u32le__no_bounds_check call, in an optimized clang
|
||||
// or gcc build, is a single MOV instruction on x86_64).
|
||||
//
|
||||
// However, the endian-agnostic implementations are slow on Microsoft's C
|
||||
// compiler (MSC). Alternative memcpy-based implementations restore speed, but
|
||||
// they are only correct on little-endian CPU architectures. Defining
|
||||
// WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE opts in to these implementations.
|
||||
//
|
||||
// https://godbolt.org/z/q4MfjzTPh
|
||||
#if defined(_MSC_VER) && !defined(__clang__) && \
|
||||
(defined(_M_ARM64) || defined(_M_X64))
|
||||
#define WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE
|
||||
#endif
|
||||
|
||||
#define wuffs_base__peek_u8be__no_bounds_check \
|
||||
wuffs_base__peek_u8__no_bounds_check
|
||||
#define wuffs_base__peek_u8le__no_bounds_check \
|
||||
@@ -1073,12 +1092,24 @@ wuffs_base__peek_u8__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__peek_u16be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint16_t x;
|
||||
memcpy(&x, p, 2);
|
||||
return _byteswap_ushort(x);
|
||||
#else
|
||||
return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__peek_u16le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint16_t x;
|
||||
memcpy(&x, p, 2);
|
||||
return x;
|
||||
#else
|
||||
return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
@@ -1095,14 +1126,26 @@ wuffs_base__peek_u24le__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__peek_u32be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint32_t x;
|
||||
memcpy(&x, p, 4);
|
||||
return _byteswap_ulong(x);
|
||||
#else
|
||||
return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |
|
||||
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__peek_u32le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint32_t x;
|
||||
memcpy(&x, p, 4);
|
||||
return x;
|
||||
#else
|
||||
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
|
||||
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
@@ -1151,18 +1194,30 @@ wuffs_base__peek_u56le__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__peek_u64be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint64_t x;
|
||||
memcpy(&x, p, 8);
|
||||
return _byteswap_uint64(x);
|
||||
#else
|
||||
return ((uint64_t)(p[0]) << 56) | ((uint64_t)(p[1]) << 48) |
|
||||
((uint64_t)(p[2]) << 40) | ((uint64_t)(p[3]) << 32) |
|
||||
((uint64_t)(p[4]) << 24) | ((uint64_t)(p[5]) << 16) |
|
||||
((uint64_t)(p[6]) << 8) | ((uint64_t)(p[7]) << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__peek_u64le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint64_t x;
|
||||
memcpy(&x, p, 8);
|
||||
return x;
|
||||
#else
|
||||
return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |
|
||||
((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |
|
||||
((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |
|
||||
((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------
|
||||
@@ -1185,7 +1240,8 @@ wuffs_base__poke_u16be__no_bounds_check(uint8_t* p, uint16_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u16le__no_bounds_check(uint8_t* p, uint16_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 2);
|
||||
@@ -1219,7 +1275,8 @@ wuffs_base__poke_u32be__no_bounds_check(uint8_t* p, uint32_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u32le__no_bounds_check(uint8_t* p, uint32_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 4);
|
||||
@@ -1305,7 +1362,8 @@ wuffs_base__poke_u64be__no_bounds_check(uint8_t* p, uint64_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u64le__no_bounds_check(uint8_t* p, uint64_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 8);
|
||||
@@ -1456,6 +1514,38 @@ wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u8 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u16 //
|
||||
wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u16 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u32 //
|
||||
wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u32 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u64 //
|
||||
wuffs_base__make_slice_u64_ij(uint64_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u64 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__empty_slice_u8() {
|
||||
wuffs_base__slice_u8 ret;
|
||||
@@ -1682,13 +1772,19 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// wuffs_base__magic_number_guess_fourcc guesses the file format of some data,
|
||||
// given its opening bytes. It returns a positive FourCC value on success.
|
||||
// given its starting bytes (the prefix_data argument) and whether or not there
|
||||
// may be further bytes (the prefix_closed argument; true means that
|
||||
// prefix_data is the entire data).
|
||||
//
|
||||
// It returns a positive FourCC value on success.
|
||||
//
|
||||
// It returns zero if nothing matches its hard-coded list of 'magic numbers'.
|
||||
//
|
||||
// It returns a negative value if a longer prefix is required for a conclusive
|
||||
// result. For example, seeing a single 'B' byte is not enough to discriminate
|
||||
// the BMP and BPG image file formats.
|
||||
// It returns a negative value if prefix_closed is false and a longer prefix is
|
||||
// required for a conclusive result. For example, a single 'B' byte (without
|
||||
// further data) is not enough to discriminate the BMP and BPG image file
|
||||
// formats. Similarly, a single '\xFF' byte might be the start of JPEG data or
|
||||
// it might be the start of some other binary data.
|
||||
//
|
||||
// It does not do a full validity check. Like any guess made from a short
|
||||
// prefix of the data, it may return false positives. Data that starts with 99
|
||||
@@ -1703,7 +1799,8 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__MAGIC sub-module, not just
|
||||
// WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix);
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// ---------------- Ranges and Rects
|
||||
|
||||
@@ -6624,7 +6721,6 @@ struct wuffs_bmp__decoder__struct {
|
||||
uint64_t scratch;
|
||||
} s_decode_image_config[1];
|
||||
struct {
|
||||
wuffs_base__status v_status;
|
||||
uint64_t scratch;
|
||||
} s_decode_frame[1];
|
||||
struct {
|
||||
@@ -6780,6 +6876,270 @@ struct wuffs_bmp__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_bzip2__error__bad_huffman_code_over_subscribed[];
|
||||
extern const char wuffs_bzip2__error__bad_huffman_code_under_subscribed[];
|
||||
extern const char wuffs_bzip2__error__bad_block_header[];
|
||||
extern const char wuffs_bzip2__error__bad_block_length[];
|
||||
extern const char wuffs_bzip2__error__bad_checksum[];
|
||||
extern const char wuffs_bzip2__error__bad_header[];
|
||||
extern const char wuffs_bzip2__error__bad_number_of_sections[];
|
||||
extern const char wuffs_bzip2__error__unsupported_block_randomization[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_BZIP2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
typedef struct wuffs_bzip2__decoder__struct wuffs_bzip2__decoder;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
|
||||
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
|
||||
//
|
||||
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
|
||||
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_bzip2__decoder__initialize(
|
||||
wuffs_bzip2__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options);
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_bzip2__decoder();
|
||||
|
||||
// ---------------- Allocs
|
||||
|
||||
// These functions allocate and initialize Wuffs structs. They return NULL if
|
||||
// memory allocation fails. If they return non-NULL, there is no need to call
|
||||
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
|
||||
// calling free on the returned pointer. That pointer is effectively a C++
|
||||
// std::unique_ptr<T, decltype(&free)>.
|
||||
|
||||
wuffs_bzip2__decoder*
|
||||
wuffs_bzip2__decoder__alloc();
|
||||
|
||||
static inline wuffs_base__io_transformer*
|
||||
wuffs_bzip2__decoder__alloc_as__wuffs_base__io_transformer() {
|
||||
return (wuffs_base__io_transformer*)(wuffs_bzip2__decoder__alloc());
|
||||
}
|
||||
|
||||
// ---------------- Upcasts
|
||||
|
||||
static inline wuffs_base__io_transformer*
|
||||
wuffs_bzip2__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
wuffs_bzip2__decoder* p) {
|
||||
return (wuffs_base__io_transformer*)p;
|
||||
}
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__set_quirk_enabled(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_bzip2__decoder__workbuf_len(
|
||||
const wuffs_bzip2__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_bzip2__decoder__transform_io(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Struct Definitions
|
||||
|
||||
// These structs' fields, and the sizeof them, are private implementation
|
||||
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||
//
|
||||
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||
|
||||
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
struct wuffs_bzip2__decoder__struct {
|
||||
// Do not access the private_impl's or private_data's fields directly. There
|
||||
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
|
||||
// the wuffs_foo__bar__baz functions.
|
||||
//
|
||||
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
|
||||
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
|
||||
|
||||
struct {
|
||||
uint32_t magic;
|
||||
uint32_t active_coroutine;
|
||||
wuffs_base__vtable vtable_for__wuffs_base__io_transformer;
|
||||
wuffs_base__vtable null_vtable;
|
||||
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint32_t f_max_incl_block_size;
|
||||
uint32_t f_block_size;
|
||||
bool f_decode_huffman_finished;
|
||||
uint8_t f_decode_huffman_which;
|
||||
uint32_t f_decode_huffman_ticks;
|
||||
uint32_t f_decode_huffman_section;
|
||||
uint32_t f_decode_huffman_run_shift;
|
||||
uint32_t f_flush_pointer;
|
||||
uint32_t f_flush_repeat_count;
|
||||
uint8_t f_flush_prev;
|
||||
bool f_ignore_checksum;
|
||||
uint32_t f_final_checksum_have;
|
||||
uint32_t f_block_checksum_have;
|
||||
uint32_t f_block_checksum_want;
|
||||
uint32_t f_original_pointer;
|
||||
uint32_t f_num_symbols;
|
||||
uint32_t f_num_huffman_codes;
|
||||
uint32_t f_num_sections;
|
||||
uint32_t f_code_lengths_bitmask;
|
||||
|
||||
uint32_t p_transform_io[1];
|
||||
uint32_t p_prepare_block[1];
|
||||
uint32_t p_read_code_lengths[1];
|
||||
uint32_t p_flush_slow[1];
|
||||
uint32_t p_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
uint32_t f_scratch;
|
||||
uint32_t f_letter_counts[256];
|
||||
uint8_t f_presence[256];
|
||||
uint8_t f_mtft[256];
|
||||
uint8_t f_huffman_selectors[32768];
|
||||
uint16_t f_huffman_trees[6][257][2];
|
||||
uint16_t f_huffman_tables[6][256];
|
||||
uint32_t f_bwt[1048576];
|
||||
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint64_t v_tag;
|
||||
uint32_t v_final_checksum_want;
|
||||
} s_transform_io[1];
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint32_t v_selector;
|
||||
} s_prepare_block[1];
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint32_t v_code_length;
|
||||
} s_read_code_lengths[1];
|
||||
struct {
|
||||
uint32_t v_flush_pointer;
|
||||
uint32_t v_flush_repeat_count;
|
||||
uint8_t v_flush_prev;
|
||||
uint32_t v_block_checksum_have;
|
||||
uint32_t v_block_size;
|
||||
uint8_t v_curr;
|
||||
uint64_t scratch;
|
||||
} s_flush_slow[1];
|
||||
struct {
|
||||
uint32_t v_node_index;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
using unique_ptr = std::unique_ptr<wuffs_bzip2__decoder, decltype(&free)>;
|
||||
|
||||
// On failure, the alloc_etc functions return nullptr. They don't throw.
|
||||
|
||||
static inline unique_ptr
|
||||
alloc() {
|
||||
return unique_ptr(wuffs_bzip2__decoder__alloc(), &free);
|
||||
}
|
||||
|
||||
static inline wuffs_base__io_transformer::unique_ptr
|
||||
alloc_as__wuffs_base__io_transformer() {
|
||||
return wuffs_base__io_transformer::unique_ptr(
|
||||
wuffs_bzip2__decoder__alloc_as__wuffs_base__io_transformer(), &free);
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
|
||||
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
// Disallow constructing or copying an object via standard C++ mechanisms,
|
||||
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
|
||||
// size and field layout is not part of the public, stable, memory-safe API.
|
||||
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
|
||||
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
|
||||
// their first argument) rather than tweaking bar.private_impl.qux fields.
|
||||
//
|
||||
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
|
||||
// order to provide convenience methods. These forward on "this", so that you
|
||||
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
|
||||
wuffs_bzip2__decoder__struct() = delete;
|
||||
wuffs_bzip2__decoder__struct(const wuffs_bzip2__decoder__struct&) = delete;
|
||||
wuffs_bzip2__decoder__struct& operator=(
|
||||
const wuffs_bzip2__decoder__struct&) = delete;
|
||||
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#if !defined(WUFFS_IMPLEMENTATION)
|
||||
// As above, the size of the struct is not part of the public API, and unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
|
||||
// allocated, not stack allocated. Its size is not intended to be known at
|
||||
// compile time, but it is unfortunately divulged as a side effect of
|
||||
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
|
||||
// instead of "sizeof T", invoking the operator. To make the two values
|
||||
// different, so that passing the latter will be rejected by the initialize
|
||||
// function, we add an arbitrary amount of dead weight.
|
||||
uint8_t dead_weight[123000000]; // 123 MB.
|
||||
#endif // !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
initialize(
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options) {
|
||||
return wuffs_bzip2__decoder__initialize(
|
||||
this, sizeof_star_self, wuffs_version, options);
|
||||
}
|
||||
|
||||
inline wuffs_base__io_transformer*
|
||||
upcast_as__wuffs_base__io_transformer() {
|
||||
return (wuffs_base__io_transformer*)this;
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_quirk_enabled(
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_bzip2__decoder__set_quirk_enabled(this, a_quirk, a_enabled);
|
||||
}
|
||||
|
||||
inline wuffs_base__range_ii_u64
|
||||
workbuf_len() const {
|
||||
return wuffs_bzip2__decoder__workbuf_len(this);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
transform_io(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
return wuffs_bzip2__decoder__transform_io(this, a_dst, a_src, a_workbuf);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
}; // struct wuffs_bzip2__decoder__struct
|
||||
|
||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_cbor__error__bad_input[];
|
||||
extern const char wuffs_cbor__error__unsupported_recursion_depth[];
|
||||
|
||||
@@ -6911,7 +7271,6 @@ struct wuffs_cbor__decoder__struct {
|
||||
struct {
|
||||
uint64_t v_string_length;
|
||||
uint32_t v_depth;
|
||||
uint32_t v_token_length;
|
||||
bool v_tagged;
|
||||
uint8_t v_indefinite_string_major_type;
|
||||
} s_decode_tokens[1];
|
||||
@@ -7344,7 +7703,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_n_clen;
|
||||
uint32_t v_i;
|
||||
uint32_t v_mask;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_n_extra_bits;
|
||||
uint8_t v_rep_symbol;
|
||||
uint32_t v_rep_count;
|
||||
@@ -7352,7 +7710,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
struct {
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_table_entry_n_bits;
|
||||
uint32_t v_lmask;
|
||||
uint32_t v_dmask;
|
||||
@@ -7360,7 +7717,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_hlen;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -7868,16 +8224,14 @@ struct wuffs_gif__decoder__struct {
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_ignore_metadata;
|
||||
bool f_report_metadata_iccp;
|
||||
bool f_report_metadata_xmp;
|
||||
uint32_t f_metadata_fourcc;
|
||||
uint64_t f_metadata_io_position;
|
||||
bool f_quirks[7];
|
||||
bool f_delayed_num_decoded_frames;
|
||||
bool f_end_of_data;
|
||||
bool f_restarted;
|
||||
bool f_previous_lzw_decode_ended_abruptly;
|
||||
bool f_seen_header;
|
||||
bool f_has_global_palette;
|
||||
uint8_t f_interlace;
|
||||
bool f_seen_num_animation_loops_value;
|
||||
@@ -7968,7 +8322,6 @@ struct wuffs_gif__decoder__struct {
|
||||
struct {
|
||||
uint64_t v_block_size;
|
||||
bool v_need_block_size;
|
||||
wuffs_base__status v_lzw_status;
|
||||
uint64_t scratch;
|
||||
} s_decode_id_part2[1];
|
||||
} private_data;
|
||||
@@ -8509,9 +8862,6 @@ struct wuffs_json__decoder__struct {
|
||||
uint32_t v_expect;
|
||||
uint32_t v_expect_after_value;
|
||||
} s_decode_tokens[1];
|
||||
struct {
|
||||
uint32_t v_neg;
|
||||
} s_decode_inf_nan[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -9169,12 +9519,13 @@ extern const char wuffs_png__error__bad_filter[];
|
||||
extern const char wuffs_png__error__bad_header[];
|
||||
extern const char wuffs_png__error__bad_text_chunk_not_latin_1[];
|
||||
extern const char wuffs_png__error__missing_palette[];
|
||||
extern const char wuffs_png__error__unsupported_cgbi_extension[];
|
||||
extern const char wuffs_png__error__unsupported_png_compression_method[];
|
||||
extern const char wuffs_png__error__unsupported_png_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_PNG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
#define WUFFS_PNG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 2251799562027015
|
||||
|
||||
#define WUFFS_PNG__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 8
|
||||
|
||||
@@ -9349,6 +9700,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_gama;
|
||||
bool f_seen_iccp;
|
||||
bool f_seen_idat;
|
||||
bool f_seen_ihdr;
|
||||
bool f_seen_plte;
|
||||
bool f_seen_srgb;
|
||||
bool f_seen_trns;
|
||||
@@ -9630,6 +9982,351 @@ struct wuffs_png__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_tga__error__bad_header[];
|
||||
extern const char wuffs_tga__error__bad_run_length_encoding[];
|
||||
extern const char wuffs_tga__error__unsupported_tga_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
typedef struct wuffs_tga__decoder__struct wuffs_tga__decoder;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
|
||||
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
|
||||
//
|
||||
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
|
||||
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options);
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder();
|
||||
|
||||
// ---------------- Allocs
|
||||
|
||||
// These functions allocate and initialize Wuffs structs. They return NULL if
|
||||
// memory allocation fails. If they return non-NULL, there is no need to call
|
||||
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
|
||||
// calling free on the returned pointer. That pointer is effectively a C++
|
||||
// std::unique_ptr<T, decltype(&free)>.
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc();
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)(wuffs_tga__decoder__alloc());
|
||||
}
|
||||
|
||||
// ---------------- Upcasts
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder* p) {
|
||||
return (wuffs_base__image_decoder*)p;
|
||||
}
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Struct Definitions
|
||||
|
||||
// These structs' fields, and the sizeof them, are private implementation
|
||||
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||
//
|
||||
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||
|
||||
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
struct wuffs_tga__decoder__struct {
|
||||
// Do not access the private_impl's or private_data's fields directly. There
|
||||
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
|
||||
// the wuffs_foo__bar__baz functions.
|
||||
//
|
||||
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
|
||||
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
|
||||
|
||||
struct {
|
||||
uint32_t magic;
|
||||
uint32_t active_coroutine;
|
||||
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
|
||||
wuffs_base__vtable null_vtable;
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
uint8_t f_header_id_length;
|
||||
uint8_t f_header_color_map_type;
|
||||
uint8_t f_header_image_type;
|
||||
uint16_t f_header_color_map_first_entry_index;
|
||||
uint16_t f_header_color_map_length;
|
||||
uint8_t f_header_color_map_entry_size;
|
||||
uint8_t f_header_pixel_depth;
|
||||
uint8_t f_header_image_descriptor;
|
||||
bool f_opaque;
|
||||
uint32_t f_scratch_bytes_per_pixel;
|
||||
uint32_t f_src_bytes_per_pixel;
|
||||
uint32_t f_src_pixfmt;
|
||||
uint64_t f_frame_config_io_position;
|
||||
wuffs_base__pixel_swizzler f_swizzler;
|
||||
|
||||
uint32_t p_decode_image_config[1];
|
||||
uint32_t p_decode_frame_config[1];
|
||||
uint32_t p_decode_frame[1];
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
uint8_t f_dst_palette[1024];
|
||||
uint8_t f_src_palette[1024];
|
||||
uint8_t f_scratch[4];
|
||||
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint64_t scratch;
|
||||
} s_decode_image_config[1];
|
||||
struct {
|
||||
uint64_t v_dst_bytes_per_pixel;
|
||||
uint32_t v_dst_x;
|
||||
uint32_t v_dst_y;
|
||||
uint64_t v_mark;
|
||||
uint32_t v_num_pixels32;
|
||||
uint32_t v_lit_length;
|
||||
uint32_t v_run_length;
|
||||
uint64_t v_num_dst_bytes;
|
||||
uint64_t scratch;
|
||||
} s_decode_frame[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
using unique_ptr = std::unique_ptr<wuffs_tga__decoder, decltype(&free)>;
|
||||
|
||||
// On failure, the alloc_etc functions return nullptr. They don't throw.
|
||||
|
||||
static inline unique_ptr
|
||||
alloc() {
|
||||
return unique_ptr(wuffs_tga__decoder__alloc(), &free);
|
||||
}
|
||||
|
||||
static inline wuffs_base__image_decoder::unique_ptr
|
||||
alloc_as__wuffs_base__image_decoder() {
|
||||
return wuffs_base__image_decoder::unique_ptr(
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder(), &free);
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
|
||||
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
// Disallow constructing or copying an object via standard C++ mechanisms,
|
||||
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
|
||||
// size and field layout is not part of the public, stable, memory-safe API.
|
||||
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
|
||||
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
|
||||
// their first argument) rather than tweaking bar.private_impl.qux fields.
|
||||
//
|
||||
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
|
||||
// order to provide convenience methods. These forward on "this", so that you
|
||||
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
|
||||
wuffs_tga__decoder__struct() = delete;
|
||||
wuffs_tga__decoder__struct(const wuffs_tga__decoder__struct&) = delete;
|
||||
wuffs_tga__decoder__struct& operator=(
|
||||
const wuffs_tga__decoder__struct&) = delete;
|
||||
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#if !defined(WUFFS_IMPLEMENTATION)
|
||||
// As above, the size of the struct is not part of the public API, and unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
|
||||
// allocated, not stack allocated. Its size is not intended to be known at
|
||||
// compile time, but it is unfortunately divulged as a side effect of
|
||||
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
|
||||
// instead of "sizeof T", invoking the operator. To make the two values
|
||||
// different, so that passing the latter will be rejected by the initialize
|
||||
// function, we add an arbitrary amount of dead weight.
|
||||
uint8_t dead_weight[123000000]; // 123 MB.
|
||||
#endif // !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
initialize(
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options) {
|
||||
return wuffs_tga__decoder__initialize(
|
||||
this, sizeof_star_self, wuffs_version, options);
|
||||
}
|
||||
|
||||
inline wuffs_base__image_decoder*
|
||||
upcast_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)this;
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_quirk_enabled(
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_tga__decoder__set_quirk_enabled(this, a_quirk, a_enabled);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_image_config(
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_image_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame_config(
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_frame_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame(
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
return wuffs_tga__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
|
||||
}
|
||||
|
||||
inline wuffs_base__rect_ie_u32
|
||||
frame_dirty_rect() const {
|
||||
return wuffs_tga__decoder__frame_dirty_rect(this);
|
||||
}
|
||||
|
||||
inline uint32_t
|
||||
num_animation_loops() const {
|
||||
return wuffs_tga__decoder__num_animation_loops(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frame_configs() const {
|
||||
return wuffs_tga__decoder__num_decoded_frame_configs(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frames() const {
|
||||
return wuffs_tga__decoder__num_decoded_frames(this);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
restart_frame(
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
return wuffs_tga__decoder__restart_frame(this, a_index, a_io_position);
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_report_metadata(
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_tga__decoder__set_report_metadata(this, a_fourcc, a_report);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
tell_me_more(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__range_ii_u64
|
||||
workbuf_len() const {
|
||||
return wuffs_tga__decoder__workbuf_len(this);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
}; // struct wuffs_tga__decoder__struct
|
||||
|
||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_wbmp__error__bad_header[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
@@ -10235,9 +10932,13 @@ class DecodeImageCallbacks {
|
||||
// Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).
|
||||
//
|
||||
// Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the
|
||||
// caller is responsible for examining the opening bytes (a prefix) of the
|
||||
// input data. SelectDecoder implementations should not modify those bytes.
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that Wuffs'
|
||||
// standard library did not recognize the image format but if SelectDecoder
|
||||
// was overridden, it may examine the input data's starting bytes and still
|
||||
// provide its own image decoder, e.g. for an exotic image file format that's
|
||||
// not in Wuffs' standard library. The prefix_etc fields have the same
|
||||
// meaning as wuffs_base__magic_number_guess_fourcc arguments. SelectDecoder
|
||||
// implementations should not modify prefix_data's contents.
|
||||
//
|
||||
// SelectDecoder might be called more than once, since some image file
|
||||
// formats can wrap others. For example, a nominal BMP file can actually
|
||||
@@ -10252,9 +10953,12 @@ class DecodeImageCallbacks {
|
||||
// - WUFFS_BASE__FOURCC__GIF
|
||||
// - WUFFS_BASE__FOURCC__NIE
|
||||
// - WUFFS_BASE__FOURCC__PNG
|
||||
// - WUFFS_BASE__FOURCC__TGA
|
||||
// - WUFFS_BASE__FOURCC__WBMP
|
||||
virtual wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
|
||||
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
@@ -15572,14 +16276,134 @@ done:
|
||||
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// ICO doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly ICO.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// first two bytes are 0x00.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/ico/
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[3] != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01: // ICO
|
||||
case 0x02: // CUR
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The Number Of Images should be positive.
|
||||
if (prefix_data.len < 6) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[4] == 0) && (prefix_data.ptr[5] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The first ICONDIRENTRY's fourth byte should be zero.
|
||||
if (prefix_data.len < 10) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[9] != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: have a separate FourCC for CUR?
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
|
||||
// TGA doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly TGA.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// second byte (prefix_data.ptr[1], the Color Map Type byte), is either 0x00 or
|
||||
// 0x01.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/tga/
|
||||
// - https://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 3) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0x09:
|
||||
case 0x0A:
|
||||
case 0x0B:
|
||||
break;
|
||||
default:
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Color Map Entry Size field (if the Color Map Type field
|
||||
// is non-zero) or else all the Color Map fields should be zero.
|
||||
if (prefix_data.len < 8) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[1] != 0x00) {
|
||||
switch (prefix_data.ptr[7]) {
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
|
||||
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Pixel Depth field.
|
||||
if (prefix_data.len < 17) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[16]) {
|
||||
case 0x01:
|
||||
case 0x08:
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0x54474120; // 'TGA 'be
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// This is similar to (but different from):
|
||||
// - the magic/Magdir tables under https://github.com/file/file
|
||||
// - the MIME Sniffing algorithm at https://mimesniff.spec.whatwg.org/
|
||||
|
||||
// table holds the 'magic numbers' (which are actually variable length
|
||||
// strings). The strings may contain NUL bytes, so the "const char* magic"
|
||||
// value starts with the length-minus-1 of the 'magic number'.
|
||||
//
|
||||
// Keep it sorted by magic[1], then magic[0] descending and finally by
|
||||
// magic[2:]. When multiple entries match, the longest one wins.
|
||||
// Keep it sorted by magic[1], then magic[0] descending (prioritizing longer
|
||||
// matches) and finally by magic[2:]. When multiple entries match, the
|
||||
// longest one wins.
|
||||
//
|
||||
// The fourcc field might be negated, in which case there's further
|
||||
// specialization (see § below).
|
||||
@@ -15588,6 +16412,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
const char* magic;
|
||||
} table[] = {
|
||||
{-0x30302020, "\x01\x00\x00"}, // '00 'be
|
||||
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
|
||||
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
|
||||
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
|
||||
{+0x424D5020, "\x01\x42\x4D"}, // BMP
|
||||
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
||||
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
||||
@@ -15595,15 +16422,16 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
|
||||
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
|
||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||
};
|
||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||
|
||||
if (prefix.len == 0) {
|
||||
return -1;
|
||||
if (prefix_data.len == 0) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint8_t pre_first_byte = prefix.ptr[0];
|
||||
uint8_t pre_first_byte = prefix_data.ptr[0];
|
||||
|
||||
int32_t fourcc = 0;
|
||||
size_t i;
|
||||
@@ -15622,11 +16450,11 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
|
||||
const char* mag_remaining_ptr = table[i].magic + 2;
|
||||
uint8_t* pre_remaining_ptr = prefix.ptr + 1;
|
||||
size_t pre_remaining_len = prefix.len - 1;
|
||||
uint8_t* pre_remaining_ptr = prefix_data.ptr + 1;
|
||||
size_t pre_remaining_len = prefix_data.len - 1;
|
||||
if (pre_remaining_len < mag_remaining_len) {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, pre_remaining_len)) {
|
||||
return -1;
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
} else {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, mag_remaining_len)) {
|
||||
@@ -15634,6 +16462,14 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix_data.len < 2) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[1] == 0x00) || (prefix_data.ptr[1] == 0x01)) {
|
||||
return wuffs_base__magic_number_guess_fourcc__maybe_tga(prefix_data,
|
||||
prefix_closed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
match:
|
||||
@@ -15642,26 +16478,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 12) {
|
||||
return -1;
|
||||
if (prefix_data.len < 12) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix_data.ptr + 8);
|
||||
if (x == 0x57454250) { // 'WEBP'be
|
||||
return 0x57454250; // 'WEBP'be
|
||||
}
|
||||
|
||||
} else if (fourcc == 0x30302020) { // '00 'be
|
||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||
if (prefix.len < 4) {
|
||||
return -1;
|
||||
} else if ((prefix.ptr[2] != 0x00) &&
|
||||
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
|
||||
// Unfortunately, some file formats also don't start with a magic
|
||||
// identifier, so we have to use heuristics (where the order matters, the
|
||||
// same as /usr/bin/file's magic/Magdir tables) as best we can. Maybe
|
||||
// it's TGA, ICO/CUR, etc. Maybe it's something else.
|
||||
int32_t tga = wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
prefix_data, prefix_closed);
|
||||
if (tga != 0) {
|
||||
return tga;
|
||||
}
|
||||
int32_t ico = wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
prefix_data, prefix_closed);
|
||||
if (ico != 0) {
|
||||
return ico;
|
||||
}
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[2] != 0x00) &&
|
||||
((prefix_data.ptr[2] >= 0x80) ||
|
||||
(prefix_data.ptr[3] != 0x00))) {
|
||||
// Roughly speaking, this could be a non-degenerate (non-0-width and
|
||||
// non-0-height) WBMP image.
|
||||
return 0x57424D50; // 'WBMP'be
|
||||
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
|
||||
(prefix.ptr[3] == 0x00)) {
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -21850,7 +22698,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -22711,7 +23559,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
(self->private_impl.f_channel_masks[3] == 0));
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
@@ -22725,7 +23573,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -22767,7 +23615,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -22778,7 +23626,8 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -22790,13 +23639,13 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
@@ -22819,7 +23668,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -22833,7 +23682,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -22880,7 +23729,7 @@ wuffs_bmp__decoder__decode_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -22888,13 +23737,11 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
if (coro_susp_point) {
|
||||
v_status = self->private_data.s_decode_frame[0].v_status;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -22906,7 +23753,6 @@ wuffs_bmp__decoder__decode_frame(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
@@ -22931,7 +23777,7 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
|
||||
wuffs_base__pixel_buffer__pixel_format(a_dst),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024)),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048)),
|
||||
wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt),
|
||||
wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024),
|
||||
a_blend);
|
||||
@@ -23006,7 +23852,7 @@ wuffs_bmp__decoder__decode_frame(
|
||||
iop_a_src += self->private_data.s_decode_frame[0].scratch;
|
||||
self->private_impl.f_pending_pad = 0;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -23017,11 +23863,10 @@ wuffs_bmp__decoder__decode_frame(
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
|
||||
self->private_data.s_decode_frame[0].v_status = v_status;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23054,7 +23899,7 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23069,7 +23914,7 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__outer__continue:;
|
||||
while (true) {
|
||||
@@ -23124,7 +23969,7 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23161,7 +24006,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23176,7 +24021,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
v_rle_state = self->private_impl.f_rle_state;
|
||||
label__outer__continue:;
|
||||
@@ -23231,7 +24076,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
v_p0 += 2;
|
||||
}
|
||||
}
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), self->private_impl.f_rle_length));
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_rle_length));
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x, self->private_impl.f_rle_length);
|
||||
v_rle_state = 0;
|
||||
goto label__middle__continue;
|
||||
@@ -23287,7 +24132,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
v_chunk_count -= 1;
|
||||
}
|
||||
v_p0 = wuffs_base__u32__min(v_p0, self->private_impl.f_rle_length);
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), v_p0));
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, v_p0));
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x, v_p0);
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_rle_length, v_p0);
|
||||
}
|
||||
@@ -23386,7 +24231,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23423,7 +24268,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23438,7 +24283,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__outer__continue:;
|
||||
while (true) {
|
||||
@@ -23511,7 +24356,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__inner__continue;
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), (8 * v_p0)));
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -23526,7 +24371,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23559,7 +24404,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23574,7 +24419,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
@@ -23680,7 +24525,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
}
|
||||
}
|
||||
v_p0 = wuffs_base__u32__min(v_p0, wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x));
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), v_p0));
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, v_p0));
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -23694,7 +24539,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23750,7 +24595,7 @@ wuffs_bmp__decoder__num_decoded_frame_configs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -23769,7 +24614,7 @@ wuffs_bmp__decoder__num_decoded_frames(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -23792,13 +24637,13 @@ wuffs_bmp__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
@@ -23897,7 +24742,7 @@ wuffs_bmp__decoder__read_palette(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -24011,7 +24856,7 @@ wuffs_bmp__decoder__read_palette(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -24064,6 +24909,1556 @@ wuffs_bmp__decoder__process_masks(
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_bzip2__error__bad_huffman_code_over_subscribed[] = "#bzip2: bad Huffman code (over-subscribed)";
|
||||
const char wuffs_bzip2__error__bad_huffman_code_under_subscribed[] = "#bzip2: bad Huffman code (under-subscribed)";
|
||||
const char wuffs_bzip2__error__bad_block_header[] = "#bzip2: bad block header";
|
||||
const char wuffs_bzip2__error__bad_block_length[] = "#bzip2: bad block length";
|
||||
const char wuffs_bzip2__error__bad_checksum[] = "#bzip2: bad checksum";
|
||||
const char wuffs_bzip2__error__bad_header[] = "#bzip2: bad header";
|
||||
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
|
||||
const char wuffs_bzip2__error__unsupported_block_randomization[] = "#bzip2: unsupported block randomization";
|
||||
const char wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state[] = "#bzip2: internal error: inconsistent Huffman decoder state";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
static const uint8_t
|
||||
WUFFS_BZIP2__CLAMP_TO_5[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
0, 1, 2, 3, 4, 5, 5, 5,
|
||||
};
|
||||
|
||||
static const uint32_t
|
||||
WUFFS_BZIP2__REV_CRC32_TABLE[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
0, 79764919, 159529838, 222504665, 319059676, 398814059, 445009330, 507990021,
|
||||
638119352, 583659535, 797628118, 726387553, 890018660, 835552979, 1015980042, 944750013,
|
||||
1276238704, 1221641927, 1167319070, 1095957929, 1595256236, 1540665371, 1452775106, 1381403509,
|
||||
1780037320, 1859660671, 1671105958, 1733955601, 2031960084, 2111593891, 1889500026, 1952343757,
|
||||
2552477408, 2632100695, 2443283854, 2506133561, 2334638140, 2414271883, 2191915858, 2254759653,
|
||||
3190512472, 3135915759, 3081330742, 3009969537, 2905550212, 2850959411, 2762807018, 2691435357,
|
||||
3560074640, 3505614887, 3719321342, 3648080713, 3342211916, 3287746299, 3467911202, 3396681109,
|
||||
4063920168, 4143685023, 4223187782, 4286162673, 3779000052, 3858754371, 3904687514, 3967668269,
|
||||
881225847, 809987520, 1023691545, 969234094, 662832811, 591600412, 771767749, 717299826,
|
||||
311336399, 374308984, 453813921, 533576470, 25881363, 88864420, 134795389, 214552010,
|
||||
2023205639, 2086057648, 1897238633, 1976864222, 1804852699, 1867694188, 1645340341, 1724971778,
|
||||
1587496639, 1516133128, 1461550545, 1406951526, 1302016099, 1230646740, 1142491917, 1087903418,
|
||||
2896545431, 2825181984, 2770861561, 2716262478, 3215044683, 3143675388, 3055782693, 3001194130,
|
||||
2326604591, 2389456536, 2200899649, 2280525302, 2578013683, 2640855108, 2418763421, 2498394922,
|
||||
3769900519, 3832873040, 3912640137, 3992402750, 4088425275, 4151408268, 4197601365, 4277358050,
|
||||
3334271071, 3263032808, 3476998961, 3422541446, 3585640067, 3514407732, 3694837229, 3640369242,
|
||||
1762451694, 1842216281, 1619975040, 1682949687, 2047383090, 2127137669, 1938468188, 2001449195,
|
||||
1325665622, 1271206113, 1183200824, 1111960463, 1543535498, 1489069629, 1434599652, 1363369299,
|
||||
622672798, 568075817, 748617968, 677256519, 907627842, 853037301, 1067152940, 995781531,
|
||||
51762726, 131386257, 177728840, 240578815, 269590778, 349224269, 429104020, 491947555,
|
||||
4046411278, 4126034873, 4172115296, 4234965207, 3794477266, 3874110821, 3953728444, 4016571915,
|
||||
3609705398, 3555108353, 3735388376, 3664026991, 3290680682, 3236090077, 3449943556, 3378572211,
|
||||
3174993278, 3120533705, 3032266256, 2961025959, 2923101090, 2868635157, 2813903052, 2742672763,
|
||||
2604032198, 2683796849, 2461293480, 2524268063, 2284983834, 2364738477, 2175806836, 2238787779,
|
||||
1569362073, 1498123566, 1409854455, 1355396672, 1317987909, 1246755826, 1192025387, 1137557660,
|
||||
2072149281, 2135122070, 1912620623, 1992383480, 1753615357, 1816598090, 1627664531, 1707420964,
|
||||
295390185, 358241886, 404320391, 483945776, 43990325, 106832002, 186451547, 266083308,
|
||||
932423249, 861060070, 1041341759, 986742920, 613929101, 542559546, 756411363, 701822548,
|
||||
3316196985, 3244833742, 3425377559, 3370778784, 3601682597, 3530312978, 3744426955, 3689838204,
|
||||
3819031489, 3881883254, 3928223919, 4007849240, 4037393693, 4100235434, 4180117107, 4259748804,
|
||||
2310601993, 2373574846, 2151335527, 2231098320, 2596047829, 2659030626, 2470359227, 2550115596,
|
||||
2947551409, 2876312838, 2788305887, 2733848168, 3165939309, 3094707162, 3040238851, 2985771188,
|
||||
};
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__prepare_block(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__read_code_lengths(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__build_huffman_tree(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which);
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__build_huffman_table(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which);
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__invert_bwt(
|
||||
wuffs_bzip2__decoder* self);
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__flush_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__flush_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__io_transformer__func_ptrs
|
||||
wuffs_bzip2__decoder__func_ptrs_for__wuffs_base__io_transformer = {
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_bzip2__decoder__set_quirk_enabled),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__slice_u8))(&wuffs_bzip2__decoder__transform_io),
|
||||
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_bzip2__decoder__workbuf_len),
|
||||
};
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_bzip2__decoder__initialize(
|
||||
wuffs_bzip2__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options){
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (sizeof(*self) != sizeof_star_self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
|
||||
}
|
||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
|
||||
}
|
||||
|
||||
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
|
||||
// The whole point of this if-check is to detect an uninitialized *self.
|
||||
// We disable the warning on GCC. Clang-5.0 does not have this warning.
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
if (self->private_impl.magic != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
|
||||
}
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
} else {
|
||||
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
|
||||
} else {
|
||||
memset(&(self->private_impl), 0, sizeof(self->private_impl));
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__io_transformer.vtable_name =
|
||||
wuffs_base__io_transformer__vtable_name;
|
||||
self->private_impl.vtable_for__wuffs_base__io_transformer.function_pointers =
|
||||
(const void*)(&wuffs_bzip2__decoder__func_ptrs_for__wuffs_base__io_transformer);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
wuffs_bzip2__decoder*
|
||||
wuffs_bzip2__decoder__alloc() {
|
||||
wuffs_bzip2__decoder* x =
|
||||
(wuffs_bzip2__decoder*)(calloc(sizeof(wuffs_bzip2__decoder), 1));
|
||||
if (!x) {
|
||||
return NULL;
|
||||
}
|
||||
if (wuffs_bzip2__decoder__initialize(
|
||||
x, sizeof(wuffs_bzip2__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
|
||||
free(x);
|
||||
return NULL;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_bzip2__decoder() {
|
||||
return sizeof(wuffs_bzip2__decoder);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func bzip2.decoder.set_quirk_enabled
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__set_quirk_enabled(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
if (a_quirk == 1) {
|
||||
self->private_impl.f_ignore_checksum = a_enabled;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.workbuf_len
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_bzip2__decoder__workbuf_len(
|
||||
const wuffs_bzip2__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_range_ii_u64(0, 0);
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.transform_io
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_bzip2__decoder__transform_io(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 1)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint64_t v_tag = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
uint32_t v_final_checksum_want = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_transform_io[0].v_i;
|
||||
v_tag = self->private_data.s_transform_io[0].v_tag;
|
||||
v_final_checksum_want = self->private_data.s_transform_io[0].v_final_checksum_want;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
if (v_c != 66) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
v_c = t_1;
|
||||
}
|
||||
if (v_c != 90) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
v_c = t_2;
|
||||
}
|
||||
if (v_c != 104) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
if ((v_c < 49) || (57 < v_c)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_max_incl_block_size = (((uint32_t)((v_c - 48))) * 100000);
|
||||
while (true) {
|
||||
v_tag = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 48) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_tag <<= 1;
|
||||
v_tag |= ((uint64_t)((self->private_impl.f_bits >> 31)));
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_tag == 25779555029136) {
|
||||
goto label__0__break;
|
||||
} else if (v_tag != 54156738319193) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_bzip2__decoder__prepare_block(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_block_size = 0;
|
||||
self->private_impl.f_decode_huffman_finished = false;
|
||||
self->private_impl.f_decode_huffman_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[0] & 7)];
|
||||
self->private_impl.f_decode_huffman_ticks = 50;
|
||||
self->private_impl.f_decode_huffman_section = 0;
|
||||
self->private_impl.f_decode_huffman_run_shift = 0;
|
||||
while ( ! self->private_impl.f_decode_huffman_finished) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_status = wuffs_bzip2__decoder__decode_huffman_fast(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (wuffs_base__status__is_error(&v_status)) {
|
||||
status = v_status;
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_decode_huffman_finished) {
|
||||
goto label__1__break;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_bzip2__decoder__decode_huffman_slow(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
label__1__break:;
|
||||
wuffs_bzip2__decoder__invert_bwt(self);
|
||||
self->private_impl.f_block_checksum_have = 4294967295;
|
||||
if (self->private_impl.f_original_pointer >= self->private_impl.f_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_flush_pointer = (self->private_data.f_bwt[self->private_impl.f_original_pointer] >> 12);
|
||||
self->private_impl.f_flush_repeat_count = 0;
|
||||
self->private_impl.f_flush_prev = 0;
|
||||
while (self->private_impl.f_block_size > 0) {
|
||||
wuffs_bzip2__decoder__flush_fast(self, a_dst);
|
||||
if (self->private_impl.f_block_size <= 0) {
|
||||
goto label__2__break;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_bzip2__decoder__flush_slow(self, a_dst);
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
label__2__break:;
|
||||
self->private_impl.f_block_checksum_have ^= 4294967295;
|
||||
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_block_checksum_have != self->private_impl.f_block_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_final_checksum_have = (self->private_impl.f_block_checksum_have ^ ((self->private_impl.f_final_checksum_have >> 31) | ((uint32_t)(self->private_impl.f_final_checksum_have << 1))));
|
||||
}
|
||||
label__0__break:;
|
||||
v_final_checksum_want = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 32) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_final_checksum_want <<= 1;
|
||||
v_final_checksum_want |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_final_checksum_have != v_final_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_transform_io[0].v_i = v_i;
|
||||
self->private_data.s_transform_io[0].v_tag = v_tag;
|
||||
self->private_data.s_transform_io[0].v_final_checksum_want = v_final_checksum_want;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.prepare_block
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__prepare_block(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_selector = 0;
|
||||
uint32_t v_sel_ff = 0;
|
||||
uint8_t v_movee = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_prepare_block[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_prepare_block[0].v_i;
|
||||
v_selector = self->private_data.s_prepare_block[0].v_selector;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_block_checksum_want = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 32) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_impl.f_block_checksum_want <<= 1;
|
||||
self->private_impl.f_block_checksum_want |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
v_c = t_1;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__unsupported_block_randomization);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
self->private_impl.f_original_pointer = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 24) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
v_c = t_2;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_impl.f_original_pointer <<= 1;
|
||||
self->private_impl.f_original_pointer |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_presence[v_i] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) != 0) {
|
||||
self->private_data.f_presence[v_i] = 1;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 16;
|
||||
}
|
||||
self->private_data.f_scratch = 0;
|
||||
v_i = 0;
|
||||
label__0__continue:;
|
||||
while (v_i < 256) {
|
||||
if (self->private_data.f_presence[v_i] == 0) {
|
||||
v_i += 16;
|
||||
goto label__0__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_data.f_scratch += (self->private_impl.f_bits >> 31);
|
||||
self->private_data.f_presence[(v_i & 255)] = ((uint8_t)((self->private_impl.f_bits >> 31)));
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
if ((v_i & 15) == 0) {
|
||||
goto label__1__break;
|
||||
}
|
||||
}
|
||||
label__1__break:;
|
||||
}
|
||||
if ((self->private_data.f_scratch < 1) || (256 < self->private_data.f_scratch)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_num_symbols = (self->private_data.f_scratch + 2);
|
||||
self->private_data.f_scratch = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 3) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_data.f_scratch <<= 1;
|
||||
self->private_data.f_scratch |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ((self->private_data.f_scratch < 2) || (6 < self->private_data.f_scratch)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_num_huffman_codes = self->private_data.f_scratch;
|
||||
self->private_data.f_scratch = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 15) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_data.f_scratch <<= 1;
|
||||
self->private_data.f_scratch |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ((self->private_data.f_scratch < 1) || (18001 < self->private_data.f_scratch)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_num_sections = self->private_data.f_scratch;
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_huffman_codes) {
|
||||
self->private_data.f_mtft[v_i] = ((uint8_t)(v_i));
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_sections) {
|
||||
v_selector = 0;
|
||||
while (true) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_7 = *iop_a_src++;
|
||||
v_c = t_7;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) == 0) {
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
goto label__2__break;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_selector += 1;
|
||||
if (v_selector >= self->private_impl.f_num_huffman_codes) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
label__2__break:;
|
||||
if (v_selector == 0) {
|
||||
self->private_data.f_huffman_selectors[v_i] = self->private_data.f_mtft[0];
|
||||
} else {
|
||||
v_sel_ff = (v_selector & 255);
|
||||
v_movee = self->private_data.f_mtft[v_sel_ff];
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_sel_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_sel_ff));
|
||||
self->private_data.f_mtft[0] = v_movee;
|
||||
self->private_data.f_huffman_selectors[v_i] = v_movee;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_huffman_codes) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_bzip2__decoder__read_code_lengths(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
v_status = wuffs_bzip2__decoder__build_huffman_tree(self, v_i);
|
||||
if (wuffs_base__status__is_error(&v_status)) {
|
||||
status = v_status;
|
||||
goto exit;
|
||||
}
|
||||
wuffs_bzip2__decoder__build_huffman_table(self, v_i);
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
v_j = 0;
|
||||
while (v_i < 256) {
|
||||
if (self->private_data.f_presence[v_i] != 0) {
|
||||
self->private_data.f_mtft[(v_j & 255)] = ((uint8_t)(v_i));
|
||||
v_j += 1;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_letter_counts[v_i] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_prepare_block[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_prepare_block[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_prepare_block[0].v_i = v_i;
|
||||
self->private_data.s_prepare_block[0].v_selector = v_selector;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.read_code_lengths
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__read_code_lengths(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_code_length = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_read_code_lengths[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_read_code_lengths[0].v_i;
|
||||
v_code_length = self->private_data.s_read_code_lengths[0].v_code_length;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_code_lengths_bitmask = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 5) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_code_length <<= 1;
|
||||
v_code_length |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_symbols) {
|
||||
while (true) {
|
||||
if ((v_code_length < 1) || (20 < v_code_length)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
v_c = t_1;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) == 0) {
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
goto label__0__break;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
v_c = t_2;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) == 0) {
|
||||
v_code_length += 1;
|
||||
} else {
|
||||
v_code_length -= 1;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
}
|
||||
label__0__break:;
|
||||
self->private_impl.f_code_lengths_bitmask |= (((uint32_t)(1)) << (v_code_length & 31));
|
||||
self->private_data.f_bwt[v_i] = v_code_length;
|
||||
v_i += 1;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_read_code_lengths[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_read_code_lengths[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_read_code_lengths[0].v_i = v_i;
|
||||
self->private_data.s_read_code_lengths[0].v_code_length = v_code_length;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.build_huffman_tree
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__build_huffman_tree(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which) {
|
||||
uint32_t v_code_length = 0;
|
||||
uint32_t v_symbol_index = 0;
|
||||
uint32_t v_num_branch_nodes = 0;
|
||||
uint32_t v_stack_height = 0;
|
||||
uint32_t v_stack_values[21] = {0};
|
||||
uint32_t v_node_index = 0;
|
||||
uint16_t v_leaf_value = 0;
|
||||
|
||||
self->private_data.f_huffman_trees[a_which][0][0] = 0;
|
||||
self->private_data.f_huffman_trees[a_which][0][1] = 0;
|
||||
v_num_branch_nodes = 1;
|
||||
v_stack_height = 1;
|
||||
v_stack_values[0] = 0;
|
||||
v_code_length = 1;
|
||||
label__0__continue:;
|
||||
while (v_code_length <= 20) {
|
||||
if ((self->private_impl.f_code_lengths_bitmask & (((uint32_t)(1)) << v_code_length)) == 0) {
|
||||
v_code_length += 1;
|
||||
goto label__0__continue;
|
||||
}
|
||||
v_symbol_index = 0;
|
||||
label__1__continue:;
|
||||
while (v_symbol_index < self->private_impl.f_num_symbols) {
|
||||
if (self->private_data.f_bwt[v_symbol_index] != v_code_length) {
|
||||
v_symbol_index += 1;
|
||||
goto label__1__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (v_stack_height <= 0) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__bad_huffman_code_over_subscribed);
|
||||
} else if (v_stack_height >= v_code_length) {
|
||||
goto label__2__break;
|
||||
}
|
||||
v_node_index = v_stack_values[(v_stack_height - 1)];
|
||||
if (self->private_data.f_huffman_trees[a_which][v_node_index][0] == 0) {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][0] = ((uint16_t)(v_num_branch_nodes));
|
||||
} else {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][1] = ((uint16_t)(v_num_branch_nodes));
|
||||
}
|
||||
if (v_num_branch_nodes >= 257) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
v_stack_values[v_stack_height] = v_num_branch_nodes;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_branch_nodes][0] = 0;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_branch_nodes][1] = 0;
|
||||
v_num_branch_nodes += 1;
|
||||
v_stack_height += 1;
|
||||
}
|
||||
label__2__break:;
|
||||
v_node_index = v_stack_values[(v_stack_height - 1)];
|
||||
if (v_symbol_index < 2) {
|
||||
v_leaf_value = ((uint16_t)((769 + v_symbol_index)));
|
||||
} else if ((v_symbol_index + 1) < self->private_impl.f_num_symbols) {
|
||||
v_leaf_value = ((uint16_t)((511 + v_symbol_index)));
|
||||
} else {
|
||||
v_leaf_value = 768;
|
||||
}
|
||||
if (self->private_data.f_huffman_trees[a_which][v_node_index][0] == 0) {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][0] = v_leaf_value;
|
||||
} else {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][1] = v_leaf_value;
|
||||
v_stack_height -= 1;
|
||||
while (v_stack_height > 0) {
|
||||
v_node_index = v_stack_values[(v_stack_height - 1)];
|
||||
if (self->private_data.f_huffman_trees[a_which][v_node_index][1] == 0) {
|
||||
goto label__3__break;
|
||||
}
|
||||
v_stack_height -= 1;
|
||||
}
|
||||
label__3__break:;
|
||||
}
|
||||
v_symbol_index += 1;
|
||||
}
|
||||
v_code_length += 1;
|
||||
}
|
||||
if (v_stack_height != 0) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.build_huffman_table
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__build_huffman_table(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which) {
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_bits = 0;
|
||||
uint16_t v_n_bits = 0;
|
||||
uint16_t v_child = 0;
|
||||
|
||||
while (v_i < 256) {
|
||||
v_bits = (v_i << 24);
|
||||
v_n_bits = 0;
|
||||
v_child = 0;
|
||||
while ((v_child < 257) && (v_n_bits < 8)) {
|
||||
v_child = self->private_data.f_huffman_trees[a_which][v_child][(v_bits >> 31)];
|
||||
v_bits <<= 1;
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
v_n_bits += 1;
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
self->private_data.f_huffman_tables[a_which][v_i] = ((uint16_t)((v_child | (v_n_bits << 12))));
|
||||
v_i += 1;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.invert_bwt
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__invert_bwt(
|
||||
wuffs_bzip2__decoder* self) {
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_letter = 0;
|
||||
uint32_t v_sum = 0;
|
||||
uint32_t v_old_sum = 0;
|
||||
|
||||
v_sum = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
v_old_sum = v_sum;
|
||||
v_sum += self->private_data.f_letter_counts[v_i];
|
||||
self->private_data.f_letter_counts[v_i] = v_old_sum;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_block_size) {
|
||||
v_letter = (self->private_data.f_bwt[v_i] & 255);
|
||||
self->private_data.f_bwt[(self->private_data.f_letter_counts[v_letter] & 1048575)] |= (v_i << 12);
|
||||
self->private_data.f_letter_counts[v_letter] += 1;
|
||||
v_i += 1;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.flush_fast
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__flush_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst) {
|
||||
uint32_t v_flush_pointer = 0;
|
||||
uint32_t v_flush_repeat_count = 0;
|
||||
uint8_t v_flush_prev = 0;
|
||||
uint32_t v_block_checksum_have = 0;
|
||||
uint32_t v_block_size = 0;
|
||||
uint32_t v_entry = 0;
|
||||
uint8_t v_curr = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
io2_a_dst = io0_a_dst + a_dst->data.len;
|
||||
if (a_dst->meta.closed) {
|
||||
io2_a_dst = iop_a_dst;
|
||||
}
|
||||
}
|
||||
|
||||
v_flush_pointer = self->private_impl.f_flush_pointer;
|
||||
v_flush_repeat_count = self->private_impl.f_flush_repeat_count;
|
||||
v_flush_prev = self->private_impl.f_flush_prev;
|
||||
v_block_checksum_have = self->private_impl.f_block_checksum_have;
|
||||
v_block_size = self->private_impl.f_block_size;
|
||||
while ((v_block_size > 0) && (((uint64_t)(io2_a_dst - iop_a_dst)) >= 255)) {
|
||||
if (v_flush_repeat_count < 4) {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
if (v_curr == v_flush_prev) {
|
||||
v_flush_repeat_count += 1;
|
||||
} else {
|
||||
v_flush_repeat_count = 1;
|
||||
}
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_curr), iop_a_dst += 1);
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
} else {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
v_flush_repeat_count = ((uint32_t)(v_curr));
|
||||
while (v_flush_repeat_count > 0) {
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) > 0) {
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_flush_prev), iop_a_dst += 1);
|
||||
}
|
||||
v_flush_repeat_count -= 1;
|
||||
}
|
||||
v_flush_repeat_count = 0;
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_flush_pointer = v_flush_pointer;
|
||||
self->private_impl.f_flush_repeat_count = v_flush_repeat_count;
|
||||
self->private_impl.f_flush_prev = v_flush_prev;
|
||||
self->private_impl.f_block_checksum_have = v_block_checksum_have;
|
||||
if (v_block_size <= 900000) {
|
||||
self->private_impl.f_block_size = v_block_size;
|
||||
}
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.flush_slow
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__flush_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_flush_pointer = 0;
|
||||
uint32_t v_flush_repeat_count = 0;
|
||||
uint8_t v_flush_prev = 0;
|
||||
uint32_t v_block_checksum_have = 0;
|
||||
uint32_t v_block_size = 0;
|
||||
uint32_t v_entry = 0;
|
||||
uint8_t v_curr = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
io2_a_dst = io0_a_dst + a_dst->data.len;
|
||||
if (a_dst->meta.closed) {
|
||||
io2_a_dst = iop_a_dst;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_flush_slow[0];
|
||||
if (coro_susp_point) {
|
||||
v_flush_pointer = self->private_data.s_flush_slow[0].v_flush_pointer;
|
||||
v_flush_repeat_count = self->private_data.s_flush_slow[0].v_flush_repeat_count;
|
||||
v_flush_prev = self->private_data.s_flush_slow[0].v_flush_prev;
|
||||
v_block_checksum_have = self->private_data.s_flush_slow[0].v_block_checksum_have;
|
||||
v_block_size = self->private_data.s_flush_slow[0].v_block_size;
|
||||
v_curr = self->private_data.s_flush_slow[0].v_curr;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
v_flush_pointer = self->private_impl.f_flush_pointer;
|
||||
v_flush_repeat_count = self->private_impl.f_flush_repeat_count;
|
||||
v_flush_prev = self->private_impl.f_flush_prev;
|
||||
v_block_checksum_have = self->private_impl.f_block_checksum_have;
|
||||
v_block_size = self->private_impl.f_block_size;
|
||||
while ((v_block_size > 0) && ! (self->private_impl.p_flush_slow[0] != 0)) {
|
||||
if (v_flush_repeat_count < 4) {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
if (v_curr == v_flush_prev) {
|
||||
v_flush_repeat_count += 1;
|
||||
} else {
|
||||
v_flush_repeat_count = 1;
|
||||
}
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
self->private_data.s_flush_slow[0].scratch = v_curr;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (iop_a_dst == io2_a_dst) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
goto suspend;
|
||||
}
|
||||
*iop_a_dst++ = ((uint8_t)(self->private_data.s_flush_slow[0].scratch));
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
} else {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
v_flush_repeat_count = ((uint32_t)(v_curr));
|
||||
while (v_flush_repeat_count > 0) {
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
self->private_data.s_flush_slow[0].scratch = v_flush_prev;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (iop_a_dst == io2_a_dst) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
goto suspend;
|
||||
}
|
||||
*iop_a_dst++ = ((uint8_t)(self->private_data.s_flush_slow[0].scratch));
|
||||
v_flush_repeat_count -= 1;
|
||||
}
|
||||
v_flush_repeat_count = 0;
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_flush_pointer = v_flush_pointer;
|
||||
self->private_impl.f_flush_repeat_count = v_flush_repeat_count;
|
||||
self->private_impl.f_flush_prev = v_flush_prev;
|
||||
self->private_impl.f_block_checksum_have = v_block_checksum_have;
|
||||
if (v_block_size <= 900000) {
|
||||
self->private_impl.f_block_size = v_block_size;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_flush_slow[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_flush_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_flush_slow[0].v_flush_pointer = v_flush_pointer;
|
||||
self->private_data.s_flush_slow[0].v_flush_repeat_count = v_flush_repeat_count;
|
||||
self->private_data.s_flush_slow[0].v_flush_prev = v_flush_prev;
|
||||
self->private_data.s_flush_slow[0].v_block_checksum_have = v_block_checksum_have;
|
||||
self->private_data.s_flush_slow[0].v_block_size = v_block_size;
|
||||
self->private_data.s_flush_slow[0].v_curr = v_curr;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.decode_huffman_fast
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_bits = 0;
|
||||
uint32_t v_n_bits = 0;
|
||||
uint32_t v_block_size = 0;
|
||||
uint8_t v_which = 0;
|
||||
uint32_t v_ticks = 0;
|
||||
uint32_t v_section = 0;
|
||||
uint32_t v_run_shift = 0;
|
||||
uint16_t v_table_entry = 0;
|
||||
uint16_t v_child = 0;
|
||||
uint32_t v_child_ff = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_output = 0;
|
||||
uint32_t v_run = 0;
|
||||
uint32_t v_mtft0 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_block_size = self->private_impl.f_block_size;
|
||||
v_which = self->private_impl.f_decode_huffman_which;
|
||||
v_ticks = self->private_impl.f_decode_huffman_ticks;
|
||||
v_section = self->private_impl.f_decode_huffman_section;
|
||||
v_run_shift = self->private_impl.f_decode_huffman_run_shift;
|
||||
label__outer__continue:;
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) >= 4) {
|
||||
if (v_ticks > 0) {
|
||||
v_ticks -= 1;
|
||||
} else {
|
||||
v_ticks = 49;
|
||||
v_section += 1;
|
||||
if (v_section >= self->private_impl.f_num_sections) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_number_of_sections);
|
||||
goto exit;
|
||||
}
|
||||
v_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(v_section & 32767)] & 7)];
|
||||
}
|
||||
v_bits |= (wuffs_base__peek_u32be__no_bounds_check(iop_a_src) >> v_n_bits);
|
||||
iop_a_src += ((31 - v_n_bits) >> 3);
|
||||
v_n_bits |= 24;
|
||||
v_table_entry = self->private_data.f_huffman_tables[v_which][(v_bits >> 24)];
|
||||
v_bits <<= (v_table_entry >> 12);
|
||||
v_n_bits -= ((uint32_t)((v_table_entry >> 12)));
|
||||
v_child = (v_table_entry & 1023);
|
||||
while (v_child < 257) {
|
||||
v_child = self->private_data.f_huffman_trees[v_which][v_child][(v_bits >> 31)];
|
||||
v_bits <<= 1;
|
||||
if (v_n_bits <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
v_n_bits -= 1;
|
||||
}
|
||||
if (v_child < 768) {
|
||||
v_child_ff = ((uint32_t)((v_child & 255)));
|
||||
v_output = ((uint32_t)(self->private_data.f_mtft[v_child_ff]));
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_child_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_child_ff));
|
||||
self->private_data.f_mtft[0] = ((uint8_t)(v_output));
|
||||
self->private_data.f_letter_counts[v_output] += 1;
|
||||
self->private_data.f_bwt[v_block_size] = v_output;
|
||||
if (v_block_size >= self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_block_size += 1;
|
||||
v_run_shift = 0;
|
||||
goto label__outer__continue;
|
||||
} else if (v_child == 768) {
|
||||
self->private_impl.f_decode_huffman_finished = true;
|
||||
goto label__outer__break;
|
||||
}
|
||||
if (v_run_shift >= 23) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_run = ((((uint32_t)(v_child)) & 3) << v_run_shift);
|
||||
v_run_shift += 1;
|
||||
v_i = v_block_size;
|
||||
v_j = (v_run + v_block_size);
|
||||
if (v_j > self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_block_size = v_j;
|
||||
v_mtft0 = ((uint32_t)(self->private_data.f_mtft[0]));
|
||||
self->private_data.f_letter_counts[v_mtft0] += v_run;
|
||||
while (v_i < v_j) {
|
||||
self->private_data.f_bwt[v_i] = v_mtft0;
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
label__outer__break:;
|
||||
self->private_impl.f_bits = v_bits;
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
self->private_impl.f_block_size = v_block_size;
|
||||
self->private_impl.f_decode_huffman_which = v_which;
|
||||
self->private_impl.f_decode_huffman_ticks = v_ticks;
|
||||
self->private_impl.f_decode_huffman_section = v_section;
|
||||
self->private_impl.f_decode_huffman_run_shift = v_run_shift;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.decode_huffman_slow
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_node_index = 0;
|
||||
uint16_t v_child = 0;
|
||||
uint32_t v_child_ff = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_output = 0;
|
||||
uint32_t v_run = 0;
|
||||
uint32_t v_mtft0 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_huffman_slow[0];
|
||||
if (coro_susp_point) {
|
||||
v_node_index = self->private_data.s_decode_huffman_slow[0].v_node_index;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
while ( ! (self->private_impl.p_decode_huffman_slow[0] != 0)) {
|
||||
if (self->private_impl.f_decode_huffman_ticks > 0) {
|
||||
self->private_impl.f_decode_huffman_ticks -= 1;
|
||||
} else {
|
||||
self->private_impl.f_decode_huffman_ticks = 49;
|
||||
self->private_impl.f_decode_huffman_section += 1;
|
||||
if (self->private_impl.f_decode_huffman_section >= self->private_impl.f_num_sections) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_number_of_sections);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_decode_huffman_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(self->private_impl.f_decode_huffman_section & 32767)] & 7)];
|
||||
}
|
||||
v_node_index = 0;
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_child = self->private_data.f_huffman_trees[self->private_impl.f_decode_huffman_which][v_node_index][(self->private_impl.f_bits >> 31)];
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
if (v_child < 257) {
|
||||
v_node_index = ((uint32_t)(v_child));
|
||||
goto label__0__continue;
|
||||
} else if (v_child < 768) {
|
||||
v_child_ff = ((uint32_t)((v_child & 255)));
|
||||
v_output = ((uint32_t)(self->private_data.f_mtft[v_child_ff]));
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_child_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_child_ff));
|
||||
self->private_data.f_mtft[0] = ((uint8_t)(v_output));
|
||||
self->private_data.f_letter_counts[v_output] += 1;
|
||||
self->private_data.f_bwt[self->private_impl.f_block_size] = v_output;
|
||||
if (self->private_impl.f_block_size >= self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_block_size += 1;
|
||||
self->private_impl.f_decode_huffman_run_shift = 0;
|
||||
goto label__0__break;
|
||||
} else if (v_child == 768) {
|
||||
self->private_impl.f_decode_huffman_finished = true;
|
||||
goto label__outer__break;
|
||||
}
|
||||
if (self->private_impl.f_decode_huffman_run_shift >= 23) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_run = ((((uint32_t)(v_child)) & 3) << self->private_impl.f_decode_huffman_run_shift);
|
||||
self->private_impl.f_decode_huffman_run_shift += 1;
|
||||
v_i = self->private_impl.f_block_size;
|
||||
v_j = (v_run + self->private_impl.f_block_size);
|
||||
if (v_j > self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_block_size = v_j;
|
||||
v_mtft0 = ((uint32_t)(self->private_data.f_mtft[0]));
|
||||
self->private_data.f_letter_counts[v_mtft0] += v_run;
|
||||
while (v_i < v_j) {
|
||||
self->private_data.f_bwt[v_i] = v_mtft0;
|
||||
v_i += 1;
|
||||
}
|
||||
goto label__0__break;
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
label__outer__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_huffman_slow[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_huffman_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_huffman_slow[0].v_node_index = v_node_index;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CBOR)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
@@ -24252,7 +26647,7 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -24265,7 +26660,7 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -24276,7 +26671,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
if (coro_susp_point) {
|
||||
v_string_length = self->private_data.s_decode_tokens[0].v_string_length;
|
||||
v_depth = self->private_data.s_decode_tokens[0].v_depth;
|
||||
v_token_length = self->private_data.s_decode_tokens[0].v_token_length;
|
||||
v_tagged = self->private_data.s_decode_tokens[0].v_tagged;
|
||||
v_indefinite_string_major_type = self->private_data.s_decode_tokens[0].v_indefinite_string_major_type;
|
||||
}
|
||||
@@ -24365,8 +26759,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
v_c_major = 0;
|
||||
v_c_minor = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_cbor__error__internal_error_inconsistent_i_o);
|
||||
@@ -24787,16 +27179,15 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_decode_tokens[0].v_string_length = v_string_length;
|
||||
self->private_data.s_decode_tokens[0].v_depth = v_depth;
|
||||
self->private_data.s_decode_tokens[0].v_token_length = v_token_length;
|
||||
self->private_data.s_decode_tokens[0].v_tagged = v_tagged;
|
||||
self->private_data.s_decode_tokens[0].v_indefinite_string_major_type = v_indefinite_string_major_type;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26211,7 +28602,7 @@ wuffs_deflate__decoder__add_history(
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), v_s);
|
||||
self->private_impl.f_history_index = 32768;
|
||||
} else {
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (self->private_impl.f_history_index & 32767)), v_s);
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_history, (self->private_impl.f_history_index & 32767), 32768), v_s);
|
||||
if (v_n_copied < ((uint64_t)(v_s.len))) {
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, v_n_copied);
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), v_s);
|
||||
@@ -26224,7 +28615,7 @@ wuffs_deflate__decoder__add_history(
|
||||
self->private_impl.f_history_index = ((self->private_impl.f_history_index & 32767) + ((uint32_t)((v_n_copied & 32767))) + v_already_full);
|
||||
}
|
||||
}
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8((self->private_data.f_history) + 32768, 257), wuffs_base__make_slice_u8(self->private_data.f_history, 33025));
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_history, 32768, 33025), wuffs_base__make_slice_u8(self->private_data.f_history, 33025));
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
@@ -26290,7 +28681,7 @@ wuffs_deflate__decoder__transform_io(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -26349,7 +28740,7 @@ wuffs_deflate__decoder__transform_io(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26377,7 +28768,7 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -26506,7 +28897,7 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26529,7 +28920,7 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -26542,7 +28933,7 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -26625,10 +29016,10 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26712,7 +29103,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -26728,7 +29119,6 @@ wuffs_deflate__decoder__init_dynamic_huffman(
|
||||
v_n_clen = self->private_data.s_init_dynamic_huffman[0].v_n_clen;
|
||||
v_i = self->private_data.s_init_dynamic_huffman[0].v_i;
|
||||
v_mask = self->private_data.s_init_dynamic_huffman[0].v_mask;
|
||||
v_table_entry = self->private_data.s_init_dynamic_huffman[0].v_table_entry;
|
||||
v_n_extra_bits = self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits;
|
||||
v_rep_symbol = self->private_data.s_init_dynamic_huffman[0].v_rep_symbol;
|
||||
v_rep_count = self->private_data.s_init_dynamic_huffman[0].v_rep_count;
|
||||
@@ -26928,14 +29318,13 @@ wuffs_deflate__decoder__init_dynamic_huffman(
|
||||
self->private_data.s_init_dynamic_huffman[0].v_n_clen = v_n_clen;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_i = v_i;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_mask = v_mask;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_table_entry = v_table_entry;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits = v_n_extra_bits;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_rep_symbol = v_rep_symbol;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_rep_count = v_rep_count;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27228,7 +29617,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27241,7 +29630,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27357,7 +29746,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27402,10 +29791,10 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27441,7 +29830,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27454,7 +29843,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27622,7 +30011,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27660,10 +30049,10 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27705,7 +30094,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27718,7 +30107,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27834,7 +30223,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27879,10 +30268,10 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27922,7 +30311,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27935,7 +30324,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27946,7 +30335,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
if (coro_susp_point) {
|
||||
v_bits = self->private_data.s_decode_huffman_slow[0].v_bits;
|
||||
v_n_bits = self->private_data.s_decode_huffman_slow[0].v_n_bits;
|
||||
v_table_entry = self->private_data.s_decode_huffman_slow[0].v_table_entry;
|
||||
v_table_entry_n_bits = self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits;
|
||||
v_lmask = self->private_data.s_decode_huffman_slow[0].v_lmask;
|
||||
v_dmask = self->private_data.s_decode_huffman_slow[0].v_dmask;
|
||||
@@ -27954,7 +30342,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_redir_mask = self->private_data.s_decode_huffman_slow[0].v_redir_mask;
|
||||
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
|
||||
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
|
||||
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28166,7 +30553,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_n_copied < v_hlen) {
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
@@ -28206,7 +30593,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
self->private_impl.p_decode_huffman_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_huffman_slow[0].v_bits = v_bits;
|
||||
self->private_data.s_decode_huffman_slow[0].v_n_bits = v_n_bits;
|
||||
self->private_data.s_decode_huffman_slow[0].v_table_entry = v_table_entry;
|
||||
self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits = v_table_entry_n_bits;
|
||||
self->private_data.s_decode_huffman_slow[0].v_lmask = v_lmask;
|
||||
self->private_data.s_decode_huffman_slow[0].v_dmask = v_dmask;
|
||||
@@ -28214,14 +30600,13 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
self->private_data.s_decode_huffman_slow[0].v_redir_mask = v_redir_mask;
|
||||
self->private_data.s_decode_huffman_slow[0].v_length = v_length;
|
||||
self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -28510,7 +30895,7 @@ wuffs_lzw__decoder__read_from(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -28652,7 +31037,7 @@ wuffs_lzw__decoder__read_from(
|
||||
self->private_impl.f_bits = v_bits;
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
self->private_impl.f_output_wi = v_output_wi;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -28674,7 +31059,7 @@ wuffs_lzw__decoder__write_to(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -28693,8 +31078,7 @@ wuffs_lzw__decoder__write_to(
|
||||
status = wuffs_base__make_status(wuffs_lzw__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
v_s = wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_output,
|
||||
8199),
|
||||
v_s = wuffs_base__make_slice_u8_ij(self->private_data.f_output,
|
||||
self->private_impl.f_output_ri,
|
||||
self->private_impl.f_output_wi);
|
||||
v_n = wuffs_base__io_writer__copy_from_slice(&iop_a_dst, io2_a_dst,v_s);
|
||||
@@ -28720,7 +31104,7 @@ wuffs_lzw__decoder__write_to(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
@@ -28742,8 +31126,7 @@ wuffs_lzw__decoder__flush(
|
||||
wuffs_base__slice_u8 v_s = {0};
|
||||
|
||||
if (self->private_impl.f_output_ri <= self->private_impl.f_output_wi) {
|
||||
v_s = wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_output,
|
||||
8199),
|
||||
v_s = wuffs_base__make_slice_u8_ij(self->private_data.f_output,
|
||||
self->private_impl.f_output_ri,
|
||||
self->private_impl.f_output_wi);
|
||||
}
|
||||
@@ -29055,7 +31438,10 @@ wuffs_gif__decoder__decode_image_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 0) {
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if ( ! self->private_impl.f_seen_header) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_header(self, a_src);
|
||||
if (status.repr) {
|
||||
@@ -29066,9 +31452,7 @@ wuffs_gif__decoder__decode_image_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence != 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
self->private_impl.f_seen_header = true;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src);
|
||||
@@ -29098,7 +31482,9 @@ wuffs_gif__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
v_ffio);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
if (self->private_impl.f_call_sequence == 0) {
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -29176,7 +31562,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29187,7 +31573,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 1) {
|
||||
if ((self->private_impl.f_call_sequence & 16) == 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
@@ -29258,7 +31644,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
self->private_impl.f_metadata_io_position,
|
||||
self->private_impl.f_metadata_io_position);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_io_position = 0;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
@@ -29276,7 +31662,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29393,16 +31779,17 @@ wuffs_gif__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
} else if (a_io_position == 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_delayed_num_decoded_frames = false;
|
||||
self->private_impl.f_end_of_data = false;
|
||||
self->private_impl.f_restarted = true;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
self->private_impl.f_num_decoded_frame_configs_value = a_index;
|
||||
self->private_impl.f_num_decoded_frames_value = a_index;
|
||||
wuffs_gif__decoder__reset_gc(self);
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
@@ -29441,7 +31828,7 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29455,52 +31842,65 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_ignore_metadata = true;
|
||||
self->private_impl.f_dirty_max_excl_y = 0;
|
||||
if ( ! self->private_impl.f_end_of_data) {
|
||||
if (self->private_impl.f_call_sequence == 0) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence != 3) {
|
||||
if (self->private_impl.f_call_sequence == 4) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_gif__decoder__skip_frame(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if ((self->private_impl.f_call_sequence & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (self->private_impl.f_end_of_data) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_gif__decoder__skip_frame(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_call_sequence >= 96) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if ((self->private_impl.f_num_decoded_frame_configs_value > 0) || (self->private_impl.f_call_sequence == 40)) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_call_sequence >= 96) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
v_background_color = self->private_impl.f_black_color_u32_argb_premul;
|
||||
if ( ! self->private_impl.f_gc_has_transparent_index) {
|
||||
v_background_color = self->private_impl.f_background_color_u32_argb_premul;
|
||||
@@ -29532,7 +31932,7 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
v_background_color);
|
||||
}
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -29547,7 +31947,7 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29572,7 +31972,7 @@ wuffs_gif__decoder__skip_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29633,6 +32033,7 @@ wuffs_gif__decoder__skip_frame(
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
}
|
||||
wuffs_gif__decoder__reset_gc(self);
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -29646,7 +32047,7 @@ wuffs_gif__decoder__skip_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29688,13 +32089,16 @@ wuffs_gif__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_ignore_metadata = true;
|
||||
if (self->private_impl.f_call_sequence != 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_quirks[5] && ((self->private_impl.f_frame_rect_x0 == self->private_impl.f_frame_rect_x1) || (self->private_impl.f_frame_rect_y0 == self->private_impl.f_frame_rect_y1))) {
|
||||
status = wuffs_base__make_status(wuffs_gif__error__bad_frame_size);
|
||||
@@ -29712,8 +32116,8 @@ wuffs_gif__decoder__decode_frame(
|
||||
}
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
wuffs_gif__decoder__reset_gc(self);
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -29737,7 +32141,6 @@ wuffs_gif__decoder__decode_frame(
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_gif__decoder__reset_gc(
|
||||
wuffs_gif__decoder* self) {
|
||||
self->private_impl.f_call_sequence = 5;
|
||||
self->private_impl.f_gc_has_transparent_index = false;
|
||||
self->private_impl.f_gc_transparent_index = 0;
|
||||
self->private_impl.f_gc_disposal = 0;
|
||||
@@ -29759,7 +32162,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29770,15 +32173,8 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if ( ! self->private_impl.f_restarted) {
|
||||
if (self->private_impl.f_call_sequence != 2) {
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
}
|
||||
} else if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
} else {
|
||||
self->private_impl.f_restarted = false;
|
||||
if ((self->private_impl.f_frame_config_io_position == 0) || (self->private_impl.f_num_decoded_frame_configs_value > 0)) {
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
@@ -29824,7 +32220,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
self->private_impl.f_delayed_num_decoded_frames = false;
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
}
|
||||
self->private_impl.f_end_of_data = true;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
@@ -29842,7 +32238,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29864,7 +32260,7 @@ wuffs_gif__decoder__decode_header(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29915,7 +32311,7 @@ wuffs_gif__decoder__decode_header(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29941,7 +32337,7 @@ wuffs_gif__decoder__decode_lsd(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30117,7 +32513,7 @@ wuffs_gif__decoder__decode_lsd(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30138,7 +32534,7 @@ wuffs_gif__decoder__decode_extension(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30210,7 +32606,7 @@ wuffs_gif__decoder__decode_extension(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30231,7 +32627,7 @@ wuffs_gif__decoder__skip_blocks(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30278,7 +32674,7 @@ wuffs_gif__decoder__skip_blocks(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30304,7 +32700,7 @@ wuffs_gif__decoder__decode_ae(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30456,17 +32852,17 @@ wuffs_gif__decoder__decode_ae(
|
||||
if ((0 < self->private_impl.f_num_animation_loops_value) && (self->private_impl.f_num_animation_loops_value <= 65535)) {
|
||||
self->private_impl.f_num_animation_loops_value += 1;
|
||||
}
|
||||
} else if (self->private_impl.f_ignore_metadata) {
|
||||
} else if (self->private_impl.f_call_sequence >= 32) {
|
||||
} else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) {
|
||||
self->private_impl.f_metadata_fourcc = 1229144912;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
} else if (v_is_xmp && self->private_impl.f_report_metadata_xmp) {
|
||||
self->private_impl.f_metadata_fourcc = 1481461792;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
@@ -30501,7 +32897,7 @@ wuffs_gif__decoder__decode_ae(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30524,7 +32920,7 @@ wuffs_gif__decoder__decode_gc(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30631,7 +33027,7 @@ wuffs_gif__decoder__decode_gc(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30650,7 +33046,7 @@ wuffs_gif__decoder__decode_id_part0(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30781,7 +33177,7 @@ wuffs_gif__decoder__decode_id_part0(
|
||||
self->private_impl.f_frame_rect_y1 += self->private_impl.f_frame_rect_y0;
|
||||
self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0;
|
||||
self->private_impl.f_dst_y = self->private_impl.f_frame_rect_y0;
|
||||
if ((self->private_impl.f_call_sequence == 0) && ! self->private_impl.f_quirks[4]) {
|
||||
if ((self->private_impl.f_num_decoded_frame_configs_value == 0) && ! self->private_impl.f_quirks[4]) {
|
||||
self->private_impl.f_width = wuffs_base__u32__max(self->private_impl.f_width, self->private_impl.f_frame_rect_x1);
|
||||
self->private_impl.f_height = wuffs_base__u32__max(self->private_impl.f_height, self->private_impl.f_frame_rect_y1);
|
||||
}
|
||||
@@ -30798,7 +33194,7 @@ wuffs_gif__decoder__decode_id_part0(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30827,7 +33223,7 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30969,7 +33365,7 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -31007,7 +33403,7 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -31018,7 +33414,6 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
if (coro_susp_point) {
|
||||
v_block_size = self->private_data.s_decode_id_part2[0].v_block_size;
|
||||
v_need_block_size = self->private_data.s_decode_id_part2[0].v_need_block_size;
|
||||
v_lzw_status = self->private_data.s_decode_id_part2[0].v_lzw_status;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -31055,7 +33450,7 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto label__0__break;
|
||||
}
|
||||
v_n_copied = wuffs_base__io_reader__limited_copy_u32_to_slice(
|
||||
&iop_a_src, io2_a_src,((uint32_t)((v_n_compressed & 4294967295))), wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_compressed, 4096), self->private_impl.f_compressed_wi));
|
||||
&iop_a_src, io2_a_src,((uint32_t)((v_n_compressed & 4294967295))), wuffs_base__make_slice_u8_ij(self->private_data.f_compressed, self->private_impl.f_compressed_wi, 4096));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_compressed_wi, ((uint64_t)(v_n_copied)));
|
||||
wuffs_base__u64__sat_sub_indirect(&v_block_size, ((uint64_t)(v_n_copied)));
|
||||
if (v_block_size > 0) {
|
||||
@@ -31087,8 +33482,7 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
&io0_v_r,
|
||||
&io1_v_r,
|
||||
&io2_v_r,
|
||||
wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_compressed,
|
||||
4096),
|
||||
wuffs_base__make_slice_u8_ij(self->private_data.f_compressed,
|
||||
self->private_impl.f_compressed_ri,
|
||||
self->private_impl.f_compressed_wi),
|
||||
0);
|
||||
@@ -31196,11 +33590,10 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
self->private_impl.p_decode_id_part2[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_id_part2[0].v_block_size = v_block_size;
|
||||
self->private_data.s_decode_id_part2[0].v_need_block_size = v_need_block_size;
|
||||
self->private_data.s_decode_id_part2[0].v_lzw_status = v_lzw_status;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -31527,7 +33920,7 @@ wuffs_gzip__decoder__transform_io(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -31540,7 +33933,7 @@ wuffs_gzip__decoder__transform_io(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -31811,10 +34204,10 @@ wuffs_gzip__decoder__transform_io(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -32304,7 +34697,7 @@ wuffs_json__decoder__decode_tokens(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -32317,7 +34710,7 @@ wuffs_json__decoder__decode_tokens(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -32388,7 +34781,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
v_whitespace_length = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
@@ -32450,7 +34842,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_string_length = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) > 4) {
|
||||
@@ -32514,8 +34905,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_c = ((uint8_t)((wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8)));
|
||||
@@ -32544,8 +34933,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_uni4_string = (((uint64_t)(wuffs_base__peek_u48le__no_bounds_check(iop_a_src))) >> 16);
|
||||
@@ -32588,9 +34975,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
v_string_length = 0;
|
||||
v_uni4_value = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_uni4_string = (wuffs_base__peek_u64le__no_bounds_check(iop_a_src + 4) >> 16);
|
||||
@@ -32646,8 +35030,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_uni8_string = wuffs_base__peek_u64le__no_bounds_check(iop_a_src + 2);
|
||||
@@ -32701,8 +35083,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_backslash_x_string = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
@@ -32752,8 +35132,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_multi_byte_utf8 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
@@ -32797,8 +35175,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_multi_byte_utf8 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
|
||||
@@ -32844,8 +35220,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(13);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_multi_byte_utf8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
@@ -33266,10 +35640,10 @@ wuffs_json__decoder__decode_tokens(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33293,7 +35667,7 @@ wuffs_json__decoder__decode_number(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33408,7 +35782,7 @@ wuffs_json__decoder__decode_number(
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
label__goto_done__break:;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
return (v_n | v_floating_point);
|
||||
@@ -33428,7 +35802,7 @@ wuffs_json__decoder__decode_digits(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33458,7 +35832,7 @@ wuffs_json__decoder__decode_digits(
|
||||
if (v_n == a_n) {
|
||||
v_n |= 256;
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
return v_n;
|
||||
@@ -33480,7 +35854,7 @@ wuffs_json__decoder__decode_leading(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33493,7 +35867,7 @@ wuffs_json__decoder__decode_leading(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33563,10 +35937,10 @@ wuffs_json__decoder__decode_leading(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33590,7 +35964,7 @@ wuffs_json__decoder__decode_comment(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33603,7 +35977,7 @@ wuffs_json__decoder__decode_comment(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33635,102 +36009,102 @@ wuffs_json__decoder__decode_comment(
|
||||
v_length = 2;
|
||||
label__comment_block__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 1) {
|
||||
if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
v_c2 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
if (v_c2 == 12074) {
|
||||
iop_a_src += 2;
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_length + 2))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 1;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 1) {
|
||||
if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
v_length += 1;
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
v_c2 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
if (v_c2 == 12074) {
|
||||
iop_a_src += 2;
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_length + 2))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 1;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
v_length += 1;
|
||||
}
|
||||
} else if ((v_c2 == 12079) && self->private_impl.f_quirks[12]) {
|
||||
iop_a_src += 2;
|
||||
v_length = 2;
|
||||
label__comment_line__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
} else if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 10) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
} else if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
v_length += 1;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 10) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
v_length += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33745,10 +36119,10 @@ wuffs_json__decoder__decode_comment(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33771,7 +36145,7 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33784,7 +36158,7 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33792,9 +36166,6 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_inf_nan[0];
|
||||
if (coro_susp_point) {
|
||||
v_neg = self->private_data.s_decode_inf_nan[0].v_neg;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
@@ -33902,14 +36273,13 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_inf_nan[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_inf_nan[0].v_neg = v_neg;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33932,7 +36302,7 @@ wuffs_json__decoder__decode_trailer(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33945,7 +36315,7 @@ wuffs_json__decoder__decode_trailer(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33966,23 +36336,21 @@ wuffs_json__decoder__decode_trailer(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
v_whitespace_length = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
v_whitespace_length = 0;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (v_whitespace_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_whitespace_length = 0;
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
goto label__outer__break;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
v_whitespace_length = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
@@ -33991,7 +36359,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_whitespace_length = 0;
|
||||
}
|
||||
if (self->private_impl.f_trailer_stop > 0) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
@@ -34014,8 +36381,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
v_c = 0;
|
||||
v_whitespace_length = 0;
|
||||
if (self->private_impl.f_comment_type > 0) {
|
||||
goto label__outer__continue;
|
||||
}
|
||||
@@ -34027,7 +36392,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_whitespace_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_whitespace_length = 0;
|
||||
if (v_c == self->private_impl.f_trailer_stop) {
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
@@ -34050,10 +36414,10 @@ wuffs_json__decoder__decode_trailer(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34233,7 +36597,7 @@ wuffs_nie__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -34402,7 +36766,7 @@ wuffs_nie__decoder__decode_image_config(
|
||||
16,
|
||||
false);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -34417,7 +36781,7 @@ wuffs_nie__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34459,7 +36823,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -34470,7 +36834,8 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -34482,13 +36847,13 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (16 != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
@@ -34511,7 +36876,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
false,
|
||||
0);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -34525,7 +36890,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34572,13 +36937,13 @@ wuffs_nie__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_nie__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
@@ -34619,7 +36984,7 @@ wuffs_nie__decoder__decode_frame(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
}
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -34661,7 +37026,7 @@ wuffs_nie__decoder__swizzle(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -34713,7 +37078,7 @@ wuffs_nie__decoder__swizzle(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34769,7 +37134,7 @@ wuffs_nie__decoder__num_decoded_frame_configs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -34788,7 +37153,7 @@ wuffs_nie__decoder__num_decoded_frames(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -34811,13 +37176,13 @@ wuffs_nie__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if ((a_index != 0) || (a_io_position != 16)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
@@ -35139,7 +37504,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -35152,7 +37517,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -35336,10 +37701,10 @@ wuffs_zlib__decoder__transform_io(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -35362,6 +37727,7 @@ const char wuffs_png__error__bad_filter[] = "#png: bad filter";
|
||||
const char wuffs_png__error__bad_header[] = "#png: bad header";
|
||||
const char wuffs_png__error__bad_text_chunk_not_latin_1[] = "#png: bad text chunk (not Latin-1)";
|
||||
const char wuffs_png__error__missing_palette[] = "#png: missing palette";
|
||||
const char wuffs_png__error__unsupported_cgbi_extension[] = "#png: unsupported CgBI extension";
|
||||
const char wuffs_png__error__unsupported_png_compression_method[] = "#png: unsupported PNG compression method";
|
||||
const char wuffs_png__error__unsupported_png_file[] = "#png: unsupported PNG file";
|
||||
const char wuffs_png__error__internal_error_inconsistent_i_o[] = "#png: internal error: inconsistent I/O";
|
||||
@@ -35607,7 +37973,8 @@ wuffs_png__decoder__choose_filter_implementations(
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_other_chunk(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
wuffs_base__io_buffer* a_src,
|
||||
bool a_framy);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_actl(
|
||||
@@ -37269,7 +39636,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -37283,16 +39650,10 @@ wuffs_png__decoder__decode_image_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 2) {
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence != 0) {
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else {
|
||||
} else if ( ! self->private_impl.f_seen_ihdr) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint64_t t_0;
|
||||
@@ -37356,6 +39717,10 @@ wuffs_png__decoder__decode_image_config(
|
||||
v_magic = t_1;
|
||||
}
|
||||
if (v_magic != 5927942488114331648) {
|
||||
if (v_magic == 5278895250759221248) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_cgbi_extension);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
@@ -37421,6 +39786,11 @@ wuffs_png__decoder__decode_image_config(
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_seen_ihdr = true;
|
||||
} else if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
@@ -37461,7 +39831,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src);
|
||||
wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src, false);
|
||||
v_status = t_4;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -37478,7 +39848,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
}
|
||||
label__2__break:;
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
@@ -37543,7 +39913,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
self->private_impl.f_first_disposal = 0;
|
||||
self->private_impl.f_first_overwrite_instead_of_blend = false;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
@@ -37558,7 +39928,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -37583,7 +39953,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -37762,7 +40132,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -37923,14 +40293,15 @@ wuffs_png__decoder__choose_filter_implementations(
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_other_chunk(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__io_buffer* a_src,
|
||||
bool a_framy) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -37941,7 +40312,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_chunk_type == 1163152464) {
|
||||
if ((self->private_impl.f_chunk_type == 1163152464) && ! a_framy) {
|
||||
if (self->private_impl.f_seen_plte) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
@@ -37968,43 +40339,8 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
}
|
||||
if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
if (self->private_impl.f_report_metadata_exif) {
|
||||
if (self->private_impl.f_seen_exif) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
@@ -38013,7 +40349,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_exif(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38023,97 +40359,6 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
self->private_impl.f_seen_exif = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) || (self->private_impl.f_chunk_type == 1951942004) || (self->private_impl.f_chunk_type == 1951945850)) {
|
||||
if (self->private_impl.f_report_metadata_kvp) {
|
||||
self->private_impl.f_metadata_flavor = 4;
|
||||
@@ -38122,6 +40367,135 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
}
|
||||
} else if ( ! a_framy) {
|
||||
if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
}
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||
@@ -38147,7 +40521,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38166,7 +40540,7 @@ wuffs_png__decoder__decode_actl(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38260,7 +40634,7 @@ wuffs_png__decoder__decode_actl(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38281,7 +40655,7 @@ wuffs_png__decoder__decode_chrm(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38557,7 +40931,7 @@ wuffs_png__decoder__decode_chrm(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38576,7 +40950,7 @@ wuffs_png__decoder__decode_exif(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38598,7 +40972,7 @@ wuffs_png__decoder__decode_exif(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38622,7 +40996,7 @@ wuffs_png__decoder__decode_fctl(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38935,7 +41309,7 @@ wuffs_png__decoder__decode_fctl(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38954,7 +41328,7 @@ wuffs_png__decoder__decode_gama(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39016,7 +41390,7 @@ wuffs_png__decoder__decode_gama(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39037,7 +41411,7 @@ wuffs_png__decoder__decode_iccp(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39105,7 +41479,7 @@ wuffs_png__decoder__decode_iccp(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39128,7 +41502,7 @@ wuffs_png__decoder__decode_plte(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39208,7 +41582,7 @@ wuffs_png__decoder__decode_plte(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39227,7 +41601,7 @@ wuffs_png__decoder__decode_srgb(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39269,7 +41643,7 @@ wuffs_png__decoder__decode_srgb(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39292,7 +41666,7 @@ wuffs_png__decoder__decode_trns(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39454,7 +41828,7 @@ wuffs_png__decoder__decode_trns(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39489,11 +41863,13 @@ wuffs_png__decoder__decode_frame_config(
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_checksum_have = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39504,10 +41880,11 @@ wuffs_png__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 255) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else if (self->private_impl.f_call_sequence < 3) {
|
||||
if ((self->private_impl.f_call_sequence & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -39519,12 +41896,12 @@ wuffs_png__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -39536,10 +41913,14 @@ wuffs_png__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_call_sequence == 255) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 48;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_num_decoded_frame_configs_value == 0) {
|
||||
self->private_impl.f_frame_rect_x0 = self->private_impl.f_first_rect_x0;
|
||||
@@ -39610,7 +41991,48 @@ wuffs_png__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_chunk_type = t_1;
|
||||
}
|
||||
if (self->private_impl.f_chunk_type == 1413571686) {
|
||||
if (self->private_impl.f_chunk_type == 1145980233) {
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
uint32_t t_2;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_frame_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
|
||||
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
|
||||
if (num_bits_2 == 24) {
|
||||
t_2 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_2 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_2)) << 56;
|
||||
}
|
||||
}
|
||||
v_checksum_have = t_2;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != 2187346606)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else if (self->private_impl.f_chunk_type == 1413571686) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
@@ -39618,7 +42040,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -39627,7 +42049,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
self->private_data.s_decode_frame_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -39637,8 +42059,24 @@ wuffs_png__decoder__decode_frame_config(
|
||||
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
|
||||
goto label__0__break;
|
||||
}
|
||||
self->private_data.s_decode_frame_config[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
status = wuffs_png__decoder__decode_other_chunk(self, a_src, true);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 48;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
self->private_data.s_decode_frame_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -39667,7 +42105,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
0);
|
||||
}
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -39681,7 +42119,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39705,7 +42143,7 @@ wuffs_png__decoder__skip_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39823,11 +42261,7 @@ wuffs_png__decoder__skip_frame(
|
||||
}
|
||||
label__0__break:;
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
|
||||
self->private_impl.f_call_sequence = 5;
|
||||
} else {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_skip_frame[0] = 0;
|
||||
@@ -39840,7 +42274,7 @@ wuffs_png__decoder__skip_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39887,7 +42321,7 @@ wuffs_png__decoder__decode_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39898,10 +42332,13 @@ wuffs_png__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 255) {
|
||||
if ((self->private_impl.f_call_sequence & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_call_sequence >= 96) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else if (self->private_impl.f_call_sequence != 4) {
|
||||
} else if (self->private_impl.f_call_sequence != 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -40038,17 +42475,34 @@ wuffs_png__decoder__decode_frame(
|
||||
if ((v_pass_width > 0) && (v_pass_height > 0)) {
|
||||
self->private_impl.f_pass_bytes_per_row = wuffs_png__decoder__calculate_bytes_per_row(self, v_pass_width);
|
||||
self->private_impl.f_pass_workbuf_length = (((uint64_t)(v_pass_height)) * (1 + self->private_impl.f_pass_bytes_per_row));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
while (true) {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf);
|
||||
v_status = t_1;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
goto label__1__break;
|
||||
} else if (wuffs_base__status__is_error(&v_status) || ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed))) {
|
||||
if (self->private_impl.f_workbuf_wi <= ((uint64_t)(a_workbuf.len))) {
|
||||
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
|
||||
}
|
||||
if (v_status.repr == wuffs_base__suspension__short_read) {
|
||||
while (true) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
}
|
||||
label__1__break:;
|
||||
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = v_status;
|
||||
@@ -40063,7 +42517,7 @@ wuffs_png__decoder__decode_frame(
|
||||
self->private_impl.f_workbuf_hist_pos_base += self->private_impl.f_pass_workbuf_length;
|
||||
}
|
||||
if ((self->private_impl.f_interlace_pass == 0) || (self->private_impl.f_interlace_pass >= 7)) {
|
||||
goto label__1__break;
|
||||
goto label__2__break;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
@@ -40074,13 +42528,9 @@ wuffs_png__decoder__decode_frame(
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
label__1__break:;
|
||||
label__2__break:;
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
|
||||
self->private_impl.f_call_sequence = 5;
|
||||
} else {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -40094,7 +42544,7 @@ wuffs_png__decoder__decode_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -40130,7 +42580,7 @@ wuffs_png__decoder__decode_pass(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -40436,7 +42886,7 @@ wuffs_png__decoder__decode_pass(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -40528,12 +42978,12 @@ wuffs_png__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
} else if ((a_index >= ((uint64_t)(self->private_impl.f_num_animation_frames_value))) || ((a_index == 0) && (a_io_position != self->private_impl.f_first_config_io_position))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
if (self->private_impl.f_interlace_pass >= 1) {
|
||||
self->private_impl.f_interlace_pass = 1;
|
||||
}
|
||||
@@ -40619,7 +43069,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -40632,7 +43082,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -40646,7 +43096,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 1) {
|
||||
if ((self->private_impl.f_call_sequence & 16) == 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
@@ -40860,7 +43310,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -40869,7 +43318,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -40941,7 +43389,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -40951,7 +43398,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -41045,7 +43491,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
@@ -41070,7 +43516,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
@@ -41087,10 +43533,10 @@ wuffs_png__decoder__tell_me_more(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -41481,6 +43927,1241 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
|
||||
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
|
||||
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__image_decoder__func_ptrs
|
||||
wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder = {
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__pixel_buffer*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__pixel_blend,
|
||||
wuffs_base__slice_u8,
|
||||
wuffs_base__decode_frame_options*))(&wuffs_tga__decoder__decode_frame),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__frame_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_frame_config),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__image_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_image_config),
|
||||
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_tga__decoder__frame_dirty_rect),
|
||||
(uint32_t(*)(const void*))(&wuffs_tga__decoder__num_animation_loops),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frame_configs),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frames),
|
||||
(wuffs_base__status(*)(void*,
|
||||
uint64_t,
|
||||
uint64_t))(&wuffs_tga__decoder__restart_frame),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_quirk_enabled),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_report_metadata),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__more_information*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__tell_me_more),
|
||||
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_tga__decoder__workbuf_len),
|
||||
};
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options){
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (sizeof(*self) != sizeof_star_self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
|
||||
}
|
||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
|
||||
}
|
||||
|
||||
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
|
||||
// The whole point of this if-check is to detect an uninitialized *self.
|
||||
// We disable the warning on GCC. Clang-5.0 does not have this warning.
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
if (self->private_impl.magic != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
|
||||
}
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
} else {
|
||||
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
|
||||
} else {
|
||||
memset(&(self->private_impl), 0, sizeof(self->private_impl));
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
|
||||
wuffs_base__image_decoder__vtable_name;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
|
||||
(const void*)(&wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc() {
|
||||
wuffs_tga__decoder* x =
|
||||
(wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1));
|
||||
if (!x) {
|
||||
return NULL;
|
||||
}
|
||||
if (wuffs_tga__decoder__initialize(
|
||||
x, sizeof(wuffs_tga__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
|
||||
free(x);
|
||||
return NULL;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder() {
|
||||
return sizeof(wuffs_tga__decoder);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func tga.decoder.set_quirk_enabled
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_image_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 1)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
uint32_t v_i = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_decode_image_config[0].v_i;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
self->private_impl.f_header_id_length = t_0;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_type = t_1;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type > 1) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_type = t_2;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type == 1) ||
|
||||
(self->private_impl.f_header_image_type == 2) ||
|
||||
(self->private_impl.f_header_image_type == 3) ||
|
||||
(self->private_impl.f_header_image_type == 9) ||
|
||||
(self->private_impl.f_header_image_type == 10) ||
|
||||
(self->private_impl.f_header_image_type == 11)) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
uint16_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3;
|
||||
if (num_bits_3 == 8) {
|
||||
t_3 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_first_entry_index = t_3;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint16_t t_4;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
|
||||
if (num_bits_4 == 8) {
|
||||
t_4 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_4 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_4)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_length = t_4;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_entry_size = t_5;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length > 256)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_header_color_map_entry_size != 15) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 16) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 24) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length != 0) || (self->private_impl.f_header_color_map_entry_size != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
uint32_t t_6;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_6;
|
||||
if (num_bits_6 == 8) {
|
||||
t_6 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_6 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_6)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_width = t_6;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
uint32_t t_7;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_7;
|
||||
if (num_bits_7 == 8) {
|
||||
t_7 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_7 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_7)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_height = t_7;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_8 = *iop_a_src++;
|
||||
self->private_impl.f_header_pixel_depth = t_8;
|
||||
}
|
||||
if ((self->private_impl.f_header_pixel_depth != 1) &&
|
||||
(self->private_impl.f_header_pixel_depth != 8) &&
|
||||
(self->private_impl.f_header_pixel_depth != 15) &&
|
||||
(self->private_impl.f_header_pixel_depth != 16) &&
|
||||
(self->private_impl.f_header_pixel_depth != 24) &&
|
||||
(self->private_impl.f_header_pixel_depth != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type | 8) == 9) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 2164523016;
|
||||
self->private_impl.f_opaque = ((self->private_impl.f_header_color_map_entry_size == 15) || (self->private_impl.f_header_color_map_entry_size == 24));
|
||||
} else if ((self->private_impl.f_header_image_type | 8) == 10) {
|
||||
if ((self->private_impl.f_header_pixel_depth == 15) || (self->private_impl.f_header_pixel_depth == 16)) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 0;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 24) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_pixfmt = 2147485832;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 32) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_header_pixel_depth == 8) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_9 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_descriptor = t_9;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_descriptor & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) {
|
||||
if (self->private_impl.f_header_color_map_entry_size == 24) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17);
|
||||
uint32_t t_10;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
|
||||
t_10 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 3;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(18);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_10;
|
||||
if (num_bits_10 == 16) {
|
||||
t_10 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_10 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_10)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_10;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
} else if (self->private_impl.f_header_color_map_entry_size == 32) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19);
|
||||
uint32_t t_11;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_11;
|
||||
if (num_bits_11 == 24) {
|
||||
t_11 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_11 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_11)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_11;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = ((uint8_t)(((v_c >> 24) & 255)));
|
||||
} else {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21);
|
||||
uint32_t t_12;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_12;
|
||||
if (num_bits_12 == 8) {
|
||||
t_12 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_12 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_12)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_12;
|
||||
}
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_src_palette[((v_i * 4) + 0)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 1)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 2)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 3)] = 255;
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__set(
|
||||
a_dst,
|
||||
self->private_impl.f_src_pixfmt,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
self->private_impl.f_opaque);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_decode_image_config[0].v_i = v_i;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 2)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__decode_image_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__frame_config__set(
|
||||
a_dst,
|
||||
wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height),
|
||||
((wuffs_base__flicks)(0)),
|
||||
0,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
0,
|
||||
self->private_impl.f_opaque,
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 3)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint32_t v_dst_x = 0;
|
||||
uint32_t v_dst_y = 0;
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_dst_start = 0;
|
||||
wuffs_base__slice_u8 v_src_palette = {0};
|
||||
uint64_t v_mark = 0;
|
||||
uint64_t v_num_pixels64 = 0;
|
||||
uint32_t v_num_pixels32 = 0;
|
||||
uint32_t v_lit_length = 0;
|
||||
uint32_t v_run_length = 0;
|
||||
uint64_t v_num_dst_bytes = 0;
|
||||
uint32_t v_num_src_bytes = 0;
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
if (coro_susp_point) {
|
||||
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
|
||||
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
|
||||
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
|
||||
v_mark = self->private_data.s_decode_frame[0].v_mark;
|
||||
v_num_pixels32 = self->private_data.s_decode_frame[0].v_num_pixels32;
|
||||
v_lit_length = self->private_data.s_decode_frame[0].v_lit_length;
|
||||
v_run_length = self->private_data.s_decode_frame[0].v_run_length;
|
||||
v_num_dst_bytes = self->private_data.s_decode_frame[0].v_num_dst_bytes;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
v_src_palette = wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024);
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
|
||||
wuffs_base__pixel_buffer__pixel_format(a_dst),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
|
||||
wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt),
|
||||
v_src_palette,
|
||||
a_blend);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = v_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
|
||||
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
|
||||
if ((v_dst_bits_per_pixel & 7) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
goto exit;
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y = ((uint32_t)(self->private_impl.f_height - 1));
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
label__resume__continue:;
|
||||
while (true) {
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
|
||||
while (v_dst_y < self->private_impl.f_height) {
|
||||
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
|
||||
v_dst_start = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_dst_start <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_start);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
while (v_dst_x < self->private_impl.f_width) {
|
||||
if (self->private_impl.f_src_bytes_per_pixel > 0) {
|
||||
if (v_lit_length > 0) {
|
||||
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
v_num_pixels64 = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(self->private_impl.f_src_bytes_per_pixel)));
|
||||
v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length)))));
|
||||
v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel);
|
||||
v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel);
|
||||
self->private_data.s_decode_frame[0].scratch = v_num_src_bytes;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_frame[0].scratch;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
|
||||
if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
v_dst_x += v_num_pixels32;
|
||||
v_lit_length = (((uint32_t)(v_lit_length - v_num_pixels32)) & 65535);
|
||||
if (v_lit_length > 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_src_bytes_per_pixel == 1) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else if (self->private_impl.f_src_bytes_per_pixel == 3) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 5) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[3] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
}
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (v_lit_length > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, 4));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
v_lit_length -= 1;
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 3) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
v_dst_x = 0;
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y -= 1;
|
||||
} else {
|
||||
v_dst_y += 1;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
}
|
||||
goto label__resume__break;
|
||||
}
|
||||
label__resume__break:;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
|
||||
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
|
||||
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
|
||||
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
|
||||
self->private_data.s_decode_frame[0].v_mark = v_mark;
|
||||
self->private_data.s_decode_frame[0].v_num_pixels32 = v_num_pixels32;
|
||||
self->private_data.s_decode_frame[0].v_lit_length = v_lit_length;
|
||||
self->private_data.s_decode_frame[0].v_run_length = v_run_length;
|
||||
self->private_data.s_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.frame_dirty_rect
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_animation_loops
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frame_configs
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frames
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.restart_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.set_report_metadata
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.tell_me_more
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 4)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.workbuf_len
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_range_ii_u64(0, 0);
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
@@ -41647,7 +45328,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -41726,7 +45407,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
true);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -41743,7 +45424,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -41785,7 +45466,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -41796,7 +45477,8 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -41808,13 +45490,13 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
@@ -41837,7 +45519,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -41851,7 +45533,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -41908,7 +45590,7 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -41926,7 +45608,8 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -41938,7 +45621,6 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
@@ -42001,7 +45683,7 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
v_dst_y += 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -42020,7 +45702,7 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -42079,7 +45761,7 @@ wuffs_wbmp__decoder__num_decoded_frame_configs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -42098,7 +45780,7 @@ wuffs_wbmp__decoder__num_decoded_frames(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -42121,13 +45803,13 @@ wuffs_wbmp__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
@@ -42927,7 +46609,8 @@ DecodeImageCallbacks::AllocWorkbufResult::AllocWorkbufResult(
|
||||
|
||||
wuffs_base__image_decoder::unique_ptr //
|
||||
DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
switch (fourcc) {
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
@@ -42953,6 +46636,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
@@ -43173,6 +46861,7 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
|
||||
wuffs_base__image_config image_config = wuffs_base__null_image_config();
|
||||
sync_io::DynIOBuffer raw_metadata_buf(max_incl_metadata_length);
|
||||
uint64_t start_pos = io_buf.reader_position();
|
||||
bool interested_in_metadata_after_the_frame = false;
|
||||
bool redirected = false;
|
||||
int32_t fourcc = 0;
|
||||
redirect:
|
||||
@@ -43180,10 +46869,17 @@ redirect:
|
||||
// Determine the image format.
|
||||
if (!redirected) {
|
||||
while (true) {
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice());
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice(),
|
||||
io_buf.meta.closed);
|
||||
if (fourcc > 0) {
|
||||
break;
|
||||
} else if ((fourcc == 0) && (io_buf.reader_length() >= 64)) {
|
||||
// Having (fourcc == 0) means that Wuffs' built in MIME sniffer
|
||||
// didn't recognize the image format. Nonetheless, custom callbacks
|
||||
// may still be able to do their own MIME sniffing, for exotic image
|
||||
// types. We try to give them at least 64 bytes of prefix data when
|
||||
// one-shot-calling callbacks.SelectDecoder. There is no mechanism
|
||||
// for the callbacks to request a longer prefix.
|
||||
break;
|
||||
} else if (io_buf.meta.closed || (io_buf.writer_length() == 0)) {
|
||||
fourcc = 0;
|
||||
@@ -43224,8 +46920,7 @@ redirect:
|
||||
|
||||
// Select the image decoder.
|
||||
image_decoder = callbacks.SelectDecoder(
|
||||
(uint32_t)fourcc,
|
||||
fourcc ? wuffs_base__empty_slice_u8() : io_buf.reader_slice());
|
||||
(uint32_t)fourcc, io_buf.reader_slice(), io_buf.meta.closed);
|
||||
if (!image_decoder) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
@@ -43241,6 +46936,7 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
@@ -43250,12 +46946,14 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_XMP) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__XMP, true);
|
||||
}
|
||||
}
|
||||
@@ -43290,7 +46988,9 @@ redirect:
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
raw_metadata_buf.drop();
|
||||
if (!interested_in_metadata_after_the_frame) {
|
||||
raw_metadata_buf.drop();
|
||||
}
|
||||
|
||||
// Select the pixel format.
|
||||
uint32_t w = image_config.pixcfg.width();
|
||||
@@ -43351,6 +47051,12 @@ redirect:
|
||||
image_decoder->decode_frame_config(&frame_config, &io_buf);
|
||||
if (id_dfc_status.repr == nullptr) {
|
||||
break;
|
||||
} else if (id_dfc_status.repr == wuffs_base__note__metadata_reported) {
|
||||
std::string error_message = DecodeImageHandleMetadata(
|
||||
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
} else if (id_dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return DecodeImageResult(id_dfc_status.message());
|
||||
} else if (io_buf.meta.closed) {
|
||||
@@ -43392,6 +47098,35 @@ redirect:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decode any metadata after the frame.
|
||||
if (interested_in_metadata_after_the_frame) {
|
||||
while (true) {
|
||||
wuffs_base__status id_dfc_status =
|
||||
image_decoder->decode_frame_config(NULL, &io_buf);
|
||||
if (id_dfc_status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else if (id_dfc_status.repr == nullptr) {
|
||||
continue;
|
||||
} else if (id_dfc_status.repr == wuffs_base__note__metadata_reported) {
|
||||
std::string error_message = DecodeImageHandleMetadata(
|
||||
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
} else if (id_dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return DecodeImageResult(id_dfc_status.message());
|
||||
} else if (io_buf.meta.closed) {
|
||||
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
|
||||
} else {
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DecodeImageResult(std::move(alloc_pixbuf_result.mem_owner),
|
||||
pixel_buffer, std::move(message));
|
||||
}
|
||||
|
||||
@@ -85,15 +85,15 @@ extern "C" {
|
||||
// each major.minor branch, the commit count should increase monotonically.
|
||||
//
|
||||
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
|
||||
// 4aa672af48fd5c11ab4c0b704a4ccf8d90eb5662 committed on 2022-01-08.
|
||||
// b0e9efff3f44dc150edb22a27297bfef668035d2 committed on 2022-10-20.
|
||||
#define WUFFS_VERSION 0x000030000
|
||||
#define WUFFS_VERSION_MAJOR 0
|
||||
#define WUFFS_VERSION_MINOR 3
|
||||
#define WUFFS_VERSION_PATCH 0
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.13"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3245
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20220108
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.13+3245.20220108"
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "rc.2"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3366
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20221020
|
||||
#define WUFFS_VERSION_STRING "0.3.0-rc.2+3366.20221020"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -717,6 +717,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Text.
|
||||
#define WUFFS_BASE__FOURCC__TEXT 0x54455854
|
||||
|
||||
// Truevision Advanced Raster Graphics Adapter.
|
||||
#define WUFFS_BASE__FOURCC__TGA 0x54474120
|
||||
|
||||
// Tagged Image File Format.
|
||||
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
|
||||
|
||||
@@ -1062,6 +1065,22 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
|
||||
|
||||
// --------
|
||||
|
||||
// Normally, the wuffs_base__peek_etc and wuffs_base__poke_etc implementations
|
||||
// are both (1) correct regardless of CPU endianness and (2) very fast (e.g. an
|
||||
// inlined wuffs_base__peek_u32le__no_bounds_check call, in an optimized clang
|
||||
// or gcc build, is a single MOV instruction on x86_64).
|
||||
//
|
||||
// However, the endian-agnostic implementations are slow on Microsoft's C
|
||||
// compiler (MSC). Alternative memcpy-based implementations restore speed, but
|
||||
// they are only correct on little-endian CPU architectures. Defining
|
||||
// WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE opts in to these implementations.
|
||||
//
|
||||
// https://godbolt.org/z/q4MfjzTPh
|
||||
#if defined(_MSC_VER) && !defined(__clang__) && \
|
||||
(defined(_M_ARM64) || defined(_M_X64))
|
||||
#define WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE
|
||||
#endif
|
||||
|
||||
#define wuffs_base__peek_u8be__no_bounds_check \
|
||||
wuffs_base__peek_u8__no_bounds_check
|
||||
#define wuffs_base__peek_u8le__no_bounds_check \
|
||||
@@ -1074,12 +1093,24 @@ wuffs_base__peek_u8__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__peek_u16be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint16_t x;
|
||||
memcpy(&x, p, 2);
|
||||
return _byteswap_ushort(x);
|
||||
#else
|
||||
return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__peek_u16le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint16_t x;
|
||||
memcpy(&x, p, 2);
|
||||
return x;
|
||||
#else
|
||||
return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
@@ -1096,14 +1127,26 @@ wuffs_base__peek_u24le__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__peek_u32be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint32_t x;
|
||||
memcpy(&x, p, 4);
|
||||
return _byteswap_ulong(x);
|
||||
#else
|
||||
return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |
|
||||
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__peek_u32le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint32_t x;
|
||||
memcpy(&x, p, 4);
|
||||
return x;
|
||||
#else
|
||||
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
|
||||
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
@@ -1152,18 +1195,30 @@ wuffs_base__peek_u56le__no_bounds_check(const uint8_t* p) {
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__peek_u64be__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint64_t x;
|
||||
memcpy(&x, p, 8);
|
||||
return _byteswap_uint64(x);
|
||||
#else
|
||||
return ((uint64_t)(p[0]) << 56) | ((uint64_t)(p[1]) << 48) |
|
||||
((uint64_t)(p[2]) << 40) | ((uint64_t)(p[3]) << 32) |
|
||||
((uint64_t)(p[4]) << 24) | ((uint64_t)(p[5]) << 16) |
|
||||
((uint64_t)(p[6]) << 8) | ((uint64_t)(p[7]) << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__peek_u64le__no_bounds_check(const uint8_t* p) {
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE)
|
||||
uint64_t x;
|
||||
memcpy(&x, p, 8);
|
||||
return x;
|
||||
#else
|
||||
return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |
|
||||
((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |
|
||||
((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |
|
||||
((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------
|
||||
@@ -1186,7 +1241,8 @@ wuffs_base__poke_u16be__no_bounds_check(uint8_t* p, uint16_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u16le__no_bounds_check(uint8_t* p, uint16_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 2);
|
||||
@@ -1220,7 +1276,8 @@ wuffs_base__poke_u32be__no_bounds_check(uint8_t* p, uint32_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u32le__no_bounds_check(uint8_t* p, uint32_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 4);
|
||||
@@ -1306,7 +1363,8 @@ wuffs_base__poke_u64be__no_bounds_check(uint8_t* p, uint64_t x) {
|
||||
|
||||
static inline void //
|
||||
wuffs_base__poke_u64le__no_bounds_check(uint8_t* p, uint64_t x) {
|
||||
#if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)
|
||||
#if defined(WUFFS_BASE__USE_MEMCPY_LE_PEEK_POKE) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__))
|
||||
// This seems to perform better on gcc 10 (but not clang 9). Clang also
|
||||
// defines "__GNUC__".
|
||||
memcpy(p, &x, 8);
|
||||
@@ -1457,6 +1515,38 @@ wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u8 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u16 //
|
||||
wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u16 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u32 //
|
||||
wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u32 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u64 //
|
||||
wuffs_base__make_slice_u64_ij(uint64_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u64 ret;
|
||||
ret.ptr = ptr + i;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__empty_slice_u8() {
|
||||
wuffs_base__slice_u8 ret;
|
||||
@@ -1683,13 +1773,19 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// wuffs_base__magic_number_guess_fourcc guesses the file format of some data,
|
||||
// given its opening bytes. It returns a positive FourCC value on success.
|
||||
// given its starting bytes (the prefix_data argument) and whether or not there
|
||||
// may be further bytes (the prefix_closed argument; true means that
|
||||
// prefix_data is the entire data).
|
||||
//
|
||||
// It returns a positive FourCC value on success.
|
||||
//
|
||||
// It returns zero if nothing matches its hard-coded list of 'magic numbers'.
|
||||
//
|
||||
// It returns a negative value if a longer prefix is required for a conclusive
|
||||
// result. For example, seeing a single 'B' byte is not enough to discriminate
|
||||
// the BMP and BPG image file formats.
|
||||
// It returns a negative value if prefix_closed is false and a longer prefix is
|
||||
// required for a conclusive result. For example, a single 'B' byte (without
|
||||
// further data) is not enough to discriminate the BMP and BPG image file
|
||||
// formats. Similarly, a single '\xFF' byte might be the start of JPEG data or
|
||||
// it might be the start of some other binary data.
|
||||
//
|
||||
// It does not do a full validity check. Like any guess made from a short
|
||||
// prefix of the data, it may return false positives. Data that starts with 99
|
||||
@@ -1704,7 +1800,8 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__MAGIC sub-module, not just
|
||||
// WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix);
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// ---------------- Ranges and Rects
|
||||
|
||||
@@ -6625,7 +6722,6 @@ struct wuffs_bmp__decoder__struct {
|
||||
uint64_t scratch;
|
||||
} s_decode_image_config[1];
|
||||
struct {
|
||||
wuffs_base__status v_status;
|
||||
uint64_t scratch;
|
||||
} s_decode_frame[1];
|
||||
struct {
|
||||
@@ -6781,6 +6877,270 @@ struct wuffs_bmp__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_bzip2__error__bad_huffman_code_over_subscribed[];
|
||||
extern const char wuffs_bzip2__error__bad_huffman_code_under_subscribed[];
|
||||
extern const char wuffs_bzip2__error__bad_block_header[];
|
||||
extern const char wuffs_bzip2__error__bad_block_length[];
|
||||
extern const char wuffs_bzip2__error__bad_checksum[];
|
||||
extern const char wuffs_bzip2__error__bad_header[];
|
||||
extern const char wuffs_bzip2__error__bad_number_of_sections[];
|
||||
extern const char wuffs_bzip2__error__unsupported_block_randomization[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_BZIP2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
typedef struct wuffs_bzip2__decoder__struct wuffs_bzip2__decoder;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
|
||||
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
|
||||
//
|
||||
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
|
||||
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_bzip2__decoder__initialize(
|
||||
wuffs_bzip2__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options);
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_bzip2__decoder();
|
||||
|
||||
// ---------------- Allocs
|
||||
|
||||
// These functions allocate and initialize Wuffs structs. They return NULL if
|
||||
// memory allocation fails. If they return non-NULL, there is no need to call
|
||||
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
|
||||
// calling free on the returned pointer. That pointer is effectively a C++
|
||||
// std::unique_ptr<T, decltype(&free)>.
|
||||
|
||||
wuffs_bzip2__decoder*
|
||||
wuffs_bzip2__decoder__alloc();
|
||||
|
||||
static inline wuffs_base__io_transformer*
|
||||
wuffs_bzip2__decoder__alloc_as__wuffs_base__io_transformer() {
|
||||
return (wuffs_base__io_transformer*)(wuffs_bzip2__decoder__alloc());
|
||||
}
|
||||
|
||||
// ---------------- Upcasts
|
||||
|
||||
static inline wuffs_base__io_transformer*
|
||||
wuffs_bzip2__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
wuffs_bzip2__decoder* p) {
|
||||
return (wuffs_base__io_transformer*)p;
|
||||
}
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__set_quirk_enabled(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_bzip2__decoder__workbuf_len(
|
||||
const wuffs_bzip2__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_bzip2__decoder__transform_io(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Struct Definitions
|
||||
|
||||
// These structs' fields, and the sizeof them, are private implementation
|
||||
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||
//
|
||||
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||
|
||||
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
struct wuffs_bzip2__decoder__struct {
|
||||
// Do not access the private_impl's or private_data's fields directly. There
|
||||
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
|
||||
// the wuffs_foo__bar__baz functions.
|
||||
//
|
||||
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
|
||||
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
|
||||
|
||||
struct {
|
||||
uint32_t magic;
|
||||
uint32_t active_coroutine;
|
||||
wuffs_base__vtable vtable_for__wuffs_base__io_transformer;
|
||||
wuffs_base__vtable null_vtable;
|
||||
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint32_t f_max_incl_block_size;
|
||||
uint32_t f_block_size;
|
||||
bool f_decode_huffman_finished;
|
||||
uint8_t f_decode_huffman_which;
|
||||
uint32_t f_decode_huffman_ticks;
|
||||
uint32_t f_decode_huffman_section;
|
||||
uint32_t f_decode_huffman_run_shift;
|
||||
uint32_t f_flush_pointer;
|
||||
uint32_t f_flush_repeat_count;
|
||||
uint8_t f_flush_prev;
|
||||
bool f_ignore_checksum;
|
||||
uint32_t f_final_checksum_have;
|
||||
uint32_t f_block_checksum_have;
|
||||
uint32_t f_block_checksum_want;
|
||||
uint32_t f_original_pointer;
|
||||
uint32_t f_num_symbols;
|
||||
uint32_t f_num_huffman_codes;
|
||||
uint32_t f_num_sections;
|
||||
uint32_t f_code_lengths_bitmask;
|
||||
|
||||
uint32_t p_transform_io[1];
|
||||
uint32_t p_prepare_block[1];
|
||||
uint32_t p_read_code_lengths[1];
|
||||
uint32_t p_flush_slow[1];
|
||||
uint32_t p_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
uint32_t f_scratch;
|
||||
uint32_t f_letter_counts[256];
|
||||
uint8_t f_presence[256];
|
||||
uint8_t f_mtft[256];
|
||||
uint8_t f_huffman_selectors[32768];
|
||||
uint16_t f_huffman_trees[6][257][2];
|
||||
uint16_t f_huffman_tables[6][256];
|
||||
uint32_t f_bwt[1048576];
|
||||
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint64_t v_tag;
|
||||
uint32_t v_final_checksum_want;
|
||||
} s_transform_io[1];
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint32_t v_selector;
|
||||
} s_prepare_block[1];
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint32_t v_code_length;
|
||||
} s_read_code_lengths[1];
|
||||
struct {
|
||||
uint32_t v_flush_pointer;
|
||||
uint32_t v_flush_repeat_count;
|
||||
uint8_t v_flush_prev;
|
||||
uint32_t v_block_checksum_have;
|
||||
uint32_t v_block_size;
|
||||
uint8_t v_curr;
|
||||
uint64_t scratch;
|
||||
} s_flush_slow[1];
|
||||
struct {
|
||||
uint32_t v_node_index;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
using unique_ptr = std::unique_ptr<wuffs_bzip2__decoder, decltype(&free)>;
|
||||
|
||||
// On failure, the alloc_etc functions return nullptr. They don't throw.
|
||||
|
||||
static inline unique_ptr
|
||||
alloc() {
|
||||
return unique_ptr(wuffs_bzip2__decoder__alloc(), &free);
|
||||
}
|
||||
|
||||
static inline wuffs_base__io_transformer::unique_ptr
|
||||
alloc_as__wuffs_base__io_transformer() {
|
||||
return wuffs_base__io_transformer::unique_ptr(
|
||||
wuffs_bzip2__decoder__alloc_as__wuffs_base__io_transformer(), &free);
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
|
||||
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
// Disallow constructing or copying an object via standard C++ mechanisms,
|
||||
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
|
||||
// size and field layout is not part of the public, stable, memory-safe API.
|
||||
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
|
||||
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
|
||||
// their first argument) rather than tweaking bar.private_impl.qux fields.
|
||||
//
|
||||
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
|
||||
// order to provide convenience methods. These forward on "this", so that you
|
||||
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
|
||||
wuffs_bzip2__decoder__struct() = delete;
|
||||
wuffs_bzip2__decoder__struct(const wuffs_bzip2__decoder__struct&) = delete;
|
||||
wuffs_bzip2__decoder__struct& operator=(
|
||||
const wuffs_bzip2__decoder__struct&) = delete;
|
||||
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#if !defined(WUFFS_IMPLEMENTATION)
|
||||
// As above, the size of the struct is not part of the public API, and unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
|
||||
// allocated, not stack allocated. Its size is not intended to be known at
|
||||
// compile time, but it is unfortunately divulged as a side effect of
|
||||
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
|
||||
// instead of "sizeof T", invoking the operator. To make the two values
|
||||
// different, so that passing the latter will be rejected by the initialize
|
||||
// function, we add an arbitrary amount of dead weight.
|
||||
uint8_t dead_weight[123000000]; // 123 MB.
|
||||
#endif // !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
initialize(
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options) {
|
||||
return wuffs_bzip2__decoder__initialize(
|
||||
this, sizeof_star_self, wuffs_version, options);
|
||||
}
|
||||
|
||||
inline wuffs_base__io_transformer*
|
||||
upcast_as__wuffs_base__io_transformer() {
|
||||
return (wuffs_base__io_transformer*)this;
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_quirk_enabled(
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_bzip2__decoder__set_quirk_enabled(this, a_quirk, a_enabled);
|
||||
}
|
||||
|
||||
inline wuffs_base__range_ii_u64
|
||||
workbuf_len() const {
|
||||
return wuffs_bzip2__decoder__workbuf_len(this);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
transform_io(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
return wuffs_bzip2__decoder__transform_io(this, a_dst, a_src, a_workbuf);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
}; // struct wuffs_bzip2__decoder__struct
|
||||
|
||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_cbor__error__bad_input[];
|
||||
extern const char wuffs_cbor__error__unsupported_recursion_depth[];
|
||||
|
||||
@@ -6912,7 +7272,6 @@ struct wuffs_cbor__decoder__struct {
|
||||
struct {
|
||||
uint64_t v_string_length;
|
||||
uint32_t v_depth;
|
||||
uint32_t v_token_length;
|
||||
bool v_tagged;
|
||||
uint8_t v_indefinite_string_major_type;
|
||||
} s_decode_tokens[1];
|
||||
@@ -7345,7 +7704,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_n_clen;
|
||||
uint32_t v_i;
|
||||
uint32_t v_mask;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_n_extra_bits;
|
||||
uint8_t v_rep_symbol;
|
||||
uint32_t v_rep_count;
|
||||
@@ -7353,7 +7711,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
struct {
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_table_entry_n_bits;
|
||||
uint32_t v_lmask;
|
||||
uint32_t v_dmask;
|
||||
@@ -7361,7 +7718,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_hlen;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -7869,16 +8225,14 @@ struct wuffs_gif__decoder__struct {
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_ignore_metadata;
|
||||
bool f_report_metadata_iccp;
|
||||
bool f_report_metadata_xmp;
|
||||
uint32_t f_metadata_fourcc;
|
||||
uint64_t f_metadata_io_position;
|
||||
bool f_quirks[7];
|
||||
bool f_delayed_num_decoded_frames;
|
||||
bool f_end_of_data;
|
||||
bool f_restarted;
|
||||
bool f_previous_lzw_decode_ended_abruptly;
|
||||
bool f_seen_header;
|
||||
bool f_has_global_palette;
|
||||
uint8_t f_interlace;
|
||||
bool f_seen_num_animation_loops_value;
|
||||
@@ -7969,7 +8323,6 @@ struct wuffs_gif__decoder__struct {
|
||||
struct {
|
||||
uint64_t v_block_size;
|
||||
bool v_need_block_size;
|
||||
wuffs_base__status v_lzw_status;
|
||||
uint64_t scratch;
|
||||
} s_decode_id_part2[1];
|
||||
} private_data;
|
||||
@@ -8510,9 +8863,6 @@ struct wuffs_json__decoder__struct {
|
||||
uint32_t v_expect;
|
||||
uint32_t v_expect_after_value;
|
||||
} s_decode_tokens[1];
|
||||
struct {
|
||||
uint32_t v_neg;
|
||||
} s_decode_inf_nan[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -9170,12 +9520,13 @@ extern const char wuffs_png__error__bad_filter[];
|
||||
extern const char wuffs_png__error__bad_header[];
|
||||
extern const char wuffs_png__error__bad_text_chunk_not_latin_1[];
|
||||
extern const char wuffs_png__error__missing_palette[];
|
||||
extern const char wuffs_png__error__unsupported_cgbi_extension[];
|
||||
extern const char wuffs_png__error__unsupported_png_compression_method[];
|
||||
extern const char wuffs_png__error__unsupported_png_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_PNG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
#define WUFFS_PNG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 2251799562027015
|
||||
|
||||
#define WUFFS_PNG__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 8
|
||||
|
||||
@@ -9350,6 +9701,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_gama;
|
||||
bool f_seen_iccp;
|
||||
bool f_seen_idat;
|
||||
bool f_seen_ihdr;
|
||||
bool f_seen_plte;
|
||||
bool f_seen_srgb;
|
||||
bool f_seen_trns;
|
||||
@@ -9631,6 +9983,351 @@ struct wuffs_png__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_tga__error__bad_header[];
|
||||
extern const char wuffs_tga__error__bad_run_length_encoding[];
|
||||
extern const char wuffs_tga__error__unsupported_tga_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
typedef struct wuffs_tga__decoder__struct wuffs_tga__decoder;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
|
||||
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
|
||||
//
|
||||
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
|
||||
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options);
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder();
|
||||
|
||||
// ---------------- Allocs
|
||||
|
||||
// These functions allocate and initialize Wuffs structs. They return NULL if
|
||||
// memory allocation fails. If they return non-NULL, there is no need to call
|
||||
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
|
||||
// calling free on the returned pointer. That pointer is effectively a C++
|
||||
// std::unique_ptr<T, decltype(&free)>.
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc();
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)(wuffs_tga__decoder__alloc());
|
||||
}
|
||||
|
||||
// ---------------- Upcasts
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder* p) {
|
||||
return (wuffs_base__image_decoder*)p;
|
||||
}
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Struct Definitions
|
||||
|
||||
// These structs' fields, and the sizeof them, are private implementation
|
||||
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||
//
|
||||
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||
|
||||
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
struct wuffs_tga__decoder__struct {
|
||||
// Do not access the private_impl's or private_data's fields directly. There
|
||||
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
|
||||
// the wuffs_foo__bar__baz functions.
|
||||
//
|
||||
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
|
||||
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
|
||||
|
||||
struct {
|
||||
uint32_t magic;
|
||||
uint32_t active_coroutine;
|
||||
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
|
||||
wuffs_base__vtable null_vtable;
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
uint8_t f_header_id_length;
|
||||
uint8_t f_header_color_map_type;
|
||||
uint8_t f_header_image_type;
|
||||
uint16_t f_header_color_map_first_entry_index;
|
||||
uint16_t f_header_color_map_length;
|
||||
uint8_t f_header_color_map_entry_size;
|
||||
uint8_t f_header_pixel_depth;
|
||||
uint8_t f_header_image_descriptor;
|
||||
bool f_opaque;
|
||||
uint32_t f_scratch_bytes_per_pixel;
|
||||
uint32_t f_src_bytes_per_pixel;
|
||||
uint32_t f_src_pixfmt;
|
||||
uint64_t f_frame_config_io_position;
|
||||
wuffs_base__pixel_swizzler f_swizzler;
|
||||
|
||||
uint32_t p_decode_image_config[1];
|
||||
uint32_t p_decode_frame_config[1];
|
||||
uint32_t p_decode_frame[1];
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
uint8_t f_dst_palette[1024];
|
||||
uint8_t f_src_palette[1024];
|
||||
uint8_t f_scratch[4];
|
||||
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint64_t scratch;
|
||||
} s_decode_image_config[1];
|
||||
struct {
|
||||
uint64_t v_dst_bytes_per_pixel;
|
||||
uint32_t v_dst_x;
|
||||
uint32_t v_dst_y;
|
||||
uint64_t v_mark;
|
||||
uint32_t v_num_pixels32;
|
||||
uint32_t v_lit_length;
|
||||
uint32_t v_run_length;
|
||||
uint64_t v_num_dst_bytes;
|
||||
uint64_t scratch;
|
||||
} s_decode_frame[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
using unique_ptr = std::unique_ptr<wuffs_tga__decoder, decltype(&free)>;
|
||||
|
||||
// On failure, the alloc_etc functions return nullptr. They don't throw.
|
||||
|
||||
static inline unique_ptr
|
||||
alloc() {
|
||||
return unique_ptr(wuffs_tga__decoder__alloc(), &free);
|
||||
}
|
||||
|
||||
static inline wuffs_base__image_decoder::unique_ptr
|
||||
alloc_as__wuffs_base__image_decoder() {
|
||||
return wuffs_base__image_decoder::unique_ptr(
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder(), &free);
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
|
||||
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
// Disallow constructing or copying an object via standard C++ mechanisms,
|
||||
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
|
||||
// size and field layout is not part of the public, stable, memory-safe API.
|
||||
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
|
||||
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
|
||||
// their first argument) rather than tweaking bar.private_impl.qux fields.
|
||||
//
|
||||
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
|
||||
// order to provide convenience methods. These forward on "this", so that you
|
||||
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
|
||||
wuffs_tga__decoder__struct() = delete;
|
||||
wuffs_tga__decoder__struct(const wuffs_tga__decoder__struct&) = delete;
|
||||
wuffs_tga__decoder__struct& operator=(
|
||||
const wuffs_tga__decoder__struct&) = delete;
|
||||
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#if !defined(WUFFS_IMPLEMENTATION)
|
||||
// As above, the size of the struct is not part of the public API, and unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
|
||||
// allocated, not stack allocated. Its size is not intended to be known at
|
||||
// compile time, but it is unfortunately divulged as a side effect of
|
||||
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
|
||||
// instead of "sizeof T", invoking the operator. To make the two values
|
||||
// different, so that passing the latter will be rejected by the initialize
|
||||
// function, we add an arbitrary amount of dead weight.
|
||||
uint8_t dead_weight[123000000]; // 123 MB.
|
||||
#endif // !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
initialize(
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options) {
|
||||
return wuffs_tga__decoder__initialize(
|
||||
this, sizeof_star_self, wuffs_version, options);
|
||||
}
|
||||
|
||||
inline wuffs_base__image_decoder*
|
||||
upcast_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)this;
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_quirk_enabled(
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_tga__decoder__set_quirk_enabled(this, a_quirk, a_enabled);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_image_config(
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_image_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame_config(
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_frame_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame(
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
return wuffs_tga__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
|
||||
}
|
||||
|
||||
inline wuffs_base__rect_ie_u32
|
||||
frame_dirty_rect() const {
|
||||
return wuffs_tga__decoder__frame_dirty_rect(this);
|
||||
}
|
||||
|
||||
inline uint32_t
|
||||
num_animation_loops() const {
|
||||
return wuffs_tga__decoder__num_animation_loops(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frame_configs() const {
|
||||
return wuffs_tga__decoder__num_decoded_frame_configs(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frames() const {
|
||||
return wuffs_tga__decoder__num_decoded_frames(this);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
restart_frame(
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
return wuffs_tga__decoder__restart_frame(this, a_index, a_io_position);
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_report_metadata(
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_tga__decoder__set_report_metadata(this, a_fourcc, a_report);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
tell_me_more(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__range_ii_u64
|
||||
workbuf_len() const {
|
||||
return wuffs_tga__decoder__workbuf_len(this);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
}; // struct wuffs_tga__decoder__struct
|
||||
|
||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_wbmp__error__bad_header[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
@@ -10236,9 +10933,13 @@ class DecodeImageCallbacks {
|
||||
// Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).
|
||||
//
|
||||
// Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the
|
||||
// caller is responsible for examining the opening bytes (a prefix) of the
|
||||
// input data. SelectDecoder implementations should not modify those bytes.
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that Wuffs'
|
||||
// standard library did not recognize the image format but if SelectDecoder
|
||||
// was overridden, it may examine the input data's starting bytes and still
|
||||
// provide its own image decoder, e.g. for an exotic image file format that's
|
||||
// not in Wuffs' standard library. The prefix_etc fields have the same
|
||||
// meaning as wuffs_base__magic_number_guess_fourcc arguments. SelectDecoder
|
||||
// implementations should not modify prefix_data's contents.
|
||||
//
|
||||
// SelectDecoder might be called more than once, since some image file
|
||||
// formats can wrap others. For example, a nominal BMP file can actually
|
||||
@@ -10253,9 +10954,12 @@ class DecodeImageCallbacks {
|
||||
// - WUFFS_BASE__FOURCC__GIF
|
||||
// - WUFFS_BASE__FOURCC__NIE
|
||||
// - WUFFS_BASE__FOURCC__PNG
|
||||
// - WUFFS_BASE__FOURCC__TGA
|
||||
// - WUFFS_BASE__FOURCC__WBMP
|
||||
virtual wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
|
||||
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
@@ -15573,14 +16277,134 @@ done:
|
||||
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// ICO doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly ICO.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// first two bytes are 0x00.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/ico/
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[3] != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01: // ICO
|
||||
case 0x02: // CUR
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The Number Of Images should be positive.
|
||||
if (prefix_data.len < 6) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[4] == 0) && (prefix_data.ptr[5] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The first ICONDIRENTRY's fourth byte should be zero.
|
||||
if (prefix_data.len < 10) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[9] != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: have a separate FourCC for CUR?
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
|
||||
// TGA doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly TGA.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// second byte (prefix_data.ptr[1], the Color Map Type byte), is either 0x00 or
|
||||
// 0x01.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/tga/
|
||||
// - https://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 3) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0x09:
|
||||
case 0x0A:
|
||||
case 0x0B:
|
||||
break;
|
||||
default:
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Color Map Entry Size field (if the Color Map Type field
|
||||
// is non-zero) or else all the Color Map fields should be zero.
|
||||
if (prefix_data.len < 8) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[1] != 0x00) {
|
||||
switch (prefix_data.ptr[7]) {
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
|
||||
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Pixel Depth field.
|
||||
if (prefix_data.len < 17) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[16]) {
|
||||
case 0x01:
|
||||
case 0x08:
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0x54474120; // 'TGA 'be
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// This is similar to (but different from):
|
||||
// - the magic/Magdir tables under https://github.com/file/file
|
||||
// - the MIME Sniffing algorithm at https://mimesniff.spec.whatwg.org/
|
||||
|
||||
// table holds the 'magic numbers' (which are actually variable length
|
||||
// strings). The strings may contain NUL bytes, so the "const char* magic"
|
||||
// value starts with the length-minus-1 of the 'magic number'.
|
||||
//
|
||||
// Keep it sorted by magic[1], then magic[0] descending and finally by
|
||||
// magic[2:]. When multiple entries match, the longest one wins.
|
||||
// Keep it sorted by magic[1], then magic[0] descending (prioritizing longer
|
||||
// matches) and finally by magic[2:]. When multiple entries match, the
|
||||
// longest one wins.
|
||||
//
|
||||
// The fourcc field might be negated, in which case there's further
|
||||
// specialization (see § below).
|
||||
@@ -15589,6 +16413,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
const char* magic;
|
||||
} table[] = {
|
||||
{-0x30302020, "\x01\x00\x00"}, // '00 'be
|
||||
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
|
||||
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
|
||||
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
|
||||
{+0x424D5020, "\x01\x42\x4D"}, // BMP
|
||||
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
||||
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
||||
@@ -15596,15 +16423,16 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
|
||||
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
|
||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||
};
|
||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||
|
||||
if (prefix.len == 0) {
|
||||
return -1;
|
||||
if (prefix_data.len == 0) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint8_t pre_first_byte = prefix.ptr[0];
|
||||
uint8_t pre_first_byte = prefix_data.ptr[0];
|
||||
|
||||
int32_t fourcc = 0;
|
||||
size_t i;
|
||||
@@ -15623,11 +16451,11 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
|
||||
const char* mag_remaining_ptr = table[i].magic + 2;
|
||||
uint8_t* pre_remaining_ptr = prefix.ptr + 1;
|
||||
size_t pre_remaining_len = prefix.len - 1;
|
||||
uint8_t* pre_remaining_ptr = prefix_data.ptr + 1;
|
||||
size_t pre_remaining_len = prefix_data.len - 1;
|
||||
if (pre_remaining_len < mag_remaining_len) {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, pre_remaining_len)) {
|
||||
return -1;
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
} else {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, mag_remaining_len)) {
|
||||
@@ -15635,6 +16463,14 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix_data.len < 2) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[1] == 0x00) || (prefix_data.ptr[1] == 0x01)) {
|
||||
return wuffs_base__magic_number_guess_fourcc__maybe_tga(prefix_data,
|
||||
prefix_closed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
match:
|
||||
@@ -15643,26 +16479,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 12) {
|
||||
return -1;
|
||||
if (prefix_data.len < 12) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix_data.ptr + 8);
|
||||
if (x == 0x57454250) { // 'WEBP'be
|
||||
return 0x57454250; // 'WEBP'be
|
||||
}
|
||||
|
||||
} else if (fourcc == 0x30302020) { // '00 'be
|
||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||
if (prefix.len < 4) {
|
||||
return -1;
|
||||
} else if ((prefix.ptr[2] != 0x00) &&
|
||||
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
|
||||
// Unfortunately, some file formats also don't start with a magic
|
||||
// identifier, so we have to use heuristics (where the order matters, the
|
||||
// same as /usr/bin/file's magic/Magdir tables) as best we can. Maybe
|
||||
// it's TGA, ICO/CUR, etc. Maybe it's something else.
|
||||
int32_t tga = wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
prefix_data, prefix_closed);
|
||||
if (tga != 0) {
|
||||
return tga;
|
||||
}
|
||||
int32_t ico = wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
prefix_data, prefix_closed);
|
||||
if (ico != 0) {
|
||||
return ico;
|
||||
}
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[2] != 0x00) &&
|
||||
((prefix_data.ptr[2] >= 0x80) ||
|
||||
(prefix_data.ptr[3] != 0x00))) {
|
||||
// Roughly speaking, this could be a non-degenerate (non-0-width and
|
||||
// non-0-height) WBMP image.
|
||||
return 0x57424D50; // 'WBMP'be
|
||||
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
|
||||
(prefix.ptr[3] == 0x00)) {
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -21851,7 +22699,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -22712,7 +23560,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
(self->private_impl.f_channel_masks[3] == 0));
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
@@ -22726,7 +23574,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -22768,7 +23616,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -22779,7 +23627,8 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -22791,13 +23640,13 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
@@ -22820,7 +23669,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -22834,7 +23683,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -22881,7 +23730,7 @@ wuffs_bmp__decoder__decode_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -22889,13 +23738,11 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
if (coro_susp_point) {
|
||||
v_status = self->private_data.s_decode_frame[0].v_status;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -22907,7 +23754,6 @@ wuffs_bmp__decoder__decode_frame(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
@@ -22932,7 +23778,7 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
|
||||
wuffs_base__pixel_buffer__pixel_format(a_dst),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024)),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048)),
|
||||
wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt),
|
||||
wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024),
|
||||
a_blend);
|
||||
@@ -23007,7 +23853,7 @@ wuffs_bmp__decoder__decode_frame(
|
||||
iop_a_src += self->private_data.s_decode_frame[0].scratch;
|
||||
self->private_impl.f_pending_pad = 0;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -23018,11 +23864,10 @@ wuffs_bmp__decoder__decode_frame(
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
|
||||
self->private_data.s_decode_frame[0].v_status = v_status;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23055,7 +23900,7 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23070,7 +23915,7 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__outer__continue:;
|
||||
while (true) {
|
||||
@@ -23125,7 +23970,7 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23162,7 +24007,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23177,7 +24022,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
v_rle_state = self->private_impl.f_rle_state;
|
||||
label__outer__continue:;
|
||||
@@ -23232,7 +24077,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
v_p0 += 2;
|
||||
}
|
||||
}
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), self->private_impl.f_rle_length));
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_rle_length));
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x, self->private_impl.f_rle_length);
|
||||
v_rle_state = 0;
|
||||
goto label__middle__continue;
|
||||
@@ -23288,7 +24133,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
v_chunk_count -= 1;
|
||||
}
|
||||
v_p0 = wuffs_base__u32__min(v_p0, self->private_impl.f_rle_length);
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), v_p0));
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, v_p0));
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x, v_p0);
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_rle_length, v_p0);
|
||||
}
|
||||
@@ -23387,7 +24232,7 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23424,7 +24269,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23439,7 +24284,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__outer__continue:;
|
||||
while (true) {
|
||||
@@ -23512,7 +24357,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__inner__continue;
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), (8 * v_p0)));
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -23527,7 +24372,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23560,7 +24405,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -23575,7 +24420,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8((self->private_data.f_scratch) + 1024, 1024));
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8_ij(self->private_data.f_scratch, 1024, 2048));
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
@@ -23681,7 +24526,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
}
|
||||
}
|
||||
v_p0 = wuffs_base__u32__min(v_p0, wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x));
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 2048), v_p0));
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, v_p0));
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -23695,7 +24540,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -23751,7 +24596,7 @@ wuffs_bmp__decoder__num_decoded_frame_configs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -23770,7 +24615,7 @@ wuffs_bmp__decoder__num_decoded_frames(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -23793,13 +24638,13 @@ wuffs_bmp__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
@@ -23898,7 +24743,7 @@ wuffs_bmp__decoder__read_palette(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -24012,7 +24857,7 @@ wuffs_bmp__decoder__read_palette(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -24065,6 +24910,1556 @@ wuffs_bmp__decoder__process_masks(
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_bzip2__error__bad_huffman_code_over_subscribed[] = "#bzip2: bad Huffman code (over-subscribed)";
|
||||
const char wuffs_bzip2__error__bad_huffman_code_under_subscribed[] = "#bzip2: bad Huffman code (under-subscribed)";
|
||||
const char wuffs_bzip2__error__bad_block_header[] = "#bzip2: bad block header";
|
||||
const char wuffs_bzip2__error__bad_block_length[] = "#bzip2: bad block length";
|
||||
const char wuffs_bzip2__error__bad_checksum[] = "#bzip2: bad checksum";
|
||||
const char wuffs_bzip2__error__bad_header[] = "#bzip2: bad header";
|
||||
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
|
||||
const char wuffs_bzip2__error__unsupported_block_randomization[] = "#bzip2: unsupported block randomization";
|
||||
const char wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state[] = "#bzip2: internal error: inconsistent Huffman decoder state";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
static const uint8_t
|
||||
WUFFS_BZIP2__CLAMP_TO_5[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
0, 1, 2, 3, 4, 5, 5, 5,
|
||||
};
|
||||
|
||||
static const uint32_t
|
||||
WUFFS_BZIP2__REV_CRC32_TABLE[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
0, 79764919, 159529838, 222504665, 319059676, 398814059, 445009330, 507990021,
|
||||
638119352, 583659535, 797628118, 726387553, 890018660, 835552979, 1015980042, 944750013,
|
||||
1276238704, 1221641927, 1167319070, 1095957929, 1595256236, 1540665371, 1452775106, 1381403509,
|
||||
1780037320, 1859660671, 1671105958, 1733955601, 2031960084, 2111593891, 1889500026, 1952343757,
|
||||
2552477408, 2632100695, 2443283854, 2506133561, 2334638140, 2414271883, 2191915858, 2254759653,
|
||||
3190512472, 3135915759, 3081330742, 3009969537, 2905550212, 2850959411, 2762807018, 2691435357,
|
||||
3560074640, 3505614887, 3719321342, 3648080713, 3342211916, 3287746299, 3467911202, 3396681109,
|
||||
4063920168, 4143685023, 4223187782, 4286162673, 3779000052, 3858754371, 3904687514, 3967668269,
|
||||
881225847, 809987520, 1023691545, 969234094, 662832811, 591600412, 771767749, 717299826,
|
||||
311336399, 374308984, 453813921, 533576470, 25881363, 88864420, 134795389, 214552010,
|
||||
2023205639, 2086057648, 1897238633, 1976864222, 1804852699, 1867694188, 1645340341, 1724971778,
|
||||
1587496639, 1516133128, 1461550545, 1406951526, 1302016099, 1230646740, 1142491917, 1087903418,
|
||||
2896545431, 2825181984, 2770861561, 2716262478, 3215044683, 3143675388, 3055782693, 3001194130,
|
||||
2326604591, 2389456536, 2200899649, 2280525302, 2578013683, 2640855108, 2418763421, 2498394922,
|
||||
3769900519, 3832873040, 3912640137, 3992402750, 4088425275, 4151408268, 4197601365, 4277358050,
|
||||
3334271071, 3263032808, 3476998961, 3422541446, 3585640067, 3514407732, 3694837229, 3640369242,
|
||||
1762451694, 1842216281, 1619975040, 1682949687, 2047383090, 2127137669, 1938468188, 2001449195,
|
||||
1325665622, 1271206113, 1183200824, 1111960463, 1543535498, 1489069629, 1434599652, 1363369299,
|
||||
622672798, 568075817, 748617968, 677256519, 907627842, 853037301, 1067152940, 995781531,
|
||||
51762726, 131386257, 177728840, 240578815, 269590778, 349224269, 429104020, 491947555,
|
||||
4046411278, 4126034873, 4172115296, 4234965207, 3794477266, 3874110821, 3953728444, 4016571915,
|
||||
3609705398, 3555108353, 3735388376, 3664026991, 3290680682, 3236090077, 3449943556, 3378572211,
|
||||
3174993278, 3120533705, 3032266256, 2961025959, 2923101090, 2868635157, 2813903052, 2742672763,
|
||||
2604032198, 2683796849, 2461293480, 2524268063, 2284983834, 2364738477, 2175806836, 2238787779,
|
||||
1569362073, 1498123566, 1409854455, 1355396672, 1317987909, 1246755826, 1192025387, 1137557660,
|
||||
2072149281, 2135122070, 1912620623, 1992383480, 1753615357, 1816598090, 1627664531, 1707420964,
|
||||
295390185, 358241886, 404320391, 483945776, 43990325, 106832002, 186451547, 266083308,
|
||||
932423249, 861060070, 1041341759, 986742920, 613929101, 542559546, 756411363, 701822548,
|
||||
3316196985, 3244833742, 3425377559, 3370778784, 3601682597, 3530312978, 3744426955, 3689838204,
|
||||
3819031489, 3881883254, 3928223919, 4007849240, 4037393693, 4100235434, 4180117107, 4259748804,
|
||||
2310601993, 2373574846, 2151335527, 2231098320, 2596047829, 2659030626, 2470359227, 2550115596,
|
||||
2947551409, 2876312838, 2788305887, 2733848168, 3165939309, 3094707162, 3040238851, 2985771188,
|
||||
};
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__prepare_block(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__read_code_lengths(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__build_huffman_tree(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which);
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__build_huffman_table(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which);
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__invert_bwt(
|
||||
wuffs_bzip2__decoder* self);
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__flush_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__flush_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__io_transformer__func_ptrs
|
||||
wuffs_bzip2__decoder__func_ptrs_for__wuffs_base__io_transformer = {
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_bzip2__decoder__set_quirk_enabled),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__slice_u8))(&wuffs_bzip2__decoder__transform_io),
|
||||
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_bzip2__decoder__workbuf_len),
|
||||
};
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_bzip2__decoder__initialize(
|
||||
wuffs_bzip2__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options){
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (sizeof(*self) != sizeof_star_self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
|
||||
}
|
||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
|
||||
}
|
||||
|
||||
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
|
||||
// The whole point of this if-check is to detect an uninitialized *self.
|
||||
// We disable the warning on GCC. Clang-5.0 does not have this warning.
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
if (self->private_impl.magic != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
|
||||
}
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
} else {
|
||||
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
|
||||
} else {
|
||||
memset(&(self->private_impl), 0, sizeof(self->private_impl));
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__io_transformer.vtable_name =
|
||||
wuffs_base__io_transformer__vtable_name;
|
||||
self->private_impl.vtable_for__wuffs_base__io_transformer.function_pointers =
|
||||
(const void*)(&wuffs_bzip2__decoder__func_ptrs_for__wuffs_base__io_transformer);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
wuffs_bzip2__decoder*
|
||||
wuffs_bzip2__decoder__alloc() {
|
||||
wuffs_bzip2__decoder* x =
|
||||
(wuffs_bzip2__decoder*)(calloc(sizeof(wuffs_bzip2__decoder), 1));
|
||||
if (!x) {
|
||||
return NULL;
|
||||
}
|
||||
if (wuffs_bzip2__decoder__initialize(
|
||||
x, sizeof(wuffs_bzip2__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
|
||||
free(x);
|
||||
return NULL;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_bzip2__decoder() {
|
||||
return sizeof(wuffs_bzip2__decoder);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func bzip2.decoder.set_quirk_enabled
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__set_quirk_enabled(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
if (a_quirk == 1) {
|
||||
self->private_impl.f_ignore_checksum = a_enabled;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.workbuf_len
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_bzip2__decoder__workbuf_len(
|
||||
const wuffs_bzip2__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_range_ii_u64(0, 0);
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.transform_io
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_bzip2__decoder__transform_io(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 1)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint64_t v_tag = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
uint32_t v_final_checksum_want = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_transform_io[0].v_i;
|
||||
v_tag = self->private_data.s_transform_io[0].v_tag;
|
||||
v_final_checksum_want = self->private_data.s_transform_io[0].v_final_checksum_want;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
if (v_c != 66) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
v_c = t_1;
|
||||
}
|
||||
if (v_c != 90) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
v_c = t_2;
|
||||
}
|
||||
if (v_c != 104) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
if ((v_c < 49) || (57 < v_c)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_max_incl_block_size = (((uint32_t)((v_c - 48))) * 100000);
|
||||
while (true) {
|
||||
v_tag = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 48) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_tag <<= 1;
|
||||
v_tag |= ((uint64_t)((self->private_impl.f_bits >> 31)));
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_tag == 25779555029136) {
|
||||
goto label__0__break;
|
||||
} else if (v_tag != 54156738319193) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_bzip2__decoder__prepare_block(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_block_size = 0;
|
||||
self->private_impl.f_decode_huffman_finished = false;
|
||||
self->private_impl.f_decode_huffman_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[0] & 7)];
|
||||
self->private_impl.f_decode_huffman_ticks = 50;
|
||||
self->private_impl.f_decode_huffman_section = 0;
|
||||
self->private_impl.f_decode_huffman_run_shift = 0;
|
||||
while ( ! self->private_impl.f_decode_huffman_finished) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_status = wuffs_bzip2__decoder__decode_huffman_fast(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (wuffs_base__status__is_error(&v_status)) {
|
||||
status = v_status;
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_decode_huffman_finished) {
|
||||
goto label__1__break;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_bzip2__decoder__decode_huffman_slow(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
label__1__break:;
|
||||
wuffs_bzip2__decoder__invert_bwt(self);
|
||||
self->private_impl.f_block_checksum_have = 4294967295;
|
||||
if (self->private_impl.f_original_pointer >= self->private_impl.f_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_flush_pointer = (self->private_data.f_bwt[self->private_impl.f_original_pointer] >> 12);
|
||||
self->private_impl.f_flush_repeat_count = 0;
|
||||
self->private_impl.f_flush_prev = 0;
|
||||
while (self->private_impl.f_block_size > 0) {
|
||||
wuffs_bzip2__decoder__flush_fast(self, a_dst);
|
||||
if (self->private_impl.f_block_size <= 0) {
|
||||
goto label__2__break;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_bzip2__decoder__flush_slow(self, a_dst);
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
label__2__break:;
|
||||
self->private_impl.f_block_checksum_have ^= 4294967295;
|
||||
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_block_checksum_have != self->private_impl.f_block_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_final_checksum_have = (self->private_impl.f_block_checksum_have ^ ((self->private_impl.f_final_checksum_have >> 31) | ((uint32_t)(self->private_impl.f_final_checksum_have << 1))));
|
||||
}
|
||||
label__0__break:;
|
||||
v_final_checksum_want = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 32) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_final_checksum_want <<= 1;
|
||||
v_final_checksum_want |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_final_checksum_have != v_final_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_transform_io[0].v_i = v_i;
|
||||
self->private_data.s_transform_io[0].v_tag = v_tag;
|
||||
self->private_data.s_transform_io[0].v_final_checksum_want = v_final_checksum_want;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.prepare_block
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__prepare_block(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_selector = 0;
|
||||
uint32_t v_sel_ff = 0;
|
||||
uint8_t v_movee = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_prepare_block[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_prepare_block[0].v_i;
|
||||
v_selector = self->private_data.s_prepare_block[0].v_selector;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_block_checksum_want = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 32) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_impl.f_block_checksum_want <<= 1;
|
||||
self->private_impl.f_block_checksum_want |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
v_c = t_1;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__unsupported_block_randomization);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
self->private_impl.f_original_pointer = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 24) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
v_c = t_2;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_impl.f_original_pointer <<= 1;
|
||||
self->private_impl.f_original_pointer |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_presence[v_i] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) != 0) {
|
||||
self->private_data.f_presence[v_i] = 1;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 16;
|
||||
}
|
||||
self->private_data.f_scratch = 0;
|
||||
v_i = 0;
|
||||
label__0__continue:;
|
||||
while (v_i < 256) {
|
||||
if (self->private_data.f_presence[v_i] == 0) {
|
||||
v_i += 16;
|
||||
goto label__0__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_data.f_scratch += (self->private_impl.f_bits >> 31);
|
||||
self->private_data.f_presence[(v_i & 255)] = ((uint8_t)((self->private_impl.f_bits >> 31)));
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
if ((v_i & 15) == 0) {
|
||||
goto label__1__break;
|
||||
}
|
||||
}
|
||||
label__1__break:;
|
||||
}
|
||||
if ((self->private_data.f_scratch < 1) || (256 < self->private_data.f_scratch)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_num_symbols = (self->private_data.f_scratch + 2);
|
||||
self->private_data.f_scratch = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 3) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_data.f_scratch <<= 1;
|
||||
self->private_data.f_scratch |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ((self->private_data.f_scratch < 2) || (6 < self->private_data.f_scratch)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_num_huffman_codes = self->private_data.f_scratch;
|
||||
self->private_data.f_scratch = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 15) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
self->private_data.f_scratch <<= 1;
|
||||
self->private_data.f_scratch |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ((self->private_data.f_scratch < 1) || (18001 < self->private_data.f_scratch)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_num_sections = self->private_data.f_scratch;
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_huffman_codes) {
|
||||
self->private_data.f_mtft[v_i] = ((uint8_t)(v_i));
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_sections) {
|
||||
v_selector = 0;
|
||||
while (true) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_7 = *iop_a_src++;
|
||||
v_c = t_7;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) == 0) {
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
goto label__2__break;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_selector += 1;
|
||||
if (v_selector >= self->private_impl.f_num_huffman_codes) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
label__2__break:;
|
||||
if (v_selector == 0) {
|
||||
self->private_data.f_huffman_selectors[v_i] = self->private_data.f_mtft[0];
|
||||
} else {
|
||||
v_sel_ff = (v_selector & 255);
|
||||
v_movee = self->private_data.f_mtft[v_sel_ff];
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_sel_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_sel_ff));
|
||||
self->private_data.f_mtft[0] = v_movee;
|
||||
self->private_data.f_huffman_selectors[v_i] = v_movee;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_huffman_codes) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_bzip2__decoder__read_code_lengths(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
v_status = wuffs_bzip2__decoder__build_huffman_tree(self, v_i);
|
||||
if (wuffs_base__status__is_error(&v_status)) {
|
||||
status = v_status;
|
||||
goto exit;
|
||||
}
|
||||
wuffs_bzip2__decoder__build_huffman_table(self, v_i);
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
v_j = 0;
|
||||
while (v_i < 256) {
|
||||
if (self->private_data.f_presence[v_i] != 0) {
|
||||
self->private_data.f_mtft[(v_j & 255)] = ((uint8_t)(v_i));
|
||||
v_j += 1;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_letter_counts[v_i] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_prepare_block[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_prepare_block[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_prepare_block[0].v_i = v_i;
|
||||
self->private_data.s_prepare_block[0].v_selector = v_selector;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.read_code_lengths
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__read_code_lengths(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_code_length = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_read_code_lengths[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_read_code_lengths[0].v_i;
|
||||
v_code_length = self->private_data.s_read_code_lengths[0].v_code_length;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_code_lengths_bitmask = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 5) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_code_length <<= 1;
|
||||
v_code_length |= (self->private_impl.f_bits >> 31);
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_num_symbols) {
|
||||
while (true) {
|
||||
if ((v_code_length < 1) || (20 < v_code_length)) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_header);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
v_c = t_1;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) == 0) {
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
goto label__0__break;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
v_c = t_2;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
if ((self->private_impl.f_bits >> 31) == 0) {
|
||||
v_code_length += 1;
|
||||
} else {
|
||||
v_code_length -= 1;
|
||||
}
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
}
|
||||
label__0__break:;
|
||||
self->private_impl.f_code_lengths_bitmask |= (((uint32_t)(1)) << (v_code_length & 31));
|
||||
self->private_data.f_bwt[v_i] = v_code_length;
|
||||
v_i += 1;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_read_code_lengths[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_read_code_lengths[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_read_code_lengths[0].v_i = v_i;
|
||||
self->private_data.s_read_code_lengths[0].v_code_length = v_code_length;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.build_huffman_tree
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__build_huffman_tree(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which) {
|
||||
uint32_t v_code_length = 0;
|
||||
uint32_t v_symbol_index = 0;
|
||||
uint32_t v_num_branch_nodes = 0;
|
||||
uint32_t v_stack_height = 0;
|
||||
uint32_t v_stack_values[21] = {0};
|
||||
uint32_t v_node_index = 0;
|
||||
uint16_t v_leaf_value = 0;
|
||||
|
||||
self->private_data.f_huffman_trees[a_which][0][0] = 0;
|
||||
self->private_data.f_huffman_trees[a_which][0][1] = 0;
|
||||
v_num_branch_nodes = 1;
|
||||
v_stack_height = 1;
|
||||
v_stack_values[0] = 0;
|
||||
v_code_length = 1;
|
||||
label__0__continue:;
|
||||
while (v_code_length <= 20) {
|
||||
if ((self->private_impl.f_code_lengths_bitmask & (((uint32_t)(1)) << v_code_length)) == 0) {
|
||||
v_code_length += 1;
|
||||
goto label__0__continue;
|
||||
}
|
||||
v_symbol_index = 0;
|
||||
label__1__continue:;
|
||||
while (v_symbol_index < self->private_impl.f_num_symbols) {
|
||||
if (self->private_data.f_bwt[v_symbol_index] != v_code_length) {
|
||||
v_symbol_index += 1;
|
||||
goto label__1__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (v_stack_height <= 0) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__bad_huffman_code_over_subscribed);
|
||||
} else if (v_stack_height >= v_code_length) {
|
||||
goto label__2__break;
|
||||
}
|
||||
v_node_index = v_stack_values[(v_stack_height - 1)];
|
||||
if (self->private_data.f_huffman_trees[a_which][v_node_index][0] == 0) {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][0] = ((uint16_t)(v_num_branch_nodes));
|
||||
} else {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][1] = ((uint16_t)(v_num_branch_nodes));
|
||||
}
|
||||
if (v_num_branch_nodes >= 257) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
v_stack_values[v_stack_height] = v_num_branch_nodes;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_branch_nodes][0] = 0;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_branch_nodes][1] = 0;
|
||||
v_num_branch_nodes += 1;
|
||||
v_stack_height += 1;
|
||||
}
|
||||
label__2__break:;
|
||||
v_node_index = v_stack_values[(v_stack_height - 1)];
|
||||
if (v_symbol_index < 2) {
|
||||
v_leaf_value = ((uint16_t)((769 + v_symbol_index)));
|
||||
} else if ((v_symbol_index + 1) < self->private_impl.f_num_symbols) {
|
||||
v_leaf_value = ((uint16_t)((511 + v_symbol_index)));
|
||||
} else {
|
||||
v_leaf_value = 768;
|
||||
}
|
||||
if (self->private_data.f_huffman_trees[a_which][v_node_index][0] == 0) {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][0] = v_leaf_value;
|
||||
} else {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][1] = v_leaf_value;
|
||||
v_stack_height -= 1;
|
||||
while (v_stack_height > 0) {
|
||||
v_node_index = v_stack_values[(v_stack_height - 1)];
|
||||
if (self->private_data.f_huffman_trees[a_which][v_node_index][1] == 0) {
|
||||
goto label__3__break;
|
||||
}
|
||||
v_stack_height -= 1;
|
||||
}
|
||||
label__3__break:;
|
||||
}
|
||||
v_symbol_index += 1;
|
||||
}
|
||||
v_code_length += 1;
|
||||
}
|
||||
if (v_stack_height != 0) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.build_huffman_table
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__build_huffman_table(
|
||||
wuffs_bzip2__decoder* self,
|
||||
uint32_t a_which) {
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_bits = 0;
|
||||
uint16_t v_n_bits = 0;
|
||||
uint16_t v_child = 0;
|
||||
|
||||
while (v_i < 256) {
|
||||
v_bits = (v_i << 24);
|
||||
v_n_bits = 0;
|
||||
v_child = 0;
|
||||
while ((v_child < 257) && (v_n_bits < 8)) {
|
||||
v_child = self->private_data.f_huffman_trees[a_which][v_child][(v_bits >> 31)];
|
||||
v_bits <<= 1;
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
v_n_bits += 1;
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
self->private_data.f_huffman_tables[a_which][v_i] = ((uint16_t)((v_child | (v_n_bits << 12))));
|
||||
v_i += 1;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.invert_bwt
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__invert_bwt(
|
||||
wuffs_bzip2__decoder* self) {
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_letter = 0;
|
||||
uint32_t v_sum = 0;
|
||||
uint32_t v_old_sum = 0;
|
||||
|
||||
v_sum = 0;
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
v_old_sum = v_sum;
|
||||
v_sum += self->private_data.f_letter_counts[v_i];
|
||||
self->private_data.f_letter_counts[v_i] = v_old_sum;
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < self->private_impl.f_block_size) {
|
||||
v_letter = (self->private_data.f_bwt[v_i] & 255);
|
||||
self->private_data.f_bwt[(self->private_data.f_letter_counts[v_letter] & 1048575)] |= (v_i << 12);
|
||||
self->private_data.f_letter_counts[v_letter] += 1;
|
||||
v_i += 1;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.flush_fast
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_bzip2__decoder__flush_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst) {
|
||||
uint32_t v_flush_pointer = 0;
|
||||
uint32_t v_flush_repeat_count = 0;
|
||||
uint8_t v_flush_prev = 0;
|
||||
uint32_t v_block_checksum_have = 0;
|
||||
uint32_t v_block_size = 0;
|
||||
uint32_t v_entry = 0;
|
||||
uint8_t v_curr = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
io2_a_dst = io0_a_dst + a_dst->data.len;
|
||||
if (a_dst->meta.closed) {
|
||||
io2_a_dst = iop_a_dst;
|
||||
}
|
||||
}
|
||||
|
||||
v_flush_pointer = self->private_impl.f_flush_pointer;
|
||||
v_flush_repeat_count = self->private_impl.f_flush_repeat_count;
|
||||
v_flush_prev = self->private_impl.f_flush_prev;
|
||||
v_block_checksum_have = self->private_impl.f_block_checksum_have;
|
||||
v_block_size = self->private_impl.f_block_size;
|
||||
while ((v_block_size > 0) && (((uint64_t)(io2_a_dst - iop_a_dst)) >= 255)) {
|
||||
if (v_flush_repeat_count < 4) {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
if (v_curr == v_flush_prev) {
|
||||
v_flush_repeat_count += 1;
|
||||
} else {
|
||||
v_flush_repeat_count = 1;
|
||||
}
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_curr), iop_a_dst += 1);
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
} else {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
v_flush_repeat_count = ((uint32_t)(v_curr));
|
||||
while (v_flush_repeat_count > 0) {
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) > 0) {
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_flush_prev), iop_a_dst += 1);
|
||||
}
|
||||
v_flush_repeat_count -= 1;
|
||||
}
|
||||
v_flush_repeat_count = 0;
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_flush_pointer = v_flush_pointer;
|
||||
self->private_impl.f_flush_repeat_count = v_flush_repeat_count;
|
||||
self->private_impl.f_flush_prev = v_flush_prev;
|
||||
self->private_impl.f_block_checksum_have = v_block_checksum_have;
|
||||
if (v_block_size <= 900000) {
|
||||
self->private_impl.f_block_size = v_block_size;
|
||||
}
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.flush_slow
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__flush_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_flush_pointer = 0;
|
||||
uint32_t v_flush_repeat_count = 0;
|
||||
uint8_t v_flush_prev = 0;
|
||||
uint32_t v_block_checksum_have = 0;
|
||||
uint32_t v_block_size = 0;
|
||||
uint32_t v_entry = 0;
|
||||
uint8_t v_curr = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
io2_a_dst = io0_a_dst + a_dst->data.len;
|
||||
if (a_dst->meta.closed) {
|
||||
io2_a_dst = iop_a_dst;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_flush_slow[0];
|
||||
if (coro_susp_point) {
|
||||
v_flush_pointer = self->private_data.s_flush_slow[0].v_flush_pointer;
|
||||
v_flush_repeat_count = self->private_data.s_flush_slow[0].v_flush_repeat_count;
|
||||
v_flush_prev = self->private_data.s_flush_slow[0].v_flush_prev;
|
||||
v_block_checksum_have = self->private_data.s_flush_slow[0].v_block_checksum_have;
|
||||
v_block_size = self->private_data.s_flush_slow[0].v_block_size;
|
||||
v_curr = self->private_data.s_flush_slow[0].v_curr;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
v_flush_pointer = self->private_impl.f_flush_pointer;
|
||||
v_flush_repeat_count = self->private_impl.f_flush_repeat_count;
|
||||
v_flush_prev = self->private_impl.f_flush_prev;
|
||||
v_block_checksum_have = self->private_impl.f_block_checksum_have;
|
||||
v_block_size = self->private_impl.f_block_size;
|
||||
while ((v_block_size > 0) && ! (self->private_impl.p_flush_slow[0] != 0)) {
|
||||
if (v_flush_repeat_count < 4) {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
if (v_curr == v_flush_prev) {
|
||||
v_flush_repeat_count += 1;
|
||||
} else {
|
||||
v_flush_repeat_count = 1;
|
||||
}
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
self->private_data.s_flush_slow[0].scratch = v_curr;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (iop_a_dst == io2_a_dst) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
goto suspend;
|
||||
}
|
||||
*iop_a_dst++ = ((uint8_t)(self->private_data.s_flush_slow[0].scratch));
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
} else {
|
||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||
v_curr = ((uint8_t)((v_entry & 255)));
|
||||
v_flush_pointer = (v_entry >> 12);
|
||||
v_flush_repeat_count = ((uint32_t)(v_curr));
|
||||
while (v_flush_repeat_count > 0) {
|
||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||
self->private_data.s_flush_slow[0].scratch = v_flush_prev;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (iop_a_dst == io2_a_dst) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
goto suspend;
|
||||
}
|
||||
*iop_a_dst++ = ((uint8_t)(self->private_data.s_flush_slow[0].scratch));
|
||||
v_flush_repeat_count -= 1;
|
||||
}
|
||||
v_flush_repeat_count = 0;
|
||||
v_flush_prev = v_curr;
|
||||
v_block_size -= 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_flush_pointer = v_flush_pointer;
|
||||
self->private_impl.f_flush_repeat_count = v_flush_repeat_count;
|
||||
self->private_impl.f_flush_prev = v_flush_prev;
|
||||
self->private_impl.f_block_checksum_have = v_block_checksum_have;
|
||||
if (v_block_size <= 900000) {
|
||||
self->private_impl.f_block_size = v_block_size;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_flush_slow[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_flush_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_flush_slow[0].v_flush_pointer = v_flush_pointer;
|
||||
self->private_data.s_flush_slow[0].v_flush_repeat_count = v_flush_repeat_count;
|
||||
self->private_data.s_flush_slow[0].v_flush_prev = v_flush_prev;
|
||||
self->private_data.s_flush_slow[0].v_block_checksum_have = v_block_checksum_have;
|
||||
self->private_data.s_flush_slow[0].v_block_size = v_block_size;
|
||||
self->private_data.s_flush_slow[0].v_curr = v_curr;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.decode_huffman_fast
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_bits = 0;
|
||||
uint32_t v_n_bits = 0;
|
||||
uint32_t v_block_size = 0;
|
||||
uint8_t v_which = 0;
|
||||
uint32_t v_ticks = 0;
|
||||
uint32_t v_section = 0;
|
||||
uint32_t v_run_shift = 0;
|
||||
uint16_t v_table_entry = 0;
|
||||
uint16_t v_child = 0;
|
||||
uint32_t v_child_ff = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_output = 0;
|
||||
uint32_t v_run = 0;
|
||||
uint32_t v_mtft0 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_block_size = self->private_impl.f_block_size;
|
||||
v_which = self->private_impl.f_decode_huffman_which;
|
||||
v_ticks = self->private_impl.f_decode_huffman_ticks;
|
||||
v_section = self->private_impl.f_decode_huffman_section;
|
||||
v_run_shift = self->private_impl.f_decode_huffman_run_shift;
|
||||
label__outer__continue:;
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) >= 4) {
|
||||
if (v_ticks > 0) {
|
||||
v_ticks -= 1;
|
||||
} else {
|
||||
v_ticks = 49;
|
||||
v_section += 1;
|
||||
if (v_section >= self->private_impl.f_num_sections) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_number_of_sections);
|
||||
goto exit;
|
||||
}
|
||||
v_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(v_section & 32767)] & 7)];
|
||||
}
|
||||
v_bits |= (wuffs_base__peek_u32be__no_bounds_check(iop_a_src) >> v_n_bits);
|
||||
iop_a_src += ((31 - v_n_bits) >> 3);
|
||||
v_n_bits |= 24;
|
||||
v_table_entry = self->private_data.f_huffman_tables[v_which][(v_bits >> 24)];
|
||||
v_bits <<= (v_table_entry >> 12);
|
||||
v_n_bits -= ((uint32_t)((v_table_entry >> 12)));
|
||||
v_child = (v_table_entry & 1023);
|
||||
while (v_child < 257) {
|
||||
v_child = self->private_data.f_huffman_trees[v_which][v_child][(v_bits >> 31)];
|
||||
v_bits <<= 1;
|
||||
if (v_n_bits <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
v_n_bits -= 1;
|
||||
}
|
||||
if (v_child < 768) {
|
||||
v_child_ff = ((uint32_t)((v_child & 255)));
|
||||
v_output = ((uint32_t)(self->private_data.f_mtft[v_child_ff]));
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_child_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_child_ff));
|
||||
self->private_data.f_mtft[0] = ((uint8_t)(v_output));
|
||||
self->private_data.f_letter_counts[v_output] += 1;
|
||||
self->private_data.f_bwt[v_block_size] = v_output;
|
||||
if (v_block_size >= self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_block_size += 1;
|
||||
v_run_shift = 0;
|
||||
goto label__outer__continue;
|
||||
} else if (v_child == 768) {
|
||||
self->private_impl.f_decode_huffman_finished = true;
|
||||
goto label__outer__break;
|
||||
}
|
||||
if (v_run_shift >= 23) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_run = ((((uint32_t)(v_child)) & 3) << v_run_shift);
|
||||
v_run_shift += 1;
|
||||
v_i = v_block_size;
|
||||
v_j = (v_run + v_block_size);
|
||||
if (v_j > self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_block_size = v_j;
|
||||
v_mtft0 = ((uint32_t)(self->private_data.f_mtft[0]));
|
||||
self->private_data.f_letter_counts[v_mtft0] += v_run;
|
||||
while (v_i < v_j) {
|
||||
self->private_data.f_bwt[v_i] = v_mtft0;
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
label__outer__break:;
|
||||
self->private_impl.f_bits = v_bits;
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
self->private_impl.f_block_size = v_block_size;
|
||||
self->private_impl.f_decode_huffman_which = v_which;
|
||||
self->private_impl.f_decode_huffman_ticks = v_ticks;
|
||||
self->private_impl.f_decode_huffman_section = v_section;
|
||||
self->private_impl.f_decode_huffman_run_shift = v_run_shift;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.decode_huffman_slow
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_huffman_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_node_index = 0;
|
||||
uint16_t v_child = 0;
|
||||
uint32_t v_child_ff = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_output = 0;
|
||||
uint32_t v_run = 0;
|
||||
uint32_t v_mtft0 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_huffman_slow[0];
|
||||
if (coro_susp_point) {
|
||||
v_node_index = self->private_data.s_decode_huffman_slow[0].v_node_index;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
while ( ! (self->private_impl.p_decode_huffman_slow[0] != 0)) {
|
||||
if (self->private_impl.f_decode_huffman_ticks > 0) {
|
||||
self->private_impl.f_decode_huffman_ticks -= 1;
|
||||
} else {
|
||||
self->private_impl.f_decode_huffman_ticks = 49;
|
||||
self->private_impl.f_decode_huffman_section += 1;
|
||||
if (self->private_impl.f_decode_huffman_section >= self->private_impl.f_num_sections) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_number_of_sections);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_decode_huffman_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(self->private_impl.f_decode_huffman_section & 32767)] & 7)];
|
||||
}
|
||||
v_node_index = 0;
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_n_bits <= 0) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
v_c = t_0;
|
||||
}
|
||||
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
|
||||
self->private_impl.f_n_bits = 8;
|
||||
}
|
||||
v_child = self->private_data.f_huffman_trees[self->private_impl.f_decode_huffman_which][v_node_index][(self->private_impl.f_bits >> 31)];
|
||||
self->private_impl.f_bits <<= 1;
|
||||
self->private_impl.f_n_bits -= 1;
|
||||
if (v_child < 257) {
|
||||
v_node_index = ((uint32_t)(v_child));
|
||||
goto label__0__continue;
|
||||
} else if (v_child < 768) {
|
||||
v_child_ff = ((uint32_t)((v_child & 255)));
|
||||
v_output = ((uint32_t)(self->private_data.f_mtft[v_child_ff]));
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_child_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_child_ff));
|
||||
self->private_data.f_mtft[0] = ((uint8_t)(v_output));
|
||||
self->private_data.f_letter_counts[v_output] += 1;
|
||||
self->private_data.f_bwt[self->private_impl.f_block_size] = v_output;
|
||||
if (self->private_impl.f_block_size >= self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_block_size += 1;
|
||||
self->private_impl.f_decode_huffman_run_shift = 0;
|
||||
goto label__0__break;
|
||||
} else if (v_child == 768) {
|
||||
self->private_impl.f_decode_huffman_finished = true;
|
||||
goto label__outer__break;
|
||||
}
|
||||
if (self->private_impl.f_decode_huffman_run_shift >= 23) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_run = ((((uint32_t)(v_child)) & 3) << self->private_impl.f_decode_huffman_run_shift);
|
||||
self->private_impl.f_decode_huffman_run_shift += 1;
|
||||
v_i = self->private_impl.f_block_size;
|
||||
v_j = (v_run + self->private_impl.f_block_size);
|
||||
if (v_j > self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_block_size = v_j;
|
||||
v_mtft0 = ((uint32_t)(self->private_data.f_mtft[0]));
|
||||
self->private_data.f_letter_counts[v_mtft0] += v_run;
|
||||
while (v_i < v_j) {
|
||||
self->private_data.f_bwt[v_i] = v_mtft0;
|
||||
v_i += 1;
|
||||
}
|
||||
goto label__0__break;
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
label__outer__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_huffman_slow[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_huffman_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_huffman_slow[0].v_node_index = v_node_index;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CBOR)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
@@ -24253,7 +26648,7 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -24266,7 +26661,7 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -24277,7 +26672,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
if (coro_susp_point) {
|
||||
v_string_length = self->private_data.s_decode_tokens[0].v_string_length;
|
||||
v_depth = self->private_data.s_decode_tokens[0].v_depth;
|
||||
v_token_length = self->private_data.s_decode_tokens[0].v_token_length;
|
||||
v_tagged = self->private_data.s_decode_tokens[0].v_tagged;
|
||||
v_indefinite_string_major_type = self->private_data.s_decode_tokens[0].v_indefinite_string_major_type;
|
||||
}
|
||||
@@ -24366,8 +26760,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
v_c_major = 0;
|
||||
v_c_minor = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_cbor__error__internal_error_inconsistent_i_o);
|
||||
@@ -24788,16 +27180,15 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_decode_tokens[0].v_string_length = v_string_length;
|
||||
self->private_data.s_decode_tokens[0].v_depth = v_depth;
|
||||
self->private_data.s_decode_tokens[0].v_token_length = v_token_length;
|
||||
self->private_data.s_decode_tokens[0].v_tagged = v_tagged;
|
||||
self->private_data.s_decode_tokens[0].v_indefinite_string_major_type = v_indefinite_string_major_type;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26212,7 +28603,7 @@ wuffs_deflate__decoder__add_history(
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), v_s);
|
||||
self->private_impl.f_history_index = 32768;
|
||||
} else {
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (self->private_impl.f_history_index & 32767)), v_s);
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_history, (self->private_impl.f_history_index & 32767), 32768), v_s);
|
||||
if (v_n_copied < ((uint64_t)(v_s.len))) {
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, v_n_copied);
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), v_s);
|
||||
@@ -26225,7 +28616,7 @@ wuffs_deflate__decoder__add_history(
|
||||
self->private_impl.f_history_index = ((self->private_impl.f_history_index & 32767) + ((uint32_t)((v_n_copied & 32767))) + v_already_full);
|
||||
}
|
||||
}
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8((self->private_data.f_history) + 32768, 257), wuffs_base__make_slice_u8(self->private_data.f_history, 33025));
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_history, 32768, 33025), wuffs_base__make_slice_u8(self->private_data.f_history, 33025));
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
@@ -26291,7 +28682,7 @@ wuffs_deflate__decoder__transform_io(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -26350,7 +28741,7 @@ wuffs_deflate__decoder__transform_io(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26378,7 +28769,7 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -26507,7 +28898,7 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26530,7 +28921,7 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -26543,7 +28934,7 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -26626,10 +29017,10 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -26713,7 +29104,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -26729,7 +29120,6 @@ wuffs_deflate__decoder__init_dynamic_huffman(
|
||||
v_n_clen = self->private_data.s_init_dynamic_huffman[0].v_n_clen;
|
||||
v_i = self->private_data.s_init_dynamic_huffman[0].v_i;
|
||||
v_mask = self->private_data.s_init_dynamic_huffman[0].v_mask;
|
||||
v_table_entry = self->private_data.s_init_dynamic_huffman[0].v_table_entry;
|
||||
v_n_extra_bits = self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits;
|
||||
v_rep_symbol = self->private_data.s_init_dynamic_huffman[0].v_rep_symbol;
|
||||
v_rep_count = self->private_data.s_init_dynamic_huffman[0].v_rep_count;
|
||||
@@ -26929,14 +29319,13 @@ wuffs_deflate__decoder__init_dynamic_huffman(
|
||||
self->private_data.s_init_dynamic_huffman[0].v_n_clen = v_n_clen;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_i = v_i;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_mask = v_mask;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_table_entry = v_table_entry;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits = v_n_extra_bits;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_rep_symbol = v_rep_symbol;
|
||||
self->private_data.s_init_dynamic_huffman[0].v_rep_count = v_rep_count;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27229,7 +29618,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27242,7 +29631,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27358,7 +29747,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27403,10 +29792,10 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27442,7 +29831,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27455,7 +29844,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27623,7 +30012,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27661,10 +30050,10 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27706,7 +30095,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27719,7 +30108,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27835,7 +30224,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27880,10 +30269,10 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -27923,7 +30312,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -27936,7 +30325,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -27947,7 +30336,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
if (coro_susp_point) {
|
||||
v_bits = self->private_data.s_decode_huffman_slow[0].v_bits;
|
||||
v_n_bits = self->private_data.s_decode_huffman_slow[0].v_n_bits;
|
||||
v_table_entry = self->private_data.s_decode_huffman_slow[0].v_table_entry;
|
||||
v_table_entry_n_bits = self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits;
|
||||
v_lmask = self->private_data.s_decode_huffman_slow[0].v_lmask;
|
||||
v_dmask = self->private_data.s_decode_huffman_slow[0].v_dmask;
|
||||
@@ -27955,7 +30343,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_redir_mask = self->private_data.s_decode_huffman_slow[0].v_redir_mask;
|
||||
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
|
||||
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
|
||||
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28167,7 +30554,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_n_copied < v_hlen) {
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
@@ -28207,7 +30594,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
self->private_impl.p_decode_huffman_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_huffman_slow[0].v_bits = v_bits;
|
||||
self->private_data.s_decode_huffman_slow[0].v_n_bits = v_n_bits;
|
||||
self->private_data.s_decode_huffman_slow[0].v_table_entry = v_table_entry;
|
||||
self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits = v_table_entry_n_bits;
|
||||
self->private_data.s_decode_huffman_slow[0].v_lmask = v_lmask;
|
||||
self->private_data.s_decode_huffman_slow[0].v_dmask = v_dmask;
|
||||
@@ -28215,14 +30601,13 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
self->private_data.s_decode_huffman_slow[0].v_redir_mask = v_redir_mask;
|
||||
self->private_data.s_decode_huffman_slow[0].v_length = v_length;
|
||||
self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -28511,7 +30896,7 @@ wuffs_lzw__decoder__read_from(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -28653,7 +31038,7 @@ wuffs_lzw__decoder__read_from(
|
||||
self->private_impl.f_bits = v_bits;
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
self->private_impl.f_output_wi = v_output_wi;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -28675,7 +31060,7 @@ wuffs_lzw__decoder__write_to(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -28694,8 +31079,7 @@ wuffs_lzw__decoder__write_to(
|
||||
status = wuffs_base__make_status(wuffs_lzw__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
v_s = wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_output,
|
||||
8199),
|
||||
v_s = wuffs_base__make_slice_u8_ij(self->private_data.f_output,
|
||||
self->private_impl.f_output_ri,
|
||||
self->private_impl.f_output_wi);
|
||||
v_n = wuffs_base__io_writer__copy_from_slice(&iop_a_dst, io2_a_dst,v_s);
|
||||
@@ -28721,7 +31105,7 @@ wuffs_lzw__decoder__write_to(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
|
||||
@@ -28743,8 +31127,7 @@ wuffs_lzw__decoder__flush(
|
||||
wuffs_base__slice_u8 v_s = {0};
|
||||
|
||||
if (self->private_impl.f_output_ri <= self->private_impl.f_output_wi) {
|
||||
v_s = wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_output,
|
||||
8199),
|
||||
v_s = wuffs_base__make_slice_u8_ij(self->private_data.f_output,
|
||||
self->private_impl.f_output_ri,
|
||||
self->private_impl.f_output_wi);
|
||||
}
|
||||
@@ -29056,7 +31439,10 @@ wuffs_gif__decoder__decode_image_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 0) {
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if ( ! self->private_impl.f_seen_header) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_header(self, a_src);
|
||||
if (status.repr) {
|
||||
@@ -29067,9 +31453,7 @@ wuffs_gif__decoder__decode_image_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence != 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
self->private_impl.f_seen_header = true;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src);
|
||||
@@ -29099,7 +31483,9 @@ wuffs_gif__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
v_ffio);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
if (self->private_impl.f_call_sequence == 0) {
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -29177,7 +31563,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29188,7 +31574,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 1) {
|
||||
if ((self->private_impl.f_call_sequence & 16) == 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
@@ -29259,7 +31645,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
self->private_impl.f_metadata_io_position,
|
||||
self->private_impl.f_metadata_io_position);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_io_position = 0;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
@@ -29277,7 +31663,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29394,16 +31780,17 @@ wuffs_gif__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
} else if (a_io_position == 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_delayed_num_decoded_frames = false;
|
||||
self->private_impl.f_end_of_data = false;
|
||||
self->private_impl.f_restarted = true;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
self->private_impl.f_num_decoded_frame_configs_value = a_index;
|
||||
self->private_impl.f_num_decoded_frames_value = a_index;
|
||||
wuffs_gif__decoder__reset_gc(self);
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
@@ -29442,7 +31829,7 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29456,52 +31843,65 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_ignore_metadata = true;
|
||||
self->private_impl.f_dirty_max_excl_y = 0;
|
||||
if ( ! self->private_impl.f_end_of_data) {
|
||||
if (self->private_impl.f_call_sequence == 0) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence != 3) {
|
||||
if (self->private_impl.f_call_sequence == 4) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_gif__decoder__skip_frame(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if ((self->private_impl.f_call_sequence & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (self->private_impl.f_end_of_data) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_gif__decoder__skip_frame(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_call_sequence >= 96) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if ((self->private_impl.f_num_decoded_frame_configs_value > 0) || (self->private_impl.f_call_sequence == 40)) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_call_sequence >= 96) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
v_background_color = self->private_impl.f_black_color_u32_argb_premul;
|
||||
if ( ! self->private_impl.f_gc_has_transparent_index) {
|
||||
v_background_color = self->private_impl.f_background_color_u32_argb_premul;
|
||||
@@ -29533,7 +31933,7 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
v_background_color);
|
||||
}
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -29548,7 +31948,7 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29573,7 +31973,7 @@ wuffs_gif__decoder__skip_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29634,6 +32034,7 @@ wuffs_gif__decoder__skip_frame(
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
}
|
||||
wuffs_gif__decoder__reset_gc(self);
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -29647,7 +32048,7 @@ wuffs_gif__decoder__skip_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29689,13 +32090,16 @@ wuffs_gif__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.f_ignore_metadata = true;
|
||||
if (self->private_impl.f_call_sequence != 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_quirks[5] && ((self->private_impl.f_frame_rect_x0 == self->private_impl.f_frame_rect_x1) || (self->private_impl.f_frame_rect_y0 == self->private_impl.f_frame_rect_y1))) {
|
||||
status = wuffs_base__make_status(wuffs_gif__error__bad_frame_size);
|
||||
@@ -29713,8 +32117,8 @@ wuffs_gif__decoder__decode_frame(
|
||||
}
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
wuffs_gif__decoder__reset_gc(self);
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -29738,7 +32142,6 @@ wuffs_gif__decoder__decode_frame(
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_gif__decoder__reset_gc(
|
||||
wuffs_gif__decoder* self) {
|
||||
self->private_impl.f_call_sequence = 5;
|
||||
self->private_impl.f_gc_has_transparent_index = false;
|
||||
self->private_impl.f_gc_transparent_index = 0;
|
||||
self->private_impl.f_gc_disposal = 0;
|
||||
@@ -29760,7 +32163,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29771,15 +32174,8 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if ( ! self->private_impl.f_restarted) {
|
||||
if (self->private_impl.f_call_sequence != 2) {
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
}
|
||||
} else if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
} else {
|
||||
self->private_impl.f_restarted = false;
|
||||
if ((self->private_impl.f_frame_config_io_position == 0) || (self->private_impl.f_num_decoded_frame_configs_value > 0)) {
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
@@ -29825,7 +32221,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
self->private_impl.f_delayed_num_decoded_frames = false;
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
}
|
||||
self->private_impl.f_end_of_data = true;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
@@ -29843,7 +32239,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29865,7 +32261,7 @@ wuffs_gif__decoder__decode_header(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -29916,7 +32312,7 @@ wuffs_gif__decoder__decode_header(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -29942,7 +32338,7 @@ wuffs_gif__decoder__decode_lsd(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30118,7 +32514,7 @@ wuffs_gif__decoder__decode_lsd(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30139,7 +32535,7 @@ wuffs_gif__decoder__decode_extension(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30211,7 +32607,7 @@ wuffs_gif__decoder__decode_extension(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30232,7 +32628,7 @@ wuffs_gif__decoder__skip_blocks(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30279,7 +32675,7 @@ wuffs_gif__decoder__skip_blocks(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30305,7 +32701,7 @@ wuffs_gif__decoder__decode_ae(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30457,17 +32853,17 @@ wuffs_gif__decoder__decode_ae(
|
||||
if ((0 < self->private_impl.f_num_animation_loops_value) && (self->private_impl.f_num_animation_loops_value <= 65535)) {
|
||||
self->private_impl.f_num_animation_loops_value += 1;
|
||||
}
|
||||
} else if (self->private_impl.f_ignore_metadata) {
|
||||
} else if (self->private_impl.f_call_sequence >= 32) {
|
||||
} else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) {
|
||||
self->private_impl.f_metadata_fourcc = 1229144912;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
} else if (v_is_xmp && self->private_impl.f_report_metadata_xmp) {
|
||||
self->private_impl.f_metadata_fourcc = 1481461792;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
@@ -30502,7 +32898,7 @@ wuffs_gif__decoder__decode_ae(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30525,7 +32921,7 @@ wuffs_gif__decoder__decode_gc(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30632,7 +33028,7 @@ wuffs_gif__decoder__decode_gc(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30651,7 +33047,7 @@ wuffs_gif__decoder__decode_id_part0(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30782,7 +33178,7 @@ wuffs_gif__decoder__decode_id_part0(
|
||||
self->private_impl.f_frame_rect_y1 += self->private_impl.f_frame_rect_y0;
|
||||
self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0;
|
||||
self->private_impl.f_dst_y = self->private_impl.f_frame_rect_y0;
|
||||
if ((self->private_impl.f_call_sequence == 0) && ! self->private_impl.f_quirks[4]) {
|
||||
if ((self->private_impl.f_num_decoded_frame_configs_value == 0) && ! self->private_impl.f_quirks[4]) {
|
||||
self->private_impl.f_width = wuffs_base__u32__max(self->private_impl.f_width, self->private_impl.f_frame_rect_x1);
|
||||
self->private_impl.f_height = wuffs_base__u32__max(self->private_impl.f_height, self->private_impl.f_frame_rect_y1);
|
||||
}
|
||||
@@ -30799,7 +33195,7 @@ wuffs_gif__decoder__decode_id_part0(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -30828,7 +33224,7 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -30970,7 +33366,7 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -31008,7 +33404,7 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -31019,7 +33415,6 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
if (coro_susp_point) {
|
||||
v_block_size = self->private_data.s_decode_id_part2[0].v_block_size;
|
||||
v_need_block_size = self->private_data.s_decode_id_part2[0].v_need_block_size;
|
||||
v_lzw_status = self->private_data.s_decode_id_part2[0].v_lzw_status;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -31056,7 +33451,7 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto label__0__break;
|
||||
}
|
||||
v_n_copied = wuffs_base__io_reader__limited_copy_u32_to_slice(
|
||||
&iop_a_src, io2_a_src,((uint32_t)((v_n_compressed & 4294967295))), wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_compressed, 4096), self->private_impl.f_compressed_wi));
|
||||
&iop_a_src, io2_a_src,((uint32_t)((v_n_compressed & 4294967295))), wuffs_base__make_slice_u8_ij(self->private_data.f_compressed, self->private_impl.f_compressed_wi, 4096));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_compressed_wi, ((uint64_t)(v_n_copied)));
|
||||
wuffs_base__u64__sat_sub_indirect(&v_block_size, ((uint64_t)(v_n_copied)));
|
||||
if (v_block_size > 0) {
|
||||
@@ -31088,8 +33483,7 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
&io0_v_r,
|
||||
&io1_v_r,
|
||||
&io2_v_r,
|
||||
wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_compressed,
|
||||
4096),
|
||||
wuffs_base__make_slice_u8_ij(self->private_data.f_compressed,
|
||||
self->private_impl.f_compressed_ri,
|
||||
self->private_impl.f_compressed_wi),
|
||||
0);
|
||||
@@ -31197,11 +33591,10 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
self->private_impl.p_decode_id_part2[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_id_part2[0].v_block_size = v_block_size;
|
||||
self->private_data.s_decode_id_part2[0].v_need_block_size = v_need_block_size;
|
||||
self->private_data.s_decode_id_part2[0].v_lzw_status = v_lzw_status;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -31528,7 +33921,7 @@ wuffs_gzip__decoder__transform_io(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -31541,7 +33934,7 @@ wuffs_gzip__decoder__transform_io(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -31812,10 +34205,10 @@ wuffs_gzip__decoder__transform_io(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -32305,7 +34698,7 @@ wuffs_json__decoder__decode_tokens(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -32318,7 +34711,7 @@ wuffs_json__decoder__decode_tokens(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -32389,7 +34782,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
v_whitespace_length = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
@@ -32451,7 +34843,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_string_length = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) > 4) {
|
||||
@@ -32515,8 +34906,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_c = ((uint8_t)((wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8)));
|
||||
@@ -32545,8 +34934,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_uni4_string = (((uint64_t)(wuffs_base__peek_u48le__no_bounds_check(iop_a_src))) >> 16);
|
||||
@@ -32589,9 +34976,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
v_string_length = 0;
|
||||
v_uni4_value = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_uni4_string = (wuffs_base__peek_u64le__no_bounds_check(iop_a_src + 4) >> 16);
|
||||
@@ -32647,8 +35031,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_uni8_string = wuffs_base__peek_u64le__no_bounds_check(iop_a_src + 2);
|
||||
@@ -32702,8 +35084,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_backslash_x_string = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
@@ -32753,8 +35133,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_multi_byte_utf8 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
@@ -32798,8 +35176,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_multi_byte_utf8 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
|
||||
@@ -32845,8 +35221,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(13);
|
||||
v_string_length = 0;
|
||||
v_char = 0;
|
||||
goto label__string_loop_outer__continue;
|
||||
}
|
||||
v_multi_byte_utf8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
@@ -33267,10 +35641,10 @@ wuffs_json__decoder__decode_tokens(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33294,7 +35668,7 @@ wuffs_json__decoder__decode_number(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33409,7 +35783,7 @@ wuffs_json__decoder__decode_number(
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
label__goto_done__break:;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
return (v_n | v_floating_point);
|
||||
@@ -33429,7 +35803,7 @@ wuffs_json__decoder__decode_digits(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33459,7 +35833,7 @@ wuffs_json__decoder__decode_digits(
|
||||
if (v_n == a_n) {
|
||||
v_n |= 256;
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
return v_n;
|
||||
@@ -33481,7 +35855,7 @@ wuffs_json__decoder__decode_leading(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33494,7 +35868,7 @@ wuffs_json__decoder__decode_leading(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33564,10 +35938,10 @@ wuffs_json__decoder__decode_leading(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33591,7 +35965,7 @@ wuffs_json__decoder__decode_comment(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33604,7 +35978,7 @@ wuffs_json__decoder__decode_comment(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33636,102 +36010,102 @@ wuffs_json__decoder__decode_comment(
|
||||
v_length = 2;
|
||||
label__comment_block__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 1) {
|
||||
if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
v_c2 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
if (v_c2 == 12074) {
|
||||
iop_a_src += 2;
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_length + 2))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 1;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 1) {
|
||||
if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
v_length += 1;
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
v_c2 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
if (v_c2 == 12074) {
|
||||
iop_a_src += 2;
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_length + 2))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 1;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_block__continue;
|
||||
}
|
||||
v_length += 1;
|
||||
}
|
||||
} else if ((v_c2 == 12079) && self->private_impl.f_quirks[12]) {
|
||||
iop_a_src += 2;
|
||||
v_length = 2;
|
||||
label__comment_line__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
} else if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 10) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
} else if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
v_length += 1;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 10) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 1;
|
||||
if (v_length >= 65533) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
}
|
||||
v_length = 0;
|
||||
goto label__comment_line__continue;
|
||||
}
|
||||
v_length += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33746,10 +36120,10 @@ wuffs_json__decoder__decode_comment(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33772,7 +36146,7 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33785,7 +36159,7 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33793,9 +36167,6 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_inf_nan[0];
|
||||
if (coro_susp_point) {
|
||||
v_neg = self->private_data.s_decode_inf_nan[0].v_neg;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
@@ -33903,14 +36274,13 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_inf_nan[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_decode_inf_nan[0].v_neg = v_neg;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -33933,7 +36303,7 @@ wuffs_json__decoder__decode_trailer(
|
||||
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -33946,7 +36316,7 @@ wuffs_json__decoder__decode_trailer(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -33967,23 +36337,21 @@ wuffs_json__decoder__decode_trailer(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
v_whitespace_length = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
v_whitespace_length = 0;
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (v_whitespace_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_whitespace_length = 0;
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
goto label__outer__break;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
v_whitespace_length = 0;
|
||||
goto label__outer__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
@@ -33992,7 +36360,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_whitespace_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_whitespace_length = 0;
|
||||
}
|
||||
if (self->private_impl.f_trailer_stop > 0) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
@@ -34015,8 +36382,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
v_c = 0;
|
||||
v_whitespace_length = 0;
|
||||
if (self->private_impl.f_comment_type > 0) {
|
||||
goto label__outer__continue;
|
||||
}
|
||||
@@ -34028,7 +36393,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(0)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_whitespace_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_whitespace_length = 0;
|
||||
if (v_c == self->private_impl.f_trailer_stop) {
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
@@ -34051,10 +36415,10 @@ wuffs_json__decoder__decode_trailer(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34234,7 +36598,7 @@ wuffs_nie__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -34403,7 +36767,7 @@ wuffs_nie__decoder__decode_image_config(
|
||||
16,
|
||||
false);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -34418,7 +36782,7 @@ wuffs_nie__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34460,7 +36824,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -34471,7 +36835,8 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -34483,13 +36848,13 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (16 != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
@@ -34512,7 +36877,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
false,
|
||||
0);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -34526,7 +36891,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34573,13 +36938,13 @@ wuffs_nie__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_nie__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
@@ -34620,7 +36985,7 @@ wuffs_nie__decoder__decode_frame(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
}
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -34662,7 +37027,7 @@ wuffs_nie__decoder__swizzle(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -34714,7 +37079,7 @@ wuffs_nie__decoder__swizzle(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -34770,7 +37135,7 @@ wuffs_nie__decoder__num_decoded_frame_configs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -34789,7 +37154,7 @@ wuffs_nie__decoder__num_decoded_frames(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -34812,13 +37177,13 @@ wuffs_nie__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if ((a_index != 0) || (a_io_position != 16)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
@@ -35140,7 +37505,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -35153,7 +37518,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -35337,10 +37702,10 @@ wuffs_zlib__decoder__transform_io(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -35363,6 +37728,7 @@ const char wuffs_png__error__bad_filter[] = "#png: bad filter";
|
||||
const char wuffs_png__error__bad_header[] = "#png: bad header";
|
||||
const char wuffs_png__error__bad_text_chunk_not_latin_1[] = "#png: bad text chunk (not Latin-1)";
|
||||
const char wuffs_png__error__missing_palette[] = "#png: missing palette";
|
||||
const char wuffs_png__error__unsupported_cgbi_extension[] = "#png: unsupported CgBI extension";
|
||||
const char wuffs_png__error__unsupported_png_compression_method[] = "#png: unsupported PNG compression method";
|
||||
const char wuffs_png__error__unsupported_png_file[] = "#png: unsupported PNG file";
|
||||
const char wuffs_png__error__internal_error_inconsistent_i_o[] = "#png: internal error: inconsistent I/O";
|
||||
@@ -35608,7 +37974,8 @@ wuffs_png__decoder__choose_filter_implementations(
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_other_chunk(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
wuffs_base__io_buffer* a_src,
|
||||
bool a_framy);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_actl(
|
||||
@@ -37270,7 +39637,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -37284,16 +39651,10 @@ wuffs_png__decoder__decode_image_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 2) {
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence != 0) {
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else {
|
||||
} else if ( ! self->private_impl.f_seen_ihdr) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint64_t t_0;
|
||||
@@ -37357,6 +39718,10 @@ wuffs_png__decoder__decode_image_config(
|
||||
v_magic = t_1;
|
||||
}
|
||||
if (v_magic != 5927942488114331648) {
|
||||
if (v_magic == 5278895250759221248) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_cgbi_extension);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
@@ -37422,6 +39787,11 @@ wuffs_png__decoder__decode_image_config(
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_seen_ihdr = true;
|
||||
} else if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
@@ -37462,7 +39832,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src);
|
||||
wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src, false);
|
||||
v_status = t_4;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -37479,7 +39849,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
}
|
||||
label__2__break:;
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
self->private_impl.f_call_sequence = 16;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
@@ -37544,7 +39914,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
self->private_impl.f_first_disposal = 0;
|
||||
self->private_impl.f_first_overwrite_instead_of_blend = false;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
@@ -37559,7 +39929,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -37584,7 +39954,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -37763,7 +40133,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -37924,14 +40294,15 @@ wuffs_png__decoder__choose_filter_implementations(
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_other_chunk(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__io_buffer* a_src,
|
||||
bool a_framy) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -37942,7 +40313,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_chunk_type == 1163152464) {
|
||||
if ((self->private_impl.f_chunk_type == 1163152464) && ! a_framy) {
|
||||
if (self->private_impl.f_seen_plte) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
@@ -37969,43 +40340,8 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
}
|
||||
if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
if (self->private_impl.f_report_metadata_exif) {
|
||||
if (self->private_impl.f_seen_exif) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
@@ -38014,7 +40350,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_exif(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38024,97 +40360,6 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
self->private_impl.f_seen_exif = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) || (self->private_impl.f_chunk_type == 1951942004) || (self->private_impl.f_chunk_type == 1951945850)) {
|
||||
if (self->private_impl.f_report_metadata_kvp) {
|
||||
self->private_impl.f_metadata_flavor = 4;
|
||||
@@ -38123,6 +40368,135 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
}
|
||||
} else if ( ! a_framy) {
|
||||
if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
}
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||
@@ -38148,7 +40522,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38167,7 +40541,7 @@ wuffs_png__decoder__decode_actl(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38261,7 +40635,7 @@ wuffs_png__decoder__decode_actl(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38282,7 +40656,7 @@ wuffs_png__decoder__decode_chrm(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38558,7 +40932,7 @@ wuffs_png__decoder__decode_chrm(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38577,7 +40951,7 @@ wuffs_png__decoder__decode_exif(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38599,7 +40973,7 @@ wuffs_png__decoder__decode_exif(
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38623,7 +40997,7 @@ wuffs_png__decoder__decode_fctl(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -38936,7 +41310,7 @@ wuffs_png__decoder__decode_fctl(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -38955,7 +41329,7 @@ wuffs_png__decoder__decode_gama(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39017,7 +41391,7 @@ wuffs_png__decoder__decode_gama(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39038,7 +41412,7 @@ wuffs_png__decoder__decode_iccp(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39106,7 +41480,7 @@ wuffs_png__decoder__decode_iccp(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39129,7 +41503,7 @@ wuffs_png__decoder__decode_plte(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39209,7 +41583,7 @@ wuffs_png__decoder__decode_plte(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39228,7 +41602,7 @@ wuffs_png__decoder__decode_srgb(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39270,7 +41644,7 @@ wuffs_png__decoder__decode_srgb(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39293,7 +41667,7 @@ wuffs_png__decoder__decode_trns(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39455,7 +41829,7 @@ wuffs_png__decoder__decode_trns(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39490,11 +41864,13 @@ wuffs_png__decoder__decode_frame_config(
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_checksum_have = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39505,10 +41881,11 @@ wuffs_png__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 255) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else if (self->private_impl.f_call_sequence < 3) {
|
||||
if ((self->private_impl.f_call_sequence & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -39520,12 +41897,12 @@ wuffs_png__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -39537,10 +41914,14 @@ wuffs_png__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_call_sequence == 255) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 48;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_num_decoded_frame_configs_value == 0) {
|
||||
self->private_impl.f_frame_rect_x0 = self->private_impl.f_first_rect_x0;
|
||||
@@ -39611,7 +41992,48 @@ wuffs_png__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_chunk_type = t_1;
|
||||
}
|
||||
if (self->private_impl.f_chunk_type == 1413571686) {
|
||||
if (self->private_impl.f_chunk_type == 1145980233) {
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
uint32_t t_2;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_frame_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
|
||||
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
|
||||
if (num_bits_2 == 24) {
|
||||
t_2 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_2 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_2)) << 56;
|
||||
}
|
||||
}
|
||||
v_checksum_have = t_2;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != 2187346606)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else if (self->private_impl.f_chunk_type == 1413571686) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
@@ -39619,7 +42041,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -39628,7 +42050,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
self->private_data.s_decode_frame_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -39638,8 +42060,24 @@ wuffs_png__decoder__decode_frame_config(
|
||||
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
|
||||
goto label__0__break;
|
||||
}
|
||||
self->private_data.s_decode_frame_config[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
status = wuffs_png__decoder__decode_other_chunk(self, a_src, true);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||
self->private_impl.f_call_sequence = 48;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
self->private_data.s_decode_frame_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -39668,7 +42106,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
0);
|
||||
}
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -39682,7 +42120,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39706,7 +42144,7 @@ wuffs_png__decoder__skip_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39824,11 +42262,7 @@ wuffs_png__decoder__skip_frame(
|
||||
}
|
||||
label__0__break:;
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
|
||||
self->private_impl.f_call_sequence = 5;
|
||||
} else {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_skip_frame[0] = 0;
|
||||
@@ -39841,7 +42275,7 @@ wuffs_png__decoder__skip_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -39888,7 +42322,7 @@ wuffs_png__decoder__decode_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -39899,10 +42333,13 @@ wuffs_png__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 255) {
|
||||
if ((self->private_impl.f_call_sequence & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_call_sequence >= 96) {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else if (self->private_impl.f_call_sequence != 4) {
|
||||
} else if (self->private_impl.f_call_sequence != 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -40039,17 +42476,34 @@ wuffs_png__decoder__decode_frame(
|
||||
if ((v_pass_width > 0) && (v_pass_height > 0)) {
|
||||
self->private_impl.f_pass_bytes_per_row = wuffs_png__decoder__calculate_bytes_per_row(self, v_pass_width);
|
||||
self->private_impl.f_pass_workbuf_length = (((uint64_t)(v_pass_height)) * (1 + self->private_impl.f_pass_bytes_per_row));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
while (true) {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf);
|
||||
v_status = t_1;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
goto label__1__break;
|
||||
} else if (wuffs_base__status__is_error(&v_status) || ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed))) {
|
||||
if (self->private_impl.f_workbuf_wi <= ((uint64_t)(a_workbuf.len))) {
|
||||
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
|
||||
}
|
||||
if (v_status.repr == wuffs_base__suspension__short_read) {
|
||||
while (true) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
}
|
||||
label__1__break:;
|
||||
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = v_status;
|
||||
@@ -40064,7 +42518,7 @@ wuffs_png__decoder__decode_frame(
|
||||
self->private_impl.f_workbuf_hist_pos_base += self->private_impl.f_pass_workbuf_length;
|
||||
}
|
||||
if ((self->private_impl.f_interlace_pass == 0) || (self->private_impl.f_interlace_pass >= 7)) {
|
||||
goto label__1__break;
|
||||
goto label__2__break;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
@@ -40075,13 +42529,9 @@ wuffs_png__decoder__decode_frame(
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
label__1__break:;
|
||||
label__2__break:;
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
|
||||
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
|
||||
self->private_impl.f_call_sequence = 5;
|
||||
} else {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -40095,7 +42545,7 @@ wuffs_png__decoder__decode_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -40131,7 +42581,7 @@ wuffs_png__decoder__decode_pass(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -40437,7 +42887,7 @@ wuffs_png__decoder__decode_pass(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -40529,12 +42979,12 @@ wuffs_png__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
} else if ((a_index >= ((uint64_t)(self->private_impl.f_num_animation_frames_value))) || ((a_index == 0) && (a_io_position != self->private_impl.f_first_config_io_position))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
if (self->private_impl.f_interlace_pass >= 1) {
|
||||
self->private_impl.f_interlace_pass = 1;
|
||||
}
|
||||
@@ -40620,7 +43070,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
@@ -40633,7 +43083,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -40647,7 +43097,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 1) {
|
||||
if ((self->private_impl.f_call_sequence & 16) == 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
@@ -40861,7 +43311,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -40870,7 +43319,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -40942,7 +43390,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -40952,7 +43399,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -41046,7 +43492,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
@@ -41071,7 +43517,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
@@ -41088,10 +43534,10 @@ wuffs_png__decoder__tell_me_more(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
if (a_dst && a_dst->data.ptr) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -41482,6 +43928,1241 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
|
||||
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
|
||||
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__image_decoder__func_ptrs
|
||||
wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder = {
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__pixel_buffer*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__pixel_blend,
|
||||
wuffs_base__slice_u8,
|
||||
wuffs_base__decode_frame_options*))(&wuffs_tga__decoder__decode_frame),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__frame_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_frame_config),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__image_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_image_config),
|
||||
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_tga__decoder__frame_dirty_rect),
|
||||
(uint32_t(*)(const void*))(&wuffs_tga__decoder__num_animation_loops),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frame_configs),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frames),
|
||||
(wuffs_base__status(*)(void*,
|
||||
uint64_t,
|
||||
uint64_t))(&wuffs_tga__decoder__restart_frame),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_quirk_enabled),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_report_metadata),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__more_information*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__tell_me_more),
|
||||
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_tga__decoder__workbuf_len),
|
||||
};
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options){
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (sizeof(*self) != sizeof_star_self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
|
||||
}
|
||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
|
||||
}
|
||||
|
||||
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
|
||||
// The whole point of this if-check is to detect an uninitialized *self.
|
||||
// We disable the warning on GCC. Clang-5.0 does not have this warning.
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
if (self->private_impl.magic != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
|
||||
}
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
} else {
|
||||
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
|
||||
} else {
|
||||
memset(&(self->private_impl), 0, sizeof(self->private_impl));
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
|
||||
wuffs_base__image_decoder__vtable_name;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
|
||||
(const void*)(&wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc() {
|
||||
wuffs_tga__decoder* x =
|
||||
(wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1));
|
||||
if (!x) {
|
||||
return NULL;
|
||||
}
|
||||
if (wuffs_tga__decoder__initialize(
|
||||
x, sizeof(wuffs_tga__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
|
||||
free(x);
|
||||
return NULL;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder() {
|
||||
return sizeof(wuffs_tga__decoder);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func tga.decoder.set_quirk_enabled
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_image_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 1)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
uint32_t v_i = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_decode_image_config[0].v_i;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
self->private_impl.f_header_id_length = t_0;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_type = t_1;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type > 1) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_type = t_2;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type == 1) ||
|
||||
(self->private_impl.f_header_image_type == 2) ||
|
||||
(self->private_impl.f_header_image_type == 3) ||
|
||||
(self->private_impl.f_header_image_type == 9) ||
|
||||
(self->private_impl.f_header_image_type == 10) ||
|
||||
(self->private_impl.f_header_image_type == 11)) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
uint16_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3;
|
||||
if (num_bits_3 == 8) {
|
||||
t_3 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_first_entry_index = t_3;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint16_t t_4;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
|
||||
if (num_bits_4 == 8) {
|
||||
t_4 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_4 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_4)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_length = t_4;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_entry_size = t_5;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length > 256)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_header_color_map_entry_size != 15) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 16) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 24) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length != 0) || (self->private_impl.f_header_color_map_entry_size != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
uint32_t t_6;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_6;
|
||||
if (num_bits_6 == 8) {
|
||||
t_6 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_6 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_6)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_width = t_6;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
uint32_t t_7;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_7;
|
||||
if (num_bits_7 == 8) {
|
||||
t_7 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_7 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_7)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_height = t_7;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_8 = *iop_a_src++;
|
||||
self->private_impl.f_header_pixel_depth = t_8;
|
||||
}
|
||||
if ((self->private_impl.f_header_pixel_depth != 1) &&
|
||||
(self->private_impl.f_header_pixel_depth != 8) &&
|
||||
(self->private_impl.f_header_pixel_depth != 15) &&
|
||||
(self->private_impl.f_header_pixel_depth != 16) &&
|
||||
(self->private_impl.f_header_pixel_depth != 24) &&
|
||||
(self->private_impl.f_header_pixel_depth != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type | 8) == 9) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 2164523016;
|
||||
self->private_impl.f_opaque = ((self->private_impl.f_header_color_map_entry_size == 15) || (self->private_impl.f_header_color_map_entry_size == 24));
|
||||
} else if ((self->private_impl.f_header_image_type | 8) == 10) {
|
||||
if ((self->private_impl.f_header_pixel_depth == 15) || (self->private_impl.f_header_pixel_depth == 16)) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 0;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 24) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_pixfmt = 2147485832;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 32) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_header_pixel_depth == 8) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_9 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_descriptor = t_9;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_descriptor & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) {
|
||||
if (self->private_impl.f_header_color_map_entry_size == 24) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17);
|
||||
uint32_t t_10;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
|
||||
t_10 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 3;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(18);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_10;
|
||||
if (num_bits_10 == 16) {
|
||||
t_10 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_10 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_10)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_10;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
} else if (self->private_impl.f_header_color_map_entry_size == 32) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19);
|
||||
uint32_t t_11;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_11;
|
||||
if (num_bits_11 == 24) {
|
||||
t_11 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_11 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_11)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_11;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = ((uint8_t)(((v_c >> 24) & 255)));
|
||||
} else {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21);
|
||||
uint32_t t_12;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_12;
|
||||
if (num_bits_12 == 8) {
|
||||
t_12 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_12 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_12)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_12;
|
||||
}
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_src_palette[((v_i * 4) + 0)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 1)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 2)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 3)] = 255;
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__set(
|
||||
a_dst,
|
||||
self->private_impl.f_src_pixfmt,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
self->private_impl.f_opaque);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_decode_image_config[0].v_i = v_i;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 2)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__decode_image_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__frame_config__set(
|
||||
a_dst,
|
||||
wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height),
|
||||
((wuffs_base__flicks)(0)),
|
||||
0,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
0,
|
||||
self->private_impl.f_opaque,
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 3)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint32_t v_dst_x = 0;
|
||||
uint32_t v_dst_y = 0;
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_dst_start = 0;
|
||||
wuffs_base__slice_u8 v_src_palette = {0};
|
||||
uint64_t v_mark = 0;
|
||||
uint64_t v_num_pixels64 = 0;
|
||||
uint32_t v_num_pixels32 = 0;
|
||||
uint32_t v_lit_length = 0;
|
||||
uint32_t v_run_length = 0;
|
||||
uint64_t v_num_dst_bytes = 0;
|
||||
uint32_t v_num_src_bytes = 0;
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
if (coro_susp_point) {
|
||||
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
|
||||
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
|
||||
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
|
||||
v_mark = self->private_data.s_decode_frame[0].v_mark;
|
||||
v_num_pixels32 = self->private_data.s_decode_frame[0].v_num_pixels32;
|
||||
v_lit_length = self->private_data.s_decode_frame[0].v_lit_length;
|
||||
v_run_length = self->private_data.s_decode_frame[0].v_run_length;
|
||||
v_num_dst_bytes = self->private_data.s_decode_frame[0].v_num_dst_bytes;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
v_src_palette = wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024);
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
|
||||
wuffs_base__pixel_buffer__pixel_format(a_dst),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
|
||||
wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt),
|
||||
v_src_palette,
|
||||
a_blend);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = v_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
|
||||
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
|
||||
if ((v_dst_bits_per_pixel & 7) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
goto exit;
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y = ((uint32_t)(self->private_impl.f_height - 1));
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
label__resume__continue:;
|
||||
while (true) {
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
|
||||
while (v_dst_y < self->private_impl.f_height) {
|
||||
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
|
||||
v_dst_start = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_dst_start <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_start);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
while (v_dst_x < self->private_impl.f_width) {
|
||||
if (self->private_impl.f_src_bytes_per_pixel > 0) {
|
||||
if (v_lit_length > 0) {
|
||||
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
v_num_pixels64 = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(self->private_impl.f_src_bytes_per_pixel)));
|
||||
v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length)))));
|
||||
v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel);
|
||||
v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel);
|
||||
self->private_data.s_decode_frame[0].scratch = v_num_src_bytes;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_frame[0].scratch;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
|
||||
if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
v_dst_x += v_num_pixels32;
|
||||
v_lit_length = (((uint32_t)(v_lit_length - v_num_pixels32)) & 65535);
|
||||
if (v_lit_length > 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_src_bytes_per_pixel == 1) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else if (self->private_impl.f_src_bytes_per_pixel == 3) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 5) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[3] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
}
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (v_lit_length > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, 4));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
v_lit_length -= 1;
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 3) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
v_dst_x = 0;
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y -= 1;
|
||||
} else {
|
||||
v_dst_y += 1;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
}
|
||||
goto label__resume__break;
|
||||
}
|
||||
label__resume__break:;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
|
||||
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
|
||||
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
|
||||
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
|
||||
self->private_data.s_decode_frame[0].v_mark = v_mark;
|
||||
self->private_data.s_decode_frame[0].v_num_pixels32 = v_num_pixels32;
|
||||
self->private_data.s_decode_frame[0].v_lit_length = v_lit_length;
|
||||
self->private_data.s_decode_frame[0].v_run_length = v_run_length;
|
||||
self->private_data.s_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.frame_dirty_rect
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_animation_loops
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frame_configs
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frames
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.restart_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.set_report_metadata
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.tell_me_more
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 4)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.workbuf_len
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_range_ii_u64(0, 0);
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
@@ -41648,7 +45329,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -41727,7 +45408,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
true);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -41744,7 +45425,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -41786,7 +45467,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -41797,7 +45478,8 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence == 32) {
|
||||
} else if (self->private_impl.f_call_sequence < 32) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -41809,13 +45491,13 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
} else if (self->private_impl.f_call_sequence == 40) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
} else if (self->private_impl.f_call_sequence == 64) {
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
@@ -41838,7 +45520,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
self->private_impl.f_call_sequence = 64;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
@@ -41852,7 +45534,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -41909,7 +45591,7 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
@@ -41927,7 +45609,8 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (self->private_impl.f_call_sequence == 64) {
|
||||
} else if (self->private_impl.f_call_sequence < 64) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -41939,7 +45622,6 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
@@ -42002,7 +45684,7 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
v_dst_y += 1;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -42021,7 +45703,7 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
@@ -42080,7 +45762,7 @@ wuffs_wbmp__decoder__num_decoded_frame_configs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
if (self->private_impl.f_call_sequence > 32) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -42099,7 +45781,7 @@ wuffs_wbmp__decoder__num_decoded_frames(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
if (self->private_impl.f_call_sequence > 64) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -42122,13 +45804,13 @@ wuffs_wbmp__decoder__restart_frame(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (self->private_impl.f_call_sequence < 32) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
@@ -42928,7 +46610,8 @@ DecodeImageCallbacks::AllocWorkbufResult::AllocWorkbufResult(
|
||||
|
||||
wuffs_base__image_decoder::unique_ptr //
|
||||
DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
switch (fourcc) {
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
@@ -42954,6 +46637,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
@@ -43174,6 +46862,7 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
|
||||
wuffs_base__image_config image_config = wuffs_base__null_image_config();
|
||||
sync_io::DynIOBuffer raw_metadata_buf(max_incl_metadata_length);
|
||||
uint64_t start_pos = io_buf.reader_position();
|
||||
bool interested_in_metadata_after_the_frame = false;
|
||||
bool redirected = false;
|
||||
int32_t fourcc = 0;
|
||||
redirect:
|
||||
@@ -43181,10 +46870,17 @@ redirect:
|
||||
// Determine the image format.
|
||||
if (!redirected) {
|
||||
while (true) {
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice());
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice(),
|
||||
io_buf.meta.closed);
|
||||
if (fourcc > 0) {
|
||||
break;
|
||||
} else if ((fourcc == 0) && (io_buf.reader_length() >= 64)) {
|
||||
// Having (fourcc == 0) means that Wuffs' built in MIME sniffer
|
||||
// didn't recognize the image format. Nonetheless, custom callbacks
|
||||
// may still be able to do their own MIME sniffing, for exotic image
|
||||
// types. We try to give them at least 64 bytes of prefix data when
|
||||
// one-shot-calling callbacks.SelectDecoder. There is no mechanism
|
||||
// for the callbacks to request a longer prefix.
|
||||
break;
|
||||
} else if (io_buf.meta.closed || (io_buf.writer_length() == 0)) {
|
||||
fourcc = 0;
|
||||
@@ -43225,8 +46921,7 @@ redirect:
|
||||
|
||||
// Select the image decoder.
|
||||
image_decoder = callbacks.SelectDecoder(
|
||||
(uint32_t)fourcc,
|
||||
fourcc ? wuffs_base__empty_slice_u8() : io_buf.reader_slice());
|
||||
(uint32_t)fourcc, io_buf.reader_slice(), io_buf.meta.closed);
|
||||
if (!image_decoder) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
@@ -43242,6 +46937,7 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
@@ -43251,12 +46947,14 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_XMP) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__XMP, true);
|
||||
}
|
||||
}
|
||||
@@ -43291,7 +46989,9 @@ redirect:
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
raw_metadata_buf.drop();
|
||||
if (!interested_in_metadata_after_the_frame) {
|
||||
raw_metadata_buf.drop();
|
||||
}
|
||||
|
||||
// Select the pixel format.
|
||||
uint32_t w = image_config.pixcfg.width();
|
||||
@@ -43352,6 +47052,12 @@ redirect:
|
||||
image_decoder->decode_frame_config(&frame_config, &io_buf);
|
||||
if (id_dfc_status.repr == nullptr) {
|
||||
break;
|
||||
} else if (id_dfc_status.repr == wuffs_base__note__metadata_reported) {
|
||||
std::string error_message = DecodeImageHandleMetadata(
|
||||
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
} else if (id_dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return DecodeImageResult(id_dfc_status.message());
|
||||
} else if (io_buf.meta.closed) {
|
||||
@@ -43393,6 +47099,35 @@ redirect:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decode any metadata after the frame.
|
||||
if (interested_in_metadata_after_the_frame) {
|
||||
while (true) {
|
||||
wuffs_base__status id_dfc_status =
|
||||
image_decoder->decode_frame_config(NULL, &io_buf);
|
||||
if (id_dfc_status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else if (id_dfc_status.repr == nullptr) {
|
||||
continue;
|
||||
} else if (id_dfc_status.repr == wuffs_base__note__metadata_reported) {
|
||||
std::string error_message = DecodeImageHandleMetadata(
|
||||
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
} else if (id_dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return DecodeImageResult(id_dfc_status.message());
|
||||
} else if (io_buf.meta.closed) {
|
||||
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
|
||||
} else {
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DecodeImageResult(std::move(alloc_pixbuf_result.mem_owner),
|
||||
pixel_buffer, std::move(message));
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ version = "0.0.1"
|
||||
authors = ["Nigel Tao <nigeltao@golang.org>"]
|
||||
|
||||
[dependencies]
|
||||
gif = "*"
|
||||
gif = "0.11"
|
||||
rustc_version_runtime = "*"
|
||||
@@ -35,7 +35,6 @@
|
||||
extern crate gif;
|
||||
extern crate rustc_version_runtime;
|
||||
|
||||
use gif::SetParameter;
|
||||
use std::time::Instant;
|
||||
|
||||
const ITERSCALE: u64 = 10;
|
||||
@@ -183,15 +182,14 @@ fn bench(
|
||||
// decode returns the number of bytes processed.
|
||||
fn decode(dst: &mut [u8], src: &[u8], output_32_bit_color: bool) -> u64 {
|
||||
let mut num_bytes = 0u64;
|
||||
let mut decoder = gif::Decoder::new(src);
|
||||
let mut options = gif::DecodeOptions::new();
|
||||
if output_32_bit_color {
|
||||
decoder.set(gif::ColorOutput::RGBA);
|
||||
options.set_color_output(gif::ColorOutput::RGBA);
|
||||
}
|
||||
|
||||
let mut reader = decoder.read_info().unwrap();
|
||||
while let Some(_) = reader.next_frame_info().unwrap() {
|
||||
num_bytes += reader.buffer_size() as u64;
|
||||
reader.read_into_buffer(dst).unwrap();
|
||||
let mut decoder = options.read_info(src).unwrap();
|
||||
while let Some(_) = decoder.next_frame_info().unwrap() {
|
||||
num_bytes += decoder.buffer_size() as u64;
|
||||
decoder.read_into_buffer(dst).unwrap();
|
||||
}
|
||||
num_bytes
|
||||
}
|
||||
@@ -4,5 +4,5 @@ version = "0.0.1"
|
||||
authors = ["Nigel Tao <nigeltao@golang.org>"]
|
||||
|
||||
[dependencies]
|
||||
png = "*"
|
||||
png = "0.17"
|
||||
rustc_version_runtime = "*"
|
||||
@@ -145,19 +145,20 @@ fn bench(
|
||||
|
||||
// decode returns the number of bytes processed.
|
||||
fn decode(dst0: &mut [u8], dst1: &mut [u8], src: &[u8]) -> u64 {
|
||||
let decoder = png::Decoder::new(src);
|
||||
let (info, mut reader) = decoder.read_info().unwrap();
|
||||
let mut decoder = png::Decoder::new(src);
|
||||
decoder.set_transformations(png::Transformations::normalize_to_color8());
|
||||
let mut reader = decoder.read_info().unwrap();
|
||||
let info = reader.next_frame(dst0).unwrap();
|
||||
let num_bytes = info.buffer_size() as u64;
|
||||
reader.next_frame(dst0).unwrap();
|
||||
if info.color_type == png::ColorType::Grayscale {
|
||||
// No conversion necessary.
|
||||
return num_bytes;
|
||||
} else if info.color_type == png::ColorType::RGB {
|
||||
} else if info.color_type == png::ColorType::Rgb {
|
||||
// Convert RGB => BGRA.
|
||||
let new_size = ((num_bytes / 3) * 4) as usize;
|
||||
rgb_to_bgra(&dst0[..num_bytes as usize], &mut dst1[..new_size]);
|
||||
return new_size as u64;
|
||||
} else if info.color_type == png::ColorType::RGBA {
|
||||
} else if info.color_type == png::ColorType::Rgba {
|
||||
// Convert RGBA => BGRA.
|
||||
for i in 0..((num_bytes / 4) as usize) {
|
||||
let d = dst0[(4 * i) + 0];
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// convert-nie-to-png.go decodes NIE from stdin and encodes PNG to stdout.
|
||||
//
|
||||
// Usage: go run convert-nie-to-png.go < foo.nie > foo.png
|
||||
|
||||
import (
|
||||
"image/png"
|
||||
"os"
|
||||
|
||||
"github.com/google/wuffs/lib/nie"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
img, err := nie.Decode(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return png.Encode(os.Stdout, img)
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// litonlylzma.go converts to and from the Literal Only LZMA compressed file
|
||||
// format, a subset of the LZMA compressed file format (e.g. as spoken by
|
||||
// /usr/bin/lzma on a Debian system).
|
||||
//
|
||||
// Usage:
|
||||
// go run litonlylzma.go -encode < foo.txt > foo.txt.litonlylzma
|
||||
// go run litonlylzma.go -decode < foo.txt.litonlylzma
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/google/wuffs/lib/litonlylzma"
|
||||
)
|
||||
|
||||
var (
|
||||
decode = flag.Bool("decode", false, "decode from LZMA")
|
||||
encode = flag.Bool("encode", false, "encode to LZMA")
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
flag.Parse()
|
||||
if *decode == *encode {
|
||||
return fmt.Errorf("exactly one of -decode and -encode needed")
|
||||
}
|
||||
src, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dst, err := []byte(nil), error(nil)
|
||||
if *decode {
|
||||
dst, _, err = litonlylzma.FileFormatLZMA.Decode(nil, src)
|
||||
} else {
|
||||
dst, err = litonlylzma.FileFormatLZMA.Encode(nil, src)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = os.Stdout.Write(dst)
|
||||
return err
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -87,7 +88,7 @@ func main1() error {
|
||||
const rep = "repeat "
|
||||
if strings.HasPrefix(s, rep) {
|
||||
args := s[len(rep):]
|
||||
count, args, ok := parseNum(args)
|
||||
count, args, ok := parseNum32(args)
|
||||
if !ok || count <= 0 || args != "[" {
|
||||
return fmt.Errorf("bad repeat command: %q", s)
|
||||
}
|
||||
@@ -156,7 +157,7 @@ func log2(u uint32) (i int32) {
|
||||
return -1
|
||||
}
|
||||
|
||||
func parseHex(s string) (num uint32, remaining string, ok bool) {
|
||||
func parseHex32(s string) (num uint32, remaining string, ok bool) {
|
||||
if i := strings.IndexByte(s, ' '); i >= 0 {
|
||||
s, remaining = s[:i], s[i+1:]
|
||||
for len(remaining) > 0 && remaining[0] == ' ' {
|
||||
@@ -176,7 +177,27 @@ func parseHex(s string) (num uint32, remaining string, ok bool) {
|
||||
return uint32(u), remaining, true
|
||||
}
|
||||
|
||||
func parseNum(s string) (num uint32, remaining string, ok bool) {
|
||||
func parseHex64(s string) (num uint64, remaining string, ok bool) {
|
||||
if i := strings.IndexByte(s, ' '); i >= 0 {
|
||||
s, remaining = s[:i], s[i+1:]
|
||||
for len(remaining) > 0 && remaining[0] == ' ' {
|
||||
remaining = remaining[1:]
|
||||
}
|
||||
}
|
||||
|
||||
if len(s) < 2 || s[0] != '0' || s[1] != 'x' {
|
||||
return 0, "", false
|
||||
}
|
||||
s = s[2:]
|
||||
|
||||
u, err := strconv.ParseUint(s, 16, 64)
|
||||
if err != nil {
|
||||
return 0, "", false
|
||||
}
|
||||
return u, remaining, true
|
||||
}
|
||||
|
||||
func parseNum32(s string) (num uint32, remaining string, ok bool) {
|
||||
if i := strings.IndexByte(s, ' '); i >= 0 {
|
||||
s, remaining = s[:i], s[i+1:]
|
||||
for len(remaining) > 0 && remaining[0] == ' ' {
|
||||
@@ -236,6 +257,70 @@ var reverse8 = [256]byte{
|
||||
|
||||
// ----
|
||||
|
||||
func init() {
|
||||
formats["bzip2"] = stateBzip2
|
||||
}
|
||||
|
||||
var bzip2Globals struct {
|
||||
stream bzip2BitStream
|
||||
}
|
||||
|
||||
func stateBzip2(line string) (stateFunc, error) {
|
||||
g := &bzip2Globals
|
||||
const (
|
||||
cmdB = "bits "
|
||||
)
|
||||
switch {
|
||||
case line == "":
|
||||
g.stream.flush()
|
||||
return stateBzip2, nil
|
||||
|
||||
case strings.HasPrefix(line, cmdB):
|
||||
s := strings.TrimSpace(line[len(cmdB):])
|
||||
n, s, ok := parseNum32(s)
|
||||
if !ok || s == "" {
|
||||
break
|
||||
}
|
||||
x, s, ok := parseHex64(s)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
g.stream.writeBits64(x, n)
|
||||
return stateBzip2, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("bad stateBzip2 command: %q", line)
|
||||
}
|
||||
|
||||
type bzip2BitStream struct {
|
||||
bits uint64
|
||||
nBits uint32 // Always within [0, 7].
|
||||
}
|
||||
|
||||
// writeBits64 writes the low n bits of b to z.
|
||||
func (z *bzip2BitStream) writeBits64(b uint64, n uint32) {
|
||||
if n > 56 {
|
||||
panic("writeBits64: n is too large")
|
||||
}
|
||||
z.bits |= b << (64 - n - z.nBits)
|
||||
z.nBits += n
|
||||
for z.nBits >= 8 {
|
||||
out = append(out, uint8(z.bits>>56))
|
||||
z.bits <<= 8
|
||||
z.nBits -= 8
|
||||
}
|
||||
}
|
||||
|
||||
func (z *bzip2BitStream) flush() {
|
||||
if z.nBits > 0 {
|
||||
out = append(out, uint8(z.bits>>56))
|
||||
z.bits = 0
|
||||
z.nBits = 0
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
func init() {
|
||||
formats["deflate"] = stateDeflate
|
||||
}
|
||||
@@ -244,20 +329,28 @@ var deflateCodeOrder = [19]uint32{
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
|
||||
}
|
||||
|
||||
var deflateHuffmanNames = [4]string{
|
||||
0: "Unused",
|
||||
1: "CodeLength",
|
||||
2: "Literal/Length",
|
||||
3: "Distance",
|
||||
}
|
||||
|
||||
type deflateHuffmanTable map[uint32]string
|
||||
|
||||
var deflateGlobals struct {
|
||||
bncData []byte
|
||||
stream deflateBitStream
|
||||
|
||||
// Dynamic Huffman state.
|
||||
// Dynamic Huffman state. whichHuffman indexes the huffmans array. See also
|
||||
// deflateHuffmanNames.
|
||||
whichHuffman uint32
|
||||
// 0=Unused, 1=CodeLength, 2=Literal/Length, 3=Distance.
|
||||
huffmans [4]deflateHuffmanTable
|
||||
huffmans [4]deflateHuffmanTable
|
||||
|
||||
// DHH (Dynamic Huffman, inside a Huffman table) state.
|
||||
prevLine string
|
||||
etcetera bool
|
||||
prevLine string
|
||||
etcetera bool
|
||||
incomplete bool
|
||||
}
|
||||
|
||||
func deflateGlobalsClearDynamicHuffmanState() {
|
||||
@@ -265,6 +358,7 @@ func deflateGlobalsClearDynamicHuffmanState() {
|
||||
deflateGlobals.huffmans = [4]deflateHuffmanTable{}
|
||||
deflateGlobals.prevLine = ""
|
||||
deflateGlobals.etcetera = false
|
||||
deflateGlobals.incomplete = false
|
||||
}
|
||||
|
||||
func deflateGlobalsCountCodes() (numLCodes uint32, numDCodes uint32, numCLCodeLengths uint32, retErr error) {
|
||||
@@ -299,6 +393,70 @@ func deflateGlobalsCountCodes() (numLCodes uint32, numDCodes uint32, numCLCodeLe
|
||||
return numLCodes, numDCodes, numCLCodeLengths, nil
|
||||
}
|
||||
|
||||
func deflateGlobalsIsHuffmanCanonical() bool {
|
||||
g := &deflateGlobals
|
||||
|
||||
// Gather the code+bitstring pairs. Deflate bitstrings cannot be longer
|
||||
// than 15 bits.
|
||||
type pair struct {
|
||||
k uint32
|
||||
v string
|
||||
}
|
||||
pairs := []pair{}
|
||||
for k, v := range g.huffmans[g.whichHuffman] {
|
||||
if len(v) > 15 {
|
||||
return false
|
||||
}
|
||||
pairs = append(pairs, pair{k, v})
|
||||
}
|
||||
if len(pairs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Sort by bitstring-length and then code.
|
||||
sort.Slice(pairs, func(i, j int) bool {
|
||||
pi, pj := &pairs[i], &pairs[j]
|
||||
if len(pi.v) != len(pj.v) {
|
||||
return len(pi.v) < len(pj.v)
|
||||
}
|
||||
return pi.k < pj.k
|
||||
})
|
||||
|
||||
// Set up a generator for the canonical bitstrings.
|
||||
buf := [15]byte{'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'}
|
||||
prevV := ""
|
||||
next := func() bool {
|
||||
if i := len(prevV); i > 0 {
|
||||
for {
|
||||
i--
|
||||
if i < 0 {
|
||||
return false
|
||||
}
|
||||
if buf[i] == '0' {
|
||||
buf[i] = '1'
|
||||
break
|
||||
}
|
||||
buf[i] = '0'
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Verify the bitstrings.
|
||||
for _, p := range pairs {
|
||||
if !next() {
|
||||
return false // Over-subscribed.
|
||||
} else if p.v != string(buf[:len(p.v)]) {
|
||||
return false // Non-canonical.
|
||||
}
|
||||
prevV = p.v
|
||||
}
|
||||
if next() != g.incomplete {
|
||||
return false // Under-subscribed.
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func deflateGlobalsWriteDynamicHuffmanTables() error {
|
||||
g := &deflateGlobals
|
||||
numLCodes, numDCodes, numCLCodeLengths, err := deflateGlobalsCountCodes()
|
||||
@@ -455,7 +613,7 @@ func stateDeflate(line string) (stateFunc, error) {
|
||||
s := line[len(cmdB):]
|
||||
for s != "" {
|
||||
x, ok := uint32(0), false
|
||||
x, s, ok = parseHex(s)
|
||||
x, s, ok = parseHex32(s)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("bad stateDeflate command: %q", line)
|
||||
}
|
||||
@@ -621,9 +779,13 @@ func stateDeflateDynamicHuffmanHuffman(line string) (stateFunc, error) {
|
||||
outer:
|
||||
switch {
|
||||
case line == "}":
|
||||
if !deflateGlobalsIsHuffmanCanonical() {
|
||||
return nil, fmt.Errorf(`"huffman %s" is non-canonical`, deflateHuffmanNames[g.whichHuffman])
|
||||
}
|
||||
g.whichHuffman = 0
|
||||
g.prevLine = ""
|
||||
g.etcetera = false
|
||||
g.incomplete = false
|
||||
|
||||
// If we have all three Huffman tables, write them.
|
||||
for i := 1; ; i++ {
|
||||
@@ -644,9 +806,13 @@ outer:
|
||||
g.etcetera = true
|
||||
return stateDeflateDynamicHuffmanHuffman, nil
|
||||
|
||||
case line == "incomplete":
|
||||
g.incomplete = true
|
||||
return stateDeflateDynamicHuffmanHuffman, nil
|
||||
|
||||
default:
|
||||
s := line
|
||||
n, s, ok := parseNum(s)
|
||||
n, s, ok := parseNum32(s)
|
||||
if !ok || s == "" {
|
||||
break
|
||||
}
|
||||
@@ -661,7 +827,7 @@ outer:
|
||||
|
||||
if g.etcetera {
|
||||
g.etcetera = false
|
||||
n0, s0, ok := parseNum(g.prevLine)
|
||||
n0, s0, ok := parseNum32(g.prevLine)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("bad etcetera command")
|
||||
}
|
||||
@@ -883,10 +1049,10 @@ func deflateParseLenDist(line string) (l uint32, d uint32, ok bool) {
|
||||
s := line
|
||||
if strings.HasPrefix(s, lStr) {
|
||||
s = s[len(lStr):]
|
||||
if l, s, ok := parseNum(s); ok && 3 <= l && l <= 258 {
|
||||
if l, s, ok := parseNum32(s); ok && 3 <= l && l <= 258 {
|
||||
if strings.HasPrefix(s, dStr) {
|
||||
s = s[len(dStr):]
|
||||
if d, s, ok := parseNum(s); ok && 1 <= d && d <= 32768 && s == "" {
|
||||
if d, s, ok := parseNum32(s); ok && 1 <= d && d <= 32768 && s == "" {
|
||||
return l, d, true
|
||||
}
|
||||
}
|
||||
@@ -953,7 +1119,7 @@ outer:
|
||||
s := line[len(cmdB):]
|
||||
for s != "" {
|
||||
x, ok := uint32(0), false
|
||||
x, s, ok = parseHex(s)
|
||||
x, s, ok = parseHex32(s)
|
||||
if !ok {
|
||||
break outer
|
||||
}
|
||||
@@ -994,7 +1160,7 @@ outer:
|
||||
flags |= 0x01
|
||||
transparentIndex = uint8(num)
|
||||
case strings.HasSuffix(term, ms):
|
||||
num, remaining, ok := parseNum(term[:len(term)-len(ms)])
|
||||
num, remaining, ok := parseNum32(term[:len(term)-len(ms)])
|
||||
if !ok || remaining != "" {
|
||||
break outer
|
||||
}
|
||||
@@ -1016,7 +1182,7 @@ outer:
|
||||
|
||||
case strings.HasPrefix(line, cmdL):
|
||||
s := line[len(cmdL):]
|
||||
litWidth, s, ok := parseNum(s)
|
||||
litWidth, s, ok := parseNum32(s)
|
||||
if !ok || litWidth < 2 || 8 < litWidth {
|
||||
break
|
||||
}
|
||||
@@ -1025,7 +1191,7 @@ outer:
|
||||
uncompressed := []byte(nil)
|
||||
for s != "" {
|
||||
x := uint32(0)
|
||||
x, s, ok = parseHex(s)
|
||||
x, s, ok = parseHex32(s)
|
||||
if !ok {
|
||||
break outer
|
||||
}
|
||||
@@ -1058,7 +1224,7 @@ outer:
|
||||
|
||||
case strings.HasPrefix(line, cmdLC):
|
||||
s := line[len(cmdLC):]
|
||||
loopCount, _, ok := parseNum(s)
|
||||
loopCount, _, ok := parseNum32(s)
|
||||
if !ok || 0xFFFF < loopCount {
|
||||
break
|
||||
}
|
||||
@@ -1109,15 +1275,15 @@ func stateGifImage(line string) (stateFunc, error) {
|
||||
switch {
|
||||
case strings.HasPrefix(line, cmdBCI):
|
||||
s := line[len(cmdBCI):]
|
||||
if i, _, ok := parseNum(s); ok {
|
||||
if i, _, ok := parseNum32(s); ok {
|
||||
g.imageBackgroundColorIndex = i
|
||||
}
|
||||
return stateGifImage, nil
|
||||
|
||||
case strings.HasPrefix(line, cmdIWH):
|
||||
s := line[len(cmdIWH):]
|
||||
if w, s, ok := parseNum(s); ok {
|
||||
if h, _, ok := parseNum(s); ok {
|
||||
if w, s, ok := parseNum32(s); ok {
|
||||
if h, _, ok := parseNum32(s); ok {
|
||||
g.imageWidth = w
|
||||
g.imageHeight = h
|
||||
return stateGifImage, nil
|
||||
@@ -1166,10 +1332,10 @@ func stateGifFrame(line string) (stateFunc, error) {
|
||||
|
||||
case strings.HasPrefix(line, cmdFLTWH):
|
||||
s := line[len(cmdFLTWH):]
|
||||
if l, s, ok := parseNum(s); ok {
|
||||
if t, s, ok := parseNum(s); ok {
|
||||
if w, s, ok := parseNum(s); ok {
|
||||
if h, _, ok := parseNum(s); ok {
|
||||
if l, s, ok := parseNum32(s); ok {
|
||||
if t, s, ok := parseNum32(s); ok {
|
||||
if w, s, ok := parseNum32(s); ok {
|
||||
if h, _, ok := parseNum32(s); ok {
|
||||
g.frameLeft = l
|
||||
g.frameTop = t
|
||||
g.frameWidth = w
|
||||
@@ -1194,9 +1360,9 @@ func stateGifImagePalette(line string) (stateFunc, error) {
|
||||
}
|
||||
|
||||
s := line
|
||||
if rgb0, s, ok := parseHex(s); ok {
|
||||
if rgb1, s, ok := parseHex(s); ok {
|
||||
if rgb2, _, ok := parseHex(s); ok {
|
||||
if rgb0, s, ok := parseHex32(s); ok {
|
||||
if rgb1, s, ok := parseHex32(s); ok {
|
||||
if rgb2, _, ok := parseHex32(s); ok {
|
||||
g.globalPalette = append(g.globalPalette,
|
||||
[4]uint8{uint8(rgb0), uint8(rgb1), uint8(rgb2), 0xFF})
|
||||
return stateGifImagePalette, nil
|
||||
@@ -1214,9 +1380,9 @@ func stateGifFramePalette(line string) (stateFunc, error) {
|
||||
}
|
||||
|
||||
s := line
|
||||
if rgb0, s, ok := parseHex(s); ok {
|
||||
if rgb1, s, ok := parseHex(s); ok {
|
||||
if rgb2, _, ok := parseHex(s); ok {
|
||||
if rgb0, s, ok := parseHex32(s); ok {
|
||||
if rgb1, s, ok := parseHex32(s); ok {
|
||||
if rgb2, _, ok := parseHex32(s); ok {
|
||||
g.localPalette = append(g.localPalette,
|
||||
[4]uint8{uint8(rgb0), uint8(rgb1), uint8(rgb2), 0xFF})
|
||||
return stateGifFramePalette, nil
|
||||
@@ -1299,7 +1465,7 @@ func statePngRaw(line string) (stateFunc, error) {
|
||||
}
|
||||
|
||||
for s := line; s != ""; {
|
||||
if x, remaining, ok := parseHex(s); ok {
|
||||
if x, remaining, ok := parseHex32(s); ok {
|
||||
g.chunkData.WriteByte(byte(x))
|
||||
s = remaining
|
||||
} else {
|
||||
@@ -1319,7 +1485,7 @@ func statePngZlib(line string) (stateFunc, error) {
|
||||
}
|
||||
|
||||
for s := line; s != ""; {
|
||||
if x, remaining, ok := parseHex(s); ok {
|
||||
if x, remaining, ok := parseHex32(s); ok {
|
||||
g.scratch[0] = byte(x)
|
||||
g.zlibWriter.Write(g.scratch[:1])
|
||||
s = remaining
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
print-average-pixel prints the average color of an image's pixels (as well as
|
||||
the image file format, width and height). It's a toy program to demonstrate how
|
||||
to use the wuffs_aux C++ API to decode an image and iterate over its pixels.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||
// functions have static storage.
|
||||
//
|
||||
// This can help the compiler ignore or discard unused code, which can produce
|
||||
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__ADLER32
|
||||
#define WUFFS_CONFIG__MODULE__AUX__BASE
|
||||
#define WUFFS_CONFIG__MODULE__AUX__IMAGE
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__BMP
|
||||
#define WUFFS_CONFIG__MODULE__CRC32
|
||||
#define WUFFS_CONFIG__MODULE__DEFLATE
|
||||
#define WUFFS_CONFIG__MODULE__GIF
|
||||
#define WUFFS_CONFIG__MODULE__LZW
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../release/c/wuffs-unsupported-snapshot.c"
|
||||
|
||||
class MyCallbacks : public wuffs_aux::DecodeImageCallbacks {
|
||||
public:
|
||||
MyCallbacks() : m_fourcc(0) {}
|
||||
|
||||
uint32_t m_fourcc;
|
||||
|
||||
private:
|
||||
wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) override {
|
||||
// Save the fourcc value (you can think of it as like a 'MIME type' but in
|
||||
// uint32_t form) before calling the superclass' implementation.
|
||||
//
|
||||
// The "if (m_fourcc == 0)" is because SelectDecoder can be called multiple
|
||||
// times. Files that are nominally BMP images can contain complete JPEG or
|
||||
// PNG images. This program prints the outer file format, the first one
|
||||
// encountered, not the inner one.
|
||||
if (m_fourcc == 0) {
|
||||
m_fourcc = fourcc;
|
||||
}
|
||||
return wuffs_aux::DecodeImageCallbacks::SelectDecoder(fourcc, prefix_data,
|
||||
prefix_closed);
|
||||
}
|
||||
|
||||
wuffs_base__pixel_format //
|
||||
SelectPixfmt(const wuffs_base__image_config& image_config) override {
|
||||
// This is the same as the superclass' implementation, but makes it
|
||||
// explicit that this program uses a single-plane pixel buffer (as opposed
|
||||
// to e.g. 3-plane YCbCr) with 4 bytes per pixel (in B, G, R, A order) and
|
||||
// premultiplied alpha.
|
||||
return wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL);
|
||||
}
|
||||
|
||||
AllocPixbufResult //
|
||||
AllocPixbuf(const wuffs_base__image_config& image_config,
|
||||
bool allow_uninitialized_memory) override {
|
||||
// This just calls the superclass' implementation, but if you wanted more
|
||||
// control about how the pixel buffer's memory is allocated and freed,
|
||||
// change the code here. For example, if you (the wuffs_aux::DecodeImage
|
||||
// caller) want to use an already-allocated buffer, instead of Wuffs (the
|
||||
// callee) allocating a new buffer.
|
||||
//
|
||||
// The example/sdl-imageviewer/sdl-imageviewer.cc file demonstrates
|
||||
// overriding the AllocPixbuf method with the "bring your own buffer"
|
||||
// approach. In the sdl-imageviewer case, the pixel buffer is allocated by
|
||||
// SDL and lent to Wuffs, instead of allocated by Wuffs.
|
||||
return wuffs_aux::DecodeImageCallbacks::AllocPixbuf(
|
||||
image_config, allow_uninitialized_memory);
|
||||
}
|
||||
};
|
||||
|
||||
void //
|
||||
handle(const char* filename, FILE* f) {
|
||||
MyCallbacks callbacks;
|
||||
wuffs_aux::sync_io::FileInput input(f);
|
||||
wuffs_aux::DecodeImageResult res = wuffs_aux::DecodeImage(callbacks, input);
|
||||
if (!res.error_message.empty()) {
|
||||
printf("%-30s %s\n", filename, res.error_message.c_str());
|
||||
return;
|
||||
} else if (res.pixbuf.pixcfg.pixel_format().repr !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) {
|
||||
printf("%-30s internal error: inconsistent pixel format\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
wuffs_base__table_u8 table = res.pixbuf.plane(0);
|
||||
uint32_t w = res.pixbuf.pixcfg.width();
|
||||
uint32_t h = res.pixbuf.pixcfg.height();
|
||||
|
||||
uint64_t count = 0;
|
||||
uint64_t color_b = 0;
|
||||
uint64_t color_g = 0;
|
||||
uint64_t color_r = 0;
|
||||
uint64_t color_a = 0;
|
||||
for (uint32_t y = 0; y < h; y++) {
|
||||
const uint8_t* ptr = table.ptr + (y * table.stride);
|
||||
for (uint32_t x = 0; x < w; x++) {
|
||||
count++;
|
||||
color_b += *ptr++;
|
||||
color_g += *ptr++;
|
||||
color_r += *ptr++;
|
||||
color_a += *ptr++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
color_b = (color_b + (count / 2)) / count;
|
||||
color_g = (color_g + (count / 2)) / count;
|
||||
color_r = (color_r + (count / 2)) / count;
|
||||
color_a = (color_a + (count / 2)) / count;
|
||||
}
|
||||
|
||||
printf("%-30s %c%c%c%c %5" PRIu32 " x %5" PRIu32
|
||||
" AverageARGB: %02X%02X%02X%02X\n", //
|
||||
filename, //
|
||||
(0xFF & (callbacks.m_fourcc >> 24)), //
|
||||
(0xFF & (callbacks.m_fourcc >> 16)), //
|
||||
(0xFF & (callbacks.m_fourcc >> 8)), //
|
||||
(0xFF & (callbacks.m_fourcc >> 0)), //
|
||||
w, h, //
|
||||
(int)(color_a), //
|
||||
(int)(color_r), //
|
||||
(int)(color_g), //
|
||||
(int)(color_b));
|
||||
|
||||
// While it's valid to deference table.ptr in this function, the end of scope
|
||||
// here means that the res.pixbuf_mem_owner destructor will free the backing
|
||||
// memory (unless you modified the AllocPixbuf method above).
|
||||
//
|
||||
// If you wanted to return the pixel buffer to the caller, either return the
|
||||
// wuffs_aux::MemOwner (a type alias for "std::unique_ptr<void,
|
||||
// decltype(&free)>") too, or call res.pixbuf_mem_owner.release() before
|
||||
// returning and manually free the backing memory at an appropriate time.
|
||||
}
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
FILE* f = fopen(argv[i], "r");
|
||||
if (!f) {
|
||||
printf("%-30s could not open file: %s\n", argv[i], strerror(errno));
|
||||
continue;
|
||||
}
|
||||
handle(argv[i], f);
|
||||
fclose(f);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -22,11 +22,16 @@ package main
|
||||
// Usage: go run print-crc32-magic-numbers.go
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
reverse = flag.Bool("reverse", false, "whether to reverse the bits")
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
@@ -35,6 +40,7 @@ func main() {
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
flag.Parse()
|
||||
tables := [16]crc32.Table{}
|
||||
tables[0] = *crc32.MakeTable(crc32.IEEE)
|
||||
|
||||
@@ -49,6 +55,9 @@ func main1() error {
|
||||
}
|
||||
|
||||
for i, t := range tables {
|
||||
if *reverse {
|
||||
reverseTable(&t)
|
||||
}
|
||||
if i != 0 {
|
||||
fmt.Println("],[")
|
||||
}
|
||||
@@ -61,3 +70,55 @@ func main1() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// reverseTable reverses the bits in the keys and values of a crc32.Table
|
||||
// (which is a [256]uint32).
|
||||
func reverseTable(t *crc32.Table) {
|
||||
revT := crc32.Table{}
|
||||
for i, v := range *t {
|
||||
revI := reverse8[i]
|
||||
revV := uint32(0)
|
||||
for j := 0; j < 32; j++ {
|
||||
if (v & (1 << j)) != 0 {
|
||||
revV |= 1 << (31 - j)
|
||||
}
|
||||
}
|
||||
revT[revI] = revV
|
||||
}
|
||||
*t = revT
|
||||
}
|
||||
|
||||
var reverse8 = [256]uint8{
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, // 0x00 - 0x07
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, // 0x08 - 0x0F
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, // 0x10 - 0x17
|
||||
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, // 0x18 - 0x1F
|
||||
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, // 0x20 - 0x27
|
||||
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, // 0x28 - 0x2F
|
||||
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, // 0x30 - 0x37
|
||||
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, // 0x38 - 0x3F
|
||||
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, // 0x40 - 0x47
|
||||
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, // 0x48 - 0x4F
|
||||
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, // 0x50 - 0x57
|
||||
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, // 0x58 - 0x5F
|
||||
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, // 0x60 - 0x67
|
||||
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, // 0x68 - 0x6F
|
||||
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, // 0x70 - 0x77
|
||||
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, // 0x78 - 0x7F
|
||||
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, // 0x80 - 0x87
|
||||
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, // 0x88 - 0x8F
|
||||
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, // 0x90 - 0x97
|
||||
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, // 0x98 - 0x9F
|
||||
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, // 0xA0 - 0xA7
|
||||
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, // 0xA8 - 0xAF
|
||||
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, // 0xB0 - 0xB7
|
||||
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, // 0xB8 - 0xBF
|
||||
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, // 0xC0 - 0xC7
|
||||
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, // 0xC8 - 0xCF
|
||||
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, // 0xD0 - 0xD7
|
||||
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, // 0xD8 - 0xDF
|
||||
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, // 0xE0 - 0xE7
|
||||
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, // 0xE8 - 0xEF
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, // 0xF0 - 0xF7
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, // 0xF8 - 0xFF
|
||||
}
|
||||
@@ -365,7 +365,7 @@ type bitVector []uint8
|
||||
// zig packs a pair of non-negative integers (i, j) into a single unique
|
||||
// non-negative integer, in a zig-zagging pattern:
|
||||
//
|
||||
// i=0 i=1 i=2 i=3 i=4 etc
|
||||
// . i=0 i=1 i=2 i=3 i=4 etc
|
||||
// j=0: 0 1 3 6 10 ...
|
||||
// j=1: 2 4 7 11 16 ...
|
||||
// j=2: 5 8 12 17 23 ...
|
||||
|
||||
@@ -0,0 +1,441 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
print-image-metadata prints images' metadata.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||
// functions have static storage.
|
||||
//
|
||||
// This can help the compiler ignore or discard unused code, which can produce
|
||||
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__ADLER32
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__BMP
|
||||
#define WUFFS_CONFIG__MODULE__CRC32
|
||||
#define WUFFS_CONFIG__MODULE__DEFLATE
|
||||
#define WUFFS_CONFIG__MODULE__GIF
|
||||
#define WUFFS_CONFIG__MODULE__LZW
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../release/c/wuffs-unsupported-snapshot.c"
|
||||
|
||||
// ----
|
||||
|
||||
#ifndef SRC_BUFFER_ARRAY_SIZE
|
||||
#define SRC_BUFFER_ARRAY_SIZE (64 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef META_BUFFER_ARRAY_SIZE
|
||||
#define META_BUFFER_ARRAY_SIZE (64 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef WORKBUF_ARRAY_SIZE
|
||||
#define WORKBUF_ARRAY_SIZE (256 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#define PRINTBUF_ARRAY_SIZE 80
|
||||
|
||||
uint8_t g_src_buffer_array[SRC_BUFFER_ARRAY_SIZE] = {0};
|
||||
uint8_t g_meta_buffer_array[META_BUFFER_ARRAY_SIZE] = {0};
|
||||
uint8_t g_workbuf_array[WORKBUF_ARRAY_SIZE] = {0};
|
||||
|
||||
uint8_t g_printbuf_array[PRINTBUF_ARRAY_SIZE] = {0};
|
||||
uint32_t g_printbuf_index = 0;
|
||||
|
||||
// ----
|
||||
|
||||
#define TRY(error_msg) \
|
||||
do { \
|
||||
const char* z = error_msg; \
|
||||
if (z) { \
|
||||
return z; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
const uint8_t //
|
||||
hexify[16] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', //
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F', //
|
||||
};
|
||||
|
||||
const uint8_t //
|
||||
printable_ascii[256] = {
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, //
|
||||
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, //
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //
|
||||
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, //
|
||||
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, //
|
||||
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, //
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, //
|
||||
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, //
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, //
|
||||
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, //
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, //
|
||||
0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, //
|
||||
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, //
|
||||
};
|
||||
|
||||
// ----
|
||||
|
||||
const char* //
|
||||
read_buffer_from_file(wuffs_base__io_buffer* buf, FILE* f) {
|
||||
if (buf->meta.closed) {
|
||||
return "main: unexpected end of file";
|
||||
}
|
||||
buf->compact();
|
||||
size_t n = fread(buf->writer_pointer(), 1, buf->writer_length(), f);
|
||||
buf->meta.wi += n;
|
||||
buf->meta.closed = feof(f);
|
||||
return ferror(f) ? "main: error reading file" : nullptr;
|
||||
}
|
||||
|
||||
void //
|
||||
print_fourcc(uint32_t fourcc) {
|
||||
printf(" %c%c%c%c\n", //
|
||||
(0xFF & (fourcc >> 24)), //
|
||||
(0xFF & (fourcc >> 16)), //
|
||||
(0xFF & (fourcc >> 8)), //
|
||||
(0xFF & (fourcc >> 0)));
|
||||
}
|
||||
|
||||
void //
|
||||
flush_hex_dump() {
|
||||
if (g_printbuf_index == 0) {
|
||||
return;
|
||||
}
|
||||
puts(static_cast<const char*>(static_cast<const void*>(g_printbuf_array)));
|
||||
g_printbuf_index = 0;
|
||||
}
|
||||
|
||||
void //
|
||||
print_hex_dump(const uint8_t* ptr, size_t len) {
|
||||
while (len--) {
|
||||
if (g_printbuf_index == 0) {
|
||||
const char* s =
|
||||
" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "
|
||||
"----------------";
|
||||
size_t n = strlen(s);
|
||||
if ((n + 1) > PRINTBUF_ARRAY_SIZE) {
|
||||
exit(1);
|
||||
}
|
||||
memcpy(&g_printbuf_array[0], s, n + 1);
|
||||
}
|
||||
const uint8_t c = *ptr++;
|
||||
g_printbuf_array[(3 * g_printbuf_index) + 4] = hexify[c >> 4];
|
||||
g_printbuf_array[(3 * g_printbuf_index) + 5] = hexify[c & 15];
|
||||
g_printbuf_array[g_printbuf_index + 55] = printable_ascii[c];
|
||||
g_printbuf_index++;
|
||||
if (g_printbuf_index == 16) {
|
||||
puts(
|
||||
static_cast<const char*>(static_cast<const void*>(g_printbuf_array)));
|
||||
g_printbuf_index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
print_raw_passthrough(wuffs_base__io_buffer* src,
|
||||
FILE* f,
|
||||
wuffs_base__range_ie_u64 r) {
|
||||
if (r.is_empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Advance src so that its reader_position is r.min_incl.
|
||||
if (src->reader_position() > r.min_incl) {
|
||||
return "main: unsupported metadata range";
|
||||
}
|
||||
while (src->reader_position() < r.min_incl) {
|
||||
if (src->writer_position() >= r.min_incl) {
|
||||
src->meta.ri = r.min_incl - src->meta.pos;
|
||||
break;
|
||||
}
|
||||
src->meta.ri = src->meta.wi;
|
||||
TRY(read_buffer_from_file(src, f));
|
||||
}
|
||||
|
||||
// Print the passthrough bytes until src's reader_position is r.max_excl.
|
||||
while (true) {
|
||||
uint64_t n0 = r.max_excl - src->reader_position();
|
||||
if (n0 == 0) {
|
||||
break;
|
||||
}
|
||||
uint64_t n1 = src->reader_length();
|
||||
uint64_t n = wuffs_base__u64__min(n0, n1);
|
||||
print_hex_dump(src->reader_pointer(), n);
|
||||
src->meta.ri += n;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* //
|
||||
print_metadata(wuffs_base__image_decoder* dec,
|
||||
wuffs_base__io_buffer* src,
|
||||
FILE* f) {
|
||||
bool printed_fourcc = false;
|
||||
while (true) {
|
||||
auto meta = wuffs_base__ptr_u8__writer(&g_meta_buffer_array[0],
|
||||
META_BUFFER_ARRAY_SIZE);
|
||||
auto minfo = wuffs_base__empty_more_information();
|
||||
auto tmm_status = dec->tell_me_more(&meta, &minfo, src);
|
||||
|
||||
if (minfo.flavor) {
|
||||
if (!printed_fourcc) {
|
||||
printed_fourcc = true;
|
||||
print_fourcc(minfo.metadata__fourcc());
|
||||
}
|
||||
|
||||
switch (minfo.flavor) {
|
||||
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH:
|
||||
TRY(print_raw_passthrough(src, f,
|
||||
minfo.metadata_raw_passthrough__range()));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM:
|
||||
print_hex_dump(meta.reader_pointer(), meta.reader_length());
|
||||
meta.meta.ri = meta.meta.wi;
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED:
|
||||
switch (minfo.metadata__fourcc()) {
|
||||
case WUFFS_BASE__FOURCC__CHRM:
|
||||
for (uint32_t i = 0; i < 8; i++) {
|
||||
printf(" %" PRId32 "\n", minfo.metadata_parsed__chrm(i));
|
||||
}
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__GAMA:
|
||||
printf(" %" PRIu32 "\n", minfo.metadata_parsed__gama());
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__SRGB:
|
||||
printf(" %" PRIu32 "\n", minfo.metadata_parsed__srgb());
|
||||
break;
|
||||
default:
|
||||
return "main: unsupported metadata FourCC";
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return "main: unsupported metadata flavor";
|
||||
}
|
||||
}
|
||||
|
||||
if (tmm_status.is_ok()) {
|
||||
break;
|
||||
} else if (tmm_status.repr == wuffs_base__suspension__short_read) {
|
||||
TRY(read_buffer_from_file(src, f));
|
||||
continue;
|
||||
} else if (tmm_status.repr == wuffs_base__suspension__short_write) {
|
||||
continue;
|
||||
} else if (tmm_status.repr !=
|
||||
wuffs_base__suspension__even_more_information) {
|
||||
return tmm_status.message();
|
||||
}
|
||||
}
|
||||
flush_hex_dump();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* //
|
||||
handle_redirect(int32_t* out_fourcc,
|
||||
wuffs_base__image_decoder* dec,
|
||||
wuffs_base__io_buffer* src,
|
||||
FILE* f) {
|
||||
auto empty = wuffs_base__empty_io_buffer();
|
||||
auto minfo = wuffs_base__empty_more_information();
|
||||
auto tmm_status = dec->tell_me_more(&empty, &minfo, src);
|
||||
if (tmm_status.repr != NULL) {
|
||||
return tmm_status.message();
|
||||
} else if (minfo.flavor !=
|
||||
WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_REDIRECT) {
|
||||
return "main: unsupported file format";
|
||||
}
|
||||
*out_fourcc = (int32_t)(minfo.io_redirect__fourcc());
|
||||
if (*out_fourcc <= 0) {
|
||||
return "main: unsupported file format";
|
||||
}
|
||||
|
||||
// Advance src so that its reader_position is r.min_incl.
|
||||
auto r = minfo.io_redirect__range();
|
||||
if (src->reader_position() > r.min_incl) {
|
||||
return "main: unsupported I/O redirect range";
|
||||
}
|
||||
while (src->reader_position() < r.min_incl) {
|
||||
if (src->writer_position() >= r.min_incl) {
|
||||
src->meta.ri = r.min_incl - src->meta.pos;
|
||||
break;
|
||||
}
|
||||
src->meta.ri = src->meta.wi;
|
||||
TRY(read_buffer_from_file(src, f));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* //
|
||||
handle(const char* filename, FILE* f) {
|
||||
auto src =
|
||||
wuffs_base__ptr_u8__writer(&g_src_buffer_array[0], SRC_BUFFER_ARRAY_SIZE);
|
||||
auto work =
|
||||
wuffs_base__ptr_u8__writer(&g_workbuf_array[0], WORKBUF_ARRAY_SIZE);
|
||||
|
||||
int32_t fourcc = 0;
|
||||
while (true) {
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(src.reader_slice(),
|
||||
src.meta.closed);
|
||||
if (fourcc > 0) {
|
||||
break;
|
||||
} else if (fourcc == 0) {
|
||||
return "main: unrecognized file format";
|
||||
} else {
|
||||
TRY(read_buffer_from_file(&src, f));
|
||||
}
|
||||
}
|
||||
|
||||
bool redirected = false;
|
||||
redirect:
|
||||
do {
|
||||
print_fourcc(fourcc);
|
||||
wuffs_base__image_decoder::unique_ptr dec(nullptr, &free);
|
||||
switch (fourcc) {
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__GIF:
|
||||
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__NIE:
|
||||
dec = wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__PNG:
|
||||
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
default:
|
||||
return "main: unsupported file format";
|
||||
}
|
||||
|
||||
dec->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
dec->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
dec->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
|
||||
dec->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
|
||||
dec->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
|
||||
dec->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
|
||||
dec->set_report_metadata(WUFFS_BASE__FOURCC__XMP, true);
|
||||
|
||||
while (true) {
|
||||
auto dfc_status = dec->decode_frame_config(NULL, &src);
|
||||
if (dfc_status.is_ok()) {
|
||||
// No-op.
|
||||
} else if (dfc_status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else if (dfc_status.repr == wuffs_base__note__metadata_reported) {
|
||||
TRY(print_metadata(dec.get(), &src, f));
|
||||
} else if (dfc_status.repr == wuffs_base__note__i_o_redirect) {
|
||||
if (redirected) {
|
||||
return "main: unsupported file format";
|
||||
}
|
||||
redirected = true;
|
||||
TRY(handle_redirect(&fourcc, dec.get(), &src, f));
|
||||
goto redirect;
|
||||
} else if (dfc_status.repr == wuffs_base__suspension__short_read) {
|
||||
TRY(read_buffer_from_file(&src, f));
|
||||
} else {
|
||||
return dfc_status.message();
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
FILE* f = fopen(argv[i], "r");
|
||||
if (!f) {
|
||||
printf("%s\n %s\n", argv[i], strerror(errno));
|
||||
continue;
|
||||
}
|
||||
printf("%s\n", argv[i]);
|
||||
const char* err = handle(argv[i], f);
|
||||
if (err) {
|
||||
printf(" %s\n", err);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -33,31 +33,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0x7FFF_FFFF],
|
||||
height : base.u32[..= 0x7FFF_FFFF],
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x03: image config decoded.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0xFF: end-of-data, usually after (the non-animated) frame decoded.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x03: via DIC
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0xFF: via DFC
|
||||
// - 0x04 -> 0xFF: via DF
|
||||
//
|
||||
// - ???? -> 0x03: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
top_down : base.bool,
|
||||
@@ -115,7 +92,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
var dst_pixfmt : base.u32
|
||||
var byte_width : base.u32
|
||||
|
||||
if (this.call_sequence <> 0) or (this.io_redirect_fourcc == 1) {
|
||||
if (this.call_sequence <> 0x00) or (this.io_redirect_fourcc == 1) {
|
||||
return base."#bad call sequence"
|
||||
} else if this.io_redirect_fourcc <> 0 {
|
||||
return base."@I/O redirect"
|
||||
@@ -389,18 +366,20 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
first_frame_is_opaque: this.channel_masks[3] == 0)
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 3 {
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 4 {
|
||||
this.call_sequence = 0xFF
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
@@ -421,16 +400,16 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
background_color: 0xFF00_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pub func decoder.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) {
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence < 4 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 4 {
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
@@ -480,7 +459,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
this.pending_pad = 0
|
||||
}
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||
@@ -1116,27 +1095,27 @@ pub func decoder.num_animation_loops() base.u32 {
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 3 {
|
||||
if this.call_sequence > 0x20 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 4 {
|
||||
if this.call_sequence > 0x40 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if args.index <> 0 {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x28
|
||||
this.frame_config_io_position = args.io_position
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -0,0 +1,403 @@
|
||||
# Bzip2
|
||||
|
||||
Bzip2 is a general purpose compression format, using Huffman codes, Run Length
|
||||
Encoding, the Move To Front Transform and the Burrows Wheeler Transform. There
|
||||
is no official specification, but Joe Tsai has written [comprehensive
|
||||
documentation](https://github.com/dsnet/compress/raw/master/doc/bzip2-format.pdf)
|
||||
of the wire format.
|
||||
|
||||
It is a block based format, which means that when decoding each block, the
|
||||
whole compressed block has to be read before a single byte of the uncompressed
|
||||
block can be written.
|
||||
|
||||
Like zlib (but unlike gzip), bzip2 just holds compressed bytes. It does not
|
||||
hold additional metadata like the original file's name or modification time.
|
||||
|
||||
|
||||
# Wire Format Worked Example
|
||||
|
||||
Let's compress "abraca". Bzip2 compresses poorly on such a short input file,
|
||||
converting 6 uncompressed bytes to 0x2b = 43 compressed bytes. Nonetheless, the
|
||||
"abraca" uncompressed text matches the example from the 1994 [BWT technical
|
||||
report](http://www.hpl.hp.com/techreports/Compaq-DEC/SRC-RR-124.pdf) (by M.
|
||||
Burrows and D. J. Wheeler) that introduced their eponymous Burrows Wheeler
|
||||
Transform.
|
||||
|
||||
$ hd abraca.txt
|
||||
00000000 61 62 72 61 63 61 |abraca|
|
||||
00000006
|
||||
$ hd abraca.txt.bz2
|
||||
00000000 42 5a 68 39 31 41 59 26 53 59 76 a7 09 95 00 00 |BZh91AY&SYv.....|
|
||||
00000010 00 81 80 38 00 10 00 20 00 21 9a 68 33 4d 30 91 |...8... .!.h3M0.|
|
||||
00000020 e2 ee 48 a7 0a 12 0e d4 e1 32 a0 |..H......2.|
|
||||
0000002b
|
||||
|
||||
Here are the bits of those 43 bytes with various bitslices labeled from (a) to
|
||||
(s). The bzip2 file format works in bits instead of bytes. It reads bits from
|
||||
MSB (Most Significant Bit) to LSB (Least Significant Bit) order and does not
|
||||
pad to byte boundaries (except at the end of the file).
|
||||
|
||||
offset xoffset ASCII hex binary bitslice
|
||||
000000 0x0000 B 0x42 0b_0100_0010 aaaa_aaaa
|
||||
000001 0x0001 Z 0x5A 0b_0101_1010 aaaa_aaaa
|
||||
000002 0x0002 h 0x68 0b_0110_1000 bbbb_bbbb
|
||||
000003 0x0003 9 0x39 0b_0011_1001 cccc_cccc
|
||||
000004 0x0004 1 0x31 0b_0011_0001 dddd_dddd
|
||||
000005 0x0005 A 0x41 0b_0100_0001 dddd_dddd
|
||||
000006 0x0006 Y 0x59 0b_0101_1001 dddd_dddd
|
||||
000007 0x0007 & 0x26 0b_0010_0110 dddd_dddd
|
||||
000008 0x0008 S 0x53 0b_0101_0011 dddd_dddd
|
||||
000009 0x0009 Y 0x59 0b_0101_1001 dddd_dddd
|
||||
000010 0x000A v 0x76 0b_0111_0110 eeee_eeee
|
||||
000011 0x000B . 0xA7 0b_1010_0111 eeee_eeee
|
||||
000012 0x000C . 0x09 0b_0000_1001 eeee_eeee
|
||||
000013 0x000D . 0x95 0b_1001_0101 eeee_eeee
|
||||
000014 0x000E . 0x00 0b_0000_0000 fggg_gggg
|
||||
000015 0x000F . 0x00 0b_0000_0000 gggg_gggg
|
||||
000016 0x0010 . 0x00 0b_0000_0000 gggg_gggg
|
||||
000017 0x0011 . 0x81 0b_1000_0001 ghhh_hhhh popcount(h) = 2
|
||||
000018 0x0012 . 0x80 0b_1000_0000 hhhh_hhhh
|
||||
000019 0x0013 8 0x38 0b_0011_1000 hiii_iiii popcount(i) = 3
|
||||
000020 0x0014 . 0x00 0b_0000_0000 iiii_iiii
|
||||
000021 0x0015 . 0x10 0b_0001_0000 ijjj_jjjj popcount(j) = 1
|
||||
000022 0x0016 . 0x00 0b_0000_0000 jjjj_jjjj
|
||||
000023 0x0017 0x20 0b_0010_0000 jkkk_llll
|
||||
000024 0x0018 . 0x00 0b_0000_0000 llll_llll
|
||||
000025 0x0019 ! 0x21 0b_0010_0001 lllm_nnnn
|
||||
000026 0x001A . 0x9A 0b_1001_1010 nnnn_nnnn
|
||||
000027 0x001B h 0x68 0b_0110_1000 nnnn_nnno
|
||||
000028 0x001C 3 0x33 0b_0011_0011 oooo_oooo
|
||||
000029 0x001D M 0x4D 0b_0100_1101 oooo_oooo
|
||||
000030 0x001E 0 0x30 0b_0011_0000 oopp_pppp
|
||||
000031 0x001F . 0x91 0b_1001_0001 pppp_pppp
|
||||
000032 0x0020 . 0xE2 0b_1110_0010 pppq_qqqq
|
||||
000033 0x0021 . 0xEE 0b_1110_1110 qqqq_qqqq
|
||||
000034 0x0022 H 0x48 0b_0100_1000 qqqq_qqqq
|
||||
000035 0x0023 . 0xA7 0b_1010_0111 qqqq_qqqq
|
||||
000036 0x0024 . 0x0A 0b_0000_1010 qqqq_qqqq
|
||||
000037 0x0025 . 0x12 0b_0001_0010 qqqq_qqqq
|
||||
000038 0x0026 . 0x0E 0b_0000_1110 qqqr_rrrr
|
||||
000039 0x0027 . 0xD4 0b_1101_0100 rrrr_rrrr
|
||||
000040 0x0028 . 0xE1 0b_1110_0001 rrrr_rrrr
|
||||
000041 0x0029 2 0x32 0b_0011_0010 rrrr_rrrr
|
||||
000042 0x002A . 0xA0 0b_1010_0000 rrrs_ssss
|
||||
|
||||
(a) A 16-bit magic number "BZ" meaning the start of the bzip2 file.
|
||||
|
||||
(b) The 'h' byte means Huffman compression. The original bzip (as in, without
|
||||
the "2" in "bzip2") used a '0' byte here to indicate arithmetic codes instead
|
||||
of Huffman codes, but arithmetic/bzip was not widely used because of patent
|
||||
concerns. This package (and worked example) only considers Huffman/bzip2.
|
||||
|
||||
(c) The '9' byte means the uncompressed block size ranges up to 900000
|
||||
(inclusive).
|
||||
|
||||
(d) A 48-bit magic number 0x314159265359 (a homage to π) means the start of a
|
||||
block.
|
||||
|
||||
(e) A 32-bit checksum. Refer to section 2.2.3.1 "BlockHeader" of [Tsai's
|
||||
document](https://github.com/dsnet/compress/raw/master/doc/bzip2-format.pdf)
|
||||
which notes, "It is the same [CRC-32] checksum used in GZip (RFC 1952, section
|
||||
8), but is slightly different due to the bit-packing differences noted in
|
||||
section 2.1".
|
||||
|
||||
(f) A "block randomized" bit, deprecated and not used here.
|
||||
|
||||
(g) The 24-bit index of the original string in the sorted list of BWT
|
||||
rotations. The [BWT technical
|
||||
report](http://www.hpl.hp.com/techreports/Compaq-DEC/SRC-RR-124.pdf) calls this
|
||||
number *I*. In this case, the value is 0x000001.
|
||||
|
||||
(h) A 16-bit bitmap of which byte values are present in the uncompressed text.
|
||||
In this case, `0b_0000_0011_0000_0000` means that there are values in the 7th
|
||||
and 8th rows (with 16 bytes per row). Its popcount (population count, the
|
||||
number of set bits) is 2, which means there are 2 further 16-bit bitmaps
|
||||
immediately following.
|
||||
|
||||
(i) The 16-bit bitmap for the 7th row in (h). `0b_0111_0000_0000_0000` means
|
||||
that the `0x61`, `0x62` and `0x63` bytes (ASCII 'a', 'b' and 'c') are present.
|
||||
|
||||
(j) The 16-bit bitmap for the 8th row in (h). `0b_0010_0000_0000_0000` means
|
||||
that the `0x72` byte (ASCII 'r') is present.
|
||||
|
||||
(k) The 3-bit number of Huffman codes. In this case, `0b_010 = 2`, the minimum
|
||||
valid value.
|
||||
|
||||
(l) The 15-bit number of sections. Each section is 50 symbols. Each symbol
|
||||
either produces one byte of uncompressed data (roughly speaking) or are one of
|
||||
three special symbols: RUNA, RUNB (both Run Length Encoding related) or EOB
|
||||
(End Of Block). The selected Huffman code can change at section boundaries.
|
||||
|
||||
(m) The array of unary encoded Huffman code selectors (one for each section).
|
||||
In this case, an array of one element, [0]. Applying the MTFT (Move To Front
|
||||
Transform) produces the same values: [0]. This part of `abraca.txt.bz2` isn't
|
||||
very enlightening but there's a more interesting example in the "MTFT Reprised"
|
||||
section below.
|
||||
|
||||
(n) The first Huffman code. More details below.
|
||||
|
||||
(o) The second Huffman code. For `abraca.txt.bz2`, the second Huffman code is
|
||||
never referenced by the selectors in the (m) bitslice but, for the record, the
|
||||
(o) bitslice is identical to the (n) bitslice and therefore produces the same
|
||||
Huffman code.
|
||||
|
||||
(p) The bitstream to feed the Huffman codes. More details below.
|
||||
|
||||
(q) A 48-bit magic number 0x177245385090 (a homage to sqrt(π)) means no further
|
||||
blocks.
|
||||
|
||||
(r) A 32-bit checksum. Refer to section 2.2.4 "StreamFooter" of [Tsai's
|
||||
document](https://github.com/dsnet/compress/raw/master/doc/bzip2-format.pdf).
|
||||
|
||||
(s) Padding up to a byte boundary.
|
||||
|
||||
|
||||
## Huffman Codes
|
||||
|
||||
The (h), (i) and (j) bitslices collectively state that there are 4 byte values
|
||||
present in the uncompressed output: 'a', 'b', 'c' and 'r'. The relevant MTFT
|
||||
uses 1 fewer symbols (m01, m02 and m03) than this count, since an m00 operation
|
||||
(see below) is redundant with the RUNA and RUNB symbols. Adding the 3 special
|
||||
symbols (RUNA, RUNB, EOB) means that each Huffman code covers 6 symbols.
|
||||
|
||||
Here's the (n) bitslice again:
|
||||
|
||||
offset xoffset ASCII hex binary bitslice
|
||||
000025 0x0019 ! 0x21 0b_0010_0001 lllm_nnnn
|
||||
000026 0x001A . 0x9A 0b_1001_1010 nnnn_nnnn
|
||||
000027 0x001B h 0x68 0b_0110_1000 nnnn_nnno
|
||||
|
||||
Its bits are "0001100110100110100". Adding spaces gives "00011 0 0 11 0 10 0 11
|
||||
0 10 0", which represents the sequence [3+0, +0, -1+0, +1+0, -1+0, +1+0].
|
||||
Adding up the deltas gives the code lengths [3, 3, 2, 3, 2, 3] and so the
|
||||
[canonical Huffman code](https://en.wikipedia.org/wiki/Canonical_Huffman_code)
|
||||
(with RUNA and RUNB before the mNN symbols and EOB after) is:
|
||||
|
||||
code length symbol
|
||||
100 3 RUNA
|
||||
101 3 RUNB
|
||||
00 2 m01
|
||||
110 3 m02
|
||||
01 2 m03
|
||||
111 3 EOB
|
||||
|
||||
Here's the (p) bitslice again.
|
||||
|
||||
offset xoffset ASCII hex binary bitslice
|
||||
000030 0x001E 0 0x30 0b_0011_0000 oopp_pppp
|
||||
000031 0x001F . 0x91 0b_1001_0001 pppp_pppp
|
||||
000032 0x0020 . 0xE2 0b_1110_0010 pppq_qqqq
|
||||
|
||||
Its bits are "11000010010001111". Adding spaces, giving "110 00 01 00 100 01
|
||||
111", makes it clearer that applying the Huffman code from the (n) bitslice to
|
||||
the (p) bitslice produces the symbol sequence [m02, m01, m03, m01, RUNA, m03,
|
||||
EOB].
|
||||
|
||||
|
||||
## Move To Front Transform
|
||||
|
||||
MTFT operates on a byte array (let's call it the "order" buffer) that's
|
||||
initialized with with the bytes-in-use in their natural order: ['a', 'b', 'c',
|
||||
'r']. Each mNN symbol emits the N'th element (using 0-based indexing) and also
|
||||
rearranges the order buffer: moving that element to the start and pushing the N
|
||||
earlier symbols one to the right.
|
||||
|
||||
There is no explicit m00 symbol. Instead, a combination of RUNA and RUNB
|
||||
symbols produce a number R meaning to repeat the 0th element R times (and leave
|
||||
the order buffer unchanged). For the `abraca.txt.bz2` example, we have one RUNA
|
||||
symbol but no RUNB symbols, which is effectively an m00 repeated once. Here's
|
||||
the production:
|
||||
|
||||
order symbol emission
|
||||
abcr m02 c
|
||||
cabr m01 a
|
||||
acbr m03 r
|
||||
racb m01 a
|
||||
arcb RUNA a
|
||||
arcb m03 b
|
||||
barc EOB
|
||||
|
||||
Tsai calls this RUNA / RUNB mechanism RLE2 (and goes into further detail on
|
||||
their semantics) and calls a later Run Length Encoding mechanism RLE1. Later
|
||||
when decoding, but when encoding, RLE1 occurs before RLE2.
|
||||
|
||||
|
||||
## Burrows Wheeler Transform
|
||||
|
||||
Reading down the emission column gives "caraab", which the [BWT technical
|
||||
report](http://www.hpl.hp.com/techreports/Compaq-DEC/SRC-RR-124.pdf) calls *L*,
|
||||
the last column of the sorted list of permutations of the uncompressed text. We
|
||||
can compute its histogram ('a' occurs 3 times, 'b', 'c' and 'r' all occur 1
|
||||
time) in a first pass over *L*, and thus the cumulative counts:
|
||||
|
||||
Byte Cumulative
|
||||
a 0
|
||||
b 3
|
||||
c 4
|
||||
r 5
|
||||
|
||||
We then compute *T* in a second pass over *L*, by assigning an incrementing
|
||||
value (relative to each cumulative count) to all the 'a' elements in *L*
|
||||
(assigning 0, 1 and 2), all the 'b' elements (assigning 3), all the 'c'
|
||||
elements (assinging 4) and all the 'r' elements (assigning 5).
|
||||
|
||||
Index L T
|
||||
0 c 4
|
||||
1 a 0
|
||||
2 r 5
|
||||
3 a 1
|
||||
4 a 2
|
||||
5 b 3
|
||||
|
||||
Starting with the *I* value given in the (g) bitslice, which was 1, calculate
|
||||
*I*, *T[I]*, *T[T[I]]*, *T[T[T[I]]]*, etc to give [1, 0, 4, 2, 5, 3]. Indexing
|
||||
*L* with these values gives "acarba" and reversing that gives "abraca", the
|
||||
uncompressed text.
|
||||
|
||||
|
||||
## Alternative BWT Inversion
|
||||
|
||||
It's not in the BWT technical report, but instead of walking *I*, *T[I]*,
|
||||
*T[T[I]]*, etc, an alternative but equivalent algorithm works on *U*, the
|
||||
inverse of the *T* vector. For example *T[4] == 2* and so *U[2] == 4*.
|
||||
|
||||
Index L T F U
|
||||
0 c 4 a 1
|
||||
1 a 0 a 3
|
||||
2 r 5 a 4
|
||||
3 a 1 b 5
|
||||
4 a 2 c 0
|
||||
5 b 3 r 2
|
||||
|
||||
Calculate *U[I]*, *U[U[I]]*, *U[U[U[I]]]*, etc to give [3, 5, 2, 4, 0, 1].
|
||||
Indexing *L* with these values gives "abraca", the uncompressed text (without
|
||||
being reversed).
|
||||
|
||||
|
||||
## Final Run Length Encoding
|
||||
|
||||
It's not used in `abraca.txt.bz2` but after BWT inversion, there's a final Run
|
||||
Length Encoding step (which Tsai calls RLE1), separate from the RUNA and RUNB
|
||||
ops mentioned above. It's triggered by four consecutive identical bytes and
|
||||
when decoding, converts strings like "AAAA\x03BBBB\x00CCCD" to
|
||||
"AAAAAAABBBBCCCD".
|
||||
|
||||
|
||||
# Another Example
|
||||
|
||||
Here's a larger file, 942 bytes uncompressed and 568 bytes bzip2-compressed.
|
||||
|
||||
$ cat romeo.txt | head
|
||||
Romeo and Juliet
|
||||
Excerpt from Act 2, Scene 2
|
||||
|
||||
JULIET
|
||||
O Romeo, Romeo! wherefore art thou Romeo?
|
||||
Deny thy father and refuse thy name;
|
||||
Or, if thou wilt not, be but sworn my love,
|
||||
And I'll no longer be a Capulet.
|
||||
|
||||
ROMEO
|
||||
$ hd romeo.txt.bz2 | head
|
||||
00000000 42 5a 68 39 31 41 59 26 53 59 f8 7d 63 30 00 00 |BZh91AY&SY.}c0..|
|
||||
00000010 8c 5f 80 00 10 60 85 10 18 be 77 9e 8a 3f ef df |._...`....w..?..|
|
||||
00000020 f0 40 02 30 e3 bb 00 22 9e a0 68 01 a1 a0 00 00 |.@.0..."..h.....|
|
||||
00000030 00 02 26 13 23 4d 21 20 6d 41 a0 d0 d0 d0 f2 80 |..&.#M! mA......|
|
||||
00000040 2a 9e f5 4f 50 f5 46 4c 23 13 09 89 82 60 4c 09 |*..OP.FL#....`L.|
|
||||
00000050 84 89 1a 9a 05 31 92 27 92 6c 88 68 7a 23 26 83 |.....1.'.l.hz#&.|
|
||||
00000060 4a b3 4b 3a 06 9b ec c7 19 bc 9a 88 60 6a 6b 42 |J.K:........`jkB|
|
||||
00000070 5a c6 8e ad c7 c3 8f a8 f0 91 d1 db e3 1b 25 b5 |Z.............%.|
|
||||
00000080 4e 06 cd f3 08 a9 af e8 82 2d 5b 54 fc 35 a9 0e |N........-[T.5..|
|
||||
00000090 13 01 17 7b 4c 98 47 24 25 d9 bd aa cd 31 da ee |...{L.G$%....1..|
|
||||
|
||||
Where `abraca.txt.bz2` had 3 + 1 = 4 possible uncompressed bytes ('a', 'b', 'c'
|
||||
and 'r'), `romeo.txt.bz2` has 1 + 5 + 4 + 12 + 7 + 14 + 10 = 53. This is
|
||||
represented in the wire format by the (h), (i) and (j) bitslices for
|
||||
`abraca.txt.bz2` and the 8 equivalent bitslices in `romeo.txt.bz2` (where we
|
||||
have repeatedly alternated the (i) and (j) bitslice labels).
|
||||
|
||||
offset xoffset ASCII hex binary bitslice
|
||||
000017 0x0011 _ 0x5F 0b_0101_1111 ghhh_hhhh popcount(h) = 7
|
||||
000018 0x0012 . 0x80 0b_1000_0000 hhhh_hhhh
|
||||
000019 0x0013 . 0x00 0b_0000_0000 hiii_iiii popcount(i) = 1
|
||||
000020 0x0014 . 0x10 0b_0001_0000 iiii_iiii
|
||||
000021 0x0015 ` 0x60 0b_0110_0000 ijjj_jjjj popcount(j) = 5
|
||||
000022 0x0016 . 0x85 0b_1000_0101 jjjj_jjjj
|
||||
000023 0x0017 . 0x10 0b_0001_0000 jiii_iiii popcount(i) = 4
|
||||
000024 0x0018 . 0x18 0b_0001_1000 iiii_iiii
|
||||
000025 0x0019 . 0xBE 0b_1011_1110 ijjj_jjjj popcount(j) = 12
|
||||
000026 0x001A w 0x77 0b_0111_0111 jjjj_jjjj
|
||||
000027 0x001B . 0x9E 0b_1001_1110 jiii_iiii popcount(i) = 7
|
||||
000028 0x001C . 0x8A 0b_1000_1010 iiii_iiii
|
||||
000029 0x001D ? 0x3F 0b_0011_1111 ijjj_jjjj popcount(j) = 14
|
||||
000030 0x001E . 0xEF 0b_1110_1111 jjjj_jjjj
|
||||
000031 0x001F . 0xDF 0b_1101_1111 jiii_iiii popcount(i) = 10
|
||||
000032 0x0020 . 0xF0 0b_1111_0000 iiii_iiii
|
||||
000033 0x0021 @ 0x40 0b_0100_0000 ikkk_llll
|
||||
|
||||
Similarly, where `abraca.txt.bz2` had 1 section (per the (l) bitslice), each
|
||||
selecting from 2 possible Huffman codes (per the (k) bitslice), `romeo.txt.bz2`
|
||||
has 17 sections, each selecting from 4 possible Huffman codes.
|
||||
|
||||
offset xoffset ASCII hex binary bitslice
|
||||
000033 0x0021 @ 0x40 0b_0100_0000 ikkk_llll
|
||||
000034 0x0022 . 0x02 0b_0000_0010 llll_llll
|
||||
000035 0x0023 0 0x30 0b_0011_0000 lllm_mmmm
|
||||
|
||||
|
||||
## MTFT Reprised
|
||||
|
||||
Bzip2 uses the [Move To Front
|
||||
Transform](https://en.wikipedia.org/wiki/Move-to-front_transform) in two
|
||||
places:
|
||||
|
||||
1. for the selectors array encoded in the (m) bitslice and
|
||||
2. for the conversion from the symbols (the Huffman code's output) to
|
||||
generating the *L* string.
|
||||
|
||||
Use 2 is discussed above but the Use 1 values for `abraca.txt.bz2` is not very
|
||||
educational, since the (m) bitslice was literally only one bit long. For
|
||||
`romeo.txt.bz2`, the equivalent (m) bitslice is 29 bits long and makes for a
|
||||
more interesting example.
|
||||
|
||||
offset xoffset ASCII hex binary bitslice
|
||||
000035 0x0023 0 0x30 0b_0011_0000 lllm_mmmm
|
||||
000036 0x0024 . 0xE3 0b_1110_0011 mmmm_mmmm
|
||||
000037 0x0025 . 0xBB 0b_1011_1011 mmmm_mmmm
|
||||
000038 0x0026 . 0x00 0b_0000_0000 mmmm_mmmm
|
||||
|
||||
The bits are "10000111000111011101100000000" which is the unary encoding of the
|
||||
17-element selector array (before applying the MTFT): [1, 0, 0, 0, 3, 0, 0, 3,
|
||||
3, 2, 0, 0, 0, 0, 0, 0, 0].
|
||||
|
||||
If we label the 4 Huffman codes to select from as w, x, y and z then the MTFT
|
||||
converts those 17 elements to "xxxxzzzywzzzzzzzz", per the table below. As
|
||||
before, each N value (pre-MTFT) emits the N'th element (using 0-based indexing)
|
||||
and also rearranges the order buffer: moving that element to the start and
|
||||
pushing the N earlier symbols one to the right.
|
||||
|
||||
order pre post
|
||||
wxyz 1 x
|
||||
xwyz 0 x
|
||||
xwyz 0 x
|
||||
xwyz 0 x
|
||||
xwyz 3 z
|
||||
zxwy 0 z
|
||||
zxwy 0 z
|
||||
zxwy 3 y
|
||||
yzxw 3 w
|
||||
wyzx 2 z
|
||||
zwyx 0 z
|
||||
zwyx 0 z
|
||||
zwyx 0 z
|
||||
zwyx 0 z
|
||||
zwyx 0 z
|
||||
zwyx 0 z
|
||||
zwyx 0 z
|
||||
|
||||
|
||||
# Even More Examples
|
||||
|
||||
Appendix A of [Tsai's
|
||||
document](https://github.com/dsnet/compress/raw/master/doc/bzip2-format.pdf)
|
||||
gives even more wire format worked examples, presented in great detail.
|
||||
@@ -0,0 +1,778 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub status "#bad Huffman code (over-subscribed)"
|
||||
pub status "#bad Huffman code (under-subscribed)"
|
||||
pub status "#bad block header"
|
||||
pub status "#bad block length"
|
||||
pub status "#bad checksum"
|
||||
pub status "#bad header"
|
||||
pub status "#bad number of sections"
|
||||
pub status "#unsupported block randomization"
|
||||
|
||||
pri status "#internal error: inconsistent Huffman decoder state"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pri const CLAMP_TO_5 : array[8] base.u8[..= 5] = [0, 1, 2, 3, 4, 5, 5, 5]
|
||||
|
||||
pub struct decoder? implements base.io_transformer(
|
||||
bits : base.u32,
|
||||
n_bits : base.u32[..= 31],
|
||||
|
||||
// Block size is measured prior to the RLE1 step.
|
||||
max_incl_block_size : base.u32[..= 900000],
|
||||
|
||||
block_size : base.u32[..= 900000],
|
||||
decode_huffman_finished : base.bool,
|
||||
decode_huffman_which : base.u8[..= 5],
|
||||
decode_huffman_ticks : base.u32[..= 50],
|
||||
decode_huffman_section : base.u32,
|
||||
decode_huffman_run_shift : base.u32[..= 23],
|
||||
|
||||
flush_pointer : base.u32[..= 1_048575],
|
||||
flush_repeat_count : base.u32[..= 255],
|
||||
flush_prev : base.u8,
|
||||
|
||||
ignore_checksum : base.bool,
|
||||
final_checksum_have : base.u32,
|
||||
block_checksum_have : base.u32,
|
||||
block_checksum_want : base.u32,
|
||||
original_pointer : base.u32,
|
||||
num_symbols : base.u32[..= 258],
|
||||
num_huffman_codes : base.u32[..= 6],
|
||||
num_sections : base.u32[..= 18001],
|
||||
code_lengths_bitmask : base.u32,
|
||||
|
||||
util : base.utility,
|
||||
)(
|
||||
scratch : base.u32,
|
||||
|
||||
letter_counts : array[256] base.u32,
|
||||
|
||||
// presence[i] being non-zero is whether the byte value i occurs in the
|
||||
// block's decompressed output.
|
||||
presence : array[256] base.u8,
|
||||
|
||||
// mtft is the Move To Front Transform state.
|
||||
mtft : array[256] base.u8,
|
||||
|
||||
// huffman_selectors selects which of the huffman_trees to use for each
|
||||
// 50-symbol section.
|
||||
huffman_selectors : array[32768] base.u8,
|
||||
|
||||
// Each array[2] base.u16 is a branch node in the Huffman tree. The
|
||||
// build_huffman_tree method comment details what the base.u16 values mean.
|
||||
//
|
||||
// Each Huffman tree has num_symbols leaf nodes and hence (num_symbols - 1)
|
||||
// branch nodes, also called internal nodes, as per
|
||||
// https://stackoverflow.com/questions/69399994/maximum-number-of-nodes-in-a-huffman-tree/69401083#69401083
|
||||
//
|
||||
// This can be proven inductively. The base case Huffman code (two symbols)
|
||||
// has one branch node (the root node). The inductive case, adding one
|
||||
// symbol to a (complete but possibly non-canonical) Huffman code replaces
|
||||
// one leaf node with one branch node (and two leaf nodes). The net gain in
|
||||
// branch nodes is +1.
|
||||
//
|
||||
// Since num_symbols' inclusive maximum is 258 (for RUNA, RUNB, 255 × mXYZ,
|
||||
// EOB), there are at most 257 branch nodes.
|
||||
huffman_trees : array[6] array[257] array[2] base.u16,
|
||||
|
||||
// huffman_tables[which] caches the result of walking huffman_trees[which]
|
||||
// for each possible 8-bit input. The base.u16 value decomposes as:
|
||||
// - The low 10 bits are the final node, where finality comes either from
|
||||
// hitting a leaf node or from spending all 8 bits of the input. As per
|
||||
// the build_huffman_tree method, a value of 0x100 = 256 or less means
|
||||
// a branch node and 0x201 = 513 or more means a leaf node.
|
||||
// - The middle 2 bits are unused.
|
||||
// - The high 4 bits are the number of input bits spent.
|
||||
huffman_tables : array[6] array[256] base.u16,
|
||||
|
||||
// bwt is the Burrows Wheeler Transform state. Per the README.md file, each
|
||||
// entry is a row with the low 8 bits holding the L column and the high 20
|
||||
// bits holding the U column. The middle 4 bits are unused.
|
||||
//
|
||||
// The read_code_lengths and build_huffman_tree methods also re-purpose
|
||||
// this buffer to temporarily hold up to 258 symbols' code lengths.
|
||||
bwt : array[1_048576] base.u32,
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
|
||||
this.ignore_checksum = args.enabled
|
||||
}
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE,
|
||||
max_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE)
|
||||
}
|
||||
|
||||
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var c : base.u8
|
||||
var i : base.u32
|
||||
var tag : base.u64
|
||||
var status : base.status
|
||||
var final_checksum_want : base.u32
|
||||
|
||||
// Read the header.
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x42 {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x5A {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x68 {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if (c < '1') or ('9' < c) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.max_incl_block_size = ((c - '0') as base.u32) * 100000
|
||||
|
||||
while true {
|
||||
// Read the 48-bit tag.
|
||||
tag = 0
|
||||
i = 0
|
||||
while i < 48 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
tag ~mod<<= 1
|
||||
tag |= (this.bits >> 31) as base.u64
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
|
||||
if tag == 0x1772_4538_5090 {
|
||||
break
|
||||
} else if tag <> 0x3141_5926_5359 {
|
||||
return "#bad block header"
|
||||
}
|
||||
|
||||
this.prepare_block?(src: args.src)
|
||||
|
||||
this.block_size = 0
|
||||
this.decode_huffman_finished = false
|
||||
this.decode_huffman_which = CLAMP_TO_5[this.huffman_selectors[0] & 7]
|
||||
this.decode_huffman_ticks = 50
|
||||
this.decode_huffman_section = 0
|
||||
this.decode_huffman_run_shift = 0
|
||||
while not this.decode_huffman_finished {
|
||||
status = this.decode_huffman_fast!(src: args.src)
|
||||
if status.is_error() {
|
||||
return status
|
||||
} else if this.decode_huffman_finished {
|
||||
break
|
||||
}
|
||||
this.decode_huffman_slow?(src: args.src)
|
||||
} endwhile
|
||||
|
||||
this.invert_bwt!()
|
||||
|
||||
this.block_checksum_have = 0xFFFF_FFFF
|
||||
if this.original_pointer >= this.block_size {
|
||||
return "#bad block length"
|
||||
}
|
||||
assert this.original_pointer < 900000 via "a < b: a < c; c <= b"(c: this.block_size)
|
||||
this.flush_pointer = this.bwt[this.original_pointer] >> 12
|
||||
this.flush_repeat_count = 0
|
||||
this.flush_prev = 0
|
||||
|
||||
while this.block_size > 0 {
|
||||
this.flush_fast!(dst: args.dst)
|
||||
if this.block_size <= 0 {
|
||||
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) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
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
|
||||
i = 0
|
||||
while i < 32 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
final_checksum_want ~mod<<= 1
|
||||
final_checksum_want |= this.bits >> 31
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
var selector : base.u32
|
||||
var sel_ff : base.u32
|
||||
var movee : base.u8
|
||||
var status : base.status
|
||||
|
||||
// Read the 32-bit block checksum.
|
||||
this.block_checksum_want = 0
|
||||
i = 0
|
||||
while i < 32 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
this.block_checksum_want ~mod<<= 1
|
||||
this.block_checksum_want |= this.bits >> 31
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
|
||||
// Read the "block randomized" bit.
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
if (this.bits >> 31) <> 0 {
|
||||
return "#unsupported block randomization"
|
||||
}
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
// Read the 24-bit original pointer. The BWT technical report calls this I.
|
||||
this.original_pointer = 0
|
||||
i = 0
|
||||
while i < 24 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
this.original_pointer ~mod<<= 1
|
||||
this.original_pointer |= this.bits >> 31
|
||||
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
|
||||
while i < 256 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
if (this.bits >> 31) <> 0 {
|
||||
this.presence[i] = 1
|
||||
}
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 16
|
||||
} endwhile
|
||||
|
||||
// Read the 16-bit low-level presence bitmaps.
|
||||
this.scratch = 0
|
||||
i = 0
|
||||
while i < 256 {
|
||||
if this.presence[i] == 0 {
|
||||
i += 16
|
||||
continue
|
||||
}
|
||||
while true {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
this.scratch ~mod+= this.bits >> 31
|
||||
this.presence[i & 0xFF] = (this.bits >> 31) as base.u8
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i ~mod+= 1
|
||||
if (i & 15) == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
} endwhile
|
||||
if (this.scratch < 1) or (256 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
this.num_symbols = this.scratch + 2
|
||||
|
||||
// Read the 3-bit number of Huffman codes.
|
||||
this.scratch = 0
|
||||
i = 0
|
||||
while i < 3 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
this.scratch ~mod<<= 1
|
||||
this.scratch |= this.bits >> 31
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
if (this.scratch < 2) or (6 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
this.num_huffman_codes = this.scratch
|
||||
|
||||
// Read the 15-bit number of sections.
|
||||
this.scratch = 0
|
||||
i = 0
|
||||
while i < 15 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
this.scratch ~mod<<= 1
|
||||
this.scratch |= this.bits >> 31
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
if (this.scratch < 1) or (18001 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
this.num_sections = this.scratch
|
||||
|
||||
// Initialize the MTFT state.
|
||||
i = 0
|
||||
while i < this.num_huffman_codes {
|
||||
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
|
||||
while i < this.num_sections {
|
||||
assert i < 18001 via "a < b: a < c; c <= b"(c: this.num_sections)
|
||||
selector = 0
|
||||
|
||||
// Read a unary encoded natural number.
|
||||
while true,
|
||||
inv i < 18001,
|
||||
{
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
if (this.bits >> 31) == 0 {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
break
|
||||
}
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
selector ~mod+= 1
|
||||
if selector >= this.num_huffman_codes {
|
||||
return "#bad block header"
|
||||
}
|
||||
} endwhile
|
||||
|
||||
// Move to front.
|
||||
if selector == 0 {
|
||||
this.huffman_selectors[i] = this.mtft[0]
|
||||
} else {
|
||||
sel_ff = selector & 0xFF
|
||||
movee = this.mtft[sel_ff]
|
||||
this.mtft[1 .. 1 + sel_ff].copy_from_slice!(
|
||||
s: this.mtft[.. sel_ff])
|
||||
this.mtft[0] = movee
|
||||
this.huffman_selectors[i] = movee
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
|
||||
// Read the Huffman codes.
|
||||
i = 0
|
||||
while i < this.num_huffman_codes {
|
||||
assert i < 6 via "a < b: a < c; c <= b"(c: this.num_huffman_codes)
|
||||
this.read_code_lengths?(src: args.src)
|
||||
status = this.build_huffman_tree!(which: i)
|
||||
if status.is_error() {
|
||||
return status
|
||||
}
|
||||
this.build_huffman_table!(which: i)
|
||||
i += 1
|
||||
} endwhile
|
||||
|
||||
// Initialize the MTFT state.
|
||||
i = 0
|
||||
j = 0
|
||||
while i < 256 {
|
||||
if this.presence[i] <> 0 {
|
||||
this.mtft[j & 0xFF] = i as base.u8
|
||||
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) {
|
||||
var c : base.u8
|
||||
var i : base.u32
|
||||
var code_length : base.u32
|
||||
|
||||
this.code_lengths_bitmask = 0
|
||||
|
||||
// Read the 5-bit starting value.
|
||||
i = 0
|
||||
while i < 5 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
code_length ~mod<<= 1
|
||||
code_length |= this.bits >> 31
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
|
||||
// Read the code lengths.
|
||||
i = 0
|
||||
while i < this.num_symbols {
|
||||
assert i < 258 via "a < b: a < c; c <= b"(c: this.num_symbols)
|
||||
while true,
|
||||
inv i < 258,
|
||||
{
|
||||
if (code_length < 1) or (20 < code_length) {
|
||||
return "#bad block header"
|
||||
}
|
||||
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
if (this.bits >> 31) == 0 {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
break
|
||||
}
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
if (this.bits >> 31) == 0 {
|
||||
code_length ~mod+= 1
|
||||
} else {
|
||||
code_length ~mod-= 1
|
||||
}
|
||||
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
|
||||
// lengths. For the "abraca.txt.bz2" example, the code lengths are:
|
||||
// - symbol=0x301 (RUNA) cl=3
|
||||
// - symbol=0x302 (RUNB) cl=3
|
||||
// - symbol=0x201 (m01) cl=2
|
||||
// - symbol=0x202 (m02) cl=3
|
||||
// - symbol=0x203 (m03) cl=2
|
||||
// - symbol=0x300 (EOB) cl=3
|
||||
//
|
||||
// The bitstring mapping is:
|
||||
// - "00" 0x201 (m01)
|
||||
// - "01" 0x203 (m03)
|
||||
// - "100" 0x301 (RUNA)
|
||||
// - "101" 0x302 (RUNB)
|
||||
// - "110" 0x202 (m02)
|
||||
// - "111" 0x300 (EOB)
|
||||
//
|
||||
// The Huffman tree has 5 branch nodes (where 5+1 is both the number of leaf
|
||||
// nodes and the number of symbols). Each branch node has two children,
|
||||
// represented by a base.u16 value. 0x100 = 256 or less means that the child is
|
||||
// a branch node. 0x201 ..= 0x2FF means an mNN leaf node. 0x300, 0x301 and
|
||||
// 0x302 mean EOB, RUNA and RUNB leaf nodes.
|
||||
// - node0 = [0x001 (node1), 0x002 (node2)]
|
||||
// - node1 = [0x201 (m01) , 0x203 (m03) ]
|
||||
// - node2 = [0x003 (node3), 0x004 (node4)]
|
||||
// - node3 = [0x301 (RUNA) , 0x302 (RUNB) ]
|
||||
// - node4 = [0x202 (m02) , 0x300 (EOB) ]
|
||||
//
|
||||
// For example, the tree walk from node0 right (1) to node2 left (0) to node3
|
||||
// left (0) to RUNA means that the RUNA bitstring is "100".
|
||||
//
|
||||
// The tree is built incrementally by considering symbols in increasing code
|
||||
// length order, maintaining a stack of nodes that's the path from the root
|
||||
// (node0) to the latest created-but-unfinished node. Created means that their
|
||||
// left child is assigned (non-zero). Unfinished means that their right child
|
||||
// is pending (zero). For example, after adding the 0x201, 0x203 and 0x301
|
||||
// symbols, we would have this (in-progress) tree:
|
||||
// - node0 = [0x001 (node1), 0x002 (node2)]
|
||||
// - node1 = [0x201 (m01) , 0x203 (m03) ]
|
||||
// - node2 = [0x003 (node3), 0 ]
|
||||
// - node3 = [0x301 (RUNA) , 0 ]
|
||||
//
|
||||
// The stack would be [node0, node2, node3]. The next symbol would fill in the
|
||||
// top of the stack, node3. If that symbol's code length matches the stack
|
||||
// height (here, 3) then it would pop the stack. Otherwise it would push new
|
||||
// nodes onto the stack until the stack height matched that code length.
|
||||
pri func decoder.build_huffman_tree!(which: base.u32[..= 5]) base.status {
|
||||
var code_length : base.u32
|
||||
var symbol_index : base.u32
|
||||
var num_branch_nodes : base.u32[..= 257]
|
||||
var stack_height : base.u32[..= 21]
|
||||
var stack_values : array[21] base.u32[..= 256]
|
||||
var node_index : base.u32[..= 256]
|
||||
var leaf_value : base.u16
|
||||
|
||||
// Push a root node.
|
||||
this.huffman_trees[args.which][0][0] = 0
|
||||
this.huffman_trees[args.which][0][1] = 0
|
||||
num_branch_nodes = 1
|
||||
stack_height = 1
|
||||
stack_values[0] = 0
|
||||
|
||||
code_length = 1
|
||||
while code_length <= 20 {
|
||||
if (this.code_lengths_bitmask & ((1 as base.u32) << code_length)) == 0 {
|
||||
code_length += 1
|
||||
continue
|
||||
}
|
||||
symbol_index = 0
|
||||
while symbol_index < this.num_symbols,
|
||||
inv code_length <= 20,
|
||||
{
|
||||
assert symbol_index < 258 via "a < b: a < c; c <= b"(c: this.num_symbols)
|
||||
if this.bwt[symbol_index] <> code_length {
|
||||
symbol_index += 1
|
||||
continue
|
||||
}
|
||||
|
||||
while true,
|
||||
inv code_length <= 20,
|
||||
inv symbol_index < 258,
|
||||
post stack_height > 0,
|
||||
{
|
||||
if stack_height <= 0 {
|
||||
return "#bad Huffman code (over-subscribed)"
|
||||
} else if stack_height >= code_length {
|
||||
break
|
||||
}
|
||||
assert stack_height < 20 via "a < b: a < c; c <= b"(c: code_length)
|
||||
|
||||
node_index = stack_values[stack_height - 1]
|
||||
if this.huffman_trees[args.which][node_index][0] == 0 {
|
||||
this.huffman_trees[args.which][node_index][0] = num_branch_nodes as base.u16
|
||||
} else {
|
||||
this.huffman_trees[args.which][node_index][1] = num_branch_nodes as base.u16
|
||||
}
|
||||
if num_branch_nodes >= 257 {
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
stack_values[stack_height] = num_branch_nodes
|
||||
this.huffman_trees[args.which][num_branch_nodes][0] = 0
|
||||
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 {
|
||||
leaf_value = (0x301 + symbol_index) as base.u16
|
||||
} else if (symbol_index + 1) < this.num_symbols {
|
||||
leaf_value = (0x1FF + symbol_index) as base.u16
|
||||
} else {
|
||||
leaf_value = 0x300
|
||||
}
|
||||
|
||||
if this.huffman_trees[args.which][node_index][0] == 0 {
|
||||
this.huffman_trees[args.which][node_index][0] = leaf_value
|
||||
} else {
|
||||
this.huffman_trees[args.which][node_index][1] = leaf_value
|
||||
stack_height -= 1
|
||||
while stack_height > 0,
|
||||
inv code_length <= 20,
|
||||
inv symbol_index < 258,
|
||||
{
|
||||
node_index = stack_values[stack_height - 1]
|
||||
if this.huffman_trees[args.which][node_index][1] == 0 {
|
||||
break
|
||||
}
|
||||
stack_height -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
symbol_index += 1
|
||||
} endwhile
|
||||
code_length += 1
|
||||
} endwhile
|
||||
|
||||
if stack_height <> 0 {
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
pri func decoder.build_huffman_table!(which: base.u32[..= 5]) {
|
||||
var i : base.u32
|
||||
var bits : base.u32
|
||||
var n_bits : base.u16[..= 8]
|
||||
var child : base.u16
|
||||
|
||||
while i < 256 {
|
||||
bits = i << 24
|
||||
n_bits = 0
|
||||
child = 0
|
||||
while (child < 257) and (n_bits < 8),
|
||||
inv i < 256,
|
||||
{
|
||||
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
|
||||
// alphabet", per the BWT technical report, except that the first data pass
|
||||
// (accumulating this.letter_counts) is integrated into the decode_huffman_etc
|
||||
// methods.
|
||||
pri func decoder.invert_bwt!() {
|
||||
var i : base.u32
|
||||
var letter : base.u32[..= 255]
|
||||
var sum : base.u32
|
||||
var old_sum : base.u32
|
||||
|
||||
// Alphabet pass.
|
||||
sum = 0
|
||||
i = 0
|
||||
while i < 256 {
|
||||
old_sum = sum
|
||||
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.
|
||||
i = 0
|
||||
while i < this.block_size {
|
||||
assert i < 900000 via "a < b: a < c; c <= b"(c: this.block_size)
|
||||
letter = this.bwt[i] & 0xFF
|
||||
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
|
||||
// -reverse flag set.
|
||||
|
||||
pri const REV_CRC32_TABLE : array[256] base.u32 = [
|
||||
0x0000_0000, 0x04C1_1DB7, 0x0982_3B6E, 0x0D43_26D9, 0x1304_76DC, 0x17C5_6B6B, 0x1A86_4DB2, 0x1E47_5005,
|
||||
0x2608_EDB8, 0x22C9_F00F, 0x2F8A_D6D6, 0x2B4B_CB61, 0x350C_9B64, 0x31CD_86D3, 0x3C8E_A00A, 0x384F_BDBD,
|
||||
0x4C11_DB70, 0x48D0_C6C7, 0x4593_E01E, 0x4152_FDA9, 0x5F15_ADAC, 0x5BD4_B01B, 0x5697_96C2, 0x5256_8B75,
|
||||
0x6A19_36C8, 0x6ED8_2B7F, 0x639B_0DA6, 0x675A_1011, 0x791D_4014, 0x7DDC_5DA3, 0x709F_7B7A, 0x745E_66CD,
|
||||
0x9823_B6E0, 0x9CE2_AB57, 0x91A1_8D8E, 0x9560_9039, 0x8B27_C03C, 0x8FE6_DD8B, 0x82A5_FB52, 0x8664_E6E5,
|
||||
0xBE2B_5B58, 0xBAEA_46EF, 0xB7A9_6036, 0xB368_7D81, 0xAD2F_2D84, 0xA9EE_3033, 0xA4AD_16EA, 0xA06C_0B5D,
|
||||
0xD432_6D90, 0xD0F3_7027, 0xDDB0_56FE, 0xD971_4B49, 0xC736_1B4C, 0xC3F7_06FB, 0xCEB4_2022, 0xCA75_3D95,
|
||||
0xF23A_8028, 0xF6FB_9D9F, 0xFBB8_BB46, 0xFF79_A6F1, 0xE13E_F6F4, 0xE5FF_EB43, 0xE8BC_CD9A, 0xEC7D_D02D,
|
||||
0x3486_7077, 0x3047_6DC0, 0x3D04_4B19, 0x39C5_56AE, 0x2782_06AB, 0x2343_1B1C, 0x2E00_3DC5, 0x2AC1_2072,
|
||||
0x128E_9DCF, 0x164F_8078, 0x1B0C_A6A1, 0x1FCD_BB16, 0x018A_EB13, 0x054B_F6A4, 0x0808_D07D, 0x0CC9_CDCA,
|
||||
0x7897_AB07, 0x7C56_B6B0, 0x7115_9069, 0x75D4_8DDE, 0x6B93_DDDB, 0x6F52_C06C, 0x6211_E6B5, 0x66D0_FB02,
|
||||
0x5E9F_46BF, 0x5A5E_5B08, 0x571D_7DD1, 0x53DC_6066, 0x4D9B_3063, 0x495A_2DD4, 0x4419_0B0D, 0x40D8_16BA,
|
||||
0xACA5_C697, 0xA864_DB20, 0xA527_FDF9, 0xA1E6_E04E, 0xBFA1_B04B, 0xBB60_ADFC, 0xB623_8B25, 0xB2E2_9692,
|
||||
0x8AAD_2B2F, 0x8E6C_3698, 0x832F_1041, 0x87EE_0DF6, 0x99A9_5DF3, 0x9D68_4044, 0x902B_669D, 0x94EA_7B2A,
|
||||
0xE0B4_1DE7, 0xE475_0050, 0xE936_2689, 0xEDF7_3B3E, 0xF3B0_6B3B, 0xF771_768C, 0xFA32_5055, 0xFEF3_4DE2,
|
||||
0xC6BC_F05F, 0xC27D_EDE8, 0xCF3E_CB31, 0xCBFF_D686, 0xD5B8_8683, 0xD179_9B34, 0xDC3A_BDED, 0xD8FB_A05A,
|
||||
0x690C_E0EE, 0x6DCD_FD59, 0x608E_DB80, 0x644F_C637, 0x7A08_9632, 0x7EC9_8B85, 0x738A_AD5C, 0x774B_B0EB,
|
||||
0x4F04_0D56, 0x4BC5_10E1, 0x4686_3638, 0x4247_2B8F, 0x5C00_7B8A, 0x58C1_663D, 0x5582_40E4, 0x5143_5D53,
|
||||
0x251D_3B9E, 0x21DC_2629, 0x2C9F_00F0, 0x285E_1D47, 0x3619_4D42, 0x32D8_50F5, 0x3F9B_762C, 0x3B5A_6B9B,
|
||||
0x0315_D626, 0x07D4_CB91, 0x0A97_ED48, 0x0E56_F0FF, 0x1011_A0FA, 0x14D0_BD4D, 0x1993_9B94, 0x1D52_8623,
|
||||
0xF12F_560E, 0xF5EE_4BB9, 0xF8AD_6D60, 0xFC6C_70D7, 0xE22B_20D2, 0xE6EA_3D65, 0xEBA9_1BBC, 0xEF68_060B,
|
||||
0xD727_BBB6, 0xD3E6_A601, 0xDEA5_80D8, 0xDA64_9D6F, 0xC423_CD6A, 0xC0E2_D0DD, 0xCDA1_F604, 0xC960_EBB3,
|
||||
0xBD3E_8D7E, 0xB9FF_90C9, 0xB4BC_B610, 0xB07D_ABA7, 0xAE3A_FBA2, 0xAAFB_E615, 0xA7B8_C0CC, 0xA379_DD7B,
|
||||
0x9B36_60C6, 0x9FF7_7D71, 0x92B4_5BA8, 0x9675_461F, 0x8832_161A, 0x8CF3_0BAD, 0x81B0_2D74, 0x8571_30C3,
|
||||
0x5D8A_9099, 0x594B_8D2E, 0x5408_ABF7, 0x50C9_B640, 0x4E8E_E645, 0x4A4F_FBF2, 0x470C_DD2B, 0x43CD_C09C,
|
||||
0x7B82_7D21, 0x7F43_6096, 0x7200_464F, 0x76C1_5BF8, 0x6886_0BFD, 0x6C47_164A, 0x6104_3093, 0x65C5_2D24,
|
||||
0x119B_4BE9, 0x155A_565E, 0x1819_7087, 0x1CD8_6D30, 0x029F_3D35, 0x065E_2082, 0x0B1D_065B, 0x0FDC_1BEC,
|
||||
0x3793_A651, 0x3352_BBE6, 0x3E11_9D3F, 0x3AD0_8088, 0x2497_D08D, 0x2056_CD3A, 0x2D15_EBE3, 0x29D4_F654,
|
||||
0xC5A9_2679, 0xC168_3BCE, 0xCC2B_1D17, 0xC8EA_00A0, 0xD6AD_50A5, 0xD26C_4D12, 0xDF2F_6BCB, 0xDBEE_767C,
|
||||
0xE3A1_CBC1, 0xE760_D676, 0xEA23_F0AF, 0xEEE2_ED18, 0xF0A5_BD1D, 0xF464_A0AA, 0xF927_8673, 0xFDE6_9BC4,
|
||||
0x89B8_FD09, 0x8D79_E0BE, 0x803A_C667, 0x84FB_DBD0, 0x9ABC_8BD5, 0x9E7D_9662, 0x933E_B0BB, 0x97FF_AD0C,
|
||||
0xAFB0_10B1, 0xAB71_0D06, 0xA632_2BDF, 0xA2F3_3668, 0xBCB4_666D, 0xB875_7BDA, 0xB536_5D03, 0xB1F7_40B4,
|
||||
]
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pri func decoder.flush_fast!(dst: base.io_writer) {
|
||||
var flush_pointer : base.u32[..= 1_048575]
|
||||
var flush_repeat_count : base.u32[..= 255]
|
||||
var flush_prev : base.u8
|
||||
var block_checksum_have : base.u32
|
||||
var block_size : base.u32
|
||||
|
||||
var entry : base.u32
|
||||
var curr : base.u8
|
||||
|
||||
flush_pointer = this.flush_pointer
|
||||
flush_repeat_count = this.flush_repeat_count
|
||||
flush_prev = this.flush_prev
|
||||
block_checksum_have = this.block_checksum_have
|
||||
block_size = this.block_size
|
||||
|
||||
while (block_size > 0) and (args.dst.length() >= 255) {
|
||||
if flush_repeat_count < 4 {
|
||||
entry = this.bwt[flush_pointer]
|
||||
curr = (entry & 0xFF) as base.u8
|
||||
flush_pointer = entry >> 12
|
||||
if curr == flush_prev {
|
||||
flush_repeat_count += 1
|
||||
} else {
|
||||
flush_repeat_count = 1
|
||||
}
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8_fast!(a: curr)
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
|
||||
} else {
|
||||
entry = this.bwt[flush_pointer]
|
||||
curr = (entry & 0xFF) as base.u8
|
||||
flush_pointer = entry >> 12
|
||||
flush_repeat_count = curr as base.u32
|
||||
while flush_repeat_count > 0,
|
||||
inv block_size > 0,
|
||||
{
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ flush_prev] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
if args.dst.length() > 0 {
|
||||
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
|
||||
this.flush_prev = flush_prev
|
||||
this.block_checksum_have = block_checksum_have
|
||||
if block_size <= 900000 {
|
||||
this.block_size = block_size
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pri func decoder.flush_slow?(dst: base.io_writer) {
|
||||
var flush_pointer : base.u32[..= 1_048575]
|
||||
var flush_repeat_count : base.u32[..= 255]
|
||||
var flush_prev : base.u8
|
||||
var block_checksum_have : base.u32
|
||||
var block_size : base.u32
|
||||
|
||||
var entry : base.u32
|
||||
var curr : base.u8
|
||||
|
||||
flush_pointer = this.flush_pointer
|
||||
flush_repeat_count = this.flush_repeat_count
|
||||
flush_prev = this.flush_prev
|
||||
block_checksum_have = this.block_checksum_have
|
||||
block_size = this.block_size
|
||||
|
||||
while (block_size > 0) and (not coroutine_resumed) {
|
||||
if flush_repeat_count < 4 {
|
||||
entry = this.bwt[flush_pointer]
|
||||
curr = (entry & 0xFF) as base.u8
|
||||
flush_pointer = entry >> 12
|
||||
if curr == flush_prev {
|
||||
flush_repeat_count += 1
|
||||
} else {
|
||||
flush_repeat_count = 1
|
||||
}
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8?(a: curr)
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
|
||||
} else {
|
||||
entry = this.bwt[flush_pointer]
|
||||
curr = (entry & 0xFF) as base.u8
|
||||
flush_pointer = entry >> 12
|
||||
flush_repeat_count = curr as base.u32
|
||||
while flush_repeat_count > 0,
|
||||
inv block_size > 0,
|
||||
{
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ flush_prev] ^
|
||||
(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
|
||||
this.flush_prev = flush_prev
|
||||
this.block_checksum_have = block_checksum_have
|
||||
if block_size <= 900000 {
|
||||
this.block_size = block_size
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
var bits : base.u32
|
||||
var n_bits : base.u32[..= 31]
|
||||
var block_size : base.u32[..= 900000]
|
||||
var which : base.u8[..= 5]
|
||||
var ticks : base.u32[..= 50]
|
||||
var section : base.u32
|
||||
var run_shift : base.u32[..= 23]
|
||||
|
||||
var table_entry : base.u16
|
||||
var child : base.u16
|
||||
var child_ff : base.u32[..= 255]
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
var output : base.u32[..= 255]
|
||||
var run : base.u32[..= 12_582912] // 12_582912 = (3 << 22)
|
||||
var mtft0 : base.u32[..= 255]
|
||||
|
||||
bits = this.bits
|
||||
n_bits = this.n_bits
|
||||
block_size = this.block_size
|
||||
which = this.decode_huffman_which
|
||||
ticks = this.decode_huffman_ticks
|
||||
section = this.decode_huffman_section
|
||||
run_shift = this.decode_huffman_run_shift
|
||||
|
||||
// Apply the Huffman trees.
|
||||
while.outer args.src.length() >= 4 {
|
||||
if ticks > 0 {
|
||||
ticks -= 1
|
||||
} else {
|
||||
ticks = 49
|
||||
section ~mod+= 1
|
||||
if section >= this.num_sections {
|
||||
return "#bad number of sections"
|
||||
}
|
||||
which = CLAMP_TO_5[this.huffman_selectors[section & 32767] & 7]
|
||||
}
|
||||
|
||||
bits |= args.src.peek_u32be() >> n_bits
|
||||
args.src.skip_u32_fast!(actual: (31 - n_bits) >> 3, worst_case: 4)
|
||||
n_bits |= 24
|
||||
|
||||
table_entry = this.huffman_tables[which][bits >> 24]
|
||||
bits ~mod<<= table_entry >> 12
|
||||
n_bits -= (table_entry >> 12) as base.u32
|
||||
child = table_entry & 0x3FF
|
||||
while child < 257 {
|
||||
child = this.huffman_trees[which][child][bits >> 31]
|
||||
bits ~mod<<= 1
|
||||
if n_bits <= 0 {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
n_bits -= 1
|
||||
} endwhile
|
||||
|
||||
if child < 0x300 { // mNN symbol.
|
||||
// Move to front.
|
||||
child_ff = (child & 0xFF) as base.u32
|
||||
output = this.mtft[child_ff] as base.u32
|
||||
this.mtft[1 .. 1 + child_ff].copy_from_slice!(
|
||||
s: this.mtft[.. child_ff])
|
||||
this.mtft[0] = output as base.u8
|
||||
|
||||
this.letter_counts[output] ~mod+= 1
|
||||
this.bwt[block_size] = output
|
||||
if block_size >= this.max_incl_block_size {
|
||||
return "#bad block length"
|
||||
}
|
||||
assert block_size < 900000 via "a < b: a < c; c <= b"(c: this.max_incl_block_size)
|
||||
block_size += 1
|
||||
run_shift = 0
|
||||
continue.outer
|
||||
} else if child == 0x300 { // EOB symbol.
|
||||
this.decode_huffman_finished = true
|
||||
break.outer
|
||||
}
|
||||
|
||||
// RUNA or RUNB symbol.
|
||||
if run_shift >= 23 {
|
||||
return "#bad block length"
|
||||
}
|
||||
run = ((child as base.u32) & 3) << run_shift
|
||||
run_shift += 1
|
||||
i = block_size
|
||||
j = run + block_size
|
||||
if j > this.max_incl_block_size {
|
||||
return "#bad block length"
|
||||
}
|
||||
assert j <= 900000 via "a <= b: a <= c; c <= b"(c: this.max_incl_block_size)
|
||||
block_size = j
|
||||
|
||||
mtft0 = this.mtft[0] as base.u32
|
||||
this.letter_counts[mtft0] ~mod+= run
|
||||
while i < j,
|
||||
pre j <= 900000,
|
||||
{
|
||||
assert i < 900000 via "a < b: a < c; c <= b"(c: j)
|
||||
this.bwt[i] = mtft0
|
||||
i += 1
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
|
||||
this.bits = bits
|
||||
this.n_bits = n_bits
|
||||
this.block_size = block_size
|
||||
this.decode_huffman_which = which
|
||||
this.decode_huffman_ticks = ticks
|
||||
this.decode_huffman_section = section
|
||||
this.decode_huffman_run_shift = run_shift
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pri func decoder.decode_huffman_slow?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var node_index : base.u32[..= 256]
|
||||
|
||||
var child : base.u16
|
||||
var child_ff : base.u32[..= 255]
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
var output : base.u32[..= 255]
|
||||
var run : base.u32[..= 12_582912] // 12_582912 = (3 << 22)
|
||||
var mtft0 : base.u32[..= 255]
|
||||
|
||||
// Apply the Huffman trees.
|
||||
while.outer not coroutine_resumed {
|
||||
if this.decode_huffman_ticks > 0 {
|
||||
this.decode_huffman_ticks -= 1
|
||||
} else {
|
||||
this.decode_huffman_ticks = 49
|
||||
this.decode_huffman_section ~mod+= 1
|
||||
if this.decode_huffman_section >= this.num_sections {
|
||||
return "#bad number of sections"
|
||||
}
|
||||
this.decode_huffman_which = CLAMP_TO_5[this.huffman_selectors[this.decode_huffman_section & 32767] & 7]
|
||||
}
|
||||
|
||||
node_index = 0
|
||||
while true {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
child = this.huffman_trees[this.decode_huffman_which][node_index][this.bits >> 31]
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if child < 257 { // Branch node.
|
||||
node_index = child as base.u32
|
||||
continue
|
||||
|
||||
} else if child < 0x300 { // mNN symbol.
|
||||
// Move to front.
|
||||
child_ff = (child & 0xFF) as base.u32
|
||||
output = this.mtft[child_ff] as base.u32
|
||||
this.mtft[1 .. 1 + child_ff].copy_from_slice!(
|
||||
s: this.mtft[.. child_ff])
|
||||
this.mtft[0] = output as base.u8
|
||||
|
||||
this.letter_counts[output] ~mod+= 1
|
||||
this.bwt[this.block_size] = output
|
||||
if this.block_size >= this.max_incl_block_size {
|
||||
return "#bad block length"
|
||||
}
|
||||
assert this.block_size < 900000 via "a < b: a < c; c <= b"(c: this.max_incl_block_size)
|
||||
this.block_size += 1
|
||||
this.decode_huffman_run_shift = 0
|
||||
break
|
||||
|
||||
} else if child == 0x300 { // EOB symbol.
|
||||
this.decode_huffman_finished = true
|
||||
break.outer
|
||||
}
|
||||
|
||||
// RUNA or RUNB symbol.
|
||||
if this.decode_huffman_run_shift >= 23 {
|
||||
return "#bad block length"
|
||||
}
|
||||
run = ((child as base.u32) & 3) << this.decode_huffman_run_shift
|
||||
this.decode_huffman_run_shift += 1
|
||||
i = this.block_size
|
||||
j = run + this.block_size
|
||||
if j > this.max_incl_block_size {
|
||||
return "#bad block length"
|
||||
}
|
||||
assert j <= 900000 via "a <= b: a <= c; c <= b"(c: this.max_incl_block_size)
|
||||
this.block_size = j
|
||||
|
||||
mtft0 = this.mtft[0] as base.u32
|
||||
this.letter_counts[mtft0] ~mod+= run
|
||||
while i < j,
|
||||
pre j <= 900000,
|
||||
{
|
||||
assert i < 900000 via "a < b: a < c; c <= b"(c: j)
|
||||
this.bwt[i] = mtft0
|
||||
i += 1
|
||||
} endwhile
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
}
|
||||
@@ -226,8 +226,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
c_major = 0
|
||||
c_minor = 0
|
||||
continue.outer
|
||||
}
|
||||
return "#internal error: inconsistent I/O"
|
||||
|
||||
@@ -143,8 +143,9 @@ The final line says that the CRC-32 checksum of "Hi\n" is `0xD522_3C9A`. This
|
||||
can be verified by running the `/usr/bin/crc32` program:
|
||||
|
||||
```
|
||||
$ echo Hi | xxd /dev/stdin
|
||||
00000000: 4869 0a Hi.
|
||||
$ echo Hi | hd /dev/stdin
|
||||
00000000 48 69 0a |Hi.|
|
||||
00000003
|
||||
$ echo Hi | crc32 /dev/stdin
|
||||
d5223c9a
|
||||
```
|
||||
|
||||
@@ -23,21 +23,23 @@ other formats are TODO.
|
||||
|
||||
For example, look at `test/data/romeo.txt*`. First, the uncompressed text:
|
||||
|
||||
$ xxd test/data/romeo.txt
|
||||
00000000: 526f 6d65 6f20 616e 6420 4a75 6c69 6574 Romeo and Juliet
|
||||
00000010: 0a45 7863 6572 7074 2066 726f 6d20 4163 .Excerpt from Ac
|
||||
$ hd test/data/romeo.txt
|
||||
00000000 52 6f 6d 65 6f 20 61 6e 64 20 4a 75 6c 69 65 74 |Romeo and Juliet|
|
||||
00000010 0a 45 78 63 65 72 70 74 20 66 72 6f 6d 20 41 63 |.Excerpt from Ac|
|
||||
etc
|
||||
00000390: 740a 536f 2073 7475 6d62 6c65 7374 206f t.So stumblest o
|
||||
000003a0: 6e20 6d79 2063 6f75 6e73 656c 3f0a n my counsel?.
|
||||
00000390 74 0a 53 6f 20 73 74 75 6d 62 6c 65 73 74 20 6f |t.So stumblest o|
|
||||
000003a0 6e 20 6d 79 20 63 6f 75 6e 73 65 6c 3f 0a |n my counsel?.|
|
||||
000003ae
|
||||
|
||||
The raw deflate encoding:
|
||||
|
||||
$ xxd test/data/romeo.txt.deflate
|
||||
00000000: 4d53 c16e db30 0cbd f32b d853 2e46 0e3d MS.n.0...+.S.F.=
|
||||
00000010: 2e87 20ed 0234 c5ba 0049 861e 861d 149b .. ..4...I......
|
||||
$ hd test/data/romeo.txt.deflate
|
||||
00000000 4d 53 c1 6e db 30 0c bd f3 2b d8 53 2e 46 0e 3d |MS.n.0...+.S.F.=|
|
||||
00000010 2e 87 20 ed 02 34 c5 ba 00 49 86 1e 86 1d 14 9b |.. ..4...I......|
|
||||
etc
|
||||
00000200: 7d13 8ffd b9a3 24bb 68f4 eb30 7a59 610d }.....$.h..0zYa.
|
||||
00000210: 7f01 ..
|
||||
00000200 7d 13 8f fd b9 a3 24 bb 68 f4 eb 30 7a 59 61 0d |}.....$.h..0zYa.|
|
||||
00000210 7f 01 |..|
|
||||
00000212
|
||||
|
||||
The gzip format wraps a variable length header (in this case, 20 bytes) and 8
|
||||
byte footer around the raw deflate data. The header contains the NUL-terminated
|
||||
@@ -45,23 +47,25 @@ C string name of the original, uncompressed file, "romeo.txt", amongst other
|
||||
data. The footer contains a 4 byte CRC32 checksum and a 4 byte length of the
|
||||
uncompressed file (0x3ae = 942 bytes).
|
||||
|
||||
$ xxd test/data/romeo.txt.gz
|
||||
00000000: 1f8b 0808 26d8 5d59 0003 726f 6d65 6f2e ....&.]Y..romeo.
|
||||
00000010: 7478 7400 4d53 c16e db30 0cbd f32b d853 txt.MS.n.0...+.S
|
||||
$ hd test/data/romeo.txt.gz
|
||||
00000000 1f 8b 08 08 26 d8 5d 59 00 03 72 6f 6d 65 6f 2e |....&.]Y..romeo.|
|
||||
00000010 74 78 74 00 4d 53 c1 6e db 30 0c bd f3 2b d8 53 |txt.MS.n.0...+.S|
|
||||
etc
|
||||
00000210: de5d 2c67 7d13 8ffd b9a3 24bb 68f4 eb30 .],g}.....$.h..0
|
||||
00000220: 7a59 610d 7f01 ef07 e5ab ae03 0000 zYa...........
|
||||
00000210 de 5d 2c 67 7d 13 8f fd b9 a3 24 bb 68 f4 eb 30 |.],g}.....$.h..0|
|
||||
00000220 7a 59 61 0d 7f 01 ef 07 e5 ab ae 03 00 00 |zYa...........|
|
||||
0000022e
|
||||
|
||||
The zlib format wraps a 2 byte header and 4 byte footer around the raw deflate
|
||||
data. The footer contains a 4 byte Adler32 checksum. TODO: move this to
|
||||
std/zlib/README.md.
|
||||
|
||||
$ xxd test/data/romeo.txt.zlib
|
||||
00000000: 789c 4d53 c16e db30 0cbd f32b d853 2e46 x.MS.n.0...+.S.F
|
||||
00000010: 0e3d 2e87 20ed 0234 c5ba 0049 861e 861d .=.. ..4...I....
|
||||
$ hd test/data/romeo.txt.zlib
|
||||
00000000 78 9c 4d 53 c1 6e db 30 0c bd f3 2b d8 53 2e 46 |x.MS.n.0...+.S.F|
|
||||
00000010 0e 3d 2e 87 20 ed 02 34 c5 ba 00 49 86 1e 86 1d |.=.. ..4...I....|
|
||||
etc
|
||||
00000200: 2c67 7d13 8ffd b9a3 24bb 68f4 eb30 7a59 ,g}.....$.h..0zY
|
||||
00000210: 610d 7f01 57bb 3ede a...W.>.
|
||||
00000200 2c 67 7d 13 8f fd b9 a3 24 bb 68 f4 eb 30 7a 59 |,g}.....$.h..0zY|
|
||||
00000210 61 0d 7f 01 57 bb 3e de |a...W.>.|
|
||||
00000218
|
||||
|
||||
|
||||
# Wire Format Worked Example
|
||||
|
||||
@@ -16,53 +16,15 @@ pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32,
|
||||
height : base.u32,
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x01: metadata reported; image config decode is in progress.
|
||||
// - 0x02: metadata finished; image config decode is in progress.
|
||||
// - 0x03: image config decoded, including the first frame's bounds, but
|
||||
// not the first frame's pixels.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0x05: frame decoded.
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
//
|
||||
// GIF is unusual (distinguishing state 0x03 / state 0x05) in that the
|
||||
// first frame's bounds can affect the overall image bounds (as per
|
||||
// A GIF's first frame's bounds affects the overall image bounds (per
|
||||
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt).
|
||||
// Decoding the first frame's bounds is part of DIC even though,
|
||||
// conceptually, it should be part of the first DFC.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x00 -> 0x03: via DIC (metadata not reported)
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0x05: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x01 -> 0x02: via TMM
|
||||
//
|
||||
// - 0x02 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x02 -> 0x03: via DIC (metadata not reported)
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0x05: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0x04: via DFC with implicit DF
|
||||
// - 0x04 -> 0x05: via DF
|
||||
//
|
||||
// - 0x05 -> 0x04: via DFC
|
||||
// - 0x05 -> 0x05: via DF with implicit DFC
|
||||
//
|
||||
// - ???? -> 0x05: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame, implicit means skip_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// - TMM is tell_me_more
|
||||
// Decoding the first frame's bounds is part of decode_image_config even
|
||||
// though it's conceptually part of the first decode_frame_config.
|
||||
call_sequence : base.u8,
|
||||
|
||||
ignore_metadata : base.bool,
|
||||
report_metadata_iccp : base.bool,
|
||||
report_metadata_xmp : base.bool,
|
||||
metadata_fourcc : base.u32,
|
||||
@@ -71,9 +33,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
quirks : array[QUIRKS_COUNT] base.bool,
|
||||
|
||||
delayed_num_decoded_frames : base.bool,
|
||||
end_of_data : base.bool,
|
||||
restarted : base.bool,
|
||||
previous_lzw_decode_ended_abruptly : base.bool,
|
||||
seen_header : base.bool,
|
||||
|
||||
has_global_palette : base.bool,
|
||||
|
||||
@@ -128,7 +89,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
if (this.call_sequence == 0) and (args.quirk >= QUIRKS_BASE) {
|
||||
if (this.call_sequence == 0x00) and (args.quirk >= QUIRKS_BASE) {
|
||||
args.quirk -= QUIRKS_BASE
|
||||
if args.quirk < QUIRKS_COUNT {
|
||||
this.quirks[args.quirk] = args.enabled
|
||||
@@ -139,17 +100,16 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var ffio : base.bool
|
||||
|
||||
if this.call_sequence == 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
} else if not this.seen_header {
|
||||
this.decode_header?(src: args.src)
|
||||
this.decode_lsd?(src: args.src)
|
||||
} else if this.call_sequence <> 2 {
|
||||
return base."#bad call sequence"
|
||||
this.seen_header = true
|
||||
}
|
||||
|
||||
this.decode_up_to_id_part1?(src: args.src)
|
||||
|
||||
// TODO: if this.end_of_data, return an error and/or set dst to zero?
|
||||
|
||||
ffio = not this.gc_has_transparent_index
|
||||
if not this.quirks[QUIRK_HONOR_BACKGROUND_COLOR - QUIRKS_BASE] {
|
||||
ffio = ffio and
|
||||
@@ -176,7 +136,9 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
first_frame_is_opaque: ffio)
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
if this.call_sequence == 0x00 {
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
@@ -190,7 +152,7 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
var chunk_length : base.u64
|
||||
|
||||
if this.call_sequence <> 1 {
|
||||
if (this.call_sequence & 0x10) == 0 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if this.metadata_fourcc == 0 {
|
||||
@@ -267,7 +229,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
y: this.metadata_io_position,
|
||||
z: this.metadata_io_position)
|
||||
}
|
||||
this.call_sequence = 2
|
||||
this.call_sequence &= 0xEF
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_io_position = 0
|
||||
return ok
|
||||
@@ -319,16 +281,17 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
} else if args.io_position == 0 {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.delayed_num_decoded_frames = false
|
||||
this.end_of_data = false
|
||||
this.restarted = true
|
||||
this.frame_config_io_position = args.io_position
|
||||
this.num_decoded_frame_configs_value = args.index
|
||||
this.num_decoded_frames_value = args.index
|
||||
this.reset_gc!()
|
||||
this.call_sequence = 0x28
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -336,25 +299,32 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
var background_color : base.u32
|
||||
var flags : base.u8
|
||||
|
||||
this.ignore_metadata = true
|
||||
|
||||
this.dirty_max_excl_y = 0
|
||||
|
||||
if not this.end_of_data {
|
||||
if this.call_sequence == 0 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence <> 3 {
|
||||
if this.call_sequence == 4 {
|
||||
this.skip_frame?(src: args.src)
|
||||
}
|
||||
this.decode_up_to_id_part1?(src: args.src)
|
||||
if (this.call_sequence & 0x10) <> 0 {
|
||||
return base."#bad call sequence"
|
||||
} else if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.skip_frame?(src: args.src)
|
||||
if this.call_sequence >= 0x60 {
|
||||
return base."@end of data"
|
||||
}
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
// This is a new "if", not an "else", because the calls above can modify
|
||||
// this.end_of_data.
|
||||
if this.end_of_data {
|
||||
return base."@end of data"
|
||||
if (this.num_decoded_frame_configs_value > 0) or (this.call_sequence == 0x28) {
|
||||
this.decode_up_to_id_part1?(src: args.src)
|
||||
if this.call_sequence >= 0x60 {
|
||||
return base."@end of data"
|
||||
}
|
||||
}
|
||||
|
||||
background_color = this.black_color_u32_argb_premul
|
||||
@@ -396,7 +366,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
}
|
||||
|
||||
this.num_decoded_frame_configs_value ~sat+= 1
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
@@ -424,13 +394,17 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
}
|
||||
this.reset_gc!()
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
// TODO: honor args.opts.
|
||||
pub func decoder.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) {
|
||||
this.ignore_metadata = true
|
||||
if this.call_sequence <> 4 {
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
if this.quirks[QUIRK_REJECT_EMPTY_FRAME - QUIRKS_BASE] and
|
||||
((this.frame_rect_x0 == this.frame_rect_x1) or (this.frame_rect_y0 == this.frame_rect_y1)) {
|
||||
@@ -441,10 +415,10 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
this.reset_gc!()
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.reset_gc!() {
|
||||
this.call_sequence = 5
|
||||
// The Image Descriptor is mandatory, but the Graphic Control extension is
|
||||
// optional. Reset the GC related fields for the next decode_frame call.
|
||||
this.gc_has_transparent_index = false
|
||||
@@ -456,14 +430,8 @@ pri func decoder.reset_gc!() {
|
||||
pri func decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
||||
var block_type : base.u8
|
||||
|
||||
if not this.restarted {
|
||||
if this.call_sequence <> 2 {
|
||||
this.frame_config_io_position = args.src.position()
|
||||
}
|
||||
} else if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
} else {
|
||||
this.restarted = false
|
||||
if (this.frame_config_io_position == 0) or (this.num_decoded_frame_configs_value > 0) {
|
||||
this.frame_config_io_position = args.src.position()
|
||||
}
|
||||
|
||||
while true {
|
||||
@@ -494,7 +462,7 @@ pri func decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
||||
this.delayed_num_decoded_frames = false
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
}
|
||||
this.end_of_data = true
|
||||
this.call_sequence = 0x60
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
@@ -692,19 +660,19 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
this.num_animation_loops_value += 1
|
||||
}
|
||||
|
||||
} else if this.ignore_metadata {
|
||||
} else if this.call_sequence >= 0x20 {
|
||||
// No-op.
|
||||
|
||||
} else if is_iccp and this.report_metadata_iccp {
|
||||
this.metadata_fourcc = 'ICCP'be
|
||||
this.metadata_io_position = args.src.position()
|
||||
this.call_sequence = 1
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
|
||||
} else if is_xmp and this.report_metadata_xmp {
|
||||
this.metadata_fourcc = 'XMP 'be
|
||||
this.metadata_io_position = args.src.position()
|
||||
this.call_sequence = 1
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
@@ -759,7 +727,7 @@ pri func decoder.decode_gc?(src: base.io_reader) {
|
||||
//
|
||||
// See the spec section 20 "Image Descriptor" on page 11.
|
||||
//
|
||||
// The code is split into three parts (part0, part 1 and part12 because
|
||||
// The code is split into three parts (part0, part 1 and part2 because
|
||||
// determining the overall image's width and height also requires decoding the
|
||||
// first frame's bounds (part0), but doesn't require decoding the first frame's
|
||||
// pixels (the other two parts). Decoding the actual pixels is split into two
|
||||
@@ -782,7 +750,7 @@ pri func decoder.decode_id_part0?(src: base.io_reader) {
|
||||
// and the bottom right extent of the first frame. See
|
||||
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for
|
||||
// more discussion.
|
||||
if (this.call_sequence == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) {
|
||||
if (this.num_decoded_frame_configs_value == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) {
|
||||
this.width = this.width.max(a: this.frame_rect_x1)
|
||||
this.height = this.height.max(a: this.frame_rect_y1)
|
||||
}
|
||||
|
||||
@@ -167,7 +167,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
whitespace_length = 0
|
||||
continue.outer
|
||||
}
|
||||
|
||||
@@ -255,7 +254,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
@@ -344,8 +342,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
c = (args.src.peek_u16le() >> 8) as base.u8
|
||||
@@ -379,8 +375,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
@@ -441,9 +435,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
uni4_value = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
uni4_string = args.src.peek_u64le_at(offset: 4) >> 16
|
||||
@@ -515,8 +506,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
uni8_string = args.src.peek_u64le_at(offset: 2)
|
||||
@@ -583,8 +572,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
@@ -647,8 +634,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad UTF-8"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
multi_byte_utf8 = args.src.peek_u16le_as_u32()
|
||||
@@ -702,8 +687,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad UTF-8"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
multi_byte_utf8 = args.src.peek_u24le_as_u32()
|
||||
@@ -762,8 +745,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
return "#bad UTF-8"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
multi_byte_utf8 = args.src.peek_u32le()
|
||||
@@ -1460,100 +1441,72 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
length = 2
|
||||
|
||||
while.comment_block true {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
|
||||
while true,
|
||||
pre args.dst.length() > 0,
|
||||
{
|
||||
if args.src.length() <= 1 {
|
||||
if length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_BLOCK,
|
||||
continued: 1,
|
||||
length: length)
|
||||
}
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
|
||||
c2 = args.src.peek_u16le()
|
||||
if c2 == '*/'le {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_BLOCK,
|
||||
continued: 0,
|
||||
length: length + 2)
|
||||
this.comment_type = 1
|
||||
return ok
|
||||
}
|
||||
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if length >= 0xFFFD {
|
||||
while.comment_block true,
|
||||
pre args.dst.length() > 0,
|
||||
{
|
||||
if args.src.length() <= 1 {
|
||||
if length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_BLOCK,
|
||||
continued: 1,
|
||||
length: length + 1)
|
||||
length = 0
|
||||
continue.comment_block
|
||||
length: length)
|
||||
}
|
||||
length += 1
|
||||
} endwhile
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
while args.dst.length() <= 0,
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
|
||||
c2 = args.src.peek_u16le()
|
||||
if c2 == '*/'le {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_BLOCK,
|
||||
continued: 0,
|
||||
length: length + 2)
|
||||
this.comment_type = 1
|
||||
return ok
|
||||
}
|
||||
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if length >= 0xFFFD {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_BLOCK,
|
||||
continued: 1,
|
||||
length: length + 1)
|
||||
while args.dst.length() <= 0,
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
length += 1
|
||||
} endwhile.comment_block
|
||||
|
||||
} else if (c2 == '//'le) and this.quirks[QUIRK_ALLOW_COMMENT_LINE - QUIRKS_BASE] {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
length = 2
|
||||
|
||||
while.comment_line true {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
|
||||
while true,
|
||||
pre args.dst.length() > 0,
|
||||
{
|
||||
if args.src.length() <= 0 {
|
||||
if args.src.is_closed() {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_LINE,
|
||||
continued: 0,
|
||||
length: length)
|
||||
this.comment_type = 2
|
||||
return ok
|
||||
} else if length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_LINE,
|
||||
continued: 1,
|
||||
length: length)
|
||||
}
|
||||
yield? base."$short read"
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if c == '\n' {
|
||||
while.comment_line true,
|
||||
pre args.dst.length() > 0,
|
||||
{
|
||||
if args.src.length() <= 0 {
|
||||
if args.src.is_closed() {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
@@ -1562,21 +1515,53 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
length: length)
|
||||
this.comment_type = 2
|
||||
return ok
|
||||
}
|
||||
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if length >= 0xFFFD {
|
||||
} else if length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_LINE,
|
||||
continued: 1,
|
||||
length: length + 1)
|
||||
length = 0
|
||||
continue.comment_line
|
||||
length: length)
|
||||
}
|
||||
length += 1
|
||||
} endwhile
|
||||
yield? base."$short read"
|
||||
while args.dst.length() <= 0,
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if c == '\n' {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_LINE,
|
||||
continued: 0,
|
||||
length: length)
|
||||
this.comment_type = 2
|
||||
return ok
|
||||
}
|
||||
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if length >= 0xFFFD {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_LINE,
|
||||
continued: 1,
|
||||
length: length + 1)
|
||||
while args.dst.length() <= 0,
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
length += 1
|
||||
} endwhile.comment_line
|
||||
}
|
||||
}
|
||||
@@ -1705,10 +1690,10 @@ pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
while.outer true {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
whitespace_length = 0
|
||||
continue.outer
|
||||
}
|
||||
|
||||
whitespace_length = 0
|
||||
while.inner true,
|
||||
pre args.dst.length() > 0,
|
||||
{
|
||||
@@ -1716,13 +1701,11 @@ pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
if whitespace_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0, value_minor: 0, continued: 0, length: whitespace_length)
|
||||
whitespace_length = 0
|
||||
}
|
||||
if args.src.is_closed() {
|
||||
break.outer
|
||||
}
|
||||
yield? base."$short read"
|
||||
whitespace_length = 0
|
||||
continue.outer
|
||||
}
|
||||
|
||||
@@ -1731,14 +1714,11 @@ pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
if whitespace_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0, value_minor: 0, continued: 0, length: whitespace_length)
|
||||
whitespace_length = 0
|
||||
}
|
||||
if this.trailer_stop > 0 {
|
||||
return "#bad input"
|
||||
}
|
||||
this.decode_comment?(dst: args.dst, src: args.src)
|
||||
c = 0
|
||||
whitespace_length = 0
|
||||
if this.comment_type > 0 {
|
||||
continue.outer
|
||||
}
|
||||
@@ -1749,7 +1729,6 @@ pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
if (whitespace_length >= 0xFFFE) or (c == this.trailer_stop) {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0, value_minor: 0, continued: 0, length: whitespace_length + 1)
|
||||
whitespace_length = 0
|
||||
if c == this.trailer_stop {
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -24,31 +24,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0x7FFF_FFFF],
|
||||
height : base.u32[..= 0x7FFF_FFFF],
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x03: image config decoded.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0xFF: end-of-data, usually after (the non-animated) frame decoded.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x03: via DIC
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0xFF: via DFC
|
||||
// - 0x04 -> 0xFF: via DF
|
||||
//
|
||||
// - ???? -> 0x03: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
dst_x : base.u32,
|
||||
@@ -64,7 +41,7 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var a : base.u32
|
||||
|
||||
if this.call_sequence <> 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
@@ -108,18 +85,20 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
first_frame_is_opaque: false)
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 3 {
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if 16 <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 4 {
|
||||
this.call_sequence = 0xFF
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
@@ -140,16 +119,16 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
background_color: 0x0000_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pub func decoder.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) {
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence < 4 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 4 {
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
@@ -177,7 +156,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||
@@ -246,27 +225,27 @@ pub func decoder.num_animation_loops() base.u32 {
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 3 {
|
||||
if this.call_sequence > 0x20 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 4 {
|
||||
if this.call_sequence > 0x40 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if (args.index <> 0) or (args.io_position <> 16) {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x28
|
||||
return ok
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ pub status "#bad filter"
|
||||
pub status "#bad header"
|
||||
pub status "#bad text chunk (not Latin-1)"
|
||||
pub status "#missing palette"
|
||||
pub status "#unsupported CgBI extension"
|
||||
pub status "#unsupported PNG compression method"
|
||||
pub status "#unsupported PNG file"
|
||||
|
||||
@@ -28,7 +29,7 @@ pri status "#internal error: inconsistent frame bounds"
|
||||
pri status "#internal error: inconsistent workbuf length"
|
||||
pri status "#internal error: zlib decoder did not exhaust its input"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x0007_FFFF_F100_0007
|
||||
|
||||
// DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL is the minimum length of the src
|
||||
// wuffs_base__io_buffer passed to the decoder.
|
||||
|
||||
@@ -17,61 +17,24 @@ use "std/zlib"
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
// The 0x00FF_FFFF limit is arbitrary (the PNG spec says 0x7FFF_FFFF) but
|
||||
// it means that (width * height * bytes_per_pixel) doesn't overflow.
|
||||
// it means that (width * height * bytes_per_pixel) doesn't overflow a u64.
|
||||
width : base.u32[..= 0x00FF_FFFF],
|
||||
height : base.u32[..= 0x00FF_FFFF],
|
||||
|
||||
// pass_bytes_per_row doesn't include the 1 byte for the per-row filter.
|
||||
pass_bytes_per_row : base.u64[..= 0x07FF_FFF8],
|
||||
|
||||
workbuf_wi : base.u64,
|
||||
workbuf_hist_pos_base : base.u64,
|
||||
workbuf_wi : base.u64,
|
||||
workbuf_hist_pos_base : base.u64,
|
||||
|
||||
// The inclusive upper bound, DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE, is
|
||||
// derived from the width and height upper bounds at up to 8 bytes per
|
||||
// pixel. It equals (((8 * M) + 1) * M), where M is 0x00FF_FFFF.
|
||||
overall_workbuf_length : base.u64[..= 0x0007_FFFF_F100_0007],
|
||||
pass_workbuf_length : base.u64[..= 0x0007_FFFF_F100_0007],
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x01: metadata reported; image config decode is in progress.
|
||||
// - 0x02: metadata finished; image config decode is in progress.
|
||||
// - 0x03: image config decoded.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0x05: frame decoded.
|
||||
// - 0xFF: end-of-data, after the final frame decoded.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x00 -> 0x03: via DIC (metadata not reported)
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0x05: via DF with implicit DIC and DFC
|
||||
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x01 -> 0x02: via TMM
|
||||
//
|
||||
// - 0x02 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x02 -> 0x03: via DIC (metadata not reported)
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0x05: via DF with implicit DFC
|
||||
// - 0x03 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0x04: via DFC with implicit DF
|
||||
// - 0x04 -> 0x05: via DF
|
||||
// - 0x04 -> 0xFF: via DFC with implicit DF
|
||||
// - 0x04 -> 0xFF: via DF
|
||||
//
|
||||
// - 0x05 -> 0x04: via DFC
|
||||
// - 0x05 -> 0x05: via DF with implicit DFC
|
||||
// - 0x05 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - ???? -> 0x03: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame, implicit means skip_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// - TMM is tell_me_more
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
report_metadata_chrm : base.bool,
|
||||
@@ -95,6 +58,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
seen_gama : base.bool,
|
||||
seen_iccp : base.bool,
|
||||
seen_idat : base.bool,
|
||||
seen_ihdr : base.bool,
|
||||
seen_plte : base.bool,
|
||||
seen_srgb : base.bool,
|
||||
seen_trns : base.bool,
|
||||
@@ -205,20 +169,21 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
var checksum_want : base.u32
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence == 2 {
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 1
|
||||
return base."@metadata reported"
|
||||
}
|
||||
} else if this.call_sequence <> 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
} else {
|
||||
} else if not this.seen_ihdr {
|
||||
magic = args.src.read_u64le?()
|
||||
if magic <> '\x89PNG\x0D\x0A\x1A\x0A'le {
|
||||
return "#bad header"
|
||||
}
|
||||
magic = args.src.read_u64le?()
|
||||
if magic <> '\x00\x00\x00\x0DIHDR'le {
|
||||
if magic == '\x00\x00\x00\x04CgBI'le {
|
||||
// TODO: add support for Apple's unofficial CgBI extension to
|
||||
// PNG, once there exists good documentation for it. See
|
||||
// https://github.com/w3c/PNG-spec/issues/45
|
||||
return "#unsupported CgBI extension"
|
||||
}
|
||||
return "#bad header"
|
||||
}
|
||||
this.chunk_type_array[0] = 'I'
|
||||
@@ -245,6 +210,10 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
if (not this.ignore_checksum) and (checksum_have <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
this.seen_ihdr = true
|
||||
} else if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
// Read up until an IDAT or fdAT chunk.
|
||||
@@ -295,7 +264,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
|
||||
while true {
|
||||
mark = args.src.mark()
|
||||
status =? this.decode_other_chunk?(src: args.src)
|
||||
status =? this.decode_other_chunk?(src: args.src, framy: false)
|
||||
if (not this.ignore_checksum) and ((this.chunk_type & ANCILLARY_BIT) == 0) {
|
||||
checksum_have = this.crc32.update_u32!(x: args.src.since(mark: mark))
|
||||
}
|
||||
@@ -308,7 +277,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
// If we have metadata, delay reading (skipping) the ancillary chunk's
|
||||
// CRC-32 checksum until the end of tell_me_more.
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 1
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
@@ -349,7 +318,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
this.first_overwrite_instead_of_blend = false
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.decode_ihdr?(src: base.io_reader) {
|
||||
@@ -541,8 +510,11 @@ pri func decoder.choose_filter_implementations!() {
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
if this.chunk_type == 'PLTE'le {
|
||||
// framy is:
|
||||
// - false when coming from decode_image_config.
|
||||
// - true when coming from decode_frame_config.
|
||||
pri func decoder.decode_other_chunk?(src: base.io_reader, framy: base.bool) {
|
||||
if (this.chunk_type == 'PLTE'le) and (not args.framy) {
|
||||
if this.seen_plte {
|
||||
return "#bad chunk"
|
||||
} else if this.color_type == 3 {
|
||||
@@ -561,24 +533,9 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
if this.chunk_type <> 'IDAT'le {
|
||||
return "#bad chunk"
|
||||
}
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'acTL'le {
|
||||
if this.seen_actl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_actl?(src: args.src)
|
||||
this.seen_actl = true
|
||||
|
||||
} else if this.chunk_type == 'cHRM'le {
|
||||
if this.report_metadata_chrm {
|
||||
if this.seen_chrm {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_chrm?(src: args.src)
|
||||
this.seen_chrm = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'eXIf'le {
|
||||
if this.chunk_type == 'eXIf'le {
|
||||
if this.report_metadata_exif {
|
||||
if this.seen_exif {
|
||||
return "#bad chunk"
|
||||
@@ -587,48 +544,6 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
this.seen_exif = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'fcTL'le {
|
||||
if this.seen_fctl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_fctl?(src: args.src)
|
||||
this.seen_fctl = true
|
||||
|
||||
} else if this.chunk_type == 'gAMA'le {
|
||||
if this.report_metadata_gama {
|
||||
if this.seen_gama {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_gama?(src: args.src)
|
||||
this.seen_gama = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'iCCP'le {
|
||||
if this.report_metadata_iccp {
|
||||
if this.seen_iccp {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_iccp?(src: args.src)
|
||||
this.seen_iccp = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'sRGB'le {
|
||||
if this.report_metadata_srgb {
|
||||
if this.seen_srgb {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_srgb?(src: args.src)
|
||||
this.seen_srgb = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'tRNS'le {
|
||||
if this.seen_trns or (this.color_type > 3) or
|
||||
((this.color_type == 3) and (not this.seen_plte)) {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_trns?(src: args.src)
|
||||
this.seen_trns = true
|
||||
|
||||
} else if (this.chunk_type == 'iTXt'le) or
|
||||
(this.chunk_type == 'tEXt'le) or
|
||||
(this.chunk_type == 'zTXt'le) {
|
||||
@@ -639,6 +554,66 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
}
|
||||
|
||||
} else if not args.framy {
|
||||
if this.chunk_type == 'acTL'le {
|
||||
if this.seen_actl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_actl?(src: args.src)
|
||||
this.seen_actl = true
|
||||
|
||||
} else if this.chunk_type == 'cHRM'le {
|
||||
if this.report_metadata_chrm {
|
||||
if this.seen_chrm {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_chrm?(src: args.src)
|
||||
this.seen_chrm = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'fcTL'le {
|
||||
if this.seen_fctl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_fctl?(src: args.src)
|
||||
this.seen_fctl = true
|
||||
|
||||
} else if this.chunk_type == 'gAMA'le {
|
||||
if this.report_metadata_gama {
|
||||
if this.seen_gama {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_gama?(src: args.src)
|
||||
this.seen_gama = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'iCCP'le {
|
||||
if this.report_metadata_iccp {
|
||||
if this.seen_iccp {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_iccp?(src: args.src)
|
||||
this.seen_iccp = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'sRGB'le {
|
||||
if this.report_metadata_srgb {
|
||||
if this.seen_srgb {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_srgb?(src: args.src)
|
||||
this.seen_srgb = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'tRNS'le {
|
||||
if this.seen_trns or (this.color_type > 3) or
|
||||
((this.color_type == 3) and (not this.seen_plte)) {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_trns?(src: args.src)
|
||||
this.seen_trns = true
|
||||
}
|
||||
}
|
||||
|
||||
if this.metadata_fourcc == 0 {
|
||||
@@ -959,19 +934,27 @@ pri func decoder.decode_trns?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence == 0xFF {
|
||||
return base."@end of data"
|
||||
} else if this.call_sequence < 3 {
|
||||
var checksum_have : base.u32
|
||||
|
||||
if (this.call_sequence & 0x10) <> 0 {
|
||||
return base."#bad call sequence"
|
||||
} else if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 3 {
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 4 {
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.skip_frame?(src: args.src)
|
||||
if this.call_sequence == 0xFF {
|
||||
return base."@end of data"
|
||||
}
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 0x30
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
if this.num_decoded_frame_configs_value == 0 {
|
||||
@@ -985,11 +968,21 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
this.frame_overwrite_instead_of_blend = this.first_overwrite_instead_of_blend
|
||||
|
||||
} else {
|
||||
// Decode the next fcTL chunk.
|
||||
// Decode the next IEND or fcTL chunk.
|
||||
while true {
|
||||
this.chunk_length = args.src.read_u32be?()
|
||||
this.chunk_type = args.src.read_u32le?()
|
||||
if this.chunk_type == 'fdAT'le {
|
||||
if this.chunk_type == 'IEND'le {
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
checksum_have = args.src.read_u32le?()
|
||||
if (not this.ignore_checksum) and (checksum_have <> 0x8260_42AE) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else if this.chunk_type == 'fdAT'le {
|
||||
return "#bad chunk"
|
||||
} else if this.chunk_type == 'fcTL'le {
|
||||
this.frame_config_io_position = args.src.position() ~mod- 8
|
||||
@@ -997,7 +990,13 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
args.src.skip?(n: 4) // Skip the checksum.
|
||||
break
|
||||
}
|
||||
args.src.skip?(n: (this.chunk_length as base.u64) + 4) // +4 for the checksum.
|
||||
|
||||
this.decode_other_chunk?(src: args.src, framy: true)
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 0x30
|
||||
return base."@metadata reported"
|
||||
}
|
||||
args.src.skip_u32?(n: 4) // Skip the checksum.
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
@@ -1018,7 +1017,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
}
|
||||
|
||||
this.num_decoded_frame_configs_value ~sat+= 1
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
@@ -1088,11 +1087,7 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
} endwhile
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
if this.num_decoded_frames_value < this.num_animation_frames_value {
|
||||
this.call_sequence = 5
|
||||
} else {
|
||||
this.call_sequence = 0xFF
|
||||
}
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.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) {
|
||||
@@ -1101,9 +1096,11 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
var pass_width : base.u32[..= 0x00FF_FFFF]
|
||||
var pass_height : base.u32[..= 0x00FF_FFFF]
|
||||
|
||||
if this.call_sequence == 0xFF {
|
||||
if (this.call_sequence & 0x10) <> 0 {
|
||||
return base."#bad call sequence"
|
||||
} else if this.call_sequence >= 0x60 {
|
||||
return base."@end of data"
|
||||
} else if this.call_sequence <> 4 {
|
||||
} else if this.call_sequence <> 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
}
|
||||
|
||||
@@ -1195,7 +1192,29 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
if (pass_width > 0) and (pass_height > 0) {
|
||||
this.pass_bytes_per_row = this.calculate_bytes_per_row(width: pass_width)
|
||||
this.pass_workbuf_length = (pass_height as base.u64) * (1 + this.pass_bytes_per_row)
|
||||
this.decode_pass?(src: args.src, workbuf: args.workbuf)
|
||||
while true {
|
||||
status =? this.decode_pass?(src: args.src, workbuf: args.workbuf)
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if status.is_error() or
|
||||
((status == base."$short read") and args.src.is_closed()) {
|
||||
// The input was truncated or invalid. Produce whatever
|
||||
// pixels we can and then, if truncated, generate "$short
|
||||
// read" forever.
|
||||
if this.workbuf_wi <= args.workbuf.length() {
|
||||
// This might return "#internal error: inconsistent
|
||||
// workbuf length" because of the ".. this.workbuf_wi".
|
||||
// We just ignore the error.
|
||||
this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf[.. this.workbuf_wi])
|
||||
}
|
||||
if status == base."$short read" {
|
||||
while true {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
status = this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
@@ -1210,11 +1229,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
} endwhile
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
if this.num_decoded_frames_value < this.num_animation_frames_value {
|
||||
this.call_sequence = 5
|
||||
} else {
|
||||
this.call_sequence = 0xFF
|
||||
}
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -1342,13 +1357,13 @@ pub func decoder.num_decoded_frames() base.u64 {
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
} else if (args.index >= (this.num_animation_frames_value as base.u64)) or
|
||||
((args.index == 0) and (args.io_position <> this.first_config_io_position)) {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x28
|
||||
if this.interlace_pass >= 1 {
|
||||
this.interlace_pass = 1
|
||||
}
|
||||
@@ -1383,7 +1398,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
var r_mark : base.u64
|
||||
var zlib_status : base.status
|
||||
|
||||
if this.call_sequence <> 1 {
|
||||
if (this.call_sequence & 0x10) == 0 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if this.metadata_fourcc == 0 {
|
||||
@@ -1503,7 +1518,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else if c2 <= 0x7F {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.ztxt_ri += 1
|
||||
@@ -1511,7 +1525,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else {
|
||||
if args.dst.length() <= 1 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.ztxt_ri += 1
|
||||
@@ -1577,7 +1590,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else if c2 <= 0x7F {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
@@ -1586,7 +1598,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else {
|
||||
if args.dst.length() <= 1 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
@@ -1649,7 +1660,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
this.metadata_is_zlib_compressed = true
|
||||
}
|
||||
|
||||
this.call_sequence = 2
|
||||
this.call_sequence &= 0xEF
|
||||
return ok
|
||||
}
|
||||
break.goto_done
|
||||
@@ -1668,7 +1679,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
|
||||
this.call_sequence = 2
|
||||
this.call_sequence &= 0xEF
|
||||
return ok
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,578 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub status "#bad header"
|
||||
pub status "#bad run length encoding"
|
||||
pub status "#unsupported TGA file"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0xFFFF],
|
||||
height : base.u32[..= 0xFFFF],
|
||||
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
header_id_length : base.u8,
|
||||
header_color_map_type : base.u8,
|
||||
header_image_type : base.u8,
|
||||
header_color_map_first_entry_index : base.u16,
|
||||
header_color_map_length : base.u16,
|
||||
header_color_map_entry_size : base.u8,
|
||||
header_pixel_depth : base.u8,
|
||||
header_image_descriptor : base.u8,
|
||||
|
||||
opaque : base.bool,
|
||||
|
||||
scratch_bytes_per_pixel : base.u32[..= 4],
|
||||
src_bytes_per_pixel : base.u32[..= 4],
|
||||
src_pixfmt : base.u32,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
util : base.utility,
|
||||
)(
|
||||
dst_palette : array[4 * 256] base.u8,
|
||||
src_palette : array[4 * 256] base.u8,
|
||||
scratch : array[4] base.u8,
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
}
|
||||
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
var i : base.u32
|
||||
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
this.header_id_length = args.src.read_u8?()
|
||||
this.header_color_map_type = args.src.read_u8?()
|
||||
if this.header_color_map_type > 1 {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.header_image_type = args.src.read_u8?()
|
||||
if (this.header_image_type == 0x01) or
|
||||
(this.header_image_type == 0x02) or
|
||||
(this.header_image_type == 0x03) or
|
||||
(this.header_image_type == 0x09) or
|
||||
(this.header_image_type == 0x0A) or
|
||||
(this.header_image_type == 0x0B) {
|
||||
// No-op.
|
||||
} else {
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.header_color_map_first_entry_index = args.src.read_u16le?()
|
||||
this.header_color_map_length = args.src.read_u16le?()
|
||||
this.header_color_map_entry_size = args.src.read_u8?()
|
||||
if this.header_color_map_type <> 0 {
|
||||
// We have a color-mapped image (in Wuffs, an indexed pixel format).
|
||||
if (this.header_color_map_first_entry_index <> 0) or
|
||||
(this.header_color_map_length > 0x100) {
|
||||
return "#unsupported TGA file"
|
||||
} else if (this.header_color_map_entry_size <> 0x0F) and
|
||||
(this.header_color_map_entry_size <> 0x10) and
|
||||
(this.header_color_map_entry_size <> 0x18) and
|
||||
(this.header_color_map_entry_size <> 0x20) {
|
||||
return "#bad header"
|
||||
}
|
||||
} else {
|
||||
// The color-map fields must be zero.
|
||||
if (this.header_color_map_first_entry_index <> 0) or
|
||||
(this.header_color_map_length <> 0) or
|
||||
(this.header_color_map_entry_size <> 0) {
|
||||
return "#bad header"
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore the X-Origin and Y-Origin fields.
|
||||
args.src.skip_u32?(n: 4)
|
||||
|
||||
this.width = args.src.read_u16le_as_u32?()
|
||||
this.height = args.src.read_u16le_as_u32?()
|
||||
|
||||
this.header_pixel_depth = args.src.read_u8?()
|
||||
if (this.header_pixel_depth <> 0x01) and
|
||||
(this.header_pixel_depth <> 0x08) and
|
||||
(this.header_pixel_depth <> 0x0F) and
|
||||
(this.header_pixel_depth <> 0x10) and
|
||||
(this.header_pixel_depth <> 0x18) and
|
||||
(this.header_pixel_depth <> 0x20) {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
if (this.header_image_type | 8) == 0x09 {
|
||||
this.scratch_bytes_per_pixel = 1
|
||||
this.src_bytes_per_pixel = 1
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL
|
||||
this.opaque =
|
||||
(this.header_color_map_entry_size == 0x0F) or
|
||||
(this.header_color_map_entry_size == 0x18)
|
||||
|
||||
} else if (this.header_image_type | 8) == 0x0A {
|
||||
if (this.header_pixel_depth == 0x0F) or
|
||||
(this.header_pixel_depth == 0x10) {
|
||||
// Wuffs' base.pixel_swizzler doesn't support BGRX5551, so
|
||||
// scratch_bytes_per_pixel and src_bytes_per_pixel are different.
|
||||
this.scratch_bytes_per_pixel = 4
|
||||
this.src_bytes_per_pixel = 0
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
} else if this.header_pixel_depth == 0x18 {
|
||||
this.scratch_bytes_per_pixel = 3
|
||||
this.src_bytes_per_pixel = 3
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGR
|
||||
this.opaque = true
|
||||
} else if this.header_pixel_depth == 0x20 {
|
||||
this.scratch_bytes_per_pixel = 4
|
||||
this.src_bytes_per_pixel = 4
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
} else {
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
|
||||
} else {
|
||||
if this.header_pixel_depth == 0x08 {
|
||||
this.scratch_bytes_per_pixel = 1
|
||||
this.src_bytes_per_pixel = 1
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y
|
||||
this.opaque = true
|
||||
} else {
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
}
|
||||
|
||||
this.header_image_descriptor = args.src.read_u8?()
|
||||
if (this.header_image_descriptor & 0x10) <> 0 {
|
||||
// We don't support right-to-left, only left-to-right pixel order.
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
|
||||
// Skip the Image ID.
|
||||
args.src.skip_u32?(n: this.header_id_length as base.u32)
|
||||
|
||||
// Read the color map.
|
||||
if this.header_color_map_type <> 0 {
|
||||
while i < (this.header_color_map_length as base.u32) {
|
||||
assert i <= 0xFFFF via "a <= b: a <= c; c <= b"(c: this.header_color_map_length as base.u32)
|
||||
if this.header_color_map_entry_size == 0x18 {
|
||||
c = args.src.read_u24le_as_u32?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c >> 0x10) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = 0xFF
|
||||
} else if this.header_color_map_entry_size == 0x20 {
|
||||
c = args.src.read_u32le?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c >> 0x10) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = ((c >> 0x18) & 0xFF) as base.u8
|
||||
} else {
|
||||
// Expand 15-bit or 16-bit color map entries.
|
||||
c = args.src.read_u16le_as_u32?()
|
||||
c5 = 0x1F & (c >> 0)
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
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()
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(
|
||||
pixfmt: this.src_pixfmt,
|
||||
pixsub: 0,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
first_frame_io_position: this.frame_config_io_position,
|
||||
first_frame_is_opaque: this.opaque)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(bounds: this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height),
|
||||
duration: 0,
|
||||
index: 0,
|
||||
io_position: this.frame_config_io_position,
|
||||
disposal: 0,
|
||||
opaque_within_bounds: this.opaque,
|
||||
overwrite_instead_of_blend: false,
|
||||
background_color: 0xFF00_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pub func decoder.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) {
|
||||
var status : base.status
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
||||
var dst_x : base.u32
|
||||
var dst_y : base.u32
|
||||
var tab : table base.u8
|
||||
var dst_palette : slice base.u8
|
||||
var dst : slice base.u8
|
||||
var dst_start : base.u64
|
||||
var src_palette : slice base.u8
|
||||
var mark : base.u64
|
||||
var num_pixels64 : base.u64
|
||||
var num_pixels32 : base.u32[..= 0xFFFF]
|
||||
var lit_length : base.u32[..= 0xFFFF]
|
||||
var run_length : base.u32[..= 0xFFFF]
|
||||
var num_dst_bytes : base.u64[..= 0x1F_FFE0]
|
||||
var num_src_bytes : base.u32[..= 0x3_FFFC]
|
||||
var c : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if this.header_color_map_type <> 0 {
|
||||
src_palette = this.src_palette[..]
|
||||
}
|
||||
status = this.swizzler.prepare!(
|
||||
dst_pixfmt: args.dst.pixel_format(),
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
|
||||
src_pixfmt: this.util.make_pixel_format(repr: this.src_pixfmt),
|
||||
src_palette: src_palette,
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
dst_pixfmt = args.dst.pixel_format()
|
||||
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
|
||||
if (dst_bits_per_pixel & 7) <> 0 {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
dst_y = this.height ~mod- 1
|
||||
}
|
||||
if (this.header_image_type & 8) == 0 {
|
||||
// No RLE (run length encoding) means that the entire row is
|
||||
// effectively literals.
|
||||
lit_length = this.width
|
||||
}
|
||||
|
||||
while.resume true {
|
||||
tab = args.dst.plane(p: 0)
|
||||
dst_palette = args.dst.palette_or_else(fallback: this.dst_palette[..])
|
||||
|
||||
while dst_y < this.height {
|
||||
dst = tab.row_u32(y: dst_y)
|
||||
dst_start = (dst_x as base.u64) * dst_bytes_per_pixel
|
||||
if dst_start <= dst.length() {
|
||||
dst = dst[dst_start ..]
|
||||
} else {
|
||||
dst = this.util.empty_slice_u8()
|
||||
}
|
||||
|
||||
while dst_x < this.width {
|
||||
assert dst_x <= 0xFFFF via "a <= b: a <= c; c <= b"(c: this.width)
|
||||
|
||||
if this.src_bytes_per_pixel > 0 {
|
||||
if lit_length > 0 {
|
||||
mark = args.src.mark()
|
||||
num_pixels64 = args.src.length() / (this.src_bytes_per_pixel as base.u64)
|
||||
num_pixels32 = num_pixels64.min(a: lit_length as base.u64) as base.u32
|
||||
num_dst_bytes = (num_pixels32 as base.u64) * dst_bytes_per_pixel
|
||||
num_src_bytes = num_pixels32 * this.src_bytes_per_pixel
|
||||
args.src.skip_u32?(n: num_src_bytes)
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: args.src.since(mark: mark))
|
||||
if num_dst_bytes <= dst.length() {
|
||||
dst = dst[num_dst_bytes ..]
|
||||
} else {
|
||||
dst = this.util.empty_slice_u8()
|
||||
}
|
||||
dst_x += num_pixels32
|
||||
lit_length = (lit_length ~mod- num_pixels32) & 0xFFFF
|
||||
if lit_length > 0 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
|
||||
} else if run_length > 0 {
|
||||
run_length -= 1
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. this.scratch_bytes_per_pixel])
|
||||
if dst_bytes_per_pixel <= dst.length() {
|
||||
dst = dst[dst_bytes_per_pixel ..]
|
||||
}
|
||||
dst_x += 1
|
||||
|
||||
} else {
|
||||
// Handle Raw vs RLE packets.
|
||||
if args.src.length() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
if args.src.peek_u8_as_u32() < 0x80 {
|
||||
lit_length = args.src.peek_u8_as_u32() + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if (lit_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
|
||||
} else {
|
||||
if this.src_bytes_per_pixel == 1 {
|
||||
if args.src.length() < 2 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[0] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} else if this.src_bytes_per_pixel == 3 {
|
||||
if args.src.length() < 4 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[0] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[1] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[2] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} else { // this.src_bytes_per_pixel == 4
|
||||
if args.src.length() < 5 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[0] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[1] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[2] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[3] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
}
|
||||
|
||||
if (run_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Wuffs' base.pixel_swizzler doesn't support BGRX5551, so
|
||||
// we manually convert to BGRX8888, one pixel at a time.
|
||||
|
||||
if lit_length > 0 {
|
||||
if args.src.length() < 2 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
c = args.src.peek_u16le_as_u32()
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
c5 = 0x1F & (c >> 0)
|
||||
this.scratch[0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
this.scratch[1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
this.scratch[2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.scratch[3] = 0xFF
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. 4])
|
||||
if dst_bytes_per_pixel <= dst.length() {
|
||||
dst = dst[dst_bytes_per_pixel ..]
|
||||
}
|
||||
dst_x += 1
|
||||
lit_length -= 1
|
||||
|
||||
} else if run_length > 0 {
|
||||
run_length -= 1
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. this.scratch_bytes_per_pixel])
|
||||
if dst_bytes_per_pixel <= dst.length() {
|
||||
dst = dst[dst_bytes_per_pixel ..]
|
||||
}
|
||||
dst_x += 1
|
||||
|
||||
} else {
|
||||
// Handle Raw vs RLE packets.
|
||||
if args.src.length() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
if args.src.peek_u8_as_u32() < 0x80 {
|
||||
lit_length = args.src.peek_u8_as_u32() + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if (lit_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
|
||||
} else {
|
||||
if args.src.length() < 3 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
c = args.src.peek_u16le_as_u32()
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
c5 = 0x1F & (c >> 0)
|
||||
this.scratch[0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
this.scratch[1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
this.scratch[2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.scratch[3] = 0xFF
|
||||
|
||||
if (run_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} endwhile
|
||||
dst_x = 0
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
dst_y ~mod-= 1
|
||||
} else { // Top-to-bottom.
|
||||
dst_y ~mod+= 1
|
||||
}
|
||||
if (this.header_image_type & 8) == 0 {
|
||||
// No RLE (run length encoding) means that the entire row is
|
||||
// effectively literals.
|
||||
lit_length = this.width
|
||||
}
|
||||
} endwhile
|
||||
break.resume
|
||||
} endwhile.resume
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
return this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height)
|
||||
}
|
||||
|
||||
pub func decoder.num_animation_loops() base.u32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 0x20 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 0x40 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if args.index <> 0 {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 0x28
|
||||
this.frame_config_io_position = args.io_position
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
// TODO: implement.
|
||||
}
|
||||
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -20,31 +20,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32,
|
||||
height : base.u32,
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x03: image config decoded.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0xFF: end-of-data, usually after (the non-animated) frame decoded.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x03: via DIC
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0xFF: via DFC
|
||||
// - 0x04 -> 0xFF: via DF
|
||||
//
|
||||
// - ???? -> 0x03: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
@@ -62,7 +39,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
var x32 : base.u32
|
||||
var x64 : base.u64
|
||||
|
||||
if this.call_sequence <> 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
@@ -116,18 +93,20 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
first_frame_is_opaque: true)
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 3 {
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 4 {
|
||||
this.call_sequence = 0xFF
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
@@ -148,7 +127,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
background_color: 0xFF00_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pub func decoder.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) {
|
||||
@@ -164,10 +143,10 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
var src : array[1] base.u8
|
||||
var c : base.u8
|
||||
|
||||
if this.call_sequence < 4 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 4 {
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
@@ -246,7 +225,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
@@ -262,27 +241,27 @@ pub func decoder.num_animation_loops() base.u32 {
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 3 {
|
||||
if this.call_sequence > 0x20 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 4 {
|
||||
if this.call_sequence > 0x40 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if args.index <> 0 {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x28
|
||||
this.frame_config_io_position = args.io_position
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2022 The Wuffs Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# ----------------
|
||||
|
||||
# This script fetches the TrueVision TGA test suite.
|
||||
|
||||
if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
echo "$0 should be run from the Wuffs test/3pdata directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check out a specific commit (from January 2022).
|
||||
git clone --quiet https://github.com/image-rs/image.git
|
||||
cd image
|
||||
git reset --quiet --hard 2e1d2e5928077eae7a92f8b5cac83ca1ae0db0cd
|
||||
cd ..
|
||||
|
||||
# Copy out the *.tga files.
|
||||
mkdir -p tgasuite
|
||||
cp image/tests/images/tga/testsuite/*.tga tgasuite
|
||||
cp image/tests/regression/tga/*.tga tgasuite
|
||||
rm -rf image
|
||||
@@ -0,0 +1,9 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
9fbe866a test/3pdata/tgasuite/cbw8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ccm8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ctc24.tga
|
||||
9fbe866a test/3pdata/tgasuite/ubw8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ucm8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/utc16.tga
|
||||
5d75ef41 test/3pdata/tgasuite/utc24.tga
|
||||
79781cfb test/3pdata/tgasuite/utc32.tga
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "bzlib.h"
|
||||
|
||||
const char* //
|
||||
mimic_bzip2_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
if (wuffs_base__io_buffer__writer_length(dst) > 0x7FFFFFFF) {
|
||||
return "dst length is too large";
|
||||
} else if (wuffs_base__io_buffer__reader_length(src) > 0x7FFFFFFF) {
|
||||
return "src length is too large";
|
||||
} else if ((wlimit < UINT64_MAX) || (rlimit < UINT64_MAX)) {
|
||||
// Supporting this would probably mean using BZ2_bzDecompress instead of
|
||||
// the simpler BZ2_bzBuffToBuffDecompress function.
|
||||
return "unsupported I/O limit";
|
||||
}
|
||||
unsigned int dlen = wuffs_base__io_buffer__writer_length(dst);
|
||||
unsigned int slen = wuffs_base__io_buffer__reader_length(src);
|
||||
int err = BZ2_bzBuffToBuffDecompress(
|
||||
((char*)wuffs_base__io_buffer__writer_pointer(dst)), &dlen,
|
||||
((char*)wuffs_base__io_buffer__reader_pointer(src)), slen, 0, 0);
|
||||
if (err != BZ_OK) {
|
||||
return "libbz2: an error occurred";
|
||||
} else if (dlen > wuffs_base__io_buffer__writer_length(dst)) {
|
||||
return "libbz2: dst buffer overflow";
|
||||
}
|
||||
dst->meta.wi += dlen;
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
This test program is typically run indirectly, by the "wuffs test" or "wuffs
|
||||
bench" commands. These commands take an optional "-mimic" flag to check that
|
||||
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
giflib for GIF, libpng for PNG, etc.
|
||||
|
||||
To manually run this test:
|
||||
|
||||
for CC in clang gcc; do
|
||||
$CC -std=c99 -Wall -Werror bzip2.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -lbz2
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__BZIP2
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
#include "../mimiclib/bzip2.c"
|
||||
#endif
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_bzip2_256_bytes_gt = {
|
||||
.want_filename = "test/data/256.bytes",
|
||||
.src_filename = "test/data/256.bytes.bz2",
|
||||
};
|
||||
|
||||
golden_test g_bzip2_bad_number_of_sections_gt = {
|
||||
.want_filename = "test/data/0.bytes",
|
||||
.src_filename = "test/data/artificial-bzip2/bad-number-of-sections.bz2",
|
||||
};
|
||||
|
||||
golden_test g_bzip2_huffman_258_gt = {
|
||||
.want_filename = "test/data/abraca.txt",
|
||||
.src_filename = "test/data/artificial-bzip2/huffman-258.bz2",
|
||||
};
|
||||
|
||||
golden_test g_bzip2_midsummer_gt = {
|
||||
.want_filename = "test/data/midsummer.txt",
|
||||
.src_filename = "test/data/midsummer.txt.bz2",
|
||||
};
|
||||
|
||||
golden_test g_bzip2_pi_gt = {
|
||||
.want_filename = "test/data/pi.txt",
|
||||
.src_filename = "test/data/pi.txt.bz2",
|
||||
};
|
||||
|
||||
// ---------------- Bzip2 Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_bzip2__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_bzip2__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__io_transformer(
|
||||
wuffs_bzip2__decoder__upcast_as__wuffs_base__io_transformer(&dec),
|
||||
"test/data/romeo.txt.bz2", 0, SIZE_MAX, 942, 0x0A);
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_bzip2_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
wuffs_bzip2__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_bzip2__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
|
||||
while (true) {
|
||||
wuffs_base__io_buffer limited_dst = make_limited_writer(*dst, wlimit);
|
||||
wuffs_base__io_buffer limited_src = make_limited_reader(*src, rlimit);
|
||||
|
||||
wuffs_base__status status = wuffs_bzip2__decoder__transform_io(
|
||||
&dec, &limited_dst, &limited_src, g_work_slice_u8);
|
||||
|
||||
dst->meta.wi += limited_dst.meta.wi;
|
||||
src->meta.ri += limited_src.meta.ri;
|
||||
|
||||
if (((wlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_write)) ||
|
||||
((rlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_read))) {
|
||||
continue;
|
||||
}
|
||||
return status.repr;
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_256_bytes() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_bzip2_decode, &g_bzip2_256_bytes_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_bad_number_of_sections() {
|
||||
CHECK_FOCUS(__func__);
|
||||
const char* have =
|
||||
do_test_io_buffers(wuffs_bzip2_decode, &g_bzip2_bad_number_of_sections_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
const char* want = wuffs_bzip2__error__bad_number_of_sections;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("have \"%s\", want \"%s\"", have, want);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_huffman_258() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_bzip2_decode, &g_bzip2_huffman_258_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_midsummer() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_bzip2_decode, &g_bzip2_midsummer_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_bzip2_decode_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_bzip2_decode, &g_bzip2_pi_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
test_mimic_bzip2_decode_256_bytes() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_bzip2_decode, &g_bzip2_256_bytes_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_bzip2_decode_midsummer() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_bzip2_decode, &g_bzip2_midsummer_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_bzip2_decode_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_bzip2_decode, &g_bzip2_pi_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Bzip2 Benches
|
||||
|
||||
const char* //
|
||||
bench_wuffs_bzip2_decode_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bzip2_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_dst,
|
||||
&g_bzip2_midsummer_gt, UINT64_MAX, UINT64_MAX, 20);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_bzip2_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bzip2_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_dst,
|
||||
&g_bzip2_pi_gt, UINT64_MAX, UINT64_MAX, 2);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
bench_mimic_bzip2_decode_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
mimic_bzip2_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_dst,
|
||||
&g_bzip2_midsummer_gt, UINT64_MAX, UINT64_MAX, 20);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_mimic_bzip2_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
mimic_bzip2_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_dst,
|
||||
&g_bzip2_pi_gt, UINT64_MAX, UINT64_MAX, 2);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_bzip2_decode_256_bytes,
|
||||
test_wuffs_bzip2_decode_bad_number_of_sections,
|
||||
test_wuffs_bzip2_decode_huffman_258,
|
||||
test_wuffs_bzip2_decode_interface,
|
||||
test_wuffs_bzip2_decode_midsummer,
|
||||
test_wuffs_bzip2_decode_pi,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_bzip2_decode_256_bytes,
|
||||
test_mimic_bzip2_decode_midsummer,
|
||||
test_mimic_bzip2_decode_pi,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_bzip2_decode_10k,
|
||||
bench_wuffs_bzip2_decode_100k,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
bench_mimic_bzip2_decode_10k,
|
||||
bench_mimic_bzip2_decode_100k,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/bzip2";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -3099,6 +3099,12 @@ test_wuffs_json_decode_quirk_allow_backslash_x() {
|
||||
|
||||
src_index += token_length;
|
||||
}
|
||||
|
||||
if (src_index != src.meta.ri) {
|
||||
RETURN_FAIL("tc=%zu: src_index: have %" PRIu64 ", want %zu", tc,
|
||||
src_index, src.meta.ri);
|
||||
}
|
||||
|
||||
uint64_t want = test_cases[tc].want_code_points;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("tc=%zu: have U+%08" PRIX64 ", want U+%08" PRIX64, tc, have,
|
||||
|
||||
@@ -810,6 +810,8 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
"U-значение", //
|
||||
"Z-Këy", //
|
||||
"Z-значение", //
|
||||
"After", //
|
||||
"Frame", //
|
||||
};
|
||||
|
||||
wuffs_png__decoder dec;
|
||||
@@ -819,14 +821,15 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__KVP, true);
|
||||
|
||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
|
||||
|
||||
size_t i = 0;
|
||||
for (;; i++) {
|
||||
while (true) {
|
||||
wuffs_base__status status =
|
||||
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
|
||||
wuffs_png__decoder__decode_frame_config(&dec, NULL, &src);
|
||||
if (wuffs_base__status__is_ok(&status)) {
|
||||
continue;
|
||||
} else if (status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else if (status.repr != wuffs_base__note__metadata_reported) {
|
||||
RETURN_FAIL("decode_image_config i=%zu: %s", i, status.repr);
|
||||
@@ -865,6 +868,7 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
}
|
||||
}
|
||||
CHECK_STRING(check_io_buffers_equal("", &have, &want));
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i != WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
This test program is typically run indirectly, by the "wuffs test" or "wuffs
|
||||
bench" commands. These commands take an optional "-mimic" flag to check that
|
||||
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
giflib for GIF, libpng for PNG, etc.
|
||||
|
||||
To manually run this test:
|
||||
|
||||
for CC in clang gcc; do
|
||||
$CC -std=c99 -Wall -Werror tga.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
// No mimic library.
|
||||
#endif
|
||||
|
||||
// ---------------- TGA Tests
|
||||
|
||||
const char* //
|
||||
wuffs_tga_decode(uint64_t* n_bytes_out,
|
||||
wuffs_base__io_buffer* dst,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
wuffs_base__pixel_format pixfmt,
|
||||
uint32_t* quirks_ptr,
|
||||
size_t quirks_len,
|
||||
wuffs_base__io_buffer* src) {
|
||||
wuffs_tga__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_tga__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
return do_run__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec),
|
||||
n_bytes_out, dst, pixfmt, quirks_ptr, quirks_len, src);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_tga_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_tga__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_tga__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec),
|
||||
"test/data/bricks-color.tga", 0, SIZE_MAX, 160, 120, 0xFF022460);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- TGA Benches
|
||||
|
||||
const char* //
|
||||
bench_wuffs_tga_decode_19k_8bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&wuffs_tga_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/bricks-nodither.tga", 0, SIZE_MAX, 1000);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_tga_decode_77k_24bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&wuffs_tga_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/bricks-color.tga", 0, SIZE_MAX, 200);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_tga_decode_interface,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_tga_decode_19k_8bpp,
|
||||
bench_wuffs_tga_decode_77k_24bpp,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/tga";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ char g_fail_msg[65536] = {0};
|
||||
#define RETURN_FAIL(...) \
|
||||
return (snprintf(g_fail_msg, sizeof(g_fail_msg), ##__VA_ARGS__) >= 0) \
|
||||
? g_fail_msg \
|
||||
: "unknown failure (snprintf-related)"
|
||||
: strcpy(g_fail_msg, "unknown failure (snprintf-related)")
|
||||
|
||||
#define INCR_FAIL(msg, ...) \
|
||||
msg += snprintf(msg, sizeof(g_fail_msg) - (msg - g_fail_msg), ##__VA_ARGS__)
|
||||
@@ -422,7 +422,8 @@ test_main(int argc, char** argv, proc* tests, proc* benches) {
|
||||
"compatible with the\n"
|
||||
"# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install "
|
||||
"it, first\n"
|
||||
"# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
"# install Go, then run \"go install "
|
||||
"golang.org/x/perf/cmd/benchstat\".\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < reps; i++) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
abraca
|
||||
@@ -0,0 +1,49 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
# This script generates test/data/abraca.txt.bz2 exactly, following the
|
||||
# description in std/bzip2/README.md and its bitslices (a) ..= (s).
|
||||
#
|
||||
# By itself, this isn't a very interesting foo.make-artificial.txt file, in
|
||||
# that it doesn't make *artificial* bzip2 test data (as opposed to test data
|
||||
# *naturally* created by the /usr/bin/bzip2 tool). But this file is a useful
|
||||
# diff-base for other bar.make-artificial.txt files in the same directory.
|
||||
|
||||
make bzip2
|
||||
|
||||
# Bitslices (a) ..= (g)
|
||||
bits 16 0x425A
|
||||
bits 8 0x68
|
||||
bits 8 0x39
|
||||
bits 48 0x314159265359
|
||||
bits 32 0x76A70995
|
||||
bits 1 0x0
|
||||
bits 24 0x000001
|
||||
|
||||
# Bitslices (h) ..= (j)
|
||||
bits 16 0x0300
|
||||
bits 16 0x7000
|
||||
bits 16 0x2000
|
||||
|
||||
# Bitslices (k) ..= (m)
|
||||
bits 3 0x2
|
||||
bits 15 0x0001
|
||||
bits 1 0x0
|
||||
|
||||
# Bitslices (n) ..= (o)
|
||||
repeat 2 [
|
||||
bits 19 0x0CD34
|
||||
]
|
||||
|
||||
# Bitslice (p)
|
||||
bits 3 0x6
|
||||
bits 2 0x0
|
||||
bits 2 0x1
|
||||
bits 2 0x0
|
||||
bits 3 0x4
|
||||
bits 2 0x1
|
||||
bits 3 0x7
|
||||
|
||||
# Bitslices (q) ..= (s)
|
||||
bits 48 0x177245385090
|
||||
bits 32 0x76A70995
|
||||
bits 5 0x00
|
||||
@@ -0,0 +1,42 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
# This modifies abraca.txt.bz2.make-artificial.txt to have 51 Huffman-coded
|
||||
# symbols (bitslice (p)) but only 1 section (bitslice (l)). At 50 symbols per
|
||||
# section, this should be invalid.
|
||||
|
||||
make bzip2
|
||||
|
||||
# Bitslices (a) ..= (g)
|
||||
bits 16 0x425A
|
||||
bits 8 0x68
|
||||
bits 8 0x39
|
||||
bits 48 0x314159265359
|
||||
bits 32 0x76A70995
|
||||
bits 1 0x0
|
||||
bits 24 0x000001
|
||||
|
||||
# Bitslices (h) ..= (j)
|
||||
bits 16 0x0300
|
||||
bits 16 0x7000
|
||||
bits 16 0x2000
|
||||
|
||||
# Bitslices (k) ..= (m)
|
||||
bits 3 0x2
|
||||
bits 15 0x0001
|
||||
bits 1 0x0
|
||||
|
||||
# Bitslices (n) ..= (o)
|
||||
repeat 2 [
|
||||
bits 19 0x0CD34
|
||||
]
|
||||
|
||||
# Bitslice (p)
|
||||
repeat 50 [
|
||||
bits 2 0x0
|
||||
]
|
||||
bits 3 0x7
|
||||
|
||||
# Bitslices (q) ..= (s)
|
||||
bits 48 0x177245385090
|
||||
bits 32 0x76A70995
|
||||
bits 5 0x00
|
||||
@@ -0,0 +1,83 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
# This modifies abraca.txt.bz2.make-artificial.txt to produce the same
|
||||
# decompressed output, "abraca", but in a more elaborate way. The Huffman codes
|
||||
# here have the full 258 symbols instead of just 6.
|
||||
|
||||
make bzip2
|
||||
|
||||
# Bitslices (a) ..= (g)
|
||||
bits 16 0x425A
|
||||
bits 8 0x68
|
||||
bits 8 0x39
|
||||
bits 48 0x314159265359
|
||||
bits 32 0x76A70995
|
||||
bits 1 0x0
|
||||
bits 24 0x000001
|
||||
|
||||
# Bitslices (h) ..= (j)
|
||||
bits 16 0xFFFF
|
||||
repeat 16 [
|
||||
bits 16 0xFFFF
|
||||
]
|
||||
|
||||
# Bitslices (k) ..= (m)
|
||||
bits 3 0x2
|
||||
bits 15 0x0001
|
||||
bits 1 0x0
|
||||
|
||||
# Bitslices (n) ..= (o)
|
||||
#
|
||||
# Both Huffman codes have 258 symbols: 254 × 8-bit symbols and then 4 × 9-bit
|
||||
# symbols.
|
||||
#
|
||||
# For small XYZ (where XYZ < 253), the mXYZ symbol's bitstring is (XYZ+1) in
|
||||
# binary. For example, the m099 symbol's bitstring is "01100100", because the
|
||||
# binary representation of 0d099+1 = 0d100 = 0x64 = 0b01100100.
|
||||
#
|
||||
# RUNA is the 8-bit bitstring "00000000".
|
||||
# RUNB is the 8-bit bitstring "00000001".
|
||||
# m001 is the 8-bit bitstring "00000010".
|
||||
# m002 is the 8-bit bitstring "00000011".
|
||||
# m003 is the 8-bit bitstring "00000100".
|
||||
# etc
|
||||
# m250 is the 8-bit bitstring "11111011".
|
||||
# m251 is the 8-bit bitstring "11111100".
|
||||
# m252 is the 8-bit bitstring "11111101".
|
||||
# m253 is the 9-bit bitstring "111111100".
|
||||
# m254 is the 9-bit bitstring "111111101".
|
||||
# m255 is the 9-bit bitstring "111111110".
|
||||
# EOB is the 9-bit bitstring "111111111".
|
||||
repeat 2 [
|
||||
bits 5 0x08
|
||||
repeat 254 [
|
||||
bits 1 0x0
|
||||
]
|
||||
bits 3 0x4
|
||||
bits 1 0x0
|
||||
bits 1 0x0
|
||||
bits 1 0x0
|
||||
]
|
||||
|
||||
# Bitslice (p)
|
||||
#
|
||||
# There are 7 symbols.
|
||||
# Order = [0x00, 0x01, 0x02, 0x03, ... 0xFF] m099 picks 'c'. 0d099+1 = 0x64.
|
||||
# Order = ['c', 0x00, 0x01, 0x02, ... 0xFF] m098 picks 'a'. 0d098+1 = 0x63.
|
||||
# Order = ['a', 'c', 0x00, 0x01, ... 0xFF] m114 picks 'r'. 0d114+1 = 0x73.
|
||||
# Order = ['r', 'a', 'c', 0x00, ... 0xFF] m001 picks 'a'. 0d001+1 = 0x02.
|
||||
# Order = ['a', 'r', 'c', 0x00, ... 0xFF] RUNA picks 'a'.
|
||||
# Order = ['a', 'r', 'c', 0x00, ... 0xFF] m100 picks 'b'. 0d100+1 = 0x65.
|
||||
# Order = ['b', 'a', 'r', 'c', ... 0xFF] EOB.
|
||||
bits 8 0x64
|
||||
bits 8 0x63
|
||||
bits 8 0x73
|
||||
bits 8 0x02
|
||||
bits 8 0x00
|
||||
bits 8 0x65
|
||||
bits 9 0x1FF
|
||||
|
||||
# Bitslices (q) ..= (s)
|
||||
bits 48 0x177245385090
|
||||
bits 32 0x76A70995
|
||||
bits 1 0x0
|
||||
@@ -22,6 +22,7 @@ blockDynamicHuffman (nonFinal) {
|
||||
#
|
||||
# The sole key/value pair is also unused. (The one below is used.)
|
||||
0 0
|
||||
incomplete
|
||||
}
|
||||
|
||||
literal "foo"
|
||||
@@ -40,12 +41,12 @@ blockDynamicHuffman (final) {
|
||||
|
||||
huffman Literal/Length {
|
||||
# 65='A', 66='B', 67='C', 68='D', 256=EOB, 257=Length3
|
||||
256 00
|
||||
257 01
|
||||
65 100
|
||||
66 101
|
||||
67 110
|
||||
68 111
|
||||
256 00
|
||||
257 01
|
||||
}
|
||||
|
||||
huffman Distance {
|
||||
@@ -56,6 +57,7 @@ blockDynamicHuffman (final) {
|
||||
# Per the second table in RFC 1951 section 3.2.5. "Compressed blocks
|
||||
# (length and distance codes)", code 3 means a distance of 4.
|
||||
3 0
|
||||
incomplete
|
||||
}
|
||||
|
||||
literal "ABCD"
|
||||
|
||||
|
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 295 B |
@@ -95,5 +95,15 @@ IDAT {
|
||||
}
|
||||
}
|
||||
|
||||
# Basic key-value pair, after the frame (after all of the IDATs).
|
||||
tEXt {
|
||||
raw {
|
||||
# "After\x00".
|
||||
0x41 0x66 0x74 0x65 0x72 0x00
|
||||
# "Frame".
|
||||
0x46 0x72 0x61 0x6D 0x65
|
||||
}
|
||||
}
|
||||
|
||||
IEND {
|
||||
}
|
||||
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
@@ -26,6 +26,7 @@ e08a7cc8 test/data/artificial-png/exif.png
|
||||
e08a7cc8 test/data/artificial-png/key-value-pairs.png
|
||||
076cb375 test/data/bricks-color.bmp
|
||||
076cb375 test/data/bricks-color.png
|
||||
076cb375 test/data/bricks-color.tga
|
||||
f36c2e80 test/data/bricks-dither.bmp
|
||||
f36c2e80 test/data/bricks-dither.gif
|
||||
f36c2e80 test/data/bricks-dither.no-ancillary.png
|
||||
@@ -34,9 +35,11 @@ c2bce675 test/data/bricks-gray.bmp
|
||||
c2bce675 test/data/bricks-gray.gif
|
||||
c2bce675 test/data/bricks-gray.no-ancillary.png
|
||||
c2bce675 test/data/bricks-gray.png
|
||||
c2bce675 test/data/bricks-gray.tga
|
||||
7aebfe6c test/data/bricks-nodither.bmp
|
||||
7aebfe6c test/data/bricks-nodither.gif
|
||||
7aebfe6c test/data/bricks-nodither.png
|
||||
7aebfe6c test/data/bricks-nodither.tga
|
||||
ae2e547d test/data/bricks-nodither.wbmp
|
||||
b47730a2 test/data/checkerboard.gamma1dot0.png
|
||||
b47730a2 test/data/checkerboard.gamma2dot2.png
|
||||
@@ -59,11 +62,13 @@ dcbb225a test/data/hippopotamus.bmp
|
||||
ed4b78fc test/data/hippopotamus.interlaced.gif
|
||||
dcbb225a test/data/hippopotamus.interlaced.png
|
||||
c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
|
||||
7c6a771b test/data/hippopotamus.interlaced.truncated.png
|
||||
d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
|
||||
dcbb225a test/data/hippopotamus.nie
|
||||
ed4b78fc test/data/hippopotamus.regular.gif
|
||||
dcbb225a test/data/hippopotamus.regular.png
|
||||
888b1c04 test/data/hippopotamus.regular.truncated.png
|
||||
2dccfe56 test/data/muybridge-frame-000.wbmp
|
||||
db2733f5 test/data/muybridge.apng
|
||||
db2733f5 test/data/muybridge.gif
|
||||
|
||||