Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
58608c4ee5 | ||
|
|
4aa672af48 | ||
|
|
f86c80e425 | ||
|
|
dda01f1a77 | ||
|
|
f3a7288357 | ||
|
|
0a8bded7f3 | ||
|
|
918b4e4535 | ||
|
|
92f74e91a7 | ||
|
|
bcecdef66b | ||
|
|
2f1b1a5311 | ||
|
|
425eefeb35 | ||
|
|
e1a6a7cd8c | ||
|
|
4e85543d9c | ||
|
|
4c04ac1127 | ||
|
|
8ef4c062d9 | ||
|
|
38b101d170 | ||
|
|
5d1473a2ca | ||
|
|
72d4a9e769 | ||
|
|
5f6a522563 | ||
|
|
4dedbedbbc | ||
|
|
a1aa15cacf | ||
|
|
ae6b366edb | ||
|
|
6acb5a4fdd | ||
|
|
3a9933f2a0 | ||
|
|
c2eb4f5b93 | ||
|
|
8397a35a50 | ||
|
|
e53497abe3 | ||
|
|
15285a6ab9 | ||
|
|
ac4d3e6420 | ||
|
|
8bd52a8791 | ||
|
|
1d8fb411ba | ||
|
|
ccbec18330 | ||
|
|
55cad41d6c | ||
|
|
f5c68a13cb | ||
|
|
f5d6ce3797 | ||
|
|
5e8b448c12 | ||
|
|
49a431f98d | ||
|
|
ede0590ead | ||
|
|
bb8623b472 | ||
|
|
010e0a69f4 | ||
|
|
a684928240 | ||
|
|
cdf3bbfb26 | ||
|
|
fe15c471df | ||
|
|
3b3331bbb3 | ||
|
|
e44920d382 | ||
|
|
3b882be500 | ||
|
|
6a8ee57ac0 |
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
|
||||
@@ -13,6 +13,8 @@
|
||||
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>
|
||||
@@ -36,6 +36,8 @@ Andrew Dassonville <dassonville.andrew@gmail.com>
|
||||
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++ \
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CcompilersDefault = "clang-9,gcc"
|
||||
CcompilersDefault = "clang,gcc"
|
||||
CcompilersUsage = `comma-separated list of C compilers`
|
||||
|
||||
FocusDefault = ""
|
||||
|
||||
@@ -124,7 +124,7 @@ Installation:
|
||||
|
||||
Like any other implemented-in-Go program, to install the ractool program:
|
||||
|
||||
go get github.com/google/wuffs/cmd/ractool
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
|
||||
Extended Example:
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ Installation:
|
||||
|
||||
Like any other implemented-in-Go program, to install the ractool program:
|
||||
|
||||
go get github.com/google/wuffs/cmd/ractool
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
|
||||
Extended Example:
|
||||
|
||||
|
||||
@@ -37,7 +37,12 @@ func doGen(wuffsRoot string, args []string) error { return doGenGenlib(wuffsR
|
||||
func doGenlib(wuffsRoot string, args []string) error { return doGenGenlib(wuffsRoot, args, true) }
|
||||
|
||||
func doGenGenlib(wuffsRoot string, args []string, genlib bool) error {
|
||||
flags := flag.NewFlagSet("gen", flag.ExitOnError)
|
||||
flagSetName := `"wuffs gen <flags> std/pkg1 std/pkg2 etc"`
|
||||
if genlib {
|
||||
flagSetName = `"wuffs genlib <flags> std/pkg1 std/pkg2 etc"`
|
||||
}
|
||||
|
||||
flags := flag.NewFlagSet(flagSetName, flag.ExitOnError)
|
||||
genlinenumFlag := flags.Bool("genlinenum", cf.GenlinenumDefault, cf.GenlinenumUsage)
|
||||
langsFlag := flags.String("langs", langsDefault, langsUsage)
|
||||
skipgendepsFlag := flags.Bool("skipgendeps", skipgendepsDefault, skipgendepsUsage)
|
||||
|
||||
@@ -52,6 +52,8 @@ The commands are:
|
||||
gen generate code for packages and dependencies
|
||||
genlib generate software libraries
|
||||
test test packages
|
||||
|
||||
Use "wuffs help <command>" for more information about a command.
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -76,6 +78,13 @@ func main1() error {
|
||||
return c.do(wuffsRoot, args[1:])
|
||||
}
|
||||
}
|
||||
if (len(args) == 2) && (args[0] == "help") {
|
||||
for _, c := range commands {
|
||||
if args[1] == c.name {
|
||||
return c.do(wuffsRoot, []string{"-help"})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
usage()
|
||||
os.Exit(1)
|
||||
|
||||
@@ -29,16 +29,26 @@ func doBench(wuffsRoot string, args []string) error { return doBenchTest(wuffsRo
|
||||
func doTest(wuffsRoot string, args []string) error { return doBenchTest(wuffsRoot, args, false) }
|
||||
|
||||
func doBenchTest(wuffsRoot string, args []string, bench bool) error {
|
||||
flags := flag.NewFlagSet("test", flag.ExitOnError)
|
||||
flagSetName := `"wuffs test <flags> std/pkg1 std/pkg2 etc"`
|
||||
if bench {
|
||||
flagSetName = `"wuffs bench <flags> std/pkg1 std/pkg2 etc"`
|
||||
}
|
||||
|
||||
flags := flag.NewFlagSet(flagSetName, flag.ExitOnError)
|
||||
ccompilersFlag := flags.String("ccompilers", cf.CcompilersDefault, cf.CcompilersUsage)
|
||||
focusFlag := flags.String("focus", cf.FocusDefault, cf.FocusUsage)
|
||||
iterscaleFlag := flags.Int("iterscale", cf.IterscaleDefault, cf.IterscaleUsage)
|
||||
langsFlag := flags.String("langs", langsDefault, langsUsage)
|
||||
mimicFlag := flags.Bool("mimic", cf.MimicDefault, cf.MimicUsage)
|
||||
repsFlag := flags.Int("reps", cf.RepsDefault, cf.RepsUsage)
|
||||
skipgenFlag := flags.Bool("skipgen", skipgenDefault, skipgenUsage)
|
||||
skipgendepsFlag := flags.Bool("skipgendeps", skipgendepsDefault, skipgendepsUsage)
|
||||
|
||||
iterscaleFlag := (*int)(nil)
|
||||
repsFlag := (*int)(nil)
|
||||
if bench {
|
||||
iterscaleFlag = flags.Int("iterscale", cf.IterscaleDefault, cf.IterscaleUsage)
|
||||
repsFlag = flags.Int("reps", cf.RepsDefault, cf.RepsUsage)
|
||||
}
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -53,13 +63,15 @@ func doBenchTest(wuffsRoot string, args []string, bench bool) error {
|
||||
if !cf.IsAlphaNumericIsh(*focusFlag) {
|
||||
return fmt.Errorf("bad -focus flag value %q", *focusFlag)
|
||||
}
|
||||
if *iterscaleFlag < cf.IterscaleMin || cf.IterscaleMax < *iterscaleFlag {
|
||||
return fmt.Errorf("bad -iterscale flag value %d, outside the range [%d ..= %d]",
|
||||
*iterscaleFlag, cf.IterscaleMin, cf.IterscaleMax)
|
||||
}
|
||||
if *repsFlag < cf.RepsMin || cf.RepsMax < *repsFlag {
|
||||
return fmt.Errorf("bad -reps flag value %d, outside the range [%d ..= %d]",
|
||||
*repsFlag, cf.RepsMin, cf.RepsMax)
|
||||
if bench {
|
||||
if *iterscaleFlag < cf.IterscaleMin || cf.IterscaleMax < *iterscaleFlag {
|
||||
return fmt.Errorf("bad -iterscale flag value %d, outside the range [%d ..= %d]",
|
||||
*iterscaleFlag, cf.IterscaleMin, cf.IterscaleMax)
|
||||
}
|
||||
if *repsFlag < cf.RepsMin || cf.RepsMax < *repsFlag {
|
||||
return fmt.Errorf("bad -reps flag value %d, outside the range [%d ..= %d]",
|
||||
*repsFlag, cf.RepsMin, cf.RepsMax)
|
||||
}
|
||||
}
|
||||
|
||||
args = flags.Args()
|
||||
|
||||
@@ -38,7 +38,7 @@ The output of those benchmark programs is compatible with the
|
||||
[benchstat](https://godoc.org/golang.org/x/perf/cmd/benchstat) tool. For
|
||||
example, that tool can calculate confidence intervals based on multiple
|
||||
benchmark runs, or calculate p-values when comparing numbers before and after a
|
||||
code change. To install it, first install Go, then run `go get
|
||||
code change. To install it, first install Go, then run `go install
|
||||
golang.org/x/perf/cmd/benchstat`.
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -40,12 +42,13 @@
|
||||
- Added slice `uintptr_low_12_bits` method.
|
||||
- Added tokens.
|
||||
- Changed `gif.decoder_workbuf_len_max_incl_worst_case` from 1 to 0.
|
||||
- Changed default C compilers from `clang-5.0,gcc` to `clang-9,gcc`.
|
||||
- Changed default C compilers from `clang-5.0,gcc` to `clang,gcc`.
|
||||
- Changed the C formatting style; removed the `-cformatter` flag.
|
||||
- Changed what the `std/gif` benchmarks actually measure.
|
||||
- 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`.
|
||||
|
||||
@@ -22,15 +22,25 @@ test suite, you might also have to install C compilers like clang and gcc, as
|
||||
well as C libraries (and their .h files) like libjpeg and libpng, as some tests
|
||||
compare that Wuffs produces exactly the same output as these other libraries.
|
||||
|
||||
Running `go get -v github.com/google/wuffs/cmd/...` will download and install
|
||||
the Wuffs tools. Change `get` to `install` to re-install those programs without
|
||||
downloading, e.g. after you've modified their source code, or after a manually
|
||||
issued `git pull`. The Wuffs tools that you'll most often use are `wuffsfmt`
|
||||
Run `git clone https://github.com/google/wuffs.git` to get the latest Wuffs
|
||||
code, `cd` into its directory and run `go install -v ./cmd/wuffs*` to install
|
||||
the Wuffs tools. The Wuffs tools that you'll most often use are `wuffsfmt`
|
||||
(analogous to `clang-format`, `gofmt` or `rustfmt`) and `wuffs` (roughly
|
||||
analogous to `make`, `go` or `cargo`).
|
||||
|
||||
You should now be able to run `wuffs test`. If all goes well, you should see
|
||||
some output containing the word "PASS" multiple times.
|
||||
You should now be able to run `wuffs test`. If you only have the `gcc` C
|
||||
compiler installed, but not `clang`, then you can run `wuffs
|
||||
test -ccompilers=gcc` instead. If all goes well, you should see some output
|
||||
containing the word "PASS" multiple times.
|
||||
|
||||
Remember to re-run `go install etc` whenever you've modified the Wuffs *tools'*
|
||||
source code (i.e. `*.go` files) or after a manually issued `git pull`. If
|
||||
you're only modifying the Wuffs *standard library's* source code (i.e.
|
||||
`*.wuffs` files), re-running `go install etc` is unnecessary.
|
||||
|
||||
If you're modifying just one particular codec in the standard library, such as
|
||||
the `std/png/*.wuffs` files, then you can exclude unrelated tests by running
|
||||
`wuffs test std/png`.
|
||||
|
||||
|
||||
## Poking Around
|
||||
|
||||
@@ -61,3 +61,4 @@ Package-specific quirks:
|
||||
|
||||
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
|
||||
- [JSON decoder quirks](/std/json/decode_quirks.wuffs)
|
||||
- [ZLIB decoder quirks](/std/zlib/decode_quirks.wuffs)
|
||||
@@ -1,6 +1,6 @@
|
||||
# Naïve Image Formats: NIE, NII, NIA
|
||||
|
||||
Status: Draft (as of December 2020). There is no compatibility guarantee yet.
|
||||
Status: Draft (as of November 2021). There is no compatibility guarantee yet.
|
||||
|
||||
A companion document has further discussion of [NIE related
|
||||
work](/doc/spec/nie-related-work.md).
|
||||
@@ -18,13 +18,14 @@ images. The 16 byte header:
|
||||
is not valid UTF-8) denotes version 1. There are no other valid versions at
|
||||
this time.
|
||||
- The second byte must be an ASCII 'b'. This denotes that the payload is in
|
||||
BGRA order (in terms of the wire format, independent of CPU endianness).
|
||||
BGRA order (not RGBA), in terms of the wire format, independent of CPU
|
||||
endianness.
|
||||
- The third byte, either an ASCII 'n' or an ASCII 'p', denotes whether the
|
||||
payload contains non-premultiplied or premultiplied alpha.
|
||||
- The fourth byte, either an ASCII '4' or an ASCII '8', denotes whether there
|
||||
are 4 or 8 bytes per pixel.
|
||||
- Future format versions may allow other byte values, but in version 1, it
|
||||
must be '\xFF', then 'b' or 'r', then 'n' or 'p', then '4' or '8'.
|
||||
must be '\xFF', then 'b', then 'n' or 'p', then '4' or '8'.
|
||||
- 4 bytes little-endian `uint32` width. The high bit must not be set.
|
||||
- 4 bytes little-endian `uint32` height. The high bit must not be set.
|
||||
|
||||
@@ -352,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)?
|
||||
@@ -369,4 +370,4 @@ in a long "E", "I" or "A" sound. It's definitely a hard "N", not a soft one.
|
||||
|
||||
---
|
||||
|
||||
Updated on December 2020.
|
||||
Updated on January 2022.
|
||||
@@ -661,7 +661,7 @@ Go programming language libraries:
|
||||
- [RAC](https://godoc.org/github.com/google/wuffs/lib/rac)
|
||||
- [RAC + Zlib](https://godoc.org/github.com/google/wuffs/lib/raczlib)
|
||||
|
||||
Command line tool, installable via `go get
|
||||
Command line tool, installable via `go install
|
||||
github.com/google/wuffs/cmd/ractool`:
|
||||
|
||||
- [ractool](https://godoc.org/github.com/google/wuffs/cmd/ractool)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -129,6 +130,8 @@ wuffs_base__frame_config g_frame_config = {0};
|
||||
int32_t g_fourcc = 0;
|
||||
uint32_t g_width = 0;
|
||||
uint32_t g_height = 0;
|
||||
uint32_t g_num_animation_loops = 0;
|
||||
uint64_t g_num_printed_frames = 0;
|
||||
|
||||
wuffs_base__image_decoder* g_image_decoder = NULL;
|
||||
union {
|
||||
@@ -136,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;
|
||||
|
||||
@@ -152,7 +156,7 @@ union {
|
||||
#endif
|
||||
|
||||
#ifndef WORKBUF_ARRAY_SIZE
|
||||
#define WORKBUF_ARRAY_SIZE (1024 * 1024)
|
||||
#define WORKBUF_ARRAY_SIZE (256 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef PIXBUF_ARRAY_SIZE
|
||||
@@ -244,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;
|
||||
@@ -298,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,
|
||||
@@ -466,6 +480,7 @@ print_nia_duration(wuffs_base__flicks duration) {
|
||||
|
||||
void //
|
||||
print_nie_frame() {
|
||||
g_num_printed_frames++;
|
||||
print_nix_header(0x45AFC36E); // "nïE" as a u32le.
|
||||
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
|
||||
if (tab.width == tab.stride) {
|
||||
@@ -490,30 +505,29 @@ print_nia_padding() {
|
||||
|
||||
void //
|
||||
print_nia_footer() {
|
||||
// For still (non-animated) images, the number of animation loops has no
|
||||
// practical effect: the pixels on screen do not change over time regardless
|
||||
// of its value. In the wire format encoding, there might be no explicit
|
||||
// "number of animation loops" value listed in the source bytes. Various
|
||||
// codec implementations may therefore choose an implicit default of 0 ("loop
|
||||
// forever") or 1 ("loop exactly once"). Either is equally valid.
|
||||
//
|
||||
// However, when comparing the output of this convert-to-NIA program (backed
|
||||
// by Wuffs' image codecs) with other convert-to-NIA programs, it is useful
|
||||
// to canonicalize still images' "number of animation loops" to 0.
|
||||
uint32_t n = g_num_animation_loops;
|
||||
if (g_num_printed_frames <= 1) {
|
||||
n = 0;
|
||||
}
|
||||
|
||||
uint8_t data[8];
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
data + 0x00,
|
||||
wuffs_base__image_decoder__num_animation_loops(g_image_decoder));
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x00, n);
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x04, 0x80000000);
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], 8));
|
||||
}
|
||||
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
g_src.data.ptr = g_src_buffer_array;
|
||||
g_src.data.len = SRC_BUFFER_ARRAY_SIZE;
|
||||
|
||||
TRY(load_image_type());
|
||||
TRY(load_image_config());
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nix_header(0x41AFC36E); // "nïA" as a u32le.
|
||||
}
|
||||
|
||||
convert_frames() {
|
||||
wuffs_base__flicks total_duration = 0;
|
||||
while (true) {
|
||||
// Decode the wuffs_base__frame_config.
|
||||
@@ -524,7 +538,7 @@ main1(int argc, char** argv) {
|
||||
if (dfc_status.repr == NULL) {
|
||||
break;
|
||||
} else if (dfc_status.repr == wuffs_base__note__end_of_data) {
|
||||
goto done;
|
||||
return NULL;
|
||||
} else if (dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return wuffs_base__status__message(&dfc_status);
|
||||
}
|
||||
@@ -539,9 +553,6 @@ main1(int argc, char** argv) {
|
||||
return "main: animation frame duration overflow";
|
||||
}
|
||||
total_duration += duration;
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_duration(total_duration);
|
||||
}
|
||||
|
||||
if (wuffs_base__frame_config__index(&g_frame_config) == 0) {
|
||||
fill_rectangle(
|
||||
@@ -562,6 +573,7 @@ main1(int argc, char** argv) {
|
||||
|
||||
// Decode the frame (the pixels).
|
||||
wuffs_base__status df_status;
|
||||
const char* decode_frame_io_error_message = NULL;
|
||||
while (true) {
|
||||
df_status = wuffs_base__image_decoder__decode_frame(
|
||||
g_image_decoder, &g_pixbuf, &g_src,
|
||||
@@ -572,18 +584,57 @@ main1(int argc, char** argv) {
|
||||
if (df_status.repr != wuffs_base__suspension__short_read) {
|
||||
break;
|
||||
}
|
||||
TRY(read_more_src());
|
||||
decode_frame_io_error_message = read_more_src();
|
||||
if (decode_frame_io_error_message != NULL) {
|
||||
// Neuter the "short read" df_status so that convert_frames returns the
|
||||
// I/O error message instead.
|
||||
df_status.repr = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
print_nie_frame();
|
||||
// Update g_num_animation_loops. It's rare in practice, but the animation
|
||||
// loop count can change over the course of decoding an image file.
|
||||
//
|
||||
// This program updates the global once per frame (even though the Wuffs
|
||||
// API also lets you call wuffs_base__image_decoder__num_animation_loops
|
||||
// just once, after the decoding is complete) to more closely match the
|
||||
// Chromium web browser. This program emits (via print_nia_footer) the
|
||||
// value from the final animation frame's update.
|
||||
//
|
||||
// Chromium image decoding uses two passes. (Wuffs' API lets you use a
|
||||
// single pass but Chromium also wraps other libraries). Its first pass
|
||||
// counts the number of animation frames (call it N). The second pass
|
||||
// decodes exactly N frames. In particular, if the animation loop count
|
||||
// would change between the end of frame N and the end of the file then
|
||||
// Chromium's design will not pick up that change, even if it's a valid
|
||||
// change in terms of the image file format.
|
||||
//
|
||||
// Specifically, for the test/data/artificial-gif/multiple-loop-counts.gif
|
||||
// file this program emits 31 (0x1F) to match Chromium, even though the
|
||||
// file arguably has a 41 (0x29) loop count after a complete decode.
|
||||
g_num_animation_loops =
|
||||
wuffs_base__image_decoder__num_animation_loops(g_image_decoder);
|
||||
|
||||
// Print a complete NIE frame (and surrounding bytes, for NIA).
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_duration(total_duration);
|
||||
}
|
||||
print_nie_frame();
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_padding();
|
||||
}
|
||||
|
||||
// Return early if there was an error decoding the frame.
|
||||
if (df_status.repr != NULL) {
|
||||
return wuffs_base__status__message(&df_status);
|
||||
} else if (decode_frame_io_error_message != NULL) {
|
||||
return decode_frame_io_error_message;
|
||||
} else if (g_flags.first_frame_only) {
|
||||
return NULL;
|
||||
}
|
||||
print_nia_padding();
|
||||
|
||||
// Dispose the frame.
|
||||
switch (wuffs_base__frame_config__disposal(&g_frame_config)) {
|
||||
case WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND: {
|
||||
fill_rectangle(
|
||||
@@ -601,10 +652,31 @@ main1(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return "main: unreachable";
|
||||
}
|
||||
|
||||
done:
|
||||
print_nia_footer();
|
||||
return NULL;
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
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";
|
||||
}
|
||||
|
||||
g_src.data.ptr = g_src_buffer_array;
|
||||
g_src.data.len = SRC_BUFFER_ARRAY_SIZE;
|
||||
|
||||
TRY(load_image_type());
|
||||
TRY(load_image_config());
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nix_header(0x41AFC36E); // "nïA" as a u32le.
|
||||
}
|
||||
const char* ret = convert_frames();
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_footer();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int //
|
||||
|
||||
@@ -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
|
||||
gzip: test/data/*.gz test/data/artificial/*.gz
|
||||
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 ../pngsuite_corpus/*.png
|
||||
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;
|
||||
|
||||
@@ -20,13 +20,14 @@ pointer. Anyway, here's what the output should look like:
|
||||
|
||||
```
|
||||
$ ./run.sh
|
||||
--- C Implementation Prints ---
|
||||
0
|
||||
12
|
||||
56789
|
||||
4294967295
|
||||
0
|
||||
3197704724
|
||||
--------
|
||||
------ Wuffs Impl Prints ------
|
||||
0
|
||||
12
|
||||
56789
|
||||
|
||||
@@ -12,67 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef USE_WUFFS
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
uint32_t ret = 0;
|
||||
for (size_t i = 0; (i < n) && p[i]; i++) {
|
||||
ret = (10 * ret) + (p[i] - '0');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else // #ifndef USE_WUFFS
|
||||
|
||||
// TODO: this 'rough edge' shouldn't be necessary. See
|
||||
// https://github.com/google/wuffs/issues/24
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
#include "./parse.c"
|
||||
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
wuffs_base__status status;
|
||||
wuffs_demo__parser* parser =
|
||||
(wuffs_demo__parser*)(malloc(sizeof__wuffs_demo__parser()));
|
||||
if (!parser) {
|
||||
printf("malloc failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = wuffs_demo__parser__initialize(parser, sizeof__wuffs_demo__parser(),
|
||||
WUFFS_VERSION, 0);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("initialize: %s\n", wuffs_base__status__message(&status));
|
||||
free(parser);
|
||||
return 0;
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer iobuf;
|
||||
iobuf.data.ptr = (uint8_t*)p;
|
||||
iobuf.data.len = n;
|
||||
iobuf.meta.wi = n;
|
||||
iobuf.meta.ri = 0;
|
||||
iobuf.meta.pos = 0;
|
||||
iobuf.meta.closed = true;
|
||||
|
||||
status = wuffs_demo__parser__parse(parser, &iobuf);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("parse: %s\n", wuffs_base__status__message(&status));
|
||||
free(parser);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t ret = wuffs_demo__parser__value(parser);
|
||||
free(parser);
|
||||
return ret;
|
||||
}
|
||||
#endif // #ifndef USE_WUFFS
|
||||
// See naive-parse.c and wuffs-parse.c for implementations of this function.
|
||||
uint32_t parse(char*, size_t);
|
||||
|
||||
void run(char* p) {
|
||||
size_t n = strlen(p) + 1; // +1 for the trailing NUL that ends a C string.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2019 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 <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
uint32_t ret = 0;
|
||||
for (size_t i = 0; (i < n) && p[i]; i++) {
|
||||
ret = (10 * ret) + (p[i] - '0');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -18,16 +18,14 @@
|
||||
CC=${CC:-gcc}
|
||||
|
||||
# You may need to run
|
||||
# go get github.com/google/wuffs/cmd/wuffs-c
|
||||
# go install github.com/google/wuffs/cmd/wuffs-c
|
||||
# beforehand, to install the wuffs-c compiler.
|
||||
wuffs-c gen -package_name demo < parse.wuffs > parse.c
|
||||
|
||||
$CC main.c
|
||||
./a.out
|
||||
echo --- C Implementation Prints ---
|
||||
$CC main.c naive-parse.c -o n.out
|
||||
./n.out
|
||||
|
||||
echo --------
|
||||
|
||||
$CC main.c -DUSE_WUFFS
|
||||
./a.out
|
||||
|
||||
rm a.out parse.c
|
||||
echo ------ Wuffs Impl Prints ------
|
||||
$CC main.c wuffs-parse.c -o w.out
|
||||
./w.out
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright 2019 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 <stdio.h>
|
||||
|
||||
// TODO: this 'rough edge' shouldn't be necessary. See
|
||||
// https://github.com/google/wuffs/issues/24
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
#include "./parse.c"
|
||||
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
wuffs_base__status status;
|
||||
|
||||
// This next line of code allocates a wuffs_demo__parser on the stack. Stack
|
||||
// allocation in C means uninitialized memory, so we need to call
|
||||
// wuffs_demo__parser__initialize afterwards.
|
||||
//
|
||||
// An alternative, allocating on the heap and initializing in a single
|
||||
// function call, is to say:
|
||||
//
|
||||
// wuffs_demo__parser* parser = wuffs_demo__parser__alloc();
|
||||
// if (!parser) {
|
||||
// // Out of memory.
|
||||
// return 0;
|
||||
// }
|
||||
// // No need to call wuffs_demo__parser__initialize, but don't forget to
|
||||
// // free(parser) before this function returns, taking extra care if this
|
||||
// // function has multiple return points. Wuffs has no destructor functions
|
||||
// // and Wuffs types never hold or own any resources in the RAII sense.
|
||||
// // Just free the memory.
|
||||
//
|
||||
// For stack allocation, the C compiler needs to know
|
||||
// sizeof(wuffs_demo__parser), but that compile-time value isn't guaranteed
|
||||
// to be stable across Wuffs versions. Stack allocation is therefore only
|
||||
// valid when the C file also #define's WUFFS_IMPLEMENTATION. When linking
|
||||
// against a separately built Wuffs library (and the Wuffs types in this
|
||||
// compilation are incomplete types), you'll have to use heap allocation.
|
||||
wuffs_demo__parser parser;
|
||||
|
||||
// Initialize (and check status). An error here means that bad arguments were
|
||||
// passed to wuffs_demo__parser__initialize.
|
||||
//
|
||||
// There are two other categories of not-OK status values, notes and
|
||||
// suspensions, but they won't be encountered in this example.
|
||||
status = wuffs_demo__parser__initialize(&parser, sizeof__wuffs_demo__parser(),
|
||||
WUFFS_VERSION, 0);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("initialize: %s\n", wuffs_base__status__message(&status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// True means that the wuffs_base__io_buffer is closed - we are at the end of
|
||||
// the input. False would mean that there might be additional data in the
|
||||
// byte stream (that this buffer is not large enough to hold all at once).
|
||||
//
|
||||
// In general, Wuffs' coroutine and suspension status mechanisms let it parse
|
||||
// arbitrarily large data streams using fixed sized buffers, but that won't
|
||||
// be encountered in this example.
|
||||
wuffs_base__io_buffer iobuf =
|
||||
wuffs_base__ptr_u8__reader((uint8_t*)p, n, true);
|
||||
|
||||
// Parse (and check status). An error here means that we had invalid input
|
||||
// (i.e. "#not a digit" or "#too large").
|
||||
//
|
||||
// There are two other categories of not-OK status values, notes and
|
||||
// suspensions, but they won't be encountered in this example.
|
||||
status = wuffs_demo__parser__parse(&parser, &iobuf);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("parse: %s\n", wuffs_base__status__message(&status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return wuffs_demo__parser__value(&parser);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -371,6 +384,10 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
|
||||
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) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
|
||||
}
|
||||
@@ -378,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);
|
||||
}
|
||||
}
|
||||
@@ -418,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();
|
||||
@@ -479,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) {
|
||||
@@ -520,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
|
||||
@@ -209,8 +216,8 @@ struct DecodeImageArgFlags {
|
||||
// DefaultValue returns 0.
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
|
||||
// GAMA, ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
|
||||
@@ -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);
|
||||
@@ -160,7 +160,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -168,7 +168,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
return 0;
|
||||
}
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
if ((size_t)(p - io1_w) < (size_t)(distance)) {
|
||||
if ((size_t)(p - io0_w) < (size_t)(distance)) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t* q = p - distance;
|
||||
@@ -205,10 +205,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -240,11 +240,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -280,11 +280,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
|
||||
@@ -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,21 +150,26 @@ 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)
|
||||
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||
{-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;
|
||||
@@ -63,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)) {
|
||||
@@ -75,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:
|
||||
@@ -83,31 +216,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 16) {
|
||||
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
|
||||
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
|
||||
if (y == 0x56503820) { // 'VP8 'be
|
||||
return 0x57503820; // 'WP8 'be
|
||||
} else if (y == 0x5650384C) { // 'VP8L'be
|
||||
return 0x5750384C; // 'WP8L'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;
|
||||
}
|
||||
|
||||
@@ -501,14 +501,23 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -545,14 +554,23 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -583,14 +601,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -627,14 +645,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -665,14 +683,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -697,14 +715,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_premul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_premul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_premul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_premul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint64_t ia = 0xFFFF - sa;
|
||||
@@ -723,14 +741,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1790,13 +1808,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1838,13 +1856,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
|
||||
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
|
||||
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
|
||||
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1913,13 +1931,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1991,13 +2009,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -2066,13 +2084,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -66,6 +66,7 @@ var FourCCs = [...][2]string{
|
||||
{"PNG ", "Portable Network Graphics"},
|
||||
{"PNM ", "Portable Anymap"},
|
||||
{"PS ", "PostScript"},
|
||||
{"QOI ", "Quite OK Image"},
|
||||
{"RAC ", "Random Access Compression"},
|
||||
{"RAW ", "Raw"},
|
||||
{"RIFF", "Resource Interchange File Format"},
|
||||
@@ -75,13 +76,13 @@ 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"},
|
||||
{"WBMP", "Wireless Bitmap"},
|
||||
{"WEBP", "Web Picture"},
|
||||
{"WOFF", "Web Open Font Format"},
|
||||
{"WP8 ", "Web Picture (VP8)"},
|
||||
{"WP8L", "Web Picture (VP8 Lossless)"},
|
||||
{"XML ", "Extensible Markup Language"},
|
||||
{"XMP ", "Extensible Metadata Platform"},
|
||||
{"XZ ", "Xz"},
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// 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 ExampleRoundTrip() {
|
||||
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 > 0 {
|
||||
fmt.Printf(" ")
|
||||
}
|
||||
fmt.Printf("%02X", c)
|
||||
}
|
||||
fmt.Printf("\n%s\n", 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.
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
// 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, a
|
||||
// subset of the LZMA compressed file format.
|
||||
//
|
||||
// Subset means that the Encode method's output is a valid LZMA file and can be
|
||||
// decompressed by the tools available at https://www.7-zip.org/sdk.html (and
|
||||
// available as /usr/bin/lzma on a Debian system).
|
||||
//
|
||||
// Subset also means that this codec's compression ratios are not as good as
|
||||
// full-LZMA (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, is that this
|
||||
// implementation is much simpler and hence easier to study. It is only a few
|
||||
// hundred 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.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.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"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnsupportedLZMAData is potentially returned by Decode.
|
||||
ErrUnsupportedLZMAData = errors.New("litonlylzma: unsupported LZMA data")
|
||||
|
||||
errInvalidLZMAData = errors.New("litonlylzma: invalid LZMA 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 the LZMA header 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. 0x1000 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"
|
||||
|
||||
// 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 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).
|
||||
//
|
||||
// This package currently defines only one valid FileFormatXxx value:
|
||||
// FileFormatLZMA. Future versions of this package could define e.g.
|
||||
// FileFormatLZMA2 or FileFormatXz such that FileFormatXz.Encode would produce
|
||||
// valid full-XZ data: a valid XZ file (that could be decoded by official XZ
|
||||
// tools) that used the LZMA compression filter, but elected not to use the
|
||||
// full capabilities of that filter (using LZ literals only, not matches).
|
||||
type FileFormat uint32
|
||||
|
||||
const (
|
||||
FileFormatInvalid = FileFormat(0)
|
||||
FileFormatLZMA = FileFormat(1)
|
||||
)
|
||||
|
||||
// Decode converts src from the Literal Only LZMA compressed file format,
|
||||
// appending the decoding to dst.
|
||||
//
|
||||
// f should be FileFormatLZMA but future versions of this package may support
|
||||
// other file formats.
|
||||
//
|
||||
// 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 ErrUnsupportedLZMAData if the source bytes look like LZMA
|
||||
// formatted data that is outside the subset-of-LZMA that this package
|
||||
// implements.
|
||||
func (f FileFormat) Decode(dst []byte, src []byte) (appendedDst []byte, remainingSrc []byte, retErr error) {
|
||||
if f != FileFormatLZMA {
|
||||
return dst, nil, errUnsupportedFileFormat
|
||||
}
|
||||
|
||||
// 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 (src[0] != lzmaHeader5[0]) ||
|
||||
(src[1] != lzmaHeader5[1]) ||
|
||||
(src[2] != lzmaHeader5[2]) ||
|
||||
(src[3] != lzmaHeader5[3]) ||
|
||||
(src[4] != lzmaHeader5[4]) ||
|
||||
(src[13] != 0x00) {
|
||||
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
|
||||
}
|
||||
|
||||
rDec := rangeDecoder{
|
||||
src: src[18:],
|
||||
bits: (uint32(src[14]) << 24) |
|
||||
(uint32(src[15]) << 16) |
|
||||
(uint32(src[16]) << 8) |
|
||||
(uint32(src[17]) << 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, nil, 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, ErrUnsupportedLZMAData
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Encode converts src to the Literal Only LZMA compressed file format,
|
||||
// appending the encoding to dst.
|
||||
//
|
||||
// f should be FileFormatLZMA but future versions of this package may support
|
||||
// other file formats.
|
||||
//
|
||||
// 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) {
|
||||
if f != FileFormatLZMA {
|
||||
return nil, errUnsupportedFileFormat
|
||||
}
|
||||
|
||||
dst = append(dst, lzmaHeader5...)
|
||||
size := len(src)
|
||||
for i := 0; i < 8; i++ {
|
||||
dst = append(dst, byte(size))
|
||||
size >>= 8
|
||||
}
|
||||
|
||||
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, nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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
|
||||
}
|
||||
|
||||
compressed, err := FileFormatLZMA.Encode(nil, original)
|
||||
if err != nil {
|
||||
tt.Fatalf("Encode: %v", err)
|
||||
}
|
||||
recovered, _, err := FileFormatLZMA.Decode(nil, compressed)
|
||||
if err != nil {
|
||||
tt.Fatalf("Decode: %v", err)
|
||||
}
|
||||
if !bytes.Equal(original, recovered) {
|
||||
tt.Fatalf("round trip produced different bytes")
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -686,6 +686,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// PostScript.
|
||||
#define WUFFS_BASE__FOURCC__PS 0x50532020
|
||||
|
||||
// Quite OK Image.
|
||||
#define WUFFS_BASE__FOURCC__QOI 0x514F4920
|
||||
|
||||
// Random Access Compression.
|
||||
#define WUFFS_BASE__FOURCC__RAC 0x52414320
|
||||
|
||||
@@ -713,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
|
||||
|
||||
@@ -725,15 +731,12 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Wireless Bitmap.
|
||||
#define WUFFS_BASE__FOURCC__WBMP 0x57424D50
|
||||
|
||||
// Web Picture.
|
||||
#define WUFFS_BASE__FOURCC__WEBP 0x57454250
|
||||
|
||||
// Web Open Font Format.
|
||||
#define WUFFS_BASE__FOURCC__WOFF 0x574F4646
|
||||
|
||||
// Web Picture (VP8).
|
||||
#define WUFFS_BASE__FOURCC__WP8 0x57503820
|
||||
|
||||
// Web Picture (VP8 Lossless).
|
||||
#define WUFFS_BASE__FOURCC__WP8L 0x5750384C
|
||||
|
||||
// Extensible Markup Language.
|
||||
#define WUFFS_BASE__FOURCC__XML 0x584D4C20
|
||||
|
||||
@@ -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,8 +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;
|
||||
uint32_t v_hdist;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -7869,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;
|
||||
@@ -7969,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;
|
||||
@@ -8510,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
|
||||
@@ -8931,6 +9280,8 @@ extern const char wuffs_zlib__error__incorrect_dictionary[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
@@ -9042,6 +9393,7 @@ struct wuffs_zlib__decoder__struct {
|
||||
bool f_header_complete;
|
||||
bool f_got_dictionary;
|
||||
bool f_want_dictionary;
|
||||
bool f_quirks[1];
|
||||
bool f_ignore_checksum;
|
||||
uint32_t f_dict_id_got;
|
||||
uint32_t f_dict_id_want;
|
||||
@@ -9167,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
|
||||
|
||||
@@ -9330,6 +9683,7 @@ struct wuffs_png__decoder__struct {
|
||||
uint64_t f_pass_workbuf_length;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_report_metadata_chrm;
|
||||
bool f_report_metadata_exif;
|
||||
bool f_report_metadata_gama;
|
||||
bool f_report_metadata_iccp;
|
||||
bool f_report_metadata_kvp;
|
||||
@@ -9342,9 +9696,11 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_actl;
|
||||
bool f_seen_chrm;
|
||||
bool f_seen_fctl;
|
||||
bool f_seen_exif;
|
||||
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;
|
||||
@@ -9626,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
|
||||
@@ -10231,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
|
||||
@@ -10248,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
|
||||
@@ -10370,8 +11078,8 @@ struct DecodeImageArgFlags {
|
||||
// DefaultValue returns 0.
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
|
||||
// GAMA, ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
@@ -11036,7 +11744,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11044,7 +11752,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
return 0;
|
||||
}
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
if ((size_t)(p - io1_w) < (size_t)(distance)) {
|
||||
if ((size_t)(p - io0_w) < (size_t)(distance)) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t* q = p - distance;
|
||||
@@ -11081,10 +11789,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11116,11 +11824,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11156,11 +11864,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -15568,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).
|
||||
@@ -15584,21 +16412,26 @@ 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)
|
||||
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||
{-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;
|
||||
@@ -15617,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)) {
|
||||
@@ -15629,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:
|
||||
@@ -15637,31 +16478,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 16) {
|
||||
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
|
||||
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
|
||||
if (y == 0x56503820) { // 'VP8 'be
|
||||
return 0x57503820; // 'WP8 'be
|
||||
} else if (y == 0x5650384C) { // 'VP8L'be
|
||||
return 0x5750384C; // 'WP8L'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;
|
||||
}
|
||||
@@ -16165,14 +17013,23 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16209,14 +17066,23 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16247,14 +17113,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16291,14 +17157,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16329,14 +17195,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -16361,14 +17227,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_premul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_premul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_premul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_premul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint64_t ia = 0xFFFF - sa;
|
||||
@@ -16387,14 +17253,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17454,13 +18320,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17502,13 +18368,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
|
||||
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
|
||||
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
|
||||
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17577,13 +18443,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17655,13 +18521,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17730,13 +18596,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -22693,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;
|
||||
@@ -22760,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));
|
||||
}
|
||||
@@ -22772,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 {
|
||||
@@ -22801,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;
|
||||
@@ -22870,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));
|
||||
}
|
||||
@@ -22888,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;
|
||||
@@ -22913,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);
|
||||
@@ -22988,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;
|
||||
@@ -22999,7 +23863,6 @@ 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:
|
||||
@@ -23051,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) {
|
||||
@@ -23158,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:;
|
||||
@@ -23213,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;
|
||||
@@ -23269,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);
|
||||
}
|
||||
@@ -23420,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) {
|
||||
@@ -23493,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;
|
||||
@@ -23556,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) {
|
||||
@@ -23662,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;
|
||||
@@ -23732,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;
|
||||
@@ -23751,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;
|
||||
@@ -23774,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);
|
||||
}
|
||||
@@ -24046,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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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
|
||||
@@ -24258,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;
|
||||
}
|
||||
@@ -24347,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);
|
||||
@@ -24769,7 +27179,6 @@ 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;
|
||||
|
||||
@@ -26193,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);
|
||||
@@ -26206,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();
|
||||
}
|
||||
|
||||
@@ -26710,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;
|
||||
@@ -26910,7 +29318,6 @@ 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;
|
||||
@@ -26990,14 +29397,17 @@ wuffs_deflate__decoder__init_huff(
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_remaining != 0) {
|
||||
if ((a_which == 1) &&
|
||||
(v_counts[1] == 1) &&
|
||||
(self->private_data.f_code_lengths[a_n_codes0] == 1) &&
|
||||
((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[0] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
if ((a_which == 1) && (v_counts[1] == 1) && ((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
v_i = 0;
|
||||
while (v_i <= 29) {
|
||||
if (self->private_data.f_code_lengths[(a_n_codes0 + v_i)] == 1) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[v_i] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
@@ -27335,9 +29745,8 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
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), (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;
|
||||
}
|
||||
@@ -27601,9 +30010,8 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
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), (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;
|
||||
}
|
||||
@@ -27814,9 +30222,8 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
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), (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;
|
||||
}
|
||||
@@ -27928,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;
|
||||
@@ -27936,8 +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;
|
||||
v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28134,55 +30538,29 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
|
||||
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
|
||||
if (v_length > v_hdist) {
|
||||
v_length -= v_hdist;
|
||||
if (v_hdist < v_length) {
|
||||
v_hlen = v_hdist;
|
||||
} else {
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
while (true) {
|
||||
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, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__4__break;
|
||||
}
|
||||
if (v_n_copied > 0) {
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist = (((uint32_t)(v_hdist + v_n_copied)) & 32767);
|
||||
if (v_hdist == 0) {
|
||||
goto label__4__break;
|
||||
}
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&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);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__inner__continue;
|
||||
}
|
||||
label__4__break:;
|
||||
if (v_hlen > 0) {
|
||||
while (true) {
|
||||
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, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__5__break;
|
||||
}
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist += v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__5__break:;
|
||||
}
|
||||
v_length -= v_hlen;
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28190,14 +30568,12 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_history(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
goto label__6__break;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__6__break:;
|
||||
}
|
||||
label__loop__break:;
|
||||
self->private_impl.f_bits = v_bits;
|
||||
@@ -28217,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;
|
||||
@@ -28225,8 +30600,6 @@ 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;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -28705,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);
|
||||
@@ -28754,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);
|
||||
}
|
||||
@@ -29067,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) {
|
||||
@@ -29078,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);
|
||||
@@ -29110,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:
|
||||
@@ -29199,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;
|
||||
}
|
||||
@@ -29270,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);
|
||||
@@ -29314,7 +31688,10 @@ wuffs_gif__decoder__num_animation_loops(
|
||||
if (self->private_impl.f_seen_num_animation_loops_value) {
|
||||
return self->private_impl.f_num_animation_loops_value;
|
||||
}
|
||||
return 1;
|
||||
if (self->private_impl.f_num_decoded_frame_configs_value > 1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func gif.decoder.num_decoded_frame_configs
|
||||
@@ -29402,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);
|
||||
}
|
||||
|
||||
@@ -29464,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;
|
||||
@@ -29541,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;
|
||||
@@ -29642,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:
|
||||
@@ -29697,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);
|
||||
@@ -29721,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;
|
||||
@@ -29746,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;
|
||||
@@ -29779,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) {
|
||||
{
|
||||
@@ -29833,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;
|
||||
}
|
||||
}
|
||||
@@ -30465,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;
|
||||
}
|
||||
@@ -30790,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);
|
||||
}
|
||||
@@ -31027,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;
|
||||
@@ -31064,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) {
|
||||
@@ -31096,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);
|
||||
@@ -31152,6 +33537,30 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto label__outer__continue;
|
||||
} else if (v_lzw_status.repr == wuffs_base__suspension__short_write) {
|
||||
goto label__inner__continue;
|
||||
} else if (self->private_impl.f_quirks[3] && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) && (self->private_impl.f_interlace == 0)) {
|
||||
if (v_need_block_size || (v_block_size > 0)) {
|
||||
self->private_data.s_decode_id_part2[0].scratch = ((uint32_t)(v_block_size));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (self->private_data.s_decode_id_part2[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_id_part2[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_id_part2[0].scratch;
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_gif__decoder__skip_blocks(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
goto label__outer__break;
|
||||
}
|
||||
status = v_lzw_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
@@ -31181,7 +33590,6 @@ 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:
|
||||
@@ -32373,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);
|
||||
@@ -32435,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) {
|
||||
@@ -32499,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)));
|
||||
@@ -32529,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);
|
||||
@@ -32573,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);
|
||||
@@ -32631,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);
|
||||
@@ -32686,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);
|
||||
@@ -32737,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)));
|
||||
@@ -32782,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)));
|
||||
@@ -32829,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);
|
||||
@@ -33620,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33777,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;
|
||||
|
||||
@@ -33887,7 +36273,6 @@ 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:
|
||||
@@ -33951,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);
|
||||
@@ -33976,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);
|
||||
@@ -33999,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;
|
||||
}
|
||||
@@ -34012,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;
|
||||
@@ -34387,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:
|
||||
@@ -34455,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));
|
||||
}
|
||||
@@ -34467,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 {
|
||||
@@ -34496,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;
|
||||
@@ -34557,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;
|
||||
@@ -34604,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;
|
||||
@@ -34754,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;
|
||||
@@ -34773,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;
|
||||
@@ -34796,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);
|
||||
}
|
||||
|
||||
@@ -34889,6 +37269,10 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_COUNT 1
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
@@ -35052,8 +37436,15 @@ wuffs_zlib__decoder__set_quirk_enabled(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
if (a_quirk == 1) {
|
||||
if (self->private_impl.f_header_complete) {
|
||||
self->private_impl.f_bad_call_sequence = true;
|
||||
} else if (a_quirk == 1) {
|
||||
self->private_impl.f_ignore_checksum = a_enabled;
|
||||
} else if (a_quirk >= 2113790976) {
|
||||
a_quirk -= 2113790976;
|
||||
if (a_quirk < 1) {
|
||||
self->private_impl.f_quirks[a_quirk] = a_enabled;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
@@ -35143,6 +37534,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
if (self->private_impl.f_bad_call_sequence) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_quirks[0]) {
|
||||
} else if ( ! self->private_impl.f_want_dictionary) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
@@ -35250,7 +37642,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum) {
|
||||
if ( ! self->private_impl.f_ignore_checksum && ! self->private_impl.f_quirks[0]) {
|
||||
v_checksum_got = wuffs_adler32__hasher__update_u32(&self->private_data.f_checksum, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
@@ -35260,38 +37652,40 @@ wuffs_zlib__decoder__transform_io(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
label__0__break:;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[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;
|
||||
if ( ! self->private_impl.f_quirks[0]) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[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_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ok:
|
||||
@@ -35333,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";
|
||||
@@ -35578,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(
|
||||
@@ -35590,6 +37986,11 @@ wuffs_png__decoder__decode_chrm(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_fctl(
|
||||
wuffs_png__decoder* self,
|
||||
@@ -37249,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;
|
||||
@@ -37322,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;
|
||||
}
|
||||
@@ -37387,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) {
|
||||
@@ -37427,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;
|
||||
@@ -37444,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;
|
||||
}
|
||||
@@ -37509,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;
|
||||
@@ -37761,8 +40165,13 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_filter_distance = 1;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
if (self->private_impl.f_interlace_pass == 0) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
} else {
|
||||
self->private_impl.f_dst_pixfmt = 2164308923;
|
||||
self->private_impl.f_src_pixfmt = 2164308923;
|
||||
}
|
||||
self->private_impl.f_filter_distance = 2;
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 2) {
|
||||
@@ -37884,7 +40293,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) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -37902,21 +40312,26 @@ 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_seen_plte || (self->private_impl.f_color_type != 3)) {
|
||||
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;
|
||||
} else if (self->private_impl.f_color_type == 3) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_png__decoder__decode_plte(self, 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_color_type == 2) || (self->private_impl.f_color_type == 6)) {
|
||||
} else {
|
||||
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(1);
|
||||
status = wuffs_png__decoder__decode_plte(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_plte = true;
|
||||
} else if ((self->private_impl.f_chunk_type & 32) == 0) {
|
||||
@@ -37924,133 +40339,26 @@ 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) {
|
||||
}
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
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(4);
|
||||
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(5);
|
||||
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(6);
|
||||
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(7);
|
||||
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(8);
|
||||
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;
|
||||
@@ -38059,10 +40367,139 @@ 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;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -38501,6 +40938,47 @@ wuffs_png__decoder__decode_chrm(
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_exif
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_chunk_length < 4) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_flavor = 3;
|
||||
self->private_impl.f_metadata_fourcc = 1163413830;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
self->private_impl.f_chunk_length = 0;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_fctl
|
||||
|
||||
static wuffs_base__status
|
||||
@@ -39385,6 +41863,8 @@ 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;
|
||||
@@ -39400,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));
|
||||
}
|
||||
@@ -39415,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));
|
||||
}
|
||||
@@ -39432,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;
|
||||
@@ -39506,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) {
|
||||
@@ -39514,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;
|
||||
@@ -39523,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;
|
||||
@@ -39533,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;
|
||||
@@ -39563,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;
|
||||
@@ -39719,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;
|
||||
@@ -39794,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));
|
||||
}
|
||||
@@ -39934,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;
|
||||
@@ -39959,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
|
||||
@@ -39970,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;
|
||||
@@ -40424,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;
|
||||
}
|
||||
@@ -40455,6 +43009,8 @@ wuffs_png__decoder__set_report_metadata(
|
||||
|
||||
if (a_fourcc == 1128813133) {
|
||||
self->private_impl.f_report_metadata_chrm = a_report;
|
||||
} else if (a_fourcc == 1163413830) {
|
||||
self->private_impl.f_report_metadata_exif = a_report;
|
||||
} else if (a_fourcc == 1195461953) {
|
||||
self->private_impl.f_report_metadata_gama = a_report;
|
||||
} else if (a_fourcc == 1229144912) {
|
||||
@@ -40540,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;
|
||||
}
|
||||
@@ -40548,396 +43104,419 @@ wuffs_png__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
while (true) {
|
||||
if (self->private_impl.f_metadata_flavor == 3) {
|
||||
while (true) {
|
||||
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
} else if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) {
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
self->private_impl.f_metadata_y = self->private_impl.f_metadata_z;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
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);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
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);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} 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(7);
|
||||
goto label__loop__continue;
|
||||
} else 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(8);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} 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__loop__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
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_c2 = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
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(4);
|
||||
v_c2 = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
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 == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
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;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
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_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} 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(6);
|
||||
goto label__loop__continue;
|
||||
} else 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(7);
|
||||
goto label__loop__continue;
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
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;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} 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(8);
|
||||
goto label__loop__continue;
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
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(9);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
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(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
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 == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
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;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
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;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
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_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[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_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
label__goto_done__break:;
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[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_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
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 &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
@@ -41348,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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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
|
||||
@@ -41593,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:
|
||||
@@ -41663,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));
|
||||
}
|
||||
@@ -41675,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 {
|
||||
@@ -41704,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;
|
||||
@@ -41793,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));
|
||||
}
|
||||
@@ -41805,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;
|
||||
@@ -41868,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;
|
||||
@@ -41946,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;
|
||||
@@ -41965,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;
|
||||
@@ -41988,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);
|
||||
}
|
||||
@@ -42794,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:
|
||||
@@ -42820,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();
|
||||
@@ -43040,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:
|
||||
@@ -43047,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;
|
||||
@@ -43091,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);
|
||||
}
|
||||
@@ -43107,6 +46935,10 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
|
||||
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) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
|
||||
}
|
||||
@@ -43114,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);
|
||||
}
|
||||
}
|
||||
@@ -43154,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();
|
||||
@@ -43215,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) {
|
||||
@@ -43256,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
|
||||
// 161e4730d8b446a72d6152b8343da8543e7518bf committed on 2021-11-18.
|
||||
// fac934b27259f37191285a8d9d1d9629ed2d9f5d committed on 2022-06-29.
|
||||
#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.11"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3198
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20211118
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.11+3198.20211118"
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "rc.1"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3360
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20220629
|
||||
#define WUFFS_VERSION_STRING "0.3.0-rc.1+3360.20220629"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -687,6 +687,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// PostScript.
|
||||
#define WUFFS_BASE__FOURCC__PS 0x50532020
|
||||
|
||||
// Quite OK Image.
|
||||
#define WUFFS_BASE__FOURCC__QOI 0x514F4920
|
||||
|
||||
// Random Access Compression.
|
||||
#define WUFFS_BASE__FOURCC__RAC 0x52414320
|
||||
|
||||
@@ -714,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
|
||||
|
||||
@@ -726,15 +732,12 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Wireless Bitmap.
|
||||
#define WUFFS_BASE__FOURCC__WBMP 0x57424D50
|
||||
|
||||
// Web Picture.
|
||||
#define WUFFS_BASE__FOURCC__WEBP 0x57454250
|
||||
|
||||
// Web Open Font Format.
|
||||
#define WUFFS_BASE__FOURCC__WOFF 0x574F4646
|
||||
|
||||
// Web Picture (VP8).
|
||||
#define WUFFS_BASE__FOURCC__WP8 0x57503820
|
||||
|
||||
// Web Picture (VP8 Lossless).
|
||||
#define WUFFS_BASE__FOURCC__WP8L 0x5750384C
|
||||
|
||||
// Extensible Markup Language.
|
||||
#define WUFFS_BASE__FOURCC__XML 0x584D4C20
|
||||
|
||||
@@ -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,8 +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;
|
||||
uint32_t v_hdist;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -7870,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;
|
||||
@@ -7970,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;
|
||||
@@ -8511,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
|
||||
@@ -8932,6 +9281,8 @@ extern const char wuffs_zlib__error__incorrect_dictionary[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
@@ -9043,6 +9394,7 @@ struct wuffs_zlib__decoder__struct {
|
||||
bool f_header_complete;
|
||||
bool f_got_dictionary;
|
||||
bool f_want_dictionary;
|
||||
bool f_quirks[1];
|
||||
bool f_ignore_checksum;
|
||||
uint32_t f_dict_id_got;
|
||||
uint32_t f_dict_id_want;
|
||||
@@ -9168,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
|
||||
|
||||
@@ -9331,6 +9684,7 @@ struct wuffs_png__decoder__struct {
|
||||
uint64_t f_pass_workbuf_length;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_report_metadata_chrm;
|
||||
bool f_report_metadata_exif;
|
||||
bool f_report_metadata_gama;
|
||||
bool f_report_metadata_iccp;
|
||||
bool f_report_metadata_kvp;
|
||||
@@ -9343,9 +9697,11 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_actl;
|
||||
bool f_seen_chrm;
|
||||
bool f_seen_fctl;
|
||||
bool f_seen_exif;
|
||||
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;
|
||||
@@ -9627,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
|
||||
@@ -10232,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
|
||||
@@ -10249,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
|
||||
@@ -10371,8 +11079,8 @@ struct DecodeImageArgFlags {
|
||||
// DefaultValue returns 0.
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
|
||||
// GAMA, ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
@@ -11037,7 +11745,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11045,7 +11753,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
return 0;
|
||||
}
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
if ((size_t)(p - io1_w) < (size_t)(distance)) {
|
||||
if ((size_t)(p - io0_w) < (size_t)(distance)) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t* q = p - distance;
|
||||
@@ -11082,10 +11790,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11117,11 +11825,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11157,11 +11865,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -15569,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).
|
||||
@@ -15585,21 +16413,26 @@ 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)
|
||||
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||
{-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;
|
||||
@@ -15618,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)) {
|
||||
@@ -15630,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:
|
||||
@@ -15638,31 +16479,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 16) {
|
||||
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
|
||||
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
|
||||
if (y == 0x56503820) { // 'VP8 'be
|
||||
return 0x57503820; // 'WP8 'be
|
||||
} else if (y == 0x5650384C) { // 'VP8L'be
|
||||
return 0x5750384C; // 'WP8L'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;
|
||||
}
|
||||
@@ -16166,14 +17014,23 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16210,14 +17067,23 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16248,14 +17114,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16292,14 +17158,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16330,14 +17196,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -16362,14 +17228,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_premul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_premul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_premul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_premul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint64_t ia = 0xFFFF - sa;
|
||||
@@ -16388,14 +17254,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17455,13 +18321,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17503,13 +18369,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
|
||||
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
|
||||
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
|
||||
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17578,13 +18444,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17656,13 +18522,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17731,13 +18597,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -22694,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;
|
||||
@@ -22761,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));
|
||||
}
|
||||
@@ -22773,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 {
|
||||
@@ -22802,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;
|
||||
@@ -22871,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));
|
||||
}
|
||||
@@ -22889,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;
|
||||
@@ -22914,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);
|
||||
@@ -22989,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;
|
||||
@@ -23000,7 +23864,6 @@ 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:
|
||||
@@ -23052,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) {
|
||||
@@ -23159,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:;
|
||||
@@ -23214,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;
|
||||
@@ -23270,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);
|
||||
}
|
||||
@@ -23421,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) {
|
||||
@@ -23494,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;
|
||||
@@ -23557,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) {
|
||||
@@ -23663,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;
|
||||
@@ -23733,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;
|
||||
@@ -23752,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;
|
||||
@@ -23775,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);
|
||||
}
|
||||
@@ -24047,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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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
|
||||
@@ -24259,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;
|
||||
}
|
||||
@@ -24348,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);
|
||||
@@ -24770,7 +27180,6 @@ 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;
|
||||
|
||||
@@ -26194,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);
|
||||
@@ -26207,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();
|
||||
}
|
||||
|
||||
@@ -26711,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;
|
||||
@@ -26911,7 +29319,6 @@ 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;
|
||||
@@ -26991,14 +29398,17 @@ wuffs_deflate__decoder__init_huff(
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_remaining != 0) {
|
||||
if ((a_which == 1) &&
|
||||
(v_counts[1] == 1) &&
|
||||
(self->private_data.f_code_lengths[a_n_codes0] == 1) &&
|
||||
((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[0] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
if ((a_which == 1) && (v_counts[1] == 1) && ((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
v_i = 0;
|
||||
while (v_i <= 29) {
|
||||
if (self->private_data.f_code_lengths[(a_n_codes0 + v_i)] == 1) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[v_i] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
@@ -27336,9 +29746,8 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
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), (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;
|
||||
}
|
||||
@@ -27602,9 +30011,8 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
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), (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;
|
||||
}
|
||||
@@ -27815,9 +30223,8 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
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), (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;
|
||||
}
|
||||
@@ -27929,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;
|
||||
@@ -27937,8 +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;
|
||||
v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28135,55 +30539,29 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
|
||||
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
|
||||
if (v_length > v_hdist) {
|
||||
v_length -= v_hdist;
|
||||
if (v_hdist < v_length) {
|
||||
v_hlen = v_hdist;
|
||||
} else {
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
while (true) {
|
||||
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, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__4__break;
|
||||
}
|
||||
if (v_n_copied > 0) {
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist = (((uint32_t)(v_hdist + v_n_copied)) & 32767);
|
||||
if (v_hdist == 0) {
|
||||
goto label__4__break;
|
||||
}
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&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);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__inner__continue;
|
||||
}
|
||||
label__4__break:;
|
||||
if (v_hlen > 0) {
|
||||
while (true) {
|
||||
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, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__5__break;
|
||||
}
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist += v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__5__break:;
|
||||
}
|
||||
v_length -= v_hlen;
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28191,14 +30569,12 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_history(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
goto label__6__break;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__6__break:;
|
||||
}
|
||||
label__loop__break:;
|
||||
self->private_impl.f_bits = v_bits;
|
||||
@@ -28218,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;
|
||||
@@ -28226,8 +30601,6 @@ 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;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -28706,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);
|
||||
@@ -28755,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);
|
||||
}
|
||||
@@ -29068,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) {
|
||||
@@ -29079,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);
|
||||
@@ -29111,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:
|
||||
@@ -29200,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;
|
||||
}
|
||||
@@ -29271,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);
|
||||
@@ -29315,7 +31689,10 @@ wuffs_gif__decoder__num_animation_loops(
|
||||
if (self->private_impl.f_seen_num_animation_loops_value) {
|
||||
return self->private_impl.f_num_animation_loops_value;
|
||||
}
|
||||
return 1;
|
||||
if (self->private_impl.f_num_decoded_frame_configs_value > 1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func gif.decoder.num_decoded_frame_configs
|
||||
@@ -29403,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);
|
||||
}
|
||||
|
||||
@@ -29465,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;
|
||||
@@ -29542,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;
|
||||
@@ -29643,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:
|
||||
@@ -29698,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);
|
||||
@@ -29722,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;
|
||||
@@ -29747,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;
|
||||
@@ -29780,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) {
|
||||
{
|
||||
@@ -29834,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;
|
||||
}
|
||||
}
|
||||
@@ -30466,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;
|
||||
}
|
||||
@@ -30791,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);
|
||||
}
|
||||
@@ -31028,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;
|
||||
@@ -31065,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) {
|
||||
@@ -31097,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);
|
||||
@@ -31153,6 +33538,30 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto label__outer__continue;
|
||||
} else if (v_lzw_status.repr == wuffs_base__suspension__short_write) {
|
||||
goto label__inner__continue;
|
||||
} else if (self->private_impl.f_quirks[3] && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) && (self->private_impl.f_interlace == 0)) {
|
||||
if (v_need_block_size || (v_block_size > 0)) {
|
||||
self->private_data.s_decode_id_part2[0].scratch = ((uint32_t)(v_block_size));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (self->private_data.s_decode_id_part2[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_id_part2[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_id_part2[0].scratch;
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_gif__decoder__skip_blocks(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
goto label__outer__break;
|
||||
}
|
||||
status = v_lzw_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
@@ -31182,7 +33591,6 @@ 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:
|
||||
@@ -32374,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);
|
||||
@@ -32436,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) {
|
||||
@@ -32500,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)));
|
||||
@@ -32530,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);
|
||||
@@ -32574,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);
|
||||
@@ -32632,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);
|
||||
@@ -32687,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);
|
||||
@@ -32738,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)));
|
||||
@@ -32783,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)));
|
||||
@@ -32830,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);
|
||||
@@ -33621,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33778,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;
|
||||
|
||||
@@ -33888,7 +36274,6 @@ 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:
|
||||
@@ -33952,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);
|
||||
@@ -33977,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);
|
||||
@@ -34000,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;
|
||||
}
|
||||
@@ -34013,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;
|
||||
@@ -34388,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:
|
||||
@@ -34456,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));
|
||||
}
|
||||
@@ -34468,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 {
|
||||
@@ -34497,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;
|
||||
@@ -34558,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;
|
||||
@@ -34605,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;
|
||||
@@ -34755,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;
|
||||
@@ -34774,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;
|
||||
@@ -34797,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);
|
||||
}
|
||||
|
||||
@@ -34890,6 +37270,10 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_COUNT 1
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
@@ -35053,8 +37437,15 @@ wuffs_zlib__decoder__set_quirk_enabled(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
if (a_quirk == 1) {
|
||||
if (self->private_impl.f_header_complete) {
|
||||
self->private_impl.f_bad_call_sequence = true;
|
||||
} else if (a_quirk == 1) {
|
||||
self->private_impl.f_ignore_checksum = a_enabled;
|
||||
} else if (a_quirk >= 2113790976) {
|
||||
a_quirk -= 2113790976;
|
||||
if (a_quirk < 1) {
|
||||
self->private_impl.f_quirks[a_quirk] = a_enabled;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
@@ -35144,6 +37535,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
if (self->private_impl.f_bad_call_sequence) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_quirks[0]) {
|
||||
} else if ( ! self->private_impl.f_want_dictionary) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
@@ -35251,7 +37643,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum) {
|
||||
if ( ! self->private_impl.f_ignore_checksum && ! self->private_impl.f_quirks[0]) {
|
||||
v_checksum_got = wuffs_adler32__hasher__update_u32(&self->private_data.f_checksum, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
@@ -35261,38 +37653,40 @@ wuffs_zlib__decoder__transform_io(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
label__0__break:;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[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;
|
||||
if ( ! self->private_impl.f_quirks[0]) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[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_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ok:
|
||||
@@ -35334,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";
|
||||
@@ -35579,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(
|
||||
@@ -35591,6 +37987,11 @@ wuffs_png__decoder__decode_chrm(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_fctl(
|
||||
wuffs_png__decoder* self,
|
||||
@@ -37250,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;
|
||||
@@ -37323,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;
|
||||
}
|
||||
@@ -37388,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) {
|
||||
@@ -37428,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;
|
||||
@@ -37445,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;
|
||||
}
|
||||
@@ -37510,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;
|
||||
@@ -37762,8 +40166,13 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_filter_distance = 1;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
if (self->private_impl.f_interlace_pass == 0) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
} else {
|
||||
self->private_impl.f_dst_pixfmt = 2164308923;
|
||||
self->private_impl.f_src_pixfmt = 2164308923;
|
||||
}
|
||||
self->private_impl.f_filter_distance = 2;
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 2) {
|
||||
@@ -37885,7 +40294,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) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -37903,21 +40313,26 @@ 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_seen_plte || (self->private_impl.f_color_type != 3)) {
|
||||
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;
|
||||
} else if (self->private_impl.f_color_type == 3) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_png__decoder__decode_plte(self, 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_color_type == 2) || (self->private_impl.f_color_type == 6)) {
|
||||
} else {
|
||||
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(1);
|
||||
status = wuffs_png__decoder__decode_plte(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_plte = true;
|
||||
} else if ((self->private_impl.f_chunk_type & 32) == 0) {
|
||||
@@ -37925,133 +40340,26 @@ 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) {
|
||||
}
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
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(4);
|
||||
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(5);
|
||||
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(6);
|
||||
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(7);
|
||||
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(8);
|
||||
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;
|
||||
@@ -38060,10 +40368,139 @@ 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;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -38502,6 +40939,47 @@ wuffs_png__decoder__decode_chrm(
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_exif
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_chunk_length < 4) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_flavor = 3;
|
||||
self->private_impl.f_metadata_fourcc = 1163413830;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
self->private_impl.f_chunk_length = 0;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_fctl
|
||||
|
||||
static wuffs_base__status
|
||||
@@ -39386,6 +41864,8 @@ 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;
|
||||
@@ -39401,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));
|
||||
}
|
||||
@@ -39416,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));
|
||||
}
|
||||
@@ -39433,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;
|
||||
@@ -39507,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) {
|
||||
@@ -39515,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;
|
||||
@@ -39524,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;
|
||||
@@ -39534,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;
|
||||
@@ -39564,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;
|
||||
@@ -39720,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;
|
||||
@@ -39795,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));
|
||||
}
|
||||
@@ -39935,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;
|
||||
@@ -39960,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
|
||||
@@ -39971,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;
|
||||
@@ -40425,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;
|
||||
}
|
||||
@@ -40456,6 +43010,8 @@ wuffs_png__decoder__set_report_metadata(
|
||||
|
||||
if (a_fourcc == 1128813133) {
|
||||
self->private_impl.f_report_metadata_chrm = a_report;
|
||||
} else if (a_fourcc == 1163413830) {
|
||||
self->private_impl.f_report_metadata_exif = a_report;
|
||||
} else if (a_fourcc == 1195461953) {
|
||||
self->private_impl.f_report_metadata_gama = a_report;
|
||||
} else if (a_fourcc == 1229144912) {
|
||||
@@ -40541,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;
|
||||
}
|
||||
@@ -40549,396 +43105,419 @@ wuffs_png__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
while (true) {
|
||||
if (self->private_impl.f_metadata_flavor == 3) {
|
||||
while (true) {
|
||||
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
} else if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) {
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
self->private_impl.f_metadata_y = self->private_impl.f_metadata_z;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
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);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
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);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} 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(7);
|
||||
goto label__loop__continue;
|
||||
} else 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(8);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} 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__loop__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
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_c2 = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
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(4);
|
||||
v_c2 = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_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;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
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 == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
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;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
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_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} 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(6);
|
||||
goto label__loop__continue;
|
||||
} else 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(7);
|
||||
goto label__loop__continue;
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
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;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} 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(8);
|
||||
goto label__loop__continue;
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
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(9);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
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(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
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 == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
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;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
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;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
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_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[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_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
label__goto_done__break:;
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[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_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
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 &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
@@ -41349,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) {
|
||||
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->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) {
|
||||
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->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) {
|
||||
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->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
|
||||
@@ -41594,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:
|
||||
@@ -41664,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));
|
||||
}
|
||||
@@ -41676,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 {
|
||||
@@ -41705,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;
|
||||
@@ -41794,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));
|
||||
}
|
||||
@@ -41806,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;
|
||||
@@ -41869,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;
|
||||
@@ -41947,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;
|
||||
@@ -41966,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;
|
||||
@@ -41989,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);
|
||||
}
|
||||
@@ -42795,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:
|
||||
@@ -42821,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();
|
||||
@@ -43041,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:
|
||||
@@ -43048,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;
|
||||
@@ -43092,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);
|
||||
}
|
||||
@@ -43108,6 +46936,10 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
|
||||
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) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
|
||||
}
|
||||
@@ -43115,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);
|
||||
}
|
||||
}
|
||||
@@ -43155,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();
|
||||
@@ -43216,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) {
|
||||
@@ -43257,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));
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ main(int argc, char** argv) {
|
||||
"compatible with the\n"
|
||||
"# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install "
|
||||
"it, first\n"
|
||||
"# install Go, then run \"go get 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 < 5; i++) {
|
||||
msg = decode(true, true);
|
||||
|
||||
@@ -81,7 +81,7 @@ func main1() error {
|
||||
fmt.Printf("#\n")
|
||||
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
|
||||
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
|
||||
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
|
||||
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
|
||||
|
||||
for i := -1; i < reps; i++ {
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -106,7 +106,7 @@ func main1() error {
|
||||
fmt.Printf("#\n")
|
||||
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
|
||||
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
|
||||
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
|
||||
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
|
||||
|
||||
for i := -1; i < reps; i++ {
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -90,7 +90,7 @@ func main1() error {
|
||||
fmt.Printf("#\n")
|
||||
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
|
||||
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
|
||||
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
|
||||
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
|
||||
|
||||
for i := -1; i < reps; i++ {
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -32,9 +32,19 @@ save=`git log -1 --pretty=format:"%H"`
|
||||
|
||||
i=0
|
||||
while [ $i -lt $num_commits ]; do
|
||||
this_hash=`git log -1 --pretty=format:"%h"`
|
||||
set +e
|
||||
$cc -O3 -o bench-history.out test/c/std/$package.c
|
||||
this_metric=`./bench-history.out -bench -focus=$focus -iterscale=$iterscale -reps=$reps | benchstat /dev/stdin | sed -ne '/^name.*speed$/,$ p' | grep $focus`
|
||||
if [ $? -ne 0 ]; then
|
||||
this_metric='compile_failed'
|
||||
else
|
||||
this_metric=`./bench-history.out -bench -focus=$focus -iterscale=$iterscale -reps=$reps | benchstat /dev/stdin | sed -ne '/^name.*speed$/,$ p' | grep $focus`
|
||||
if [ $? -ne 0 ]; then
|
||||
this_metric='bench_failed'
|
||||
fi
|
||||
fi
|
||||
set -e
|
||||
|
||||
this_hash=`git log -1 --pretty=format:"%h"`
|
||||
echo $this_hash $this_metric
|
||||
git checkout --quiet HEAD^
|
||||
i=$((i + 1))
|
||||
|
||||
@@ -47,7 +47,7 @@ fn main() {
|
||||
print!("#\n");
|
||||
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
|
||||
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
|
||||
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
|
||||
let mut dst = vec![0u8; 64 * 1024 * 1024];
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -52,7 +51,7 @@ fn main() {
|
||||
print!("#\n");
|
||||
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
|
||||
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
|
||||
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
|
||||
let mut dst = vec![0u8; 64 * 1024 * 1024];
|
||||
|
||||
@@ -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 = "*"
|
||||
@@ -45,7 +45,7 @@ fn main() {
|
||||
print!("#\n");
|
||||
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
|
||||
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
|
||||
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
|
||||
let mut dst0 = vec![0u8; 64 * 1024 * 1024];
|
||||
let mut dst1 = vec![0u8; 64 * 1024 * 1024];
|
||||
@@ -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)
|
||||
}
|
||||
@@ -587,20 +745,20 @@ func stateDeflateDynamicHuffman(line string) (stateFunc, error) {
|
||||
return stateDeflateDynamicHuffman, nil
|
||||
|
||||
} else if l, d, ok := deflateParseLenDist(line); ok {
|
||||
if (l != 3) || (d != 2) {
|
||||
return nil, fmt.Errorf("TODO: support len/dist pairs for dynamic Huffman blocks")
|
||||
if (l > 10) || (d > 4) {
|
||||
return nil, fmt.Errorf("TODO: support len/dist ExtraBits > 0 for dynamic Huffman blocks")
|
||||
}
|
||||
// len 3 is code 257, with no extra bits.
|
||||
if s := g.huffmans[2][257]; s != "" {
|
||||
// len 3 is code 257, len 4 is code 258, etc. All with no ExtraBits.
|
||||
if s := g.huffmans[2][l+254]; s != "" {
|
||||
deflateGlobalsWriteDynamicHuffmanBits(s)
|
||||
} else {
|
||||
return nil, fmt.Errorf("no code for literal/length symbol 257")
|
||||
return nil, fmt.Errorf("no code for literal/length symbol %d", l+254)
|
||||
}
|
||||
// dist 2 is code 1, with no extra bits.
|
||||
if s := g.huffmans[3][1]; s != "" {
|
||||
// dist 1 is code 0, dist 2 is code 1, etc. All with no ExtraBits.
|
||||
if s := g.huffmans[3][d-1]; s != "" {
|
||||
deflateGlobalsWriteDynamicHuffmanBits(s)
|
||||
} else {
|
||||
return nil, fmt.Errorf("no code for distance symbol 2")
|
||||
return nil, fmt.Errorf("no code for distance symbol %d", d-1)
|
||||
}
|
||||
return stateDeflateDynamicHuffman, nil
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ for f in $sources; do
|
||||
if [ -f $f ]; then
|
||||
handle $f
|
||||
elif [ -d $f ]; then
|
||||
for g in `find $f -type f | sort`; do
|
||||
for g in `find $f -type f | LANG=C sort`; do
|
||||
handle $g
|
||||
done
|
||||
else
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -628,17 +628,21 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
} endwhile
|
||||
if remaining <> 0 {
|
||||
// As a special case, allow a degenerate H-D Huffman table, with only
|
||||
// one 1-bit code, for the smallest possible distance.
|
||||
// one 1-bit code.
|
||||
if (args.which == 1) and (counts[1] == 1) and
|
||||
(this.code_lengths[args.n_codes0] == 1) and
|
||||
(((counts[0] as base.u32) + args.n_codes0 + 1) == args.n_codes1) {
|
||||
|
||||
this.n_huffs_bits[1] = 1
|
||||
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[0] | 1
|
||||
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
|
||||
return ok
|
||||
i = 0
|
||||
while i <= 29 {
|
||||
if this.code_lengths[args.n_codes0 + i] == 1 {
|
||||
this.n_huffs_bits[1] = 1
|
||||
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[i] | 1
|
||||
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
|
||||
return ok
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
|
||||
|
||||
@@ -219,18 +219,14 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
|
||||
@@ -324,18 +324,14 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
|
||||
@@ -218,18 +218,14 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
|
||||
@@ -201,63 +201,38 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
n_bits -= table_entry_n_bits
|
||||
}
|
||||
|
||||
while true {
|
||||
while.inner true {
|
||||
// Copy from this.history.
|
||||
if ((dist_minus_1 + 1) as base.u64) > args.dst.history_length() {
|
||||
// Set (hlen, hdist) to be the length-distance pair to copy
|
||||
// from this.history, and (length, distance) to be the
|
||||
// remaining length-distance pair to copy from args.dst.
|
||||
// from this.history.
|
||||
hdist = (((dist_minus_1 + 1) as base.u64) - args.dst.history_length()) as base.u32
|
||||
if length > hdist {
|
||||
assert hdist < length via "a < b: b > a"()
|
||||
if hdist < length {
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c: length)
|
||||
length -= hdist
|
||||
hlen = hdist
|
||||
assert hlen <= length via "a <= b: a == c; c <= b"(c: hdist)
|
||||
} else {
|
||||
hlen = length
|
||||
length = 0
|
||||
assert hlen <= length via "a <= b: a == b"()
|
||||
}
|
||||
|
||||
hdist ~mod+= ((this.transformed_history_count ~mod- args.dst.history_position()) & 0xFFFF_FFFF) as base.u32
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
while true {
|
||||
n_copied = args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000])
|
||||
if hlen <= n_copied {
|
||||
hlen = 0
|
||||
break
|
||||
}
|
||||
if n_copied > 0 {
|
||||
hlen -= n_copied
|
||||
hdist = (hdist ~mod+ n_copied) & 0x7FFF
|
||||
if hdist == 0 {
|
||||
// Wrap around the this.history ringbuffer.
|
||||
break
|
||||
}
|
||||
}
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
n_copied = args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if n_copied < hlen {
|
||||
assert n_copied < length via "a < b: a < c; c <= b"(c: hlen)
|
||||
assert length > n_copied via "a > b: b < a"()
|
||||
length -= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
// Copy from the start of this.history, if we wrapped around.
|
||||
if hlen > 0 {
|
||||
while true {
|
||||
n_copied = args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000])
|
||||
if hlen <= n_copied {
|
||||
hlen = 0
|
||||
break
|
||||
}
|
||||
hlen -= n_copied
|
||||
hdist ~mod+= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
continue.inner
|
||||
}
|
||||
|
||||
assert length >= hlen via "a >= b: b <= a"()
|
||||
length -= hlen
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
@@ -268,12 +243,11 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
n_copied = args.dst.limited_copy_u32_from_history!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
if length <= n_copied {
|
||||
length = 0
|
||||
break
|
||||
continue.loop
|
||||
}
|
||||
length -= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
} endwhile.inner
|
||||
} endwhile.loop
|
||||
|
||||
// TODO: "assert n_bits < 8"? What about (bits >> n_bits)?
|
||||
|
||||
@@ -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
|
||||
@@ -277,7 +239,21 @@ pub func decoder.num_animation_loops() base.u32 {
|
||||
if this.seen_num_animation_loops_value {
|
||||
return this.num_animation_loops_value
|
||||
}
|
||||
return 1
|
||||
// Absent an explicit animation loop count, default to 1 meaning "play each
|
||||
// frame exactly once" for animated GIFs and 0 meaning "loop forever" for
|
||||
// still (non-animated) GIFs.
|
||||
//
|
||||
// In practice, returning 1 or 0 has no difference for still GIFs, in that
|
||||
// either way, the pixels on screen do not change over time. However,
|
||||
// returning 0 here matches other Wuffs image decoders (e.g. BMP, PNG)
|
||||
// returning 0 for their still images.
|
||||
//
|
||||
// As a consequence, if a still GIF is losslessly converted to a still BMP
|
||||
// and both of those are then converted to NIA, the two NIA outputs match.
|
||||
if this.num_decoded_frame_configs_value > 1 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
@@ -305,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
|
||||
}
|
||||
|
||||
@@ -322,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
|
||||
@@ -382,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) {
|
||||
@@ -410,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)) {
|
||||
@@ -427,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
|
||||
@@ -442,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 {
|
||||
@@ -480,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
|
||||
@@ -678,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"
|
||||
}
|
||||
|
||||
@@ -745,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
|
||||
@@ -768,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)
|
||||
}
|
||||
@@ -954,6 +936,17 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
continue.outer
|
||||
} else if lzw_status == base."$short write" {
|
||||
continue.inner
|
||||
} else if this.quirks[QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA - QUIRKS_BASE] and
|
||||
(this.dst_y >= this.frame_rect_y1) and (this.interlace == 0) {
|
||||
// It's invalid LZW-compressed data, but we still have a full
|
||||
// frame and have opted in to QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA,
|
||||
// so treat it like the lzw_status.is_ok() case, other than not
|
||||
// clearing this.previous_lzw_decode_ended_abruptly.
|
||||
if need_block_size or (block_size > 0) {
|
||||
args.src.skip_u32?(n: block_size as base.u32)
|
||||
this.skip_blocks?(src: args.src)
|
||||
}
|
||||
break.outer
|
||||
}
|
||||
return lzw_status
|
||||
} endwhile.inner
|
||||
|
||||
@@ -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,
|
||||
@@ -56,7 +33,6 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
util : base.utility,
|
||||
)(
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
@@ -65,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"
|
||||
}
|
||||
|
||||
@@ -109,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"
|
||||
@@ -141,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"
|
||||
}
|
||||
@@ -178,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 {
|
||||
@@ -247,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,64 +17,28 @@ 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,
|
||||
report_metadata_exif : base.bool,
|
||||
report_metadata_gama : base.bool,
|
||||
report_metadata_iccp : base.bool,
|
||||
report_metadata_kvp : base.bool,
|
||||
@@ -90,9 +54,11 @@ pub struct decoder? implements base.image_decoder(
|
||||
seen_actl : base.bool,
|
||||
seen_chrm : base.bool,
|
||||
seen_fctl : base.bool,
|
||||
seen_exif : base.bool,
|
||||
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,
|
||||
@@ -203,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'
|
||||
@@ -243,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.
|
||||
@@ -293,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))
|
||||
}
|
||||
@@ -306,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"
|
||||
}
|
||||
|
||||
@@ -347,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) {
|
||||
@@ -441,8 +412,14 @@ pri func decoder.assign_filter_distance!() {
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y
|
||||
this.filter_distance = 1
|
||||
} else if this.depth == 16 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__Y_16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y_16BE
|
||||
if this.interlace_pass == 0 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__Y_16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y_16BE
|
||||
} else {
|
||||
// Interlaced means choosing filter_and_swizzle_tricky.
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
}
|
||||
this.filter_distance = 2
|
||||
}
|
||||
|
||||
@@ -533,77 +510,40 @@ pri func decoder.choose_filter_implementations!() {
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
if this.chunk_type == 'PLTE'le {
|
||||
if this.seen_plte or (this.color_type <> 3) {
|
||||
// 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 {
|
||||
// Color type 3 means paletted.
|
||||
this.decode_plte?(src: args.src)
|
||||
} else if (this.color_type == 2) or (this.color_type == 6) {
|
||||
// Color types 2 and 6 means RGB and RGBA. In these cases, the PLTE
|
||||
// chunk is merely a hint, like a sPLT "suggested palette" chunk.
|
||||
// We ignore it.
|
||||
} else {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_plte?(src: args.src)
|
||||
this.seen_plte = true
|
||||
|
||||
} else if (this.chunk_type & ANCILLARY_BIT) == 0 {
|
||||
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 {
|
||||
if this.chunk_type == 'eXIf'le {
|
||||
if this.report_metadata_exif {
|
||||
if this.seen_exif {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_chrm?(src: args.src)
|
||||
this.seen_chrm = true
|
||||
this.decode_exif?(src: args.src)
|
||||
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) {
|
||||
@@ -614,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 {
|
||||
@@ -675,6 +675,18 @@ pri func decoder.decode_chrm?(src: base.io_reader) {
|
||||
this.metadata_z |= (0xFF_FFFF & u) << 40
|
||||
}
|
||||
|
||||
pri func decoder.decode_exif?(src: base.io_reader) {
|
||||
if this.chunk_length < 4 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
this.metadata_fourcc = 'EXIF'be
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = args.src.position()
|
||||
this.metadata_z = this.metadata_y ~sat+ (this.chunk_length as base.u64)
|
||||
this.chunk_length = 0
|
||||
}
|
||||
|
||||
pri func decoder.decode_fctl?(src: base.io_reader) {
|
||||
var x0 : base.u32
|
||||
var y0 : base.u32
|
||||
@@ -922,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 {
|
||||
@@ -948,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
|
||||
@@ -960,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
|
||||
}
|
||||
@@ -981,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) {
|
||||
@@ -1051,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) {
|
||||
@@ -1064,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)
|
||||
}
|
||||
|
||||
@@ -1158,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
|
||||
@@ -1173,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) {
|
||||
@@ -1305,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
|
||||
}
|
||||
@@ -1324,6 +1376,8 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
if args.fourcc == 'CHRM'be {
|
||||
this.report_metadata_chrm = args.report
|
||||
} else if args.fourcc == 'EXIF'be {
|
||||
this.report_metadata_exif = args.report
|
||||
} else if args.fourcc == 'GAMA'be {
|
||||
this.report_metadata_gama = args.report
|
||||
} else if args.fourcc == 'ICCP'be {
|
||||
@@ -1344,13 +1398,34 @@ 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 {
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
while.goto_done true {{
|
||||
if this.metadata_flavor == base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH {
|
||||
while true {
|
||||
if args.src.position() <> this.metadata_y {
|
||||
return base."#bad I/O position"
|
||||
} else if args.minfo <> nullptr {
|
||||
args.minfo.set!(
|
||||
flavor: this.metadata_flavor,
|
||||
w: this.metadata_fourcc,
|
||||
x: this.metadata_x,
|
||||
y: this.metadata_y,
|
||||
z: this.metadata_z)
|
||||
}
|
||||
if this.metadata_y >= this.metadata_z {
|
||||
break.goto_done
|
||||
}
|
||||
this.metadata_y = this.metadata_z
|
||||
yield? base."$even more information"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.metadata_is_zlib_compressed {
|
||||
if this.zlib_is_dirty {
|
||||
this.zlib.reset!()
|
||||
@@ -1443,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
|
||||
@@ -1451,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
|
||||
@@ -1517,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
|
||||
@@ -1526,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
|
||||
@@ -1589,22 +1660,26 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
this.metadata_is_zlib_compressed = true
|
||||
}
|
||||
|
||||
} else {
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.call_sequence &= 0xEF
|
||||
return ok
|
||||
}
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
|
||||
// Skip the ancillary chunk's CRC-32 checksum.
|
||||
args.src.skip?(n: 4)
|
||||
|
||||
this.metadata_flavor = 0
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
|
||||
this.call_sequence = 2
|
||||
// Skip the ancillary chunk's CRC-32 checksum.
|
||||
args.src.skip?(n: 4)
|
||||
|
||||
this.metadata_flavor = 0
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
|
||||
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,33 @@
|
||||
// Copyright 2021 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.
|
||||
|
||||
// --------
|
||||
|
||||
// Quirks are discussed in (/doc/note/quirks.md).
|
||||
//
|
||||
// The base38 encoding of "zlib" is 0x1F_7F79. Left shifting by 10 gives
|
||||
// 0x7DFD_E400.
|
||||
pri const QUIRKS_BASE : base.u32 = 0x7DFD_E400
|
||||
|
||||
// --------
|
||||
|
||||
// When this quirk is enabled, the decoder speaks just raw deflate, without
|
||||
// zlib's configuration prefix and checksum suffix wrapped around that.
|
||||
//
|
||||
// A zlib.decoder basically becomes a deflate.decoder. This is useful when the
|
||||
// caller might want to choose between the two related-but-slightly-different
|
||||
// formats at run time but would rather not allocate two separate decoders.
|
||||
pub const QUIRK_JUST_RAW_DEFLATE : base.u32 = 0x7DFD_E400 | 0x00
|
||||
|
||||
pri const QUIRKS_COUNT : base.u32 = 0x01
|
||||
@@ -33,6 +33,8 @@ pub struct decoder? implements base.io_transformer(
|
||||
got_dictionary : base.bool,
|
||||
want_dictionary : base.bool,
|
||||
|
||||
quirks : array[QUIRKS_COUNT] base.bool,
|
||||
|
||||
ignore_checksum : base.bool,
|
||||
checksum : adler32.hasher,
|
||||
|
||||
@@ -60,8 +62,15 @@ pub func decoder.add_dictionary!(dict: slice base.u8) {
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
|
||||
if this.header_complete {
|
||||
this.bad_call_sequence = true
|
||||
} else if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
|
||||
this.ignore_checksum = args.enabled
|
||||
} else if args.quirk >= QUIRKS_BASE {
|
||||
args.quirk -= QUIRKS_BASE
|
||||
if args.quirk < QUIRKS_COUNT {
|
||||
this.quirks[args.quirk] = args.enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +89,8 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
|
||||
if this.bad_call_sequence {
|
||||
return base."#bad call sequence"
|
||||
} else if this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
|
||||
// No-op.
|
||||
} else if not this.want_dictionary {
|
||||
x = args.src.read_u16be?()
|
||||
if ((x >> 8) & 0x0F) <> 0x08 {
|
||||
@@ -112,7 +123,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
while true {
|
||||
mark = args.dst.mark()
|
||||
status =? this.flate.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if not this.ignore_checksum {
|
||||
if (not this.ignore_checksum) and (not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE]) {
|
||||
checksum_got = this.checksum.update_u32!(x: args.dst.since(mark: mark))
|
||||
}
|
||||
if status.is_ok() {
|
||||
@@ -120,9 +131,12 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
checksum_want = args.src.read_u32be?()
|
||||
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
|
||||
if not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
|
||||
checksum_want = args.src.read_u32be?()
|
||||
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: reset state (e.g. want_dictionary), so that we can read concat'ed
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Ignore everything without a dot.
|
||||
#
|
||||
# This ignores "pngsuite" but not "fetch-pngsuite.sh".
|
||||
*
|
||||
!*.*
|
||||
@@ -0,0 +1,5 @@
|
||||
This directory contains third party test data, not checked into the repository
|
||||
directly for download size and copyright reasons.
|
||||
|
||||
It also contains derived summary data files (such as `nia-checksums-of-*.txt`)
|
||||
which *are* checked into the repository, for regression testing.
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2021 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 PngSuite collection of PNG images.
|
||||
|
||||
if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
echo "$0 should be run from the Wuffs test/3pdata directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p pngsuite
|
||||
curl --silent http://www.schaik.com/pngsuite/PngSuite-2017jul19.tgz | tar -xzf /dev/stdin -C pngsuite
|
||||
@@ -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,29 @@
|
||||
As per [the PngSuite page](http://www.schaik.com/pngsuite/#corrupted), every
|
||||
`x*.png` file in the test suite is invalid PNG.
|
||||
|
||||
Nonetheless, `nia-checksums-of-pngsuite.txt` contains an entry for
|
||||
`xcsn0g01.png`, meaning that `convert-to-nia` decoded *some* pixels for it.
|
||||
This is working as intended, because the `xcsn0g01.png` invalidity is in its
|
||||
`IDAT` chunk's checksum (compared to `xhdn0g08.png`'s corruption in its `IHDR`
|
||||
chunk's checksum).
|
||||
|
||||
The `convert-to-nia` semantics are that, provided that it can decode a complete
|
||||
image configuration (width, height, pixel format, etc which, for PNG, comes
|
||||
from the `IHDR` chunk), it outputs *as many pixels as possible* (even if that's
|
||||
zero pixels) so that it gives a 'best effort' decoding for truncated images.
|
||||
Indeed, the NIA conversion for `xcsn0g01.png` holds all-zero pixels (and a
|
||||
"png: bad checksum" error message on stderr) but also a zero exit code.
|
||||
|
||||
```
|
||||
$ gen/bin/example-convert-to-nia < test/3pdata/pngsuite/xcsn0g01.png | hd
|
||||
00000000 6e c3 af 41 ff 62 6e 34 20 00 00 00 20 00 00 00 |n..A.bn4 ... ...|
|
||||
00000010 00 00 00 00 00 00 00 00 6e c3 af 45 ff 62 6e 34 |........n..E.bn4|
|
||||
00000020 20 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 | ... ...........|
|
||||
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|
||||
*
|
||||
00001020 00 00 00 00 00 00 00 00 |........|
|
||||
00001028
|
||||
png: bad checksum
|
||||
$ echo $?
|
||||
0
|
||||
```
|
||||
@@ -0,0 +1,164 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
aac44167 test/3pdata/pngsuite/PngSuite.png
|
||||
926d3aa2 test/3pdata/pngsuite/basi0g01.png
|
||||
8f50bdc6 test/3pdata/pngsuite/basi0g02.png
|
||||
6d612626 test/3pdata/pngsuite/basi0g04.png
|
||||
024cf410 test/3pdata/pngsuite/basi0g08.png
|
||||
bb956205 test/3pdata/pngsuite/basi0g16.png
|
||||
d1ae61d3 test/3pdata/pngsuite/basi2c08.png
|
||||
84bc9be8 test/3pdata/pngsuite/basi2c16.png
|
||||
49bc6b98 test/3pdata/pngsuite/basi3p01.png
|
||||
ad12897b test/3pdata/pngsuite/basi3p02.png
|
||||
81c22b59 test/3pdata/pngsuite/basi3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/basi3p08.png
|
||||
1b468494 test/3pdata/pngsuite/basi4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/basi4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/basi6a08.png
|
||||
b039babf test/3pdata/pngsuite/basi6a16.png
|
||||
926d3aa2 test/3pdata/pngsuite/basn0g01.png
|
||||
8f50bdc6 test/3pdata/pngsuite/basn0g02.png
|
||||
6d612626 test/3pdata/pngsuite/basn0g04.png
|
||||
024cf410 test/3pdata/pngsuite/basn0g08.png
|
||||
bb956205 test/3pdata/pngsuite/basn0g16.png
|
||||
d1ae61d3 test/3pdata/pngsuite/basn2c08.png
|
||||
84bc9be8 test/3pdata/pngsuite/basn2c16.png
|
||||
49bc6b98 test/3pdata/pngsuite/basn3p01.png
|
||||
ad12897b test/3pdata/pngsuite/basn3p02.png
|
||||
81c22b59 test/3pdata/pngsuite/basn3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/basn3p08.png
|
||||
1b468494 test/3pdata/pngsuite/basn4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/basn4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/basn6a08.png
|
||||
b039babf test/3pdata/pngsuite/basn6a16.png
|
||||
1b468494 test/3pdata/pngsuite/bgai4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/bgai4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/bgan6a08.png
|
||||
b039babf test/3pdata/pngsuite/bgan6a16.png
|
||||
1b468494 test/3pdata/pngsuite/bgbn4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/bggn4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/bgwn6a08.png
|
||||
b039babf test/3pdata/pngsuite/bgyn6a16.png
|
||||
b58985e2 test/3pdata/pngsuite/ccwn2c08.png
|
||||
b7f7127d test/3pdata/pngsuite/ccwn3p08.png
|
||||
c7b4c0fa test/3pdata/pngsuite/cdfn2c08.png
|
||||
dabf7a40 test/3pdata/pngsuite/cdhn2c08.png
|
||||
8491ddf5 test/3pdata/pngsuite/cdsn2c08.png
|
||||
d9282a90 test/3pdata/pngsuite/cdun2c08.png
|
||||
81c22b59 test/3pdata/pngsuite/ch1n3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/ch2n3p08.png
|
||||
b3334ede test/3pdata/pngsuite/cm0n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/cm7n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/cm9n0g04.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs3n2c16.png
|
||||
d565507c test/3pdata/pngsuite/cs3n3p08.png
|
||||
2f5a21b9 test/3pdata/pngsuite/cs5n2c08.png
|
||||
2f5a21b9 test/3pdata/pngsuite/cs5n3p08.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs8n2c08.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs8n3p08.png
|
||||
b3334ede test/3pdata/pngsuite/ct0n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/ct1n0g04.png
|
||||
1bfcb6e6 test/3pdata/pngsuite/cten0g04.png
|
||||
8e493daf test/3pdata/pngsuite/ctfn0g04.png
|
||||
417a539e test/3pdata/pngsuite/ctgn0g04.png
|
||||
28033324 test/3pdata/pngsuite/cthn0g04.png
|
||||
71a82501 test/3pdata/pngsuite/ctjn0g04.png
|
||||
b3334ede test/3pdata/pngsuite/ctzn0g04.png
|
||||
aa5328d3 test/3pdata/pngsuite/exif2c08.png
|
||||
b81f03cc test/3pdata/pngsuite/f00n0g08.png
|
||||
4a12368c test/3pdata/pngsuite/f00n2c08.png
|
||||
7fe4a9d8 test/3pdata/pngsuite/f01n0g08.png
|
||||
36758edc test/3pdata/pngsuite/f01n2c08.png
|
||||
e0ab5774 test/3pdata/pngsuite/f02n0g08.png
|
||||
5e613513 test/3pdata/pngsuite/f02n2c08.png
|
||||
0719e3fa test/3pdata/pngsuite/f03n0g08.png
|
||||
c4709cc1 test/3pdata/pngsuite/f03n2c08.png
|
||||
457f1dab test/3pdata/pngsuite/f04n0g08.png
|
||||
7ec3c986 test/3pdata/pngsuite/f04n2c08.png
|
||||
1f319e46 test/3pdata/pngsuite/f99n0g04.png
|
||||
6000bb5b test/3pdata/pngsuite/g03n0g16.png
|
||||
aa019a24 test/3pdata/pngsuite/g03n2c08.png
|
||||
8f0a3383 test/3pdata/pngsuite/g03n3p04.png
|
||||
f3a44153 test/3pdata/pngsuite/g04n0g16.png
|
||||
3e852c56 test/3pdata/pngsuite/g04n2c08.png
|
||||
edb3555b test/3pdata/pngsuite/g04n3p04.png
|
||||
6b105de1 test/3pdata/pngsuite/g05n0g16.png
|
||||
938803a0 test/3pdata/pngsuite/g05n2c08.png
|
||||
9f7ad612 test/3pdata/pngsuite/g05n3p04.png
|
||||
28816978 test/3pdata/pngsuite/g07n0g16.png
|
||||
fedb8920 test/3pdata/pngsuite/g07n2c08.png
|
||||
9373010e test/3pdata/pngsuite/g07n3p04.png
|
||||
58eb5aca test/3pdata/pngsuite/g10n0g16.png
|
||||
8c5550d0 test/3pdata/pngsuite/g10n2c08.png
|
||||
a6120550 test/3pdata/pngsuite/g10n3p04.png
|
||||
14cc7e1c test/3pdata/pngsuite/g25n0g16.png
|
||||
fd0f349f test/3pdata/pngsuite/g25n2c08.png
|
||||
eb13812a test/3pdata/pngsuite/g25n3p04.png
|
||||
bb956205 test/3pdata/pngsuite/oi1n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi1n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi2n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi2n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi4n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi4n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi9n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi9n2c16.png
|
||||
84bc9be8 test/3pdata/pngsuite/pp0n2c16.png
|
||||
8ed1f246 test/3pdata/pngsuite/pp0n6a08.png
|
||||
024cf410 test/3pdata/pngsuite/ps1n0g08.png
|
||||
84bc9be8 test/3pdata/pngsuite/ps1n2c16.png
|
||||
024cf410 test/3pdata/pngsuite/ps2n0g08.png
|
||||
84bc9be8 test/3pdata/pngsuite/ps2n2c16.png
|
||||
7cf2b7b2 test/3pdata/pngsuite/s01i3p01.png
|
||||
7cf2b7b2 test/3pdata/pngsuite/s01n3p01.png
|
||||
ffa30c78 test/3pdata/pngsuite/s02i3p01.png
|
||||
ffa30c78 test/3pdata/pngsuite/s02n3p01.png
|
||||
ad298c62 test/3pdata/pngsuite/s03i3p01.png
|
||||
ad298c62 test/3pdata/pngsuite/s03n3p01.png
|
||||
2c30132c test/3pdata/pngsuite/s04i3p01.png
|
||||
2c30132c test/3pdata/pngsuite/s04n3p01.png
|
||||
5fb20358 test/3pdata/pngsuite/s05i3p02.png
|
||||
5fb20358 test/3pdata/pngsuite/s05n3p02.png
|
||||
764e90bd test/3pdata/pngsuite/s06i3p02.png
|
||||
764e90bd test/3pdata/pngsuite/s06n3p02.png
|
||||
9eebca92 test/3pdata/pngsuite/s07i3p02.png
|
||||
9eebca92 test/3pdata/pngsuite/s07n3p02.png
|
||||
d57f2e84 test/3pdata/pngsuite/s08i3p02.png
|
||||
d57f2e84 test/3pdata/pngsuite/s08n3p02.png
|
||||
7585127f test/3pdata/pngsuite/s09i3p02.png
|
||||
7585127f test/3pdata/pngsuite/s09n3p02.png
|
||||
034051a8 test/3pdata/pngsuite/s32i3p04.png
|
||||
034051a8 test/3pdata/pngsuite/s32n3p04.png
|
||||
a377dcdd test/3pdata/pngsuite/s33i3p04.png
|
||||
a377dcdd test/3pdata/pngsuite/s33n3p04.png
|
||||
5bcd998d test/3pdata/pngsuite/s34i3p04.png
|
||||
5bcd998d test/3pdata/pngsuite/s34n3p04.png
|
||||
1cefbbe2 test/3pdata/pngsuite/s35i3p04.png
|
||||
1cefbbe2 test/3pdata/pngsuite/s35n3p04.png
|
||||
97c763a3 test/3pdata/pngsuite/s36i3p04.png
|
||||
97c763a3 test/3pdata/pngsuite/s36n3p04.png
|
||||
2d6bd687 test/3pdata/pngsuite/s37i3p04.png
|
||||
2d6bd687 test/3pdata/pngsuite/s37n3p04.png
|
||||
169951e5 test/3pdata/pngsuite/s38i3p04.png
|
||||
169951e5 test/3pdata/pngsuite/s38n3p04.png
|
||||
17a92eb2 test/3pdata/pngsuite/s39i3p04.png
|
||||
17a92eb2 test/3pdata/pngsuite/s39n3p04.png
|
||||
8cc6b93d test/3pdata/pngsuite/s40i3p04.png
|
||||
8cc6b93d test/3pdata/pngsuite/s40n3p04.png
|
||||
4e406947 test/3pdata/pngsuite/tbbn0g04.png
|
||||
c6e83019 test/3pdata/pngsuite/tbbn2c16.png
|
||||
46deef3b test/3pdata/pngsuite/tbbn3p08.png
|
||||
c6e83019 test/3pdata/pngsuite/tbgn2c16.png
|
||||
46deef3b test/3pdata/pngsuite/tbgn3p08.png
|
||||
c6e83019 test/3pdata/pngsuite/tbrn2c08.png
|
||||
2289ed1e test/3pdata/pngsuite/tbwn0g16.png
|
||||
46deef3b test/3pdata/pngsuite/tbwn3p08.png
|
||||
46deef3b test/3pdata/pngsuite/tbyn3p08.png
|
||||
59b23555 test/3pdata/pngsuite/tm3n3p02.png
|
||||
f2457b64 test/3pdata/pngsuite/tp0n0g08.png
|
||||
05846c5f test/3pdata/pngsuite/tp0n2c08.png
|
||||
3d7708a8 test/3pdata/pngsuite/tp0n3p08.png
|
||||
46deef3b test/3pdata/pngsuite/tp1n3p08.png
|
||||
f286cbfc test/3pdata/pngsuite/xcsn0g01.png
|
||||
9098c4d8 test/3pdata/pngsuite/z00n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z03n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z06n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z09n2c08.png
|
||||
@@ -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);
|
||||
}
|
||||
@@ -89,13 +89,13 @@ golden_test g_deflate_deflate_backref_crosses_blocks_gt = {
|
||||
"backref-crosses-blocks.deflate",
|
||||
};
|
||||
|
||||
golden_test g_deflate_deflate_degenerate_huffman_unused_gt = {
|
||||
golden_test g_deflate_deflate_degenerate_huffman_gt = {
|
||||
.want_filename =
|
||||
"test/data/artificial-deflate/"
|
||||
"degenerate-huffman-unused.deflate.decompressed",
|
||||
"degenerate-huffman.deflate.decompressed",
|
||||
.src_filename =
|
||||
"test/data/artificial-deflate/"
|
||||
"degenerate-huffman-unused.deflate",
|
||||
"degenerate-huffman.deflate",
|
||||
};
|
||||
|
||||
golden_test g_deflate_deflate_distance_32768_gt = {
|
||||
@@ -213,10 +213,10 @@ test_wuffs_deflate_decode_deflate_backref_crosses_blocks() {
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman_unused() {
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_deflate_decode,
|
||||
&g_deflate_deflate_degenerate_huffman_unused_gt,
|
||||
&g_deflate_deflate_degenerate_huffman_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
@@ -722,10 +722,10 @@ test_mimic_deflate_decode_deflate_backref_crosses_blocks() {
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman_unused() {
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_deflate_decode,
|
||||
&g_deflate_deflate_degenerate_huffman_unused_gt,
|
||||
&g_deflate_deflate_degenerate_huffman_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
@@ -890,7 +890,7 @@ proc g_tests[] = {
|
||||
|
||||
test_wuffs_deflate_decode_256_bytes,
|
||||
test_wuffs_deflate_decode_deflate_backref_crosses_blocks,
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman_unused,
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman,
|
||||
test_wuffs_deflate_decode_deflate_distance_32768,
|
||||
test_wuffs_deflate_decode_deflate_distance_code_31,
|
||||
test_wuffs_deflate_decode_deflate_huffman_primlen_9,
|
||||
@@ -911,7 +911,7 @@ proc g_tests[] = {
|
||||
|
||||
test_mimic_deflate_decode_256_bytes,
|
||||
test_mimic_deflate_decode_deflate_backref_crosses_blocks,
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman_unused,
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman,
|
||||
test_mimic_deflate_decode_deflate_distance_32768,
|
||||
test_mimic_deflate_decode_deflate_distance_code_31,
|
||||
test_mimic_deflate_decode_deflate_huffman_primlen_9,
|
||||
|
||||
@@ -252,11 +252,6 @@ do_test_wuffs_gif_decode(const char* filename,
|
||||
|
||||
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
|
||||
&pb, &ic.pixcfg, g_pixel_slice_u8));
|
||||
|
||||
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
|
||||
if (have != 1) {
|
||||
RETURN_FAIL("num_animation_loops: have %" PRIu32 ", want 1", have);
|
||||
}
|
||||
}
|
||||
|
||||
int num_iters = 0;
|
||||
@@ -422,6 +417,16 @@ do_test_wuffs_gif_decode(const char* filename,
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
|
||||
uint32_t want =
|
||||
(wuffs_gif__decoder__num_decoded_frame_configs(&dec) > 1) ? 1 : 0;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("num_animation_loops: have %" PRIu32 ", want %" PRIu32, have,
|
||||
want);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1510,7 +1515,7 @@ test_wuffs_gif_decode_multiple_loop_counts() {
|
||||
// loop counts are the number of animation loops *after* the first play
|
||||
// through, and Wuffs' are the number *including* the first play through.
|
||||
|
||||
uint32_t want_num_animation_loops[4] = {1, 1, 51, 31};
|
||||
uint32_t want_num_animation_loops[4] = {0, 1, 51, 31};
|
||||
|
||||
uint32_t i = 0;
|
||||
while (true) {
|
||||
@@ -1598,11 +1603,20 @@ test_wuffs_gif_decode_pixel_data_too_much_sans_quirk() {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(
|
||||
read_file(&src, "test/data/artificial-gif/pixel-data-too-much.gif"));
|
||||
|
||||
return do_test_wuffs_gif_decode_expecting(
|
||||
src, 0, wuffs_base__error__too_much_data, false);
|
||||
src.meta = wuffs_base__empty_io_buffer_meta();
|
||||
CHECK_STRING(read_file(
|
||||
&src, "test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif"));
|
||||
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
|
||||
src, 0, wuffs_lzw__error__bad_code, false));
|
||||
|
||||
src.meta = wuffs_base__empty_io_buffer_meta();
|
||||
CHECK_STRING(read_file(
|
||||
&src, "test/data/artificial-gif/pixel-data-too-much-good-lzw.gif"));
|
||||
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
|
||||
src, 0, wuffs_base__error__too_much_data, false));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
@@ -1611,11 +1625,20 @@ test_wuffs_gif_decode_pixel_data_too_much_with_quirk() {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(
|
||||
read_file(&src, "test/data/artificial-gif/pixel-data-too-much.gif"));
|
||||
|
||||
return do_test_wuffs_gif_decode_expecting(
|
||||
src, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, NULL, false);
|
||||
src.meta = wuffs_base__empty_io_buffer_meta();
|
||||
CHECK_STRING(read_file(
|
||||
&src, "test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif"));
|
||||
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
|
||||
src, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, NULL, false));
|
||||
|
||||
src.meta = wuffs_base__empty_io_buffer_meta();
|
||||
CHECK_STRING(read_file(
|
||||
&src, "test/data/artificial-gif/pixel-data-too-much-good-lzw.gif"));
|
||||
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
|
||||
src, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, NULL, false));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -634,6 +634,71 @@ test_wuffs_png_decode_metadata_chrm_gama_srgb() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_png_decode_metadata_exif() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/artificial-png/exif.png"));
|
||||
|
||||
wuffs_png__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_png__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__EXIF, true);
|
||||
|
||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||
wuffs_base__io_buffer empty = wuffs_base__empty_io_buffer();
|
||||
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
|
||||
|
||||
wuffs_base__status status =
|
||||
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
|
||||
if (status.repr != wuffs_base__note__metadata_reported) {
|
||||
RETURN_FAIL("decode_image_config #0: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__note__metadata_reported);
|
||||
}
|
||||
|
||||
status = wuffs_png__decoder__tell_me_more(&dec, &empty, &minfo, &src);
|
||||
if (status.repr != wuffs_base__suspension__even_more_information) {
|
||||
RETURN_FAIL("tell_me_more #0: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__suspension__even_more_information);
|
||||
}
|
||||
|
||||
// "hd test/data/artificial-png/exif.png" says 0x29..0x33 holds "LoremIpsum".
|
||||
wuffs_base__range_ie_u64 have =
|
||||
wuffs_base__more_information__metadata_raw_passthrough__range(&minfo);
|
||||
wuffs_base__range_ie_u64 want = wuffs_base__make_range_ie_u64(0x29, 0x33);
|
||||
if (!wuffs_base__range_ie_u64__equals(&have, want)) {
|
||||
RETURN_FAIL("range #0: have 0x%" PRIx64 "..0x%" PRIX64 ", want 0x%" PRIx64
|
||||
"..0x%" PRIX64,
|
||||
have.min_incl, have.max_excl, want.min_incl, want.max_excl);
|
||||
} else if ((src.meta.ri == 0x29) && (src.meta.wi >= 0x33)) {
|
||||
src.meta.ri = 0x33;
|
||||
}
|
||||
|
||||
status = wuffs_png__decoder__tell_me_more(&dec, &empty, &minfo, &src);
|
||||
if (status.repr != NULL) {
|
||||
RETURN_FAIL("tell_me_more #1: have \"%s\", want \"(null)\"", status.repr);
|
||||
}
|
||||
have = wuffs_base__more_information__metadata_raw_passthrough__range(&minfo);
|
||||
if (!wuffs_base__range_ie_u64__is_empty(&have)) {
|
||||
RETURN_FAIL("tell_me_more #1: non-empty range");
|
||||
}
|
||||
|
||||
status = wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
|
||||
if (status.repr != NULL) {
|
||||
RETURN_FAIL("decode_image_config #1: have \"%s\", want \"(null)\"",
|
||||
status.repr);
|
||||
} else if (wuffs_base__pixel_config__width(&ic.pixcfg) != 1) {
|
||||
RETURN_FAIL("decode_image_config #1: have %" PRIu32 ", want 1",
|
||||
wuffs_base__pixel_config__width(&ic.pixcfg));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_png_decode_metadata_iccp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -745,6 +810,8 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
"U-значение", //
|
||||
"Z-Këy", //
|
||||
"Z-значение", //
|
||||
"After", //
|
||||
"Frame", //
|
||||
};
|
||||
|
||||
wuffs_png__decoder dec;
|
||||
@@ -754,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);
|
||||
@@ -794,12 +862,13 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
});
|
||||
if (i < WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
|
||||
size_t n = strlen(wants[i]);
|
||||
if (n < want.data.len) {
|
||||
if (n <= want.data.len) {
|
||||
memcpy(want.data.ptr, wants[i], n);
|
||||
want.meta.wi = n;
|
||||
}
|
||||
}
|
||||
CHECK_STRING(check_io_buffers_equal("", &have, &want));
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i != WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
|
||||
@@ -1201,6 +1270,7 @@ proc g_tests[] = {
|
||||
test_wuffs_png_decode_frame_config,
|
||||
test_wuffs_png_decode_interface,
|
||||
test_wuffs_png_decode_metadata_chrm_gama_srgb,
|
||||
test_wuffs_png_decode_metadata_exif,
|
||||
test_wuffs_png_decode_metadata_iccp,
|
||||
test_wuffs_png_decode_metadata_kvp,
|
||||
test_wuffs_png_decode_restart_frame,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -71,6 +71,11 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_deflate_romeo_gt = {
|
||||
.want_filename = "test/data/romeo.txt",
|
||||
.src_filename = "test/data/romeo.txt.deflate",
|
||||
};
|
||||
|
||||
golden_test g_zlib_midsummer_gt = {
|
||||
.want_filename = "test/data/midsummer.txt",
|
||||
.src_filename = "test/data/midsummer.txt.zlib",
|
||||
@@ -107,6 +112,42 @@ test_wuffs_zlib_decode_interface() {
|
||||
"test/data/romeo.txt.zlib", 0, SIZE_MAX, 942, 0x0A);
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_raw_deflate_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
wuffs_zlib__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
|
||||
// This wuffs_zlib__decoder__set_quirk_enabled call is the only difference
|
||||
// between wuffs_raw_deflate_decode and wuffs_zlib_decode immediately below.
|
||||
wuffs_zlib__decoder__set_quirk_enabled(
|
||||
&dec, WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE, true);
|
||||
|
||||
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_zlib__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* //
|
||||
wuffs_zlib_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
@@ -240,6 +281,13 @@ test_wuffs_zlib_decode_pi() {
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_zlib_decode_raw_deflate_romeo() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_raw_deflate_decode, &g_deflate_romeo_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_zlib_decode_sheep() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -376,6 +424,7 @@ proc g_tests[] = {
|
||||
test_wuffs_zlib_decode_interface,
|
||||
test_wuffs_zlib_decode_midsummer,
|
||||
test_wuffs_zlib_decode_pi,
|
||||
test_wuffs_zlib_decode_raw_deflate_romeo,
|
||||
test_wuffs_zlib_decode_sheep,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
@@ -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 get 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++) {
|
||||
|
||||
@@ -11,6 +11,7 @@ ImageMagick's `convert` command line tool. The `*.wbmp` versions were generated
|
||||
by the `script/convert-png-to-wbmp.go` command line tool. The `*.webp` versions
|
||||
were generated by the cwebp command line tool. The `*.no-ancillary.png` files
|
||||
were generated by the `script/strip-png-ancillary-chunks.go` command line tool.
|
||||
The `*.qoi` files were generated by the qoiconv command line tool.
|
||||
|
||||
The `*.apng` files were generated by `gif2apng`. Those with finite animation
|
||||
loop counts were manually patched to correct for a `gif2apng` bug.
|
||||
|
||||
@@ -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
|
||||
@@ -1 +0,0 @@
|
||||
foo
|
||||
@@ -1,27 +0,0 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make deflate
|
||||
|
||||
blockDynamicHuffman (final) {
|
||||
huffman CodeLength {
|
||||
1 00
|
||||
2 01
|
||||
17 10
|
||||
18 11
|
||||
}
|
||||
|
||||
huffman Literal/Length {
|
||||
# 102='f', 111='o', 256=EOB
|
||||
111 0
|
||||
102 10
|
||||
256 11
|
||||
}
|
||||
|
||||
huffman Distance {
|
||||
# Incomplete. There is no key/value pair whose value starts with "1".
|
||||
0 0
|
||||
}
|
||||
|
||||
literal "foo"
|
||||
endOfBlock
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
Running degenerate-huffman-unused.deflate through script/print-bits.go and
|
||||
adding commentary:
|
||||
Running degenerate-huffman.deflate through script/print-bits.go and adding
|
||||
commentary:
|
||||
|
||||
offset xoffset ASCII hex binary
|
||||
000000 0x0000 . 0x05 0b_...._.101 Dynamic Huffman block, final
|
||||
000000 0x0000 . 0x05 0b_0000_0... NumLCodes: 257
|
||||
000000 0x0000 . 0x04 0b_...._.100 Dynamic Huffman block, non-final
|
||||
000000 0x0000 . 0x04 0b_0000_0... NumLCodes: 257
|
||||
000001 0x0001 . 0xC0 0b_...0_0000 NumDCodes: 1
|
||||
000001 0x0001 . 0xC0 0b_110._.... NumCLCodeLengths: 18
|
||||
000002 0x0002 ! 0x21 0b_...._...1
|
||||
@@ -63,4 +63,7 @@ Apply H-L and H-D.
|
||||
000013 0x000D . 0x89 0b_..0._.... lcode: 111 literal 'o'
|
||||
000013 0x000D . 0x89 0b_.0.._.... lcode: 111 literal 'o'
|
||||
000013 0x000D . 0x89 0b_1..._.... lcode: 256 end of block
|
||||
000014 0x000E . 0x01 0b_...._...1
|
||||
000014 0x000E . 0x1B 0b_...._...1
|
||||
|
||||
The second Dynamic Huffman block (the final one) continues after that, but this
|
||||
commentary stops here.
|
||||
@@ -0,0 +1 @@
|
||||
fooABCDABC
|
||||
@@ -0,0 +1,66 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make deflate
|
||||
|
||||
blockDynamicHuffman (nonFinal) {
|
||||
huffman CodeLength {
|
||||
1 00
|
||||
2 01
|
||||
17 10
|
||||
18 11
|
||||
}
|
||||
|
||||
huffman Literal/Length {
|
||||
# 102='f', 111='o', 256=EOB
|
||||
111 0
|
||||
102 10
|
||||
256 11
|
||||
}
|
||||
|
||||
huffman Distance {
|
||||
# Incomplete. There is no key/value pair whose value starts with "1".
|
||||
#
|
||||
# The sole key/value pair is also unused. (The one below is used.)
|
||||
0 0
|
||||
incomplete
|
||||
}
|
||||
|
||||
literal "foo"
|
||||
endOfBlock
|
||||
}
|
||||
|
||||
blockDynamicHuffman (final) {
|
||||
huffman CodeLength {
|
||||
0 00
|
||||
1 01
|
||||
2 100
|
||||
3 101
|
||||
17 110
|
||||
18 111
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
huffman Distance {
|
||||
# Incomplete. There is no key/value pair whose value starts with "1".
|
||||
#
|
||||
# The sole key/value pair is also used. (The one above is unused.)
|
||||
#
|
||||
# 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"
|
||||
len 3 dist 4
|
||||
endOfBlock
|
||||
}
|
||||
|
After Width: | Height: | Size: 41 B |
@@ -0,0 +1,37 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make gif
|
||||
|
||||
header
|
||||
|
||||
image {
|
||||
imageWidthHeight 2 2
|
||||
palette {
|
||||
0x00 0x00 0xFF
|
||||
0x11 0x00 0xFF
|
||||
0x22 0x00 0xFF
|
||||
0x33 0x00 0xFF
|
||||
}
|
||||
}
|
||||
|
||||
frame {
|
||||
frameLeftTopWidthHeight 0 0 2 2
|
||||
}
|
||||
|
||||
# The frame area is 4 pixels and we supply 4 but then an invalid LZW code.
|
||||
# Compare with pixel-data-too-much-good-lzw.gif.make-artificial.txt
|
||||
#
|
||||
# The disassembly (see also std/lzw/README.md) is:
|
||||
#
|
||||
# 0x02 LZW literal width.
|
||||
# 0x02 GIF block length.
|
||||
# 0x84 0xF1 = 0b1111_0001_1000_0100 (little endian).
|
||||
# 0b...._...._...._.100 3-bit Clear code.
|
||||
# 0b...._...._..00_0... 3-bit Literal 0x00.
|
||||
# 0b...._...1_10.._.... 3-bit Copy code (2 bytes).
|
||||
# 0b...._000._...._.... 3-bit Literal 0x00.
|
||||
# 0b1111_...._...._.... 4-bit Invalid code.
|
||||
# 0x00 GIF block terminator.
|
||||
bytes 0x02 0x02 0x84 0xF1 0x00
|
||||
|
||||
trailer
|
||||
|
After Width: | Height: | Size: 41 B |
@@ -0,0 +1,37 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make gif
|
||||
|
||||
header
|
||||
|
||||
image {
|
||||
imageWidthHeight 2 2
|
||||
palette {
|
||||
0x00 0x00 0xFF
|
||||
0x11 0x00 0xFF
|
||||
0x22 0x00 0xFF
|
||||
0x33 0x00 0xFF
|
||||
}
|
||||
}
|
||||
|
||||
frame {
|
||||
frameLeftTopWidthHeight 0 0 2 2
|
||||
}
|
||||
|
||||
# The frame area is 4 pixels but we supply 5 (that's still valid LZW data).
|
||||
# Compare with pixel-data-too-much-bad-lzw.gif.make-artificial.txt
|
||||
#
|
||||
# The equivalent bytes' disassembly (see also std/lzw/README.md) is:
|
||||
#
|
||||
# 0x02 LZW literal width.
|
||||
# 0x02 GIF block length.
|
||||
# 0x84 0x5D = 0b0101_1101_1000_0100 (little endian).
|
||||
# 0b...._...._...._.100 3-bit Clear code.
|
||||
# 0b...._...._..00_0... 3-bit Literal 0x00.
|
||||
# 0b...._...1_10.._.... 3-bit Copy code (2 bytes).
|
||||
# 0b...._110._...._.... 3-bit Copy code (2 bytes).
|
||||
# 0b0101_...._...._.... 4-bit End code.
|
||||
# 0x00 GIF block terminator.
|
||||
lzw 2 0x00 0x00 0x00 0x00 0x00
|
||||
|
||||
trailer
|
||||
|
Before Width: | Height: | Size: 41 B |
@@ -1,23 +0,0 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make gif
|
||||
|
||||
header
|
||||
|
||||
image {
|
||||
imageWidthHeight 2 2
|
||||
palette {
|
||||
0x00 0x00 0xFF
|
||||
0x11 0x00 0xFF
|
||||
0x22 0x00 0xFF
|
||||
0x33 0x00 0xFF
|
||||
}
|
||||
}
|
||||
|
||||
frame {
|
||||
frameLeftTopWidthHeight 0 0 2 2
|
||||
}
|
||||
# The frame is 4 pixels, but we supply 5.
|
||||
lzw 2 0x00 0x00 0x00 0x00 0x00
|
||||
|
||||
trailer
|
||||
|
After Width: | Height: | Size: 93 B |
@@ -0,0 +1,32 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make png
|
||||
|
||||
magic
|
||||
|
||||
IHDR {
|
||||
raw {
|
||||
# Width, height.
|
||||
0x00 0x00 0x00 0x01
|
||||
0x00 0x00 0x00 0x01
|
||||
# Depth, color, compression, filter, interlace.
|
||||
0x08 0x00 0x00 0x00 0x00
|
||||
}
|
||||
}
|
||||
|
||||
eXIf {
|
||||
raw {
|
||||
# "LoremIpsum" isn't valid EXIF data. It's just a placeholder.
|
||||
0x4C 0x6F 0x72 0x65 0x6D 0x49 0x70 0x73 0x75 0x6D
|
||||
}
|
||||
}
|
||||
|
||||
IDAT {
|
||||
zlib {
|
||||
# 1x1 gray pixels (with filter bytes).
|
||||
0x00 0x80
|
||||
}
|
||||
}
|
||||
|
||||
IEND {
|
||||
}
|
||||
|
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 |
@@ -9,63 +9,71 @@ e651a889 test/data/animated-red-blue.000002.nie
|
||||
f9a10dac test/data/artificial-gif/background-color.gif
|
||||
36e7d9c7 test/data/artificial-gif/empty-palette.gif
|
||||
db4c30eb test/data/artificial-gif/frame-out-of-bounds.gif
|
||||
fdcc644f test/data/artificial-gif/metadata-empty.gif
|
||||
fdcc644f test/data/artificial-gif/metadata-full.gif
|
||||
6d03b5f3 test/data/artificial-gif/multiple-graphic-controls.gif
|
||||
47c877fd test/data/artificial-gif/multiple-loop-counts.gif
|
||||
76c44866 test/data/artificial-gif/no-frames.gif
|
||||
6ec818c3 test/data/artificial-gif/pixel-data-none.gif
|
||||
5e57adb2 test/data/artificial-gif/pixel-data-not-enough.gif
|
||||
3e29f88a test/data/artificial-gif/pixel-data-too-much.gif
|
||||
f50d1d50 test/data/artificial-gif/small-frame-interlaced.gif
|
||||
f2dc2c43 test/data/artificial-gif/metadata-empty.gif
|
||||
f2dc2c43 test/data/artificial-gif/metadata-full.gif
|
||||
a1a9b56d test/data/artificial-gif/multiple-graphic-controls.gif
|
||||
046a2d07 test/data/artificial-gif/multiple-loop-counts.gif
|
||||
ba6e48f8 test/data/artificial-gif/no-frames.gif
|
||||
f33b9bc1 test/data/artificial-gif/pixel-data-none.gif
|
||||
ac9d76d8 test/data/artificial-gif/pixel-data-not-enough.gif
|
||||
2342e3fc test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif
|
||||
2342e3fc test/data/artificial-gif/pixel-data-too-much-good-lzw.gif
|
||||
39a71dce test/data/artificial-gif/small-frame-interlaced.gif
|
||||
beaec397 test/data/artificial-gif/transparent-index.gif
|
||||
6ec818c3 test/data/artificial-gif/zero-width-frame.gif
|
||||
f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
|
||||
0564b364 test/data/artificial-png/apng-skip-idat.png
|
||||
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
|
||||
3fc62e1e test/data/bricks-dither.gif
|
||||
f36c2e80 test/data/bricks-dither.gif
|
||||
f36c2e80 test/data/bricks-dither.no-ancillary.png
|
||||
f36c2e80 test/data/bricks-dither.png
|
||||
c2bce675 test/data/bricks-gray.bmp
|
||||
0e16e6eb test/data/bricks-gray.gif
|
||||
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
|
||||
b641fef2 test/data/bricks-nodither.gif
|
||||
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
|
||||
aa3e6c7c test/data/crude-flag.nie
|
||||
3014b4c0 test/data/gifplayer-muybridge.gif
|
||||
030f5a48 test/data/harvesters.bmp
|
||||
0d213dc4 test/data/harvesters.gif
|
||||
c18b3d5a test/data/harvesters.gif
|
||||
030f5a48 test/data/harvesters.png
|
||||
e776c90f test/data/hat.bmp
|
||||
a161a63a test/data/hat.gif
|
||||
6dcba6a4 test/data/hat.gif
|
||||
e776c90f test/data/hat.png
|
||||
d30bfe5d test/data/hat.wbmp
|
||||
33a44f22 test/data/hibiscus.primitive.bmp
|
||||
e948122d test/data/hibiscus.primitive.gif
|
||||
25e212b3 test/data/hibiscus.primitive.gif
|
||||
33a44f22 test/data/hibiscus.primitive.png
|
||||
60040742 test/data/hibiscus.regular.bmp
|
||||
7b8dda15 test/data/hibiscus.regular.gif
|
||||
b727da8b test/data/hibiscus.regular.gif
|
||||
60040742 test/data/hibiscus.regular.png
|
||||
dcbb225a test/data/hippopotamus.bmp
|
||||
21e17862 test/data/hippopotamus.interlaced.gif
|
||||
ed4b78fc test/data/hippopotamus.interlaced.gif
|
||||
dcbb225a test/data/hippopotamus.interlaced.png
|
||||
a80781a1 test/data/hippopotamus.interlaced.truncated.gif
|
||||
1f11edb9 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
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
|
||||
21e17862 test/data/hippopotamus.regular.gif
|
||||
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
|
||||
bf7e8c96 test/data/pjw-thumbnail.bmp
|
||||
73d48c08 test/data/pjw-thumbnail.gif
|
||||
bf7e8c96 test/data/pjw-thumbnail.gif
|
||||
bf7e8c96 test/data/pjw-thumbnail.png
|
||||
38cb4cbf test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png
|
||||
38cb4cbf test/data/red-blue-gradient.gamma1dot0.png
|
||||
|
||||