mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Compare commits
72
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
No files matched your search
@@ -0,0 +1 @@
|
||||
BasedOnStyle: Chromium
|
||||
+2
-2
@@ -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++ \
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
- 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`.
|
||||
@@ -47,6 +48,7 @@
|
||||
- Made `wuffs_base__pixel_format` a struct.
|
||||
- Made `wuffs_base__pixel_subsampling` a struct.
|
||||
- Made `wuffs_base__status` a struct.
|
||||
- Prohibited iterate loops inside coroutines.
|
||||
- Removed `ack_metadata_chunk?`.
|
||||
- Removed `wuffs_base__frame_config__blend`.
|
||||
- Renamed I/O `available` methods to `length`.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Binary file not shown.
|
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`.
|
||||
+26
-20
@@ -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;
|
||||
}
|
||||
@@ -658,7 +658,9 @@ convert_frames() {
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
if (g_flags.remaining_argc > 0) {
|
||||
return "main: bad argument: use \"program < input\", not \"program input\"";
|
||||
} else if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ wuffs_base__slice_u8 g_workbuf = {0};
|
||||
wuffs_base__slice_u8 g_printbuf = {0};
|
||||
|
||||
bool g_first_play = true;
|
||||
bool g_still_image = false;
|
||||
uint32_t g_num_loops_remaining = 0;
|
||||
wuffs_base__image_config g_ic = {0};
|
||||
wuffs_base__pixel_buffer g_pb = {0};
|
||||
@@ -494,6 +495,7 @@ play() {
|
||||
|
||||
if (g_first_play) {
|
||||
g_first_play = false;
|
||||
g_still_image = wuffs_gif__decoder__num_decoded_frame_configs(&dec) <= 1;
|
||||
g_num_loops_remaining = wuffs_gif__decoder__num_animation_loops(&dec);
|
||||
}
|
||||
|
||||
@@ -509,7 +511,9 @@ main1(int argc, char** argv) {
|
||||
TRY(read_stdin());
|
||||
while (true) {
|
||||
TRY(play());
|
||||
if (g_num_loops_remaining == 0) {
|
||||
if (g_still_image) {
|
||||
break;
|
||||
} else if (g_num_loops_remaining == 0) {
|
||||
continue;
|
||||
}
|
||||
g_num_loops_remaining--;
|
||||
|
||||
@@ -35,6 +35,8 @@ matters if the image has fully or partially transparent pixels.
|
||||
The '1' to '8' keys change the magnification zoom (or minification zoom with
|
||||
the shift key). The '0' key toggles nearest neighbor and bilinear filtering.
|
||||
|
||||
The arrow keys (or hjkl keys) scroll the image. The '`' key resets.
|
||||
|
||||
The Escape key quits.
|
||||
*/
|
||||
|
||||
@@ -108,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 {
|
||||
@@ -308,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;
|
||||
@@ -335,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);
|
||||
@@ -407,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) {
|
||||
@@ -469,6 +490,44 @@ load(xcb_connection_t* c, xcb_window_t w, const char* filename) {
|
||||
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).
|
||||
//
|
||||
// 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) {
|
||||
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);
|
||||
@@ -532,6 +591,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;
|
||||
@@ -544,12 +606,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);
|
||||
}
|
||||
@@ -589,6 +653,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':
|
||||
@@ -619,6 +708,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) {
|
||||
@@ -634,6 +755,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.
|
||||
|
||||
+3
-2
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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,125 @@
|
||||
// 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__io_buffer){
|
||||
.data = ((wuffs_base__slice_u8){
|
||||
.ptr = dst_buffer,
|
||||
.len = 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,6 +15,7 @@
|
||||
# https://github.com/google/oss-fuzz/blob/master/projects/wuffs/Dockerfile
|
||||
|
||||
bmp: test/data/*.bmp ../bmpsuite_corpus/*.bmp
|
||||
bzip2: test/data/*.bz2
|
||||
cbor: test/data/*.cbor
|
||||
gif: test/data/*.gif test/data/artificial-gif/*.gif
|
||||
gzip: test/data/*.gz
|
||||
|
||||
@@ -310,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:
|
||||
@@ -384,6 +385,7 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
@@ -393,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);
|
||||
}
|
||||
}
|
||||
@@ -433,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();
|
||||
@@ -494,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) {
|
||||
@@ -535,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));
|
||||
}
|
||||
|
||||
@@ -1192,6 +1192,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;
|
||||
|
||||
@@ -139,8 +139,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
// 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).
|
||||
@@ -149,6 +150,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
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)
|
||||
@@ -156,6 +160,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
{-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
|
||||
};
|
||||
|
||||
+35
-42
@@ -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 {
|
||||
|
||||
+32
-41
@@ -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)
|
||||
|
||||
+21
-11
@@ -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 {
|
||||
|
||||
+3
-1
@@ -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())
|
||||
}
|
||||
|
||||
+146
@@ -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
|
||||
}
|
||||
+2403
-474
@@ -1459,6 +1459,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;
|
||||
@@ -6634,7 +6666,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 {
|
||||
@@ -6790,6 +6821,272 @@ 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_huffman_codes[];
|
||||
extern const char wuffs_bzip2__error__bad_number_of_sections[];
|
||||
extern const char wuffs_bzip2__error__unsupported_huffman_code[];
|
||||
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][1024][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[];
|
||||
|
||||
@@ -6921,7 +7218,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];
|
||||
@@ -7354,7 +7650,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;
|
||||
@@ -7362,7 +7657,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;
|
||||
@@ -7370,7 +7664,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_hlen;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -7878,16 +8171,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;
|
||||
@@ -7978,7 +8269,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;
|
||||
@@ -8519,9 +8809,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
|
||||
@@ -9179,12 +9466,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
|
||||
|
||||
@@ -9359,6 +9647,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_gama;
|
||||
bool f_seen_iccp;
|
||||
bool f_seen_idat;
|
||||
bool f_seen_ihdr;
|
||||
bool f_seen_plte;
|
||||
bool f_seen_srgb;
|
||||
bool f_seen_trns;
|
||||
@@ -16059,8 +16348,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
// 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).
|
||||
@@ -16069,6 +16359,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
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)
|
||||
@@ -16076,6 +16369,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
{-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
|
||||
};
|
||||
@@ -23212,7 +23506,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;
|
||||
@@ -23279,7 +23573,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));
|
||||
}
|
||||
@@ -23291,13 +23586,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 {
|
||||
@@ -23320,7 +23615,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;
|
||||
@@ -23389,13 +23684,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));
|
||||
}
|
||||
@@ -23407,7 +23700,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;
|
||||
@@ -23432,7 +23724,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);
|
||||
@@ -23507,7 +23799,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;
|
||||
@@ -23518,7 +23810,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:
|
||||
@@ -23570,7 +23861,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) {
|
||||
@@ -23677,7 +23968,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:;
|
||||
@@ -23732,7 +24023,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;
|
||||
@@ -23788,7 +24079,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);
|
||||
}
|
||||
@@ -23939,7 +24230,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) {
|
||||
@@ -24012,7 +24303,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;
|
||||
@@ -24075,7 +24366,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) {
|
||||
@@ -24181,7 +24472,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;
|
||||
@@ -24251,7 +24542,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;
|
||||
@@ -24270,7 +24561,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;
|
||||
@@ -24293,13 +24584,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);
|
||||
}
|
||||
@@ -24565,6 +24856,1550 @@ 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_huffman_codes[] = "#bzip2: bad number of Huffman codes";
|
||||
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
|
||||
const char wuffs_bzip2__error__unsupported_huffman_code[] = "#bzip2: unsupported Huffman code";
|
||||
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_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_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_nodes));
|
||||
} else {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][1] = ((uint16_t)(v_num_nodes));
|
||||
}
|
||||
if (v_num_nodes >= 1023) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__unsupported_huffman_code);
|
||||
}
|
||||
v_stack_values[v_stack_height] = v_num_nodes;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_nodes][0] = 0;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_nodes][1] = 0;
|
||||
v_num_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)((1280 + v_symbol_index)));
|
||||
} else if ((v_symbol_index + 1) < self->private_impl.f_num_symbols) {
|
||||
v_leaf_value = ((uint16_t)((1023 + v_symbol_index)));
|
||||
} else {
|
||||
v_leaf_value = 2047;
|
||||
}
|
||||
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 < 1024) && (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;
|
||||
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 & 2047);
|
||||
while (v_child < 1024) {
|
||||
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 < 1280) {
|
||||
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 > 1281) {
|
||||
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 - 1279))) << 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;
|
||||
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 < 1024) {
|
||||
v_node_index = ((uint32_t)(v_child));
|
||||
goto label__0__continue;
|
||||
} else if (v_child < 1280) {
|
||||
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 > 1281) {
|
||||
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 - 1279))) << 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
|
||||
@@ -24777,7 +26612,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;
|
||||
}
|
||||
@@ -24866,8 +26700,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);
|
||||
@@ -25288,7 +27120,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;
|
||||
|
||||
@@ -26712,7 +28543,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);
|
||||
@@ -26725,7 +28556,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();
|
||||
}
|
||||
|
||||
@@ -27229,7 +29060,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;
|
||||
@@ -27429,7 +29259,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;
|
||||
@@ -27858,7 +29687,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28123,7 +29952,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28335,7 +30164,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28447,7 +30276,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;
|
||||
@@ -28455,7 +30283,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_redir_mask = self->private_data.s_decode_huffman_slow[0].v_redir_mask;
|
||||
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
|
||||
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
|
||||
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28667,7 +30494,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_n_copied < v_hlen) {
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
@@ -28707,7 +30534,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;
|
||||
@@ -28715,7 +30541,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;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -29194,8 +31019,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);
|
||||
@@ -29243,8 +31067,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);
|
||||
}
|
||||
@@ -29556,7 +31379,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) {
|
||||
@@ -29567,9 +31393,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);
|
||||
@@ -29599,7 +31423,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:
|
||||
@@ -29688,7 +31514,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;
|
||||
}
|
||||
@@ -29759,7 +31585,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);
|
||||
@@ -29894,16 +31720,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);
|
||||
}
|
||||
|
||||
@@ -29956,52 +31783,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;
|
||||
@@ -30033,7 +31873,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;
|
||||
@@ -30134,6 +31974,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:
|
||||
@@ -30189,13 +32030,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);
|
||||
@@ -30213,8 +32057,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;
|
||||
@@ -30238,7 +32082,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;
|
||||
@@ -30271,15 +32114,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) {
|
||||
{
|
||||
@@ -30325,7 +32161,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;
|
||||
}
|
||||
}
|
||||
@@ -30957,17 +32793,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;
|
||||
}
|
||||
@@ -31282,7 +33118,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);
|
||||
}
|
||||
@@ -31519,7 +33355,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;
|
||||
@@ -31556,7 +33391,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) {
|
||||
@@ -31588,8 +33423,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);
|
||||
@@ -31697,7 +33531,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:
|
||||
@@ -32889,7 +34722,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);
|
||||
@@ -32951,7 +34783,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) {
|
||||
@@ -33015,8 +34846,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)));
|
||||
@@ -33045,8 +34874,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);
|
||||
@@ -33089,9 +34916,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);
|
||||
@@ -33147,8 +34971,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);
|
||||
@@ -33202,8 +35024,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);
|
||||
@@ -33253,8 +35073,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)));
|
||||
@@ -33298,8 +35116,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)));
|
||||
@@ -33345,8 +35161,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);
|
||||
@@ -34136,102 +35950,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34293,9 +36107,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;
|
||||
|
||||
@@ -34403,7 +36214,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:
|
||||
@@ -34467,23 +36277,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);
|
||||
@@ -34492,7 +36300,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);
|
||||
@@ -34515,8 +36322,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;
|
||||
}
|
||||
@@ -34528,7 +36333,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;
|
||||
@@ -34903,7 +36707,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:
|
||||
@@ -34971,7 +36775,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));
|
||||
}
|
||||
@@ -34983,13 +36788,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 {
|
||||
@@ -35012,7 +36817,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;
|
||||
@@ -35073,13 +36878,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;
|
||||
@@ -35120,7 +36925,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;
|
||||
@@ -35270,7 +37075,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;
|
||||
@@ -35289,7 +37094,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;
|
||||
@@ -35312,13 +37117,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);
|
||||
}
|
||||
|
||||
@@ -35863,6 +37668,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";
|
||||
@@ -36108,7 +37914,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(
|
||||
@@ -37784,16 +39591,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;
|
||||
@@ -37857,6 +39658,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;
|
||||
}
|
||||
@@ -37922,6 +39727,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) {
|
||||
@@ -37962,7 +39772,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;
|
||||
@@ -37979,7 +39789,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;
|
||||
}
|
||||
@@ -38044,7 +39854,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;
|
||||
@@ -38424,7 +40234,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;
|
||||
@@ -38442,7 +40253,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_chunk_type == 1163152464) {
|
||||
if ((self->private_impl.f_chunk_type == 1163152464) && ! a_framy) {
|
||||
if (self->private_impl.f_seen_plte) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
@@ -38469,43 +40280,8 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
}
|
||||
if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
if (self->private_impl.f_report_metadata_exif) {
|
||||
if (self->private_impl.f_seen_exif) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
@@ -38514,7 +40290,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_exif(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38524,97 +40300,6 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
self->private_impl.f_seen_exif = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) || (self->private_impl.f_chunk_type == 1951942004) || (self->private_impl.f_chunk_type == 1951945850)) {
|
||||
if (self->private_impl.f_report_metadata_kvp) {
|
||||
self->private_impl.f_metadata_flavor = 4;
|
||||
@@ -38623,6 +40308,135 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
}
|
||||
} else if ( ! a_framy) {
|
||||
if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
}
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||
@@ -39990,6 +41804,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;
|
||||
@@ -40005,10 +41821,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));
|
||||
}
|
||||
@@ -40020,12 +41837,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));
|
||||
}
|
||||
@@ -40037,10 +41854,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;
|
||||
@@ -40111,7 +41932,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) {
|
||||
@@ -40119,7 +41981,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;
|
||||
@@ -40128,7 +41990,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;
|
||||
@@ -40138,8 +42000,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;
|
||||
@@ -40168,7 +42046,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;
|
||||
@@ -40324,11 +42202,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;
|
||||
@@ -40399,10 +42273,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));
|
||||
}
|
||||
@@ -40539,17 +42416,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;
|
||||
@@ -40564,7 +42458,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
|
||||
@@ -40575,13 +42469,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;
|
||||
@@ -41029,12 +42919,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;
|
||||
}
|
||||
@@ -41147,7 +43037,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;
|
||||
}
|
||||
@@ -41361,7 +43251,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -41370,7 +43259,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -41442,7 +43330,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -41452,7 +43339,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -41546,7 +43432,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
@@ -41571,7 +43457,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
@@ -42562,7 +44448,7 @@ wuffs_tga__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
self->private_impl.f_opaque);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -42631,7 +44517,8 @@ wuffs_tga__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));
|
||||
}
|
||||
@@ -42643,13 +44530,13 @@ wuffs_tga__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 {
|
||||
@@ -42672,7 +44559,7 @@ wuffs_tga__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;
|
||||
@@ -42773,7 +44660,8 @@ wuffs_tga__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));
|
||||
}
|
||||
@@ -42785,7 +44673,6 @@ wuffs_tga__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;
|
||||
@@ -42866,7 +44753,7 @@ wuffs_tga__decoder__decode_frame(
|
||||
}
|
||||
} 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__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
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);
|
||||
}
|
||||
@@ -42956,7 +44843,7 @@ wuffs_tga__decoder__decode_frame(
|
||||
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__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
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);
|
||||
}
|
||||
@@ -43012,7 +44899,7 @@ wuffs_tga__decoder__decode_frame(
|
||||
goto label__resume__break;
|
||||
}
|
||||
label__resume__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -43093,7 +44980,7 @@ wuffs_tga__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;
|
||||
@@ -43112,7 +44999,7 @@ wuffs_tga__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;
|
||||
@@ -43135,13 +45022,13 @@ wuffs_tga__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);
|
||||
}
|
||||
@@ -43461,7 +45348,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:
|
||||
@@ -43531,7 +45418,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));
|
||||
}
|
||||
@@ -43543,13 +45431,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 {
|
||||
@@ -43572,7 +45460,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;
|
||||
@@ -43661,7 +45549,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));
|
||||
}
|
||||
@@ -43673,7 +45562,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;
|
||||
@@ -43736,7 +45624,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;
|
||||
@@ -43814,7 +45702,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;
|
||||
@@ -43833,7 +45721,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;
|
||||
@@ -43856,13 +45744,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);
|
||||
}
|
||||
@@ -44914,6 +46802,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:
|
||||
@@ -44988,6 +46877,7 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
@@ -44997,12 +46887,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);
|
||||
}
|
||||
}
|
||||
@@ -45037,7 +46929,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();
|
||||
@@ -45098,6 +46992,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) {
|
||||
@@ -45139,6 +47039,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));
|
||||
}
|
||||
|
||||
+2408
-479
@@ -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
|
||||
// adfd2965cc104f3de6cccaed5095721d042c1251 committed on 2022-01-18.
|
||||
// 3ff4bf46746fff230d4704f8c5a35a1665ddbd56 committed on 2022-06-03.
|
||||
#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.14"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3273
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20220118
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.14+3273.20220118"
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.15"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3345
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20220603
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.15+3345.20220603"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -1460,6 +1460,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;
|
||||
@@ -6635,7 +6667,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 {
|
||||
@@ -6791,6 +6822,272 @@ 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_huffman_codes[];
|
||||
extern const char wuffs_bzip2__error__bad_number_of_sections[];
|
||||
extern const char wuffs_bzip2__error__unsupported_huffman_code[];
|
||||
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][1024][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[];
|
||||
|
||||
@@ -6922,7 +7219,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];
|
||||
@@ -7355,7 +7651,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;
|
||||
@@ -7363,7 +7658,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;
|
||||
@@ -7371,7 +7665,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_hlen;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -7879,16 +8172,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;
|
||||
@@ -7979,7 +8270,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;
|
||||
@@ -8520,9 +8810,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
|
||||
@@ -9180,12 +9467,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
|
||||
|
||||
@@ -9360,6 +9648,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_gama;
|
||||
bool f_seen_iccp;
|
||||
bool f_seen_idat;
|
||||
bool f_seen_ihdr;
|
||||
bool f_seen_plte;
|
||||
bool f_seen_srgb;
|
||||
bool f_seen_trns;
|
||||
@@ -16060,8 +16349,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
// 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).
|
||||
@@ -16070,6 +16360,9 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
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)
|
||||
@@ -16077,6 +16370,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
{-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
|
||||
};
|
||||
@@ -23213,7 +23507,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;
|
||||
@@ -23280,7 +23574,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));
|
||||
}
|
||||
@@ -23292,13 +23587,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 {
|
||||
@@ -23321,7 +23616,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;
|
||||
@@ -23390,13 +23685,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));
|
||||
}
|
||||
@@ -23408,7 +23701,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;
|
||||
@@ -23433,7 +23725,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);
|
||||
@@ -23508,7 +23800,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;
|
||||
@@ -23519,7 +23811,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:
|
||||
@@ -23571,7 +23862,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) {
|
||||
@@ -23678,7 +23969,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:;
|
||||
@@ -23733,7 +24024,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;
|
||||
@@ -23789,7 +24080,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);
|
||||
}
|
||||
@@ -23940,7 +24231,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) {
|
||||
@@ -24013,7 +24304,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;
|
||||
@@ -24076,7 +24367,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) {
|
||||
@@ -24182,7 +24473,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;
|
||||
@@ -24252,7 +24543,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;
|
||||
@@ -24271,7 +24562,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;
|
||||
@@ -24294,13 +24585,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);
|
||||
}
|
||||
@@ -24566,6 +24857,1550 @@ 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_huffman_codes[] = "#bzip2: bad number of Huffman codes";
|
||||
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
|
||||
const char wuffs_bzip2__error__unsupported_huffman_code[] = "#bzip2: unsupported Huffman code";
|
||||
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_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_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_nodes));
|
||||
} else {
|
||||
self->private_data.f_huffman_trees[a_which][v_node_index][1] = ((uint16_t)(v_num_nodes));
|
||||
}
|
||||
if (v_num_nodes >= 1023) {
|
||||
return wuffs_base__make_status(wuffs_bzip2__error__unsupported_huffman_code);
|
||||
}
|
||||
v_stack_values[v_stack_height] = v_num_nodes;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_nodes][0] = 0;
|
||||
self->private_data.f_huffman_trees[a_which][v_num_nodes][1] = 0;
|
||||
v_num_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)((1280 + v_symbol_index)));
|
||||
} else if ((v_symbol_index + 1) < self->private_impl.f_num_symbols) {
|
||||
v_leaf_value = ((uint16_t)((1023 + v_symbol_index)));
|
||||
} else {
|
||||
v_leaf_value = 2047;
|
||||
}
|
||||
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 < 1024) && (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;
|
||||
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 & 2047);
|
||||
while (v_child < 1024) {
|
||||
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 < 1280) {
|
||||
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 > 1281) {
|
||||
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 - 1279))) << 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;
|
||||
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 < 1024) {
|
||||
v_node_index = ((uint32_t)(v_child));
|
||||
goto label__0__continue;
|
||||
} else if (v_child < 1280) {
|
||||
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 > 1281) {
|
||||
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 - 1279))) << 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
|
||||
@@ -24778,7 +26613,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;
|
||||
}
|
||||
@@ -24867,8 +26701,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);
|
||||
@@ -25289,7 +27121,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;
|
||||
|
||||
@@ -26713,7 +28544,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);
|
||||
@@ -26726,7 +28557,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();
|
||||
}
|
||||
|
||||
@@ -27230,7 +29061,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;
|
||||
@@ -27430,7 +29260,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;
|
||||
@@ -27859,7 +29688,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28124,7 +29953,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28336,7 +30165,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28448,7 +30277,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;
|
||||
@@ -28456,7 +30284,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_redir_mask = self->private_data.s_decode_huffman_slow[0].v_redir_mask;
|
||||
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
|
||||
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
|
||||
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28668,7 +30495,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__make_slice_u8_ij(self->private_data.f_history, ((self->private_impl.f_history_index - v_hdist) & 32767), 33025));
|
||||
if (v_n_copied < v_hlen) {
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
@@ -28708,7 +30535,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;
|
||||
@@ -28716,7 +30542,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;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -29195,8 +31020,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);
|
||||
@@ -29244,8 +31068,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);
|
||||
}
|
||||
@@ -29557,7 +31380,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) {
|
||||
@@ -29568,9 +31394,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);
|
||||
@@ -29600,7 +31424,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:
|
||||
@@ -29689,7 +31515,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;
|
||||
}
|
||||
@@ -29760,7 +31586,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);
|
||||
@@ -29895,16 +31721,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);
|
||||
}
|
||||
|
||||
@@ -29957,52 +31784,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;
|
||||
@@ -30034,7 +31874,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;
|
||||
@@ -30135,6 +31975,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:
|
||||
@@ -30190,13 +32031,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);
|
||||
@@ -30214,8 +32058,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;
|
||||
@@ -30239,7 +32083,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;
|
||||
@@ -30272,15 +32115,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) {
|
||||
{
|
||||
@@ -30326,7 +32162,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;
|
||||
}
|
||||
}
|
||||
@@ -30958,17 +32794,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;
|
||||
}
|
||||
@@ -31283,7 +33119,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);
|
||||
}
|
||||
@@ -31520,7 +33356,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;
|
||||
@@ -31557,7 +33392,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) {
|
||||
@@ -31589,8 +33424,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);
|
||||
@@ -31698,7 +33532,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:
|
||||
@@ -32890,7 +34723,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);
|
||||
@@ -32952,7 +34784,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) {
|
||||
@@ -33016,8 +34847,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)));
|
||||
@@ -33046,8 +34875,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);
|
||||
@@ -33090,9 +34917,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);
|
||||
@@ -33148,8 +34972,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);
|
||||
@@ -33203,8 +35025,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);
|
||||
@@ -33254,8 +35074,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)));
|
||||
@@ -33299,8 +35117,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)));
|
||||
@@ -33346,8 +35162,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);
|
||||
@@ -34137,102 +35951,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34294,9 +36108,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;
|
||||
|
||||
@@ -34404,7 +36215,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:
|
||||
@@ -34468,23 +36278,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);
|
||||
@@ -34493,7 +36301,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);
|
||||
@@ -34516,8 +36323,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;
|
||||
}
|
||||
@@ -34529,7 +36334,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;
|
||||
@@ -34904,7 +36708,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:
|
||||
@@ -34972,7 +36776,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));
|
||||
}
|
||||
@@ -34984,13 +36789,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 {
|
||||
@@ -35013,7 +36818,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;
|
||||
@@ -35074,13 +36879,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;
|
||||
@@ -35121,7 +36926,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;
|
||||
@@ -35271,7 +37076,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;
|
||||
@@ -35290,7 +37095,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;
|
||||
@@ -35313,13 +37118,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);
|
||||
}
|
||||
|
||||
@@ -35864,6 +37669,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";
|
||||
@@ -36109,7 +37915,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(
|
||||
@@ -37785,16 +39592,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;
|
||||
@@ -37858,6 +39659,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;
|
||||
}
|
||||
@@ -37923,6 +39728,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) {
|
||||
@@ -37963,7 +39773,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;
|
||||
@@ -37980,7 +39790,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;
|
||||
}
|
||||
@@ -38045,7 +39855,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;
|
||||
@@ -38425,7 +40235,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;
|
||||
@@ -38443,7 +40254,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_chunk_type == 1163152464) {
|
||||
if ((self->private_impl.f_chunk_type == 1163152464) && ! a_framy) {
|
||||
if (self->private_impl.f_seen_plte) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
@@ -38470,43 +40281,8 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
}
|
||||
if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
if (self->private_impl.f_report_metadata_exif) {
|
||||
if (self->private_impl.f_seen_exif) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
@@ -38515,7 +40291,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_png__decoder__decode_exif(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38525,97 +40301,6 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
self->private_impl.f_seen_exif = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) || (self->private_impl.f_chunk_type == 1951942004) || (self->private_impl.f_chunk_type == 1951945850)) {
|
||||
if (self->private_impl.f_report_metadata_kvp) {
|
||||
self->private_impl.f_metadata_flavor = 4;
|
||||
@@ -38624,6 +40309,135 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
}
|
||||
} else if ( ! a_framy) {
|
||||
if (self->private_impl.f_chunk_type == 1280598881) {
|
||||
if (self->private_impl.f_seen_actl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_png__decoder__decode_actl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_actl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1297238115) {
|
||||
if (self->private_impl.f_report_metadata_chrm) {
|
||||
if (self->private_impl.f_seen_chrm) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
status = wuffs_png__decoder__decode_chrm(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_fctl = true;
|
||||
} else if (self->private_impl.f_chunk_type == 1095582055) {
|
||||
if (self->private_impl.f_report_metadata_gama) {
|
||||
if (self->private_impl.f_seen_gama) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_gama = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
if (self->private_impl.f_report_metadata_iccp) {
|
||||
if (self->private_impl.f_seen_iccp) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_iccp = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1111970419) {
|
||||
if (self->private_impl.f_report_metadata_srgb) {
|
||||
if (self->private_impl.f_seen_srgb) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_srgb = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
}
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||
@@ -39991,6 +41805,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;
|
||||
@@ -40006,10 +41822,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));
|
||||
}
|
||||
@@ -40021,12 +41838,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));
|
||||
}
|
||||
@@ -40038,10 +41855,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;
|
||||
@@ -40112,7 +41933,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) {
|
||||
@@ -40120,7 +41982,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;
|
||||
@@ -40129,7 +41991,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;
|
||||
@@ -40139,8 +42001,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;
|
||||
@@ -40169,7 +42047,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;
|
||||
@@ -40325,11 +42203,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;
|
||||
@@ -40400,10 +42274,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));
|
||||
}
|
||||
@@ -40540,17 +42417,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;
|
||||
@@ -40565,7 +42459,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
|
||||
@@ -40576,13 +42470,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;
|
||||
@@ -41030,12 +42920,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;
|
||||
}
|
||||
@@ -41148,7 +43038,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;
|
||||
}
|
||||
@@ -41362,7 +43252,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -41371,7 +43260,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
@@ -41443,7 +43331,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -41453,7 +43340,6 @@ wuffs_png__decoder__tell_me_more(
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
@@ -41547,7 +43433,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
@@ -41572,7 +43458,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
self->private_impl.f_call_sequence &= 239;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
@@ -42563,7 +44449,7 @@ wuffs_tga__decoder__decode_image_config(
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
self->private_impl.f_opaque);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_call_sequence = 32;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -42632,7 +44518,8 @@ wuffs_tga__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));
|
||||
}
|
||||
@@ -42644,13 +44531,13 @@ wuffs_tga__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 {
|
||||
@@ -42673,7 +44560,7 @@ wuffs_tga__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;
|
||||
@@ -42774,7 +44661,8 @@ wuffs_tga__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));
|
||||
}
|
||||
@@ -42786,7 +44674,6 @@ wuffs_tga__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;
|
||||
@@ -42867,7 +44754,7 @@ wuffs_tga__decoder__decode_frame(
|
||||
}
|
||||
} 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__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
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);
|
||||
}
|
||||
@@ -42957,7 +44844,7 @@ wuffs_tga__decoder__decode_frame(
|
||||
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__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
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);
|
||||
}
|
||||
@@ -43013,7 +44900,7 @@ wuffs_tga__decoder__decode_frame(
|
||||
goto label__resume__break;
|
||||
}
|
||||
label__resume__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
self->private_impl.f_call_sequence = 96;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
@@ -43094,7 +44981,7 @@ wuffs_tga__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;
|
||||
@@ -43113,7 +45000,7 @@ wuffs_tga__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;
|
||||
@@ -43136,13 +45023,13 @@ wuffs_tga__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);
|
||||
}
|
||||
@@ -43462,7 +45349,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:
|
||||
@@ -43532,7 +45419,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));
|
||||
}
|
||||
@@ -43544,13 +45432,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 {
|
||||
@@ -43573,7 +45461,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;
|
||||
@@ -43662,7 +45550,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));
|
||||
}
|
||||
@@ -43674,7 +45563,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;
|
||||
@@ -43737,7 +45625,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;
|
||||
@@ -43815,7 +45703,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;
|
||||
@@ -43834,7 +45722,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;
|
||||
@@ -43857,13 +45745,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);
|
||||
}
|
||||
@@ -44915,6 +46803,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:
|
||||
@@ -44989,6 +46878,7 @@ redirect:
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
interested_in_metadata_after_the_frame = true;
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
@@ -44998,12 +46888,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);
|
||||
}
|
||||
}
|
||||
@@ -45038,7 +46930,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();
|
||||
@@ -45099,6 +46993,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) {
|
||||
@@ -45140,6 +47040,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));
|
||||
}
|
||||
|
||||
@@ -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,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;
|
||||
}
|
||||
+19
-40
@@ -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,768 @@
|
||||
// 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 Huffman codes"
|
||||
pub status "#bad number of sections"
|
||||
pub status "#unsupported Huffman code"
|
||||
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 Huffman tree node. The build_huffman_tree
|
||||
// method comment details what the base.u16 values mean.
|
||||
//
|
||||
// 1024 is just a guess for the worst case number of nodes needed. TODO: be
|
||||
// more rigorous about deriving this upper bound.
|
||||
huffman_trees : array[6] array[1024] 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 11 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 0x3FF = 1023 or less means
|
||||
// a branch node and 0x400 = 1024 or more means a leaf node.
|
||||
// - The middle bit is 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=0x500 (RUNA) cl=3
|
||||
// - symbol=0x501 (RUNB) cl=3
|
||||
// - symbol=0x401 (m01) cl=2
|
||||
// - symbol=0x402 (m02) cl=3
|
||||
// - symbol=0x403 (m03) cl=2
|
||||
// - symbol=0x7FF (EOB) cl=3
|
||||
//
|
||||
// The bitstring mapping is:
|
||||
// - "00" 0x401 (m01)
|
||||
// - "01" 0x403 (m03)
|
||||
// - "100" 0x500 (RUNA)
|
||||
// - "101" 0x501 (RUNB)
|
||||
// - "110" 0x402 (m02)
|
||||
// - "111" 0x7FF (EOB)
|
||||
//
|
||||
// The Huffman tree has 5 nodes. Each node has two children, represented by a
|
||||
// base.u16 value. 1023 or less means that the child is a branch node. 1024 =
|
||||
// 0x400 or above means a leaf node (with the symbol values as above).
|
||||
// - node0 = [0x001 (node1), 0x002 (node2)]
|
||||
// - node1 = [0x401 (m01) , 0x403 (m03) ]
|
||||
// - node2 = [0x003 (node3), 0x004 (node4)]
|
||||
// - node3 = [0x500 (RUNA) , 0x501 (RUNB) ]
|
||||
// - node4 = [0x402 (m02) , 0x7FF (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 0x401, 0x403 and 0x500
|
||||
// symbols, we would have this (in-progress) tree:
|
||||
// - node0 = [0x001 (node1), 0x002 (node2)]
|
||||
// - node1 = [0x401 (m01) , 0x403 (m03) ]
|
||||
// - node2 = [0x003 (node3), 0 ]
|
||||
// - node3 = [0x500 (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_nodes : base.u32[..= 1023]
|
||||
var stack_height : base.u32[..= 21]
|
||||
var stack_values : array[21] base.u32[..= 1023]
|
||||
var node_index : base.u32[..= 1023]
|
||||
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_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_nodes as base.u16
|
||||
} else {
|
||||
this.huffman_trees[args.which][node_index][1] = num_nodes as base.u16
|
||||
}
|
||||
if num_nodes >= 1023 {
|
||||
return "#unsupported Huffman code"
|
||||
}
|
||||
stack_values[stack_height] = num_nodes
|
||||
this.huffman_trees[args.which][num_nodes][0] = 0
|
||||
this.huffman_trees[args.which][num_nodes][1] = 0
|
||||
num_nodes += 1
|
||||
stack_height += 1
|
||||
} endwhile
|
||||
|
||||
node_index = stack_values[stack_height - 1]
|
||||
if symbol_index < 2 {
|
||||
leaf_value = (0x500 + symbol_index) as base.u16
|
||||
} else if (symbol_index + 1) < this.num_symbols {
|
||||
leaf_value = (0x3FF + symbol_index) as base.u16
|
||||
} else {
|
||||
leaf_value = 0x7FF
|
||||
}
|
||||
|
||||
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 < 1024) 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,124 @@
|
||||
// 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[..= 16_777216] // 16_777216 = (2 << 23)
|
||||
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
|
||||
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 & 0x7FF
|
||||
while child < 1024 {
|
||||
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 < 1280 { // 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 > 1281 { // EOB symbol.
|
||||
this.decode_huffman_finished = true
|
||||
break.outer
|
||||
}
|
||||
|
||||
// RUNA or RUNB symbol.
|
||||
if run_shift >= 23 {
|
||||
return "#bad block length"
|
||||
}
|
||||
run = ((child - 1279) as base.u32) << 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,102 @@
|
||||
// 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[..= 1023]
|
||||
|
||||
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[..= 16_777216] // 16_777216 = (2 << 23)
|
||||
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
|
||||
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 < 1024 { // Branch node.
|
||||
node_index = child as base.u32
|
||||
continue
|
||||
|
||||
} else if child < 1280 { // 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 > 1281 { // 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 - 1279) as base.u32) << 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"
|
||||
|
||||
+3
-2
@@ -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
|
||||
```
|
||||
|
||||
+24
-20
@@ -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
|
||||
|
||||
+57
-89
@@ -16,53 +16,15 @@ pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32,
|
||||
height : base.u32,
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x01: metadata reported; image config decode is in progress.
|
||||
// - 0x02: metadata finished; image config decode is in progress.
|
||||
// - 0x03: image config decoded, including the first frame's bounds, but
|
||||
// not the first frame's pixels.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0x05: frame decoded.
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
//
|
||||
// GIF is unusual (distinguishing state 0x03 / state 0x05) in that the
|
||||
// first frame's bounds can affect the overall image bounds (as per
|
||||
// A GIF's first frame's bounds affects the overall image bounds (per
|
||||
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt).
|
||||
// Decoding the first frame's bounds is part of DIC even though,
|
||||
// conceptually, it should be part of the first DFC.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x00 -> 0x03: via DIC (metadata not reported)
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0x05: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x01 -> 0x02: via TMM
|
||||
//
|
||||
// - 0x02 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x02 -> 0x03: via DIC (metadata not reported)
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0x05: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0x04: via DFC with implicit DF
|
||||
// - 0x04 -> 0x05: via DF
|
||||
//
|
||||
// - 0x05 -> 0x04: via DFC
|
||||
// - 0x05 -> 0x05: via DF with implicit DFC
|
||||
//
|
||||
// - ???? -> 0x05: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame, implicit means skip_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// - TMM is tell_me_more
|
||||
// Decoding the first frame's bounds is part of decode_image_config even
|
||||
// though it's conceptually part of the first decode_frame_config.
|
||||
call_sequence : base.u8,
|
||||
|
||||
ignore_metadata : base.bool,
|
||||
report_metadata_iccp : base.bool,
|
||||
report_metadata_xmp : base.bool,
|
||||
metadata_fourcc : base.u32,
|
||||
@@ -71,9 +33,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
quirks : array[QUIRKS_COUNT] base.bool,
|
||||
|
||||
delayed_num_decoded_frames : base.bool,
|
||||
end_of_data : base.bool,
|
||||
restarted : base.bool,
|
||||
previous_lzw_decode_ended_abruptly : base.bool,
|
||||
seen_header : base.bool,
|
||||
|
||||
has_global_palette : base.bool,
|
||||
|
||||
@@ -128,7 +89,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
if (this.call_sequence == 0) and (args.quirk >= QUIRKS_BASE) {
|
||||
if (this.call_sequence == 0x00) and (args.quirk >= QUIRKS_BASE) {
|
||||
args.quirk -= QUIRKS_BASE
|
||||
if args.quirk < QUIRKS_COUNT {
|
||||
this.quirks[args.quirk] = args.enabled
|
||||
@@ -139,17 +100,16 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var ffio : base.bool
|
||||
|
||||
if this.call_sequence == 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
} else if not this.seen_header {
|
||||
this.decode_header?(src: args.src)
|
||||
this.decode_lsd?(src: args.src)
|
||||
} else if this.call_sequence <> 2 {
|
||||
return base."#bad call sequence"
|
||||
this.seen_header = true
|
||||
}
|
||||
|
||||
this.decode_up_to_id_part1?(src: args.src)
|
||||
|
||||
// TODO: if this.end_of_data, return an error and/or set dst to zero?
|
||||
|
||||
ffio = not this.gc_has_transparent_index
|
||||
if not this.quirks[QUIRK_HONOR_BACKGROUND_COLOR - QUIRKS_BASE] {
|
||||
ffio = ffio and
|
||||
@@ -176,7 +136,9 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
first_frame_is_opaque: ffio)
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
if this.call_sequence == 0x00 {
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
@@ -190,7 +152,7 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
var chunk_length : base.u64
|
||||
|
||||
if this.call_sequence <> 1 {
|
||||
if (this.call_sequence & 0x10) == 0 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if this.metadata_fourcc == 0 {
|
||||
@@ -267,7 +229,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
y: this.metadata_io_position,
|
||||
z: this.metadata_io_position)
|
||||
}
|
||||
this.call_sequence = 2
|
||||
this.call_sequence &= 0xEF
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_io_position = 0
|
||||
return ok
|
||||
@@ -319,16 +281,17 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
} else if args.io_position == 0 {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.delayed_num_decoded_frames = false
|
||||
this.end_of_data = false
|
||||
this.restarted = true
|
||||
this.frame_config_io_position = args.io_position
|
||||
this.num_decoded_frame_configs_value = args.index
|
||||
this.num_decoded_frames_value = args.index
|
||||
this.reset_gc!()
|
||||
this.call_sequence = 0x28
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -336,25 +299,32 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
var background_color : base.u32
|
||||
var flags : base.u8
|
||||
|
||||
this.ignore_metadata = true
|
||||
|
||||
this.dirty_max_excl_y = 0
|
||||
|
||||
if not this.end_of_data {
|
||||
if this.call_sequence == 0 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence <> 3 {
|
||||
if this.call_sequence == 4 {
|
||||
this.skip_frame?(src: args.src)
|
||||
}
|
||||
this.decode_up_to_id_part1?(src: args.src)
|
||||
if (this.call_sequence & 0x10) <> 0 {
|
||||
return base."#bad call sequence"
|
||||
} else if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.skip_frame?(src: args.src)
|
||||
if this.call_sequence >= 0x60 {
|
||||
return base."@end of data"
|
||||
}
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
// This is a new "if", not an "else", because the calls above can modify
|
||||
// this.end_of_data.
|
||||
if this.end_of_data {
|
||||
return base."@end of data"
|
||||
if (this.num_decoded_frame_configs_value > 0) or (this.call_sequence == 0x28) {
|
||||
this.decode_up_to_id_part1?(src: args.src)
|
||||
if this.call_sequence >= 0x60 {
|
||||
return base."@end of data"
|
||||
}
|
||||
}
|
||||
|
||||
background_color = this.black_color_u32_argb_premul
|
||||
@@ -396,7 +366,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
}
|
||||
|
||||
this.num_decoded_frame_configs_value ~sat+= 1
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
@@ -424,13 +394,17 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
}
|
||||
this.reset_gc!()
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
// TODO: honor args.opts.
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
this.ignore_metadata = true
|
||||
if this.call_sequence <> 4 {
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
if this.quirks[QUIRK_REJECT_EMPTY_FRAME - QUIRKS_BASE] and
|
||||
((this.frame_rect_x0 == this.frame_rect_x1) or (this.frame_rect_y0 == this.frame_rect_y1)) {
|
||||
@@ -441,10 +415,10 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
this.reset_gc!()
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.reset_gc!() {
|
||||
this.call_sequence = 5
|
||||
// The Image Descriptor is mandatory, but the Graphic Control extension is
|
||||
// optional. Reset the GC related fields for the next decode_frame call.
|
||||
this.gc_has_transparent_index = false
|
||||
@@ -456,14 +430,8 @@ pri func decoder.reset_gc!() {
|
||||
pri func decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
||||
var block_type : base.u8
|
||||
|
||||
if not this.restarted {
|
||||
if this.call_sequence <> 2 {
|
||||
this.frame_config_io_position = args.src.position()
|
||||
}
|
||||
} else if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
} else {
|
||||
this.restarted = false
|
||||
if (this.frame_config_io_position == 0) or (this.num_decoded_frame_configs_value > 0) {
|
||||
this.frame_config_io_position = args.src.position()
|
||||
}
|
||||
|
||||
while true {
|
||||
@@ -494,7 +462,7 @@ pri func decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
||||
this.delayed_num_decoded_frames = false
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
}
|
||||
this.end_of_data = true
|
||||
this.call_sequence = 0x60
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
@@ -692,19 +660,19 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
this.num_animation_loops_value += 1
|
||||
}
|
||||
|
||||
} else if this.ignore_metadata {
|
||||
} else if this.call_sequence >= 0x20 {
|
||||
// No-op.
|
||||
|
||||
} else if is_iccp and this.report_metadata_iccp {
|
||||
this.metadata_fourcc = 'ICCP'be
|
||||
this.metadata_io_position = args.src.position()
|
||||
this.call_sequence = 1
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
|
||||
} else if is_xmp and this.report_metadata_xmp {
|
||||
this.metadata_fourcc = 'XMP 'be
|
||||
this.metadata_io_position = args.src.position()
|
||||
this.call_sequence = 1
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
@@ -759,7 +727,7 @@ pri func decoder.decode_gc?(src: base.io_reader) {
|
||||
//
|
||||
// See the spec section 20 "Image Descriptor" on page 11.
|
||||
//
|
||||
// The code is split into three parts (part0, part 1 and part12 because
|
||||
// The code is split into three parts (part0, part 1 and part2 because
|
||||
// determining the overall image's width and height also requires decoding the
|
||||
// first frame's bounds (part0), but doesn't require decoding the first frame's
|
||||
// pixels (the other two parts). Decoding the actual pixels is split into two
|
||||
@@ -782,7 +750,7 @@ pri func decoder.decode_id_part0?(src: base.io_reader) {
|
||||
// and the bottom right extent of the first frame. See
|
||||
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for
|
||||
// more discussion.
|
||||
if (this.call_sequence == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) {
|
||||
if (this.num_decoded_frame_configs_value == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) {
|
||||
this.width = this.width.max(a: this.frame_rect_x1)
|
||||
this.height = this.height.max(a: this.frame_rect_y1)
|
||||
}
|
||||
|
||||
+96
-117
@@ -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
|
||||
}
|
||||
|
||||
+19
-40
@@ -24,31 +24,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0x7FFF_FFFF],
|
||||
height : base.u32[..= 0x7FFF_FFFF],
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x03: image config decoded.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0xFF: end-of-data, usually after (the non-animated) frame decoded.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x03: via DIC
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0xFF: via DFC
|
||||
// - 0x04 -> 0xFF: via DF
|
||||
//
|
||||
// - ???? -> 0x03: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
dst_x : base.u32,
|
||||
@@ -64,7 +41,7 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var a : base.u32
|
||||
|
||||
if this.call_sequence <> 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
@@ -108,18 +85,20 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
first_frame_is_opaque: false)
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 3 {
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if 16 <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 4 {
|
||||
this.call_sequence = 0xFF
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
@@ -140,16 +119,16 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
background_color: 0x0000_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence < 4 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 4 {
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
@@ -177,7 +156,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
||||
@@ -246,27 +225,27 @@ pub func decoder.num_animation_loops() base.u32 {
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 3 {
|
||||
if this.call_sequence > 0x20 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 4 {
|
||||
if this.call_sequence > 0x40 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if (args.index <> 0) or (args.io_position <> 16) {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x28
|
||||
return ok
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ pub status "#bad filter"
|
||||
pub status "#bad header"
|
||||
pub status "#bad text chunk (not Latin-1)"
|
||||
pub status "#missing palette"
|
||||
pub status "#unsupported CgBI extension"
|
||||
pub status "#unsupported PNG compression method"
|
||||
pub status "#unsupported PNG file"
|
||||
|
||||
@@ -28,7 +29,7 @@ pri status "#internal error: inconsistent frame bounds"
|
||||
pri status "#internal error: inconsistent workbuf length"
|
||||
pri status "#internal error: zlib decoder did not exhaust its input"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x0007_FFFF_F100_0007
|
||||
|
||||
// DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL is the minimum length of the src
|
||||
// wuffs_base__io_buffer passed to the decoder.
|
||||
|
||||
+162
-151
@@ -17,61 +17,24 @@ use "std/zlib"
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
// The 0x00FF_FFFF limit is arbitrary (the PNG spec says 0x7FFF_FFFF) but
|
||||
// it means that (width * height * bytes_per_pixel) doesn't overflow.
|
||||
// it means that (width * height * bytes_per_pixel) doesn't overflow a u64.
|
||||
width : base.u32[..= 0x00FF_FFFF],
|
||||
height : base.u32[..= 0x00FF_FFFF],
|
||||
|
||||
// pass_bytes_per_row doesn't include the 1 byte for the per-row filter.
|
||||
pass_bytes_per_row : base.u64[..= 0x07FF_FFF8],
|
||||
|
||||
workbuf_wi : base.u64,
|
||||
workbuf_hist_pos_base : base.u64,
|
||||
workbuf_wi : base.u64,
|
||||
workbuf_hist_pos_base : base.u64,
|
||||
|
||||
// The inclusive upper bound, DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE, is
|
||||
// derived from the width and height upper bounds at up to 8 bytes per
|
||||
// pixel. It equals (((8 * M) + 1) * M), where M is 0x00FF_FFFF.
|
||||
overall_workbuf_length : base.u64[..= 0x0007_FFFF_F100_0007],
|
||||
pass_workbuf_length : base.u64[..= 0x0007_FFFF_F100_0007],
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x01: metadata reported; image config decode is in progress.
|
||||
// - 0x02: metadata finished; image config decode is in progress.
|
||||
// - 0x03: image config decoded.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0x05: frame decoded.
|
||||
// - 0xFF: end-of-data, after the final frame decoded.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x00 -> 0x03: via DIC (metadata not reported)
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0x05: via DF with implicit DIC and DFC
|
||||
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x01 -> 0x02: via TMM
|
||||
//
|
||||
// - 0x02 -> 0x01: via DIC (metadata reported)
|
||||
// - 0x02 -> 0x03: via DIC (metadata not reported)
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0x05: via DF with implicit DFC
|
||||
// - 0x03 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0x04: via DFC with implicit DF
|
||||
// - 0x04 -> 0x05: via DF
|
||||
// - 0x04 -> 0xFF: via DFC with implicit DF
|
||||
// - 0x04 -> 0xFF: via DF
|
||||
//
|
||||
// - 0x05 -> 0x04: via DFC
|
||||
// - 0x05 -> 0x05: via DF with implicit DFC
|
||||
// - 0x05 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - ???? -> 0x03: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame, implicit means skip_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
// - TMM is tell_me_more
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
report_metadata_chrm : base.bool,
|
||||
@@ -95,6 +58,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
seen_gama : base.bool,
|
||||
seen_iccp : base.bool,
|
||||
seen_idat : base.bool,
|
||||
seen_ihdr : base.bool,
|
||||
seen_plte : base.bool,
|
||||
seen_srgb : base.bool,
|
||||
seen_trns : base.bool,
|
||||
@@ -205,20 +169,21 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
var checksum_want : base.u32
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence == 2 {
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 1
|
||||
return base."@metadata reported"
|
||||
}
|
||||
} else if this.call_sequence <> 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
} else {
|
||||
} else if not this.seen_ihdr {
|
||||
magic = args.src.read_u64le?()
|
||||
if magic <> '\x89PNG\x0D\x0A\x1A\x0A'le {
|
||||
return "#bad header"
|
||||
}
|
||||
magic = args.src.read_u64le?()
|
||||
if magic <> '\x00\x00\x00\x0DIHDR'le {
|
||||
if magic == '\x00\x00\x00\x04CgBI'le {
|
||||
// TODO: add support for Apple's unofficial CgBI extension to
|
||||
// PNG, once there exists good documentation for it. See
|
||||
// https://github.com/w3c/PNG-spec/issues/45
|
||||
return "#unsupported CgBI extension"
|
||||
}
|
||||
return "#bad header"
|
||||
}
|
||||
this.chunk_type_array[0] = 'I'
|
||||
@@ -245,6 +210,10 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
if (not this.ignore_checksum) and (checksum_have <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
this.seen_ihdr = true
|
||||
} else if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
// Read up until an IDAT or fdAT chunk.
|
||||
@@ -295,7 +264,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
|
||||
while true {
|
||||
mark = args.src.mark()
|
||||
status =? this.decode_other_chunk?(src: args.src)
|
||||
status =? this.decode_other_chunk?(src: args.src, framy: false)
|
||||
if (not this.ignore_checksum) and ((this.chunk_type & ANCILLARY_BIT) == 0) {
|
||||
checksum_have = this.crc32.update_u32!(x: args.src.since(mark: mark))
|
||||
}
|
||||
@@ -308,7 +277,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
// If we have metadata, delay reading (skipping) the ancillary chunk's
|
||||
// CRC-32 checksum until the end of tell_me_more.
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 1
|
||||
this.call_sequence = 0x10
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
@@ -349,7 +318,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
this.first_overwrite_instead_of_blend = false
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.decode_ihdr?(src: base.io_reader) {
|
||||
@@ -541,8 +510,11 @@ pri func decoder.choose_filter_implementations!() {
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
if this.chunk_type == 'PLTE'le {
|
||||
// framy is:
|
||||
// - false when coming from decode_image_config.
|
||||
// - true when coming from decode_frame_config.
|
||||
pri func decoder.decode_other_chunk?(src: base.io_reader, framy: base.bool) {
|
||||
if (this.chunk_type == 'PLTE'le) and (not args.framy) {
|
||||
if this.seen_plte {
|
||||
return "#bad chunk"
|
||||
} else if this.color_type == 3 {
|
||||
@@ -561,24 +533,9 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
if this.chunk_type <> 'IDAT'le {
|
||||
return "#bad chunk"
|
||||
}
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'acTL'le {
|
||||
if this.seen_actl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_actl?(src: args.src)
|
||||
this.seen_actl = true
|
||||
|
||||
} else if this.chunk_type == 'cHRM'le {
|
||||
if this.report_metadata_chrm {
|
||||
if this.seen_chrm {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_chrm?(src: args.src)
|
||||
this.seen_chrm = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'eXIf'le {
|
||||
if this.chunk_type == 'eXIf'le {
|
||||
if this.report_metadata_exif {
|
||||
if this.seen_exif {
|
||||
return "#bad chunk"
|
||||
@@ -587,48 +544,6 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
this.seen_exif = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'fcTL'le {
|
||||
if this.seen_fctl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_fctl?(src: args.src)
|
||||
this.seen_fctl = true
|
||||
|
||||
} else if this.chunk_type == 'gAMA'le {
|
||||
if this.report_metadata_gama {
|
||||
if this.seen_gama {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_gama?(src: args.src)
|
||||
this.seen_gama = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'iCCP'le {
|
||||
if this.report_metadata_iccp {
|
||||
if this.seen_iccp {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_iccp?(src: args.src)
|
||||
this.seen_iccp = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'sRGB'le {
|
||||
if this.report_metadata_srgb {
|
||||
if this.seen_srgb {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_srgb?(src: args.src)
|
||||
this.seen_srgb = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'tRNS'le {
|
||||
if this.seen_trns or (this.color_type > 3) or
|
||||
((this.color_type == 3) and (not this.seen_plte)) {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_trns?(src: args.src)
|
||||
this.seen_trns = true
|
||||
|
||||
} else if (this.chunk_type == 'iTXt'le) or
|
||||
(this.chunk_type == 'tEXt'le) or
|
||||
(this.chunk_type == 'zTXt'le) {
|
||||
@@ -639,6 +554,66 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
}
|
||||
|
||||
} else if not args.framy {
|
||||
if this.chunk_type == 'acTL'le {
|
||||
if this.seen_actl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_actl?(src: args.src)
|
||||
this.seen_actl = true
|
||||
|
||||
} else if this.chunk_type == 'cHRM'le {
|
||||
if this.report_metadata_chrm {
|
||||
if this.seen_chrm {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_chrm?(src: args.src)
|
||||
this.seen_chrm = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'fcTL'le {
|
||||
if this.seen_fctl {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_fctl?(src: args.src)
|
||||
this.seen_fctl = true
|
||||
|
||||
} else if this.chunk_type == 'gAMA'le {
|
||||
if this.report_metadata_gama {
|
||||
if this.seen_gama {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_gama?(src: args.src)
|
||||
this.seen_gama = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'iCCP'le {
|
||||
if this.report_metadata_iccp {
|
||||
if this.seen_iccp {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_iccp?(src: args.src)
|
||||
this.seen_iccp = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'sRGB'le {
|
||||
if this.report_metadata_srgb {
|
||||
if this.seen_srgb {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_srgb?(src: args.src)
|
||||
this.seen_srgb = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'tRNS'le {
|
||||
if this.seen_trns or (this.color_type > 3) or
|
||||
((this.color_type == 3) and (not this.seen_plte)) {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_trns?(src: args.src)
|
||||
this.seen_trns = true
|
||||
}
|
||||
}
|
||||
|
||||
if this.metadata_fourcc == 0 {
|
||||
@@ -959,19 +934,27 @@ pri func decoder.decode_trns?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence == 0xFF {
|
||||
return base."@end of data"
|
||||
} else if this.call_sequence < 3 {
|
||||
var checksum_have : base.u32
|
||||
|
||||
if (this.call_sequence & 0x10) <> 0 {
|
||||
return base."#bad call sequence"
|
||||
} else if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 3 {
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 4 {
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.skip_frame?(src: args.src)
|
||||
if this.call_sequence == 0xFF {
|
||||
return base."@end of data"
|
||||
}
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 0x30
|
||||
return base."@metadata reported"
|
||||
}
|
||||
|
||||
if this.num_decoded_frame_configs_value == 0 {
|
||||
@@ -985,11 +968,21 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
this.frame_overwrite_instead_of_blend = this.first_overwrite_instead_of_blend
|
||||
|
||||
} else {
|
||||
// Decode the next fcTL chunk.
|
||||
// Decode the next IEND or fcTL chunk.
|
||||
while true {
|
||||
this.chunk_length = args.src.read_u32be?()
|
||||
this.chunk_type = args.src.read_u32le?()
|
||||
if this.chunk_type == 'fdAT'le {
|
||||
if this.chunk_type == 'IEND'le {
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
checksum_have = args.src.read_u32le?()
|
||||
if (not this.ignore_checksum) and (checksum_have <> 0x8260_42AE) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else if this.chunk_type == 'fdAT'le {
|
||||
return "#bad chunk"
|
||||
} else if this.chunk_type == 'fcTL'le {
|
||||
this.frame_config_io_position = args.src.position() ~mod- 8
|
||||
@@ -997,7 +990,13 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
args.src.skip?(n: 4) // Skip the checksum.
|
||||
break
|
||||
}
|
||||
args.src.skip?(n: (this.chunk_length as base.u64) + 4) // +4 for the checksum.
|
||||
|
||||
this.decode_other_chunk?(src: args.src, framy: true)
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 0x30
|
||||
return base."@metadata reported"
|
||||
}
|
||||
args.src.skip_u32?(n: 4) // Skip the checksum.
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
@@ -1018,7 +1017,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
}
|
||||
|
||||
this.num_decoded_frame_configs_value ~sat+= 1
|
||||
this.call_sequence = 4
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
@@ -1088,11 +1087,7 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
} endwhile
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
if this.num_decoded_frames_value < this.num_animation_frames_value {
|
||||
this.call_sequence = 5
|
||||
} else {
|
||||
this.call_sequence = 0xFF
|
||||
}
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -1101,9 +1096,11 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
var pass_width : base.u32[..= 0x00FF_FFFF]
|
||||
var pass_height : base.u32[..= 0x00FF_FFFF]
|
||||
|
||||
if this.call_sequence == 0xFF {
|
||||
if (this.call_sequence & 0x10) <> 0 {
|
||||
return base."#bad call sequence"
|
||||
} else if this.call_sequence >= 0x60 {
|
||||
return base."@end of data"
|
||||
} else if this.call_sequence <> 4 {
|
||||
} else if this.call_sequence <> 0x40 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
}
|
||||
|
||||
@@ -1195,7 +1192,29 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
if (pass_width > 0) and (pass_height > 0) {
|
||||
this.pass_bytes_per_row = this.calculate_bytes_per_row(width: pass_width)
|
||||
this.pass_workbuf_length = (pass_height as base.u64) * (1 + this.pass_bytes_per_row)
|
||||
this.decode_pass?(src: args.src, workbuf: args.workbuf)
|
||||
while true {
|
||||
status =? this.decode_pass?(src: args.src, workbuf: args.workbuf)
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if status.is_error() or
|
||||
((status == base."$short read") and args.src.is_closed()) {
|
||||
// The input was truncated or invalid. Produce whatever
|
||||
// pixels we can and then, if truncated, generate "$short
|
||||
// read" forever.
|
||||
if this.workbuf_wi <= args.workbuf.length() {
|
||||
// This might return "#internal error: inconsistent
|
||||
// workbuf length" because of the ".. this.workbuf_wi".
|
||||
// We just ignore the error.
|
||||
this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf[.. this.workbuf_wi])
|
||||
}
|
||||
if status == base."$short read" {
|
||||
while true {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
status = this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
@@ -1210,11 +1229,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
} endwhile
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
if this.num_decoded_frames_value < this.num_animation_frames_value {
|
||||
this.call_sequence = 5
|
||||
} else {
|
||||
this.call_sequence = 0xFF
|
||||
}
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -1342,13 +1357,13 @@ pub func decoder.num_decoded_frames() base.u64 {
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
} else if (args.index >= (this.num_animation_frames_value as base.u64)) or
|
||||
((args.index == 0) and (args.io_position <> this.first_config_io_position)) {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 3
|
||||
this.call_sequence = 0x28
|
||||
if this.interlace_pass >= 1 {
|
||||
this.interlace_pass = 1
|
||||
}
|
||||
@@ -1383,7 +1398,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
var r_mark : base.u64
|
||||
var zlib_status : base.status
|
||||
|
||||
if this.call_sequence <> 1 {
|
||||
if (this.call_sequence & 0x10) == 0 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if this.metadata_fourcc == 0 {
|
||||
@@ -1503,7 +1518,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else if c2 <= 0x7F {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.ztxt_ri += 1
|
||||
@@ -1511,7 +1525,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else {
|
||||
if args.dst.length() <= 1 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.ztxt_ri += 1
|
||||
@@ -1577,7 +1590,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else if c2 <= 0x7F {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
@@ -1586,7 +1598,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
} else {
|
||||
if args.dst.length() <= 1 {
|
||||
yield? base."$short write"
|
||||
c2 = 0
|
||||
continue.loop
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
@@ -1649,7 +1660,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
this.metadata_is_zlib_compressed = true
|
||||
}
|
||||
|
||||
this.call_sequence = 2
|
||||
this.call_sequence &= 0xEF
|
||||
return ok
|
||||
}
|
||||
break.goto_done
|
||||
@@ -1668,7 +1679,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
|
||||
this.call_sequence = 2
|
||||
this.call_sequence &= 0xEF
|
||||
return ok
|
||||
}
|
||||
|
||||
|
||||
+19
-40
@@ -22,31 +22,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0xFFFF],
|
||||
height : base.u32[..= 0xFFFF],
|
||||
|
||||
// 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,
|
||||
|
||||
header_id_length : base.u8,
|
||||
@@ -82,7 +59,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
var i : base.u32
|
||||
|
||||
if this.call_sequence <> 0 {
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
@@ -245,18 +222,20 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
first_frame_is_opaque: this.opaque)
|
||||
}
|
||||
|
||||
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"
|
||||
@@ -277,7 +256,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) {
|
||||
@@ -302,10 +281,10 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
var c : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
|
||||
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"
|
||||
}
|
||||
@@ -545,7 +524,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
break.resume
|
||||
} endwhile.resume
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
@@ -561,27 +540,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
|
||||
}
|
||||
|
||||
+19
-40
@@ -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,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,264 @@
|
||||
// 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_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_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_interface,
|
||||
test_wuffs_bzip2_decode_midsummer,
|
||||
test_wuffs_bzip2_decode_pi,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_bzip2_decode_256_bytes,
|
||||
test_mimic_bzip2_decode_midsummer,
|
||||
test_mimic_bzip2_decode_pi,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_bzip2_decode_10k,
|
||||
bench_wuffs_bzip2_decode_100k,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
bench_mimic_bzip2_decode_10k,
|
||||
bench_mimic_bzip2_decode_100k,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/bzip2";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -3099,6 +3099,12 @@ test_wuffs_json_decode_quirk_allow_backslash_x() {
|
||||
|
||||
src_index += token_length;
|
||||
}
|
||||
|
||||
if (src_index != src.meta.ri) {
|
||||
RETURN_FAIL("tc=%zu: src_index: have %" PRIu64 ", want %zu", tc,
|
||||
src_index, src.meta.ri);
|
||||
}
|
||||
|
||||
uint64_t want = test_cases[tc].want_code_points;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("tc=%zu: have U+%08" PRIX64 ", want U+%08" PRIX64, tc, have,
|
||||
|
||||
+7
-3
@@ -810,6 +810,8 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
"U-значение", //
|
||||
"Z-Këy", //
|
||||
"Z-значение", //
|
||||
"After", //
|
||||
"Frame", //
|
||||
};
|
||||
|
||||
wuffs_png__decoder dec;
|
||||
@@ -819,14 +821,15 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__KVP, true);
|
||||
|
||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
|
||||
|
||||
size_t i = 0;
|
||||
for (;; i++) {
|
||||
while (true) {
|
||||
wuffs_base__status status =
|
||||
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
|
||||
wuffs_png__decoder__decode_frame_config(&dec, NULL, &src);
|
||||
if (wuffs_base__status__is_ok(&status)) {
|
||||
continue;
|
||||
} else if (status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else if (status.repr != wuffs_base__note__metadata_reported) {
|
||||
RETURN_FAIL("decode_image_config i=%zu: %s", i, status.repr);
|
||||
@@ -865,6 +868,7 @@ test_wuffs_png_decode_metadata_kvp() {
|
||||
}
|
||||
}
|
||||
CHECK_STRING(check_io_buffers_equal("", &have, &want));
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i != WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
|
||||
|
||||
+37
-2
@@ -69,6 +69,23 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
|
||||
// ---------------- 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__);
|
||||
@@ -92,7 +109,24 @@ test_wuffs_tga_decode_interface() {
|
||||
|
||||
// ---------------- TGA Benches
|
||||
|
||||
// No 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
|
||||
|
||||
@@ -119,7 +153,8 @@ proc g_tests[] = {
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
// No TGA benches.
|
||||
bench_wuffs_tga_decode_19k_8bpp,
|
||||
bench_wuffs_tga_decode_77k_24bpp,
|
||||
|
||||
#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 install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
"# install Go, then run \"go install "
|
||||
"golang.org/x/perf/cmd/benchstat\".\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < reps; i++) {
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
abraca
|
||||
Binary file not shown.
Binary file not shown.
|
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 {
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -62,11 +62,13 @@ dcbb225a test/data/hippopotamus.bmp
|
||||
ed4b78fc test/data/hippopotamus.interlaced.gif
|
||||
dcbb225a test/data/hippopotamus.interlaced.png
|
||||
c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
|
||||
7c6a771b test/data/hippopotamus.interlaced.truncated.png
|
||||
d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
|
||||
dcbb225a test/data/hippopotamus.nie
|
||||
ed4b78fc test/data/hippopotamus.regular.gif
|
||||
dcbb225a test/data/hippopotamus.regular.png
|
||||
888b1c04 test/data/hippopotamus.regular.truncated.png
|
||||
2dccfe56 test/data/muybridge-frame-000.wbmp
|
||||
db2733f5 test/data/muybridge.apng
|
||||
db2733f5 test/data/muybridge.gif
|
||||
|
||||
Reference in new issue
Block a user