mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Compare commits
190
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c89b3bc6d8 | ||
|
|
a07eb7704b | ||
|
|
bd27cc0d9b | ||
|
|
d06700f00b | ||
|
|
870cfd18a7 | ||
|
|
ffb64df0a0 | ||
|
|
3215f6afac | ||
|
|
8a722790af | ||
|
|
d270839e3f | ||
|
|
c9fff5b207 | ||
|
|
fb769ff82f | ||
|
|
5e0b2ae0d5 | ||
|
|
a7fb1e8d69 | ||
|
|
ce1f59e9ce | ||
|
|
42b070e487 | ||
|
|
f9c384d6b2 | ||
|
|
d0603f3b94 | ||
|
|
c6aebf819f | ||
|
|
8fe987e0b2 | ||
|
|
d1a9749571 | ||
|
|
f37cfcf554 | ||
|
|
cc9ee184d0 | ||
|
|
fab0dd534a | ||
|
|
3be81643cc | ||
|
|
495f0280a8 | ||
|
|
b64a761067 | ||
|
|
7a57e2b600 | ||
|
|
4111785304 | ||
|
|
affa1e02d4 | ||
|
|
97b727a1ae | ||
|
|
37a3c3ce9b | ||
|
|
5d4bb4c6e4 | ||
|
|
aae5997e12 | ||
|
|
6c8a43390b | ||
|
|
5654506497 | ||
|
|
00e6e71672 | ||
|
|
09f4500e19 | ||
|
|
16705a1816 | ||
|
|
3c1df67681 | ||
|
|
c4aa5e60d0 | ||
|
|
d446e71e1f | ||
|
|
bf3afab25a | ||
|
|
92ff96359a | ||
|
|
e541e0cf79 | ||
|
|
e1f803324b | ||
|
|
58d2a80691 | ||
|
|
77541659f3 | ||
|
|
9c704c4a6a | ||
|
|
5bf4c2cb51 | ||
|
|
a3bfb57003 | ||
|
|
da0d51d802 | ||
|
|
f169822680 | ||
|
|
a27a7598f0 | ||
|
|
4209264a85 | ||
|
|
fdd08200e3 | ||
|
|
d8c3deb028 | ||
|
|
00a01abc4e | ||
|
|
d7f6b81d31 | ||
|
|
2142aa65fc | ||
|
|
8ed5d1327b | ||
|
|
a9a6d8ac55 | ||
|
|
f32bfe95c6 | ||
|
|
5c693c9de8 | ||
|
|
1596343889 | ||
|
|
b6b0f84187 | ||
|
|
7077c20cb6 | ||
|
|
9958d6c520 | ||
|
|
f5bb519320 | ||
|
|
b2c7c69227 | ||
|
|
24151f8132 | ||
|
|
3bad76cd2c | ||
|
|
f1a9d34494 | ||
|
|
da40cdf29f | ||
|
|
b4cd9b8d3c | ||
|
|
bdfbdf407e | ||
|
|
0c9b700df0 | ||
|
|
a6676851e3 | ||
|
|
44bb271c21 | ||
|
|
b922c28a8e | ||
|
|
13c72db350 | ||
|
|
27407b5332 | ||
|
|
a9739a8921 | ||
|
|
793ab36569 | ||
|
|
1c0b07f1aa | ||
|
|
22b4ff4842 | ||
|
|
5b62289c63 | ||
|
|
8ff5693d9d | ||
|
|
f06858f395 | ||
|
|
47ed32b6ce | ||
|
|
22fd87efc6 | ||
|
|
5ec31fc291 | ||
|
|
c0264e4496 | ||
|
|
06599b8e9b | ||
|
|
4e20ba6876 | ||
|
|
6017c37232 | ||
|
|
6c71bb229b | ||
|
|
2f7fbd0f34 | ||
|
|
749e3559f2 | ||
|
|
94e32e8e56 | ||
|
|
782e78a689 | ||
|
|
6f4db1b138 | ||
|
|
30133ad4b2 | ||
|
|
d2a63a7e34 | ||
|
|
76a17ce742 | ||
|
|
8b3e598572 | ||
|
|
03bb04d80c | ||
|
|
af6c7b56af | ||
|
|
764169165a | ||
|
|
9ef114be43 | ||
|
|
98dae3c1c0 | ||
|
|
2b4e8ce6a2 | ||
|
|
e8ec21976c | ||
|
|
569a91892e | ||
|
|
e5dc87e4d3 | ||
|
|
be1b1b564c | ||
|
|
d2ecc20141 | ||
|
|
9fb3859488 | ||
|
|
6482ba3923 | ||
|
|
e8af2d0635 | ||
|
|
c21cc95713 | ||
|
|
d9bb6d4b4f | ||
|
|
29e49cded4 | ||
|
|
caa7711b30 | ||
|
|
ab06be047b | ||
|
|
76cb4bd757 | ||
|
|
13115e4e1d | ||
|
|
0719c911f6 | ||
|
|
d4ececf1d4 | ||
|
|
1e5cf45090 | ||
|
|
4dbea68208 | ||
|
|
992fd9622a | ||
|
|
9f42d1fbb8 | ||
|
|
c77989d162 | ||
|
|
77fa011072 | ||
|
|
2afec50f62 | ||
|
|
5a7299b5c2 | ||
|
|
cf927b20bf | ||
|
|
79af52bb24 | ||
|
|
a440f6dd5b | ||
|
|
13d9d259e8 | ||
|
|
33db93f617 | ||
|
|
ce0cee444d | ||
|
|
41a83f2e29 | ||
|
|
cc01be3b17 | ||
|
|
6668b604d3 | ||
|
|
eed1af7bee | ||
|
|
b4e09690a7 | ||
|
|
d40b7fbd7e | ||
|
|
0164364106 | ||
|
|
c4d2fa13da | ||
|
|
9520d6de36 | ||
|
|
bf0492b59a | ||
|
|
988af1c03c | ||
|
|
57f01ec3f6 | ||
|
|
42d3b4d692 | ||
|
|
4f45ddcb0c | ||
|
|
8de7f559e0 | ||
|
|
dc269f3f54 | ||
|
|
82ea1985b4 | ||
|
|
e517ca4bee | ||
|
|
7fb80a047b | ||
|
|
2c2bb9baa5 | ||
|
|
df1d4f64e2 | ||
|
|
b20c177a08 | ||
|
|
190f249031 | ||
|
|
357bfdaef3 | ||
|
|
6e9d392d39 | ||
|
|
8900769a72 | ||
|
|
1670b9c321 | ||
|
|
5407f39386 | ||
|
|
9a68ec70c6 | ||
|
|
883ad62c2f | ||
|
|
054c6c964b | ||
|
|
2890d76845 | ||
|
|
8cfde80759 | ||
|
|
b900be0315 | ||
|
|
712e42e938 | ||
|
|
b4c70c39bc | ||
|
|
dd75f3215a | ||
|
|
f81deb6b6e | ||
|
|
b9c737eb37 | ||
|
|
9b89170869 | ||
|
|
ad7fda33dd | ||
|
|
920ac3e5c5 | ||
|
|
b2ab3ba008 | ||
|
|
6a6e8d3f09 | ||
|
|
50abf5eb6a | ||
|
|
71dca5adce | ||
|
|
e0636e3255 | ||
|
|
310f5011b5 |
No files matched your search
@@ -58,8 +58,8 @@ Just run your favorite C/C++ compiler (e.g. `gcc` or `g++`) on the
|
||||
`example/foo/*.{c,cc}` file. Pass `-O3` or equivalent for an optimized build:
|
||||
|
||||
```
|
||||
gcc -O3 example/bzcat/bzcat.c -o my-bzcat
|
||||
./my-bzcat < test/data/romeo.txt.bz2
|
||||
gcc -O3 example/mzcat/mzcat.c -o my-mzcat
|
||||
./my-mzcat < test/data/romeo.txt.bz2
|
||||
```
|
||||
|
||||
Some example programs require additional libraries:
|
||||
|
||||
@@ -62,6 +62,12 @@ files), implying that it cannot allocate or free memory (and is therefore
|
||||
trivially safe against things like memory leaks, use-after-frees and
|
||||
double-frees).
|
||||
|
||||
It produces [Sans I/O style](https://sans-io.readthedocs.io/) libraries (but C
|
||||
libraries, not Python), meaning that they are agnostic to ['function
|
||||
colors'](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/).
|
||||
They can be combined with synchronous or asynchronous I/O, as the library
|
||||
caller (not library implementation) is responsible for the actual I/O.
|
||||
|
||||
The idea isn't to write your whole program in Wuffs, **only the parts that are
|
||||
both performance-conscious and security-conscious**. For example, while
|
||||
technically possible, it is unlikely that a Wuffs compiler would be worth
|
||||
@@ -217,11 +223,16 @@ The [Note](/doc/note) directory also contains various short articles.
|
||||
|
||||
# Status
|
||||
|
||||
Version 0.3. The API and ABI aren't stabilized yet. The compiler undoubtedly
|
||||
has bugs. Assertion checking needs more rigor, especially around side effects
|
||||
and aliasing, and being sufficiently well specified to allow alternative
|
||||
implementations. Lots of detail needs work, but the broad brushstrokes are
|
||||
there.
|
||||
Version 0.3 (April 2023) is the latest stable version. Stable means that
|
||||
its API won't change any further, but being a "version 0.x" means that:
|
||||
|
||||
- It will not have long term support.
|
||||
- Newer versions make no promises about compatibility.
|
||||
|
||||
The compiler undoubtedly has bugs. Assertion checking needs more rigor,
|
||||
especially around side effects and aliasing, and being sufficiently well
|
||||
specified to allow alternative implementations. Lots of detail needs work, but
|
||||
the broad brushstrokes are there.
|
||||
|
||||
Nonetheless, Wuffs' GIF decoder has shipped in the Google Chrome web browser
|
||||
[since June
|
||||
@@ -272,4 +283,4 @@ overflows.
|
||||
|
||||
---
|
||||
|
||||
Updated on September 2023.
|
||||
Updated on November 2023.
|
||||
+13
-1
@@ -51,7 +51,7 @@ wuffs gen
|
||||
# http://fastcompression.blogspot.com/2019/01/compiler-warnings.html
|
||||
# with some further flags from
|
||||
# https://review.coreboot.org/plugins/gitiles/coreboot/+/17848b65c38c32fa9630925ca8a15203a0617788/Makefile.inc#480
|
||||
WARNING_FLAGS="-Wall -Werror -Wpedantic -Wcast-qual -Wcast-align -Wpointer-arith -Wfloat-equal -Wundef -Wvla -Wconversion -Wshadow -Wredundant-decls"
|
||||
WARNING_FLAGS="-Wall -Werror -Wpedantic -Wcast-qual -Wcast-align -Wpointer-arith -Wfloat-equal -Wundef -Wvla -Wconversion -Wshadow -Wredundant-decls -Wunused-const-variable"
|
||||
C_WARNING_FLAGS="$WARNING_FLAGS -Wstrict-prototypes -Wold-style-definition"
|
||||
CXX_WARNING_FLAGS="$WARNING_FLAGS"
|
||||
|
||||
@@ -106,6 +106,18 @@ set -e
|
||||
|
||||
# ----
|
||||
|
||||
echo "Running gen/bin/example-mzcat"
|
||||
set +e
|
||||
script/print-mzcat-checksums.sh | \
|
||||
diff --unified test/mzcat-checksums-of-data.txt /dev/stdin
|
||||
if [ $? != 0 ]; then
|
||||
echo "Unexpected change in test/mzcat-checksums-of-data.txt"
|
||||
exit 1
|
||||
fi
|
||||
set -e
|
||||
|
||||
# ----
|
||||
|
||||
for f in gen/bin/fuzz-*; do
|
||||
echo "Running $f"
|
||||
$f test/data > /dev/null
|
||||
|
||||
+38
-8
@@ -6,37 +6,67 @@
|
||||
The LICENSE has changed from a single license (Apache 2) to a dual license
|
||||
(Apache 2 or MIT, at your option).
|
||||
|
||||
- Added `compact_retaining` and `history_retain_length`.
|
||||
- Added `base.bitvec256`.
|
||||
- Added `base.optional_u63`.
|
||||
- Added `base.hasher_bitvec256`.
|
||||
- Added `base.hasher_u32` `update!` and `checksum_u32` methods.
|
||||
- Added `base.hasher_u64`.
|
||||
- Added `compact_retaining` and `dst_history_retain_length`.
|
||||
- Added `example/toy-aux-image`.
|
||||
- Added `example/mzcat`.
|
||||
- Added `get_quirk(key: u32) u64`.
|
||||
- Added `hasher_u32` `update!` and `checksum_u32` methods.
|
||||
- Added `hasher_u64`.
|
||||
- Added `if.likely` and `if.unlikely`.
|
||||
- Added `slice_var as nptr array[etc] etc` conversion.
|
||||
- Added `std/crc64`.
|
||||
- Added `std/jpeg`.
|
||||
- Added `std/lzip`.
|
||||
- Added `std/lzma`.
|
||||
- Added `std/netpbm`.
|
||||
- Added `std/qoi`.
|
||||
- Added `std/sha256`.
|
||||
- Added `std/vp8`.
|
||||
- Added `std/webp`.
|
||||
- Added `std/xxhash32`.
|
||||
- Added `std/xxhash64`.
|
||||
- Added `std/xz`.
|
||||
- Added `WUFFS_BASE__QUIRK_QUALITY`.
|
||||
- Added `WUFFS_CONFIG__DISABLE_MSVC_CPU_ARCH__X86_64_FAMILY`.
|
||||
- Added `WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST`.
|
||||
- Added `WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V2`.
|
||||
- Added `WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V3`.
|
||||
- Added `wuffs_base__status__is_truncated_input_error`.
|
||||
- Changed `lzw.set_literal_width` to `lzw.set_quirk`.
|
||||
- Changed `set_quirk_enabled!(quirk: u32, enabled: bool)` to `set_quirk!(key:
|
||||
u32, value: u64) status`.
|
||||
- Deprecate `std/lzw.decoder.flush`.
|
||||
- Halve the sizeof `wuffs_foo__bar::unique_ptr`.
|
||||
- Remove the `std/gif -> std/lzw` dependency.
|
||||
- Deprecated `std/lzw.decoder.flush`.
|
||||
- Fixed `PIXEL_FORMAT__YA_{NON,}PREMUL` constant values.
|
||||
- Generated constants now default to unsigned.
|
||||
- Halved the sizeof `wuffs_foo__bar::unique_ptr`.
|
||||
- Let `std/png` decode PNG color type 4 to `PIXEL_FORMAT__YA_NONPREMUL` (two
|
||||
channels) instead of `PIXEL_FORMAT__BGRA_NONPREMUL` (four channels).
|
||||
- Removed the `std/gif -> std/lzw` dependency.
|
||||
- Removed `endwhile` keyword.
|
||||
- Removed `example/bzcat`.
|
||||
- Set image decoder pixel width and height inclusive maximum to `0xFF_FFFF`,
|
||||
down from `0x7FFF_FFFF`.
|
||||
|
||||
The dot points below probably aren't of interest unless you're _writing_ Wuffs
|
||||
code (instead of writing C/C++ code that _uses_ Wuffs' standard library).
|
||||
|
||||
- Added `if.likely` and `if.unlikely`.
|
||||
- Added `io_forget_history`.
|
||||
- Added `slice_var as nptr array[etc] etc` conversion.
|
||||
- Added read-only type decorators: `roarray`, `roslice` and `rotable`.
|
||||
- Banned recursive function calls.
|
||||
- Renamed `base` `min/max` argument from `a` to `no_more/less_than`.
|
||||
- Wuffs struct private data now needs a "+" between the "()" pairs.
|
||||
- `wuffsfmt` double-indents hanging lines and each indent is now 4 spaces (not
|
||||
a tab).
|
||||
|
||||
|
||||
## 2024-04-19 version 0.3.4
|
||||
|
||||
- Have `std/png` ignore tRNS chunks for color types 4 (YA) and 6 (RGBA).
|
||||
|
||||
|
||||
## 2023-04-08 version 0.3.3
|
||||
|
||||
The `wuffs_base__parse_number_f64` function has been further optimized.
|
||||
|
||||
@@ -62,10 +62,23 @@ Common quirks:
|
||||
at a cost of being less able to detect data corruption and to deviate from a
|
||||
strict reading of the relevant file format specifications, accepting some
|
||||
inputs that are technically invalid (but otherwise decode fine).
|
||||
- `WUFFS_BASE__QUIRK_QUALITY` configures decoders (for a lossy format, where
|
||||
there is some leeway in "a/the correct decoding") or encoders to use lower
|
||||
than, equal to or higher than the default quality setting. Lower-than-default
|
||||
obviously produces a worse result on some measure. But, if the codec behavior
|
||||
depends on the quirk value, lowering quality can improve other measures:
|
||||
being faster (less time taken), lighter (less "work buffer" memory required),
|
||||
etc. Conversely, asking for higher quality might be a no-op (depending on the
|
||||
codec) but, if it does affect behavior, it typically trades off in the other
|
||||
direction: higher quality and/or tighter (smaller output) but also slower,
|
||||
heavier, etc.
|
||||
|
||||
Package-specific quirks:
|
||||
|
||||
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
|
||||
- [JPEG decoder quirks](/std/jpeg/decode_quirks.wuffs)
|
||||
- [JSON decoder quirks](/std/json/decode_quirks.wuffs)
|
||||
- [LZMA decoder quirks](/std/lzma/decode_quirks.wuffs)
|
||||
- [LZW decoder quirks](/std/lzw/decode_quirks.wuffs)
|
||||
- [XZ decoder quirks](/std/xz/decode_quirks.wuffs)
|
||||
- [ZLIB decoder quirks](/std/zlib/decode_quirks.wuffs)
|
||||
+27
-17
@@ -45,23 +45,33 @@ compiles. Opt in by also defining `WUFFS_CONFIG__MODULES` and then also
|
||||
`WUFFS_CONFIG__MODULE__ETC` for each `ETC` (and its dependencies, listed below)
|
||||
to enable.
|
||||
|
||||
- `ADLER32: BASE`
|
||||
- `BMP: BASE`
|
||||
- `BZIP2: BASE`
|
||||
- `CBOR: BASE`
|
||||
- `CRC32: BASE`
|
||||
- `DEFLATE: BASE`
|
||||
- `GIF: BASE`
|
||||
- `GZIP: BASE, CRC32, DEFLATE`
|
||||
- `JPEG: BASE`
|
||||
- `JSON: BASE`
|
||||
- `LZW: BASE`
|
||||
- `NETPBM: BASE`
|
||||
- `NIE: BASE`
|
||||
- `PNG: BASE, ADLER32, CRC32, DEFLATE, ZLIB`
|
||||
- `TGA: BASE`
|
||||
- `WBMP: BASE`
|
||||
- `ZLIB: BASE, ADLER32, DEFLATE`
|
||||
- `ADLER32: BASE`
|
||||
- `BMP: BASE`
|
||||
- `BZIP2: BASE`
|
||||
- `CBOR: BASE`
|
||||
- `CRC32: BASE`
|
||||
- `CRC64: BASE`
|
||||
- `DEFLATE: BASE`
|
||||
- `GIF: BASE`
|
||||
- `GZIP: BASE, CRC32, DEFLATE`
|
||||
- `JPEG: BASE`
|
||||
- `JSON: BASE`
|
||||
- `LZIP: BASE, CRC32, LZMA`
|
||||
- `LZMA: BASE`
|
||||
- `LZW: BASE`
|
||||
- `NETPBM: BASE`
|
||||
- `NIE: BASE`
|
||||
- `PNG: BASE, ADLER32, CRC32, DEFLATE, ZLIB`
|
||||
- `QOI: BASE`
|
||||
- `SHA256: BASE`
|
||||
- `TGA: BASE`
|
||||
- `VP8: BASE`
|
||||
- `WBMP: BASE`
|
||||
- `WEBP: BASE, VP8`
|
||||
- `XXHASH32: BASE`
|
||||
- `XXHASH64: BASE`
|
||||
- `XZ: BASE, CRC32, CRC64, LZMA, SHA256`
|
||||
- `ZLIB: BASE, ADLER32, DEFLATE`
|
||||
|
||||
For the [auxiliary modules](/doc/note/auxiliary-code.md):
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ APIs](https://github.com/google/wuffs/issues/73), after Wuffs v0.2 is released.
|
||||
|
||||
In Wuffs syntax, the `base.io_transformer` methods are:
|
||||
|
||||
- `dst_history_retain_length() u64`
|
||||
- `get_quirk(key: u32) u64`
|
||||
- `history_retain_length() u64`
|
||||
- `set_quirk!(key: u32, value: u64) status`
|
||||
- `transform_io?(dst: io_writer, src: io_reader, workbuf: slice u8)`
|
||||
- `workbuf_len() range_ii_u64`
|
||||
@@ -37,19 +37,25 @@ In Wuffs syntax, the `base.io_transformer` methods are:
|
||||
- [std/bzip2](/std/bzip2)
|
||||
- [std/deflate](/std/deflate)
|
||||
- [std/gzip](/std/gzip)
|
||||
- [std/lzip](/std/lzip)
|
||||
- [std/lzma](/std/lzma)
|
||||
- [std/lzw](/std/lzw)
|
||||
- [std/xz](/std/xz)
|
||||
- [std/zlib](/std/zlib)
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
- [example/bzcat](/example/bzcat)
|
||||
- [example/mzcat](/example/mzcat)
|
||||
- [example/toy-genlib](/example/toy-genlib)
|
||||
- [example/zcat](/example/zcat)
|
||||
|
||||
|
||||
## [Quirks](/doc/note/quirks.md)
|
||||
|
||||
- [LZMA decoder quirks](/std/lzma/decode_quirks.wuffs)
|
||||
- [LZW decoder quirks](/std/lzw/decode_quirks.wuffs)
|
||||
- [XZ decoder quirks](/std/xz/decode_quirks.wuffs)
|
||||
- [Zlib decoder quirks](/std/zlib/decode_quirks.wuffs)
|
||||
|
||||
|
||||
|
||||
+5
-2
@@ -36,14 +36,17 @@ In Wuffs syntax, the `base.hasher_u32` methods are:
|
||||
- `update!(x: slice u8)`
|
||||
- `update_u32!(x: slice u8) u32`
|
||||
|
||||
The `base.hasher_u64` methods are similar, except for the obvious difference of
|
||||
calculating a 64-bit (not 32-bit) checksum.
|
||||
The `base.hasher_u64` and `base.hasher_bitvec256` methods are similar, except
|
||||
for the obvious difference of calculating a 64-bit or 256-bit (not 32-bit)
|
||||
checksum.
|
||||
|
||||
|
||||
## Implementations
|
||||
|
||||
- [std/adler32](/std/adler32)
|
||||
- [std/crc32](/std/crc32)
|
||||
- [std/crc64](/std/crc64)
|
||||
- [std/sha256](/std/sha256)
|
||||
- [std/xxhash32](/std/xxhash32)
|
||||
- [std/xxhash64](/std/xxhash64)
|
||||
|
||||
|
||||
@@ -111,7 +111,6 @@ In Wuffs syntax, the `base.image_decoder` methods are:
|
||||
- `decode_image_config?(dst: nptr image_config, src: io_reader)`
|
||||
- `frame_dirty_rect() rect_ie_u32`
|
||||
- `get_quirk(key: u32) u64`
|
||||
- `history_retain_length() u64`
|
||||
- `num_animation_loops() u32`
|
||||
- `num_decoded_frame_configs() u64`
|
||||
- `num_decoded_frames() u64`
|
||||
@@ -130,8 +129,10 @@ In Wuffs syntax, the `base.image_decoder` methods are:
|
||||
- [std/netpbm](/std/netpbm)
|
||||
- [std/nie](/std/nie)
|
||||
- [std/png](/std/png)
|
||||
- [std/qoi](/std/qoi)
|
||||
- [std/tga](/std/tga)
|
||||
- [std/wbmp](/std/wbmp)
|
||||
- [std/webp](/std/webp)
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -25,6 +25,7 @@ https://skia-review.googlesource.com/c/skia/+/290618
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -65,10 +66,28 @@ https://skia-review.googlesource.com/c/skia/+/290618
|
||||
#define WUFFS_CONFIG__MODULE__NETPBM
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__QOI
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__VP8
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__WEBP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the
|
||||
// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller
|
||||
// programs (in terms of binary size). By default (without these macros),
|
||||
// Wuffs' standard library can decode images to a variety of pixel formats,
|
||||
// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format
|
||||
// is selectable at runtime. Using these macros essentially makes the selection
|
||||
// at compile time, by narrowing the list of supported destination pixel
|
||||
// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as
|
||||
// part of the wuffs_base__image_config argument) to the decode_frame method.
|
||||
//
|
||||
// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method,
|
||||
// the implicit destination pixel format is BGRA_PREMUL.
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL
|
||||
|
||||
// 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.
|
||||
@@ -146,10 +165,14 @@ union {
|
||||
wuffs_netpbm__decoder netpbm;
|
||||
wuffs_nie__decoder nie;
|
||||
wuffs_png__decoder png;
|
||||
wuffs_qoi__decoder qoi;
|
||||
wuffs_tga__decoder tga;
|
||||
wuffs_wbmp__decoder wbmp;
|
||||
wuffs_webp__decoder webp;
|
||||
} g_potential_decoders;
|
||||
|
||||
wuffs_crc32__ieee_hasher g_digest_hasher;
|
||||
|
||||
// ----
|
||||
|
||||
#define BYTES_PER_PIXEL 4
|
||||
@@ -194,6 +217,7 @@ struct {
|
||||
|
||||
bool fail_if_unsandboxed;
|
||||
bool first_frame_only;
|
||||
bool output_crc32_digest;
|
||||
bool output_netpbm;
|
||||
} g_flags = {0};
|
||||
|
||||
@@ -227,7 +251,17 @@ parse_flags(int argc, char** argv) {
|
||||
g_flags.first_frame_only = true;
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "output-crc32-digest")) {
|
||||
if (g_flags.output_crc32_digest || g_flags.output_netpbm) {
|
||||
return "main: multiple --output-etc flags";
|
||||
}
|
||||
g_flags.output_crc32_digest = true;
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "p") || !strcmp(arg, "output-netpbm")) {
|
||||
if (g_flags.output_crc32_digest || g_flags.output_netpbm) {
|
||||
return "main: multiple --output-etc flags";
|
||||
}
|
||||
g_flags.output_netpbm = true;
|
||||
continue;
|
||||
}
|
||||
@@ -250,12 +284,27 @@ parse_flags(int argc, char** argv) {
|
||||
static void //
|
||||
ignore_return_value(int ignored) {}
|
||||
|
||||
ssize_t //
|
||||
write_to_stdout(const void* ptr, size_t len) {
|
||||
if (len > SSIZE_MAX) {
|
||||
return -EFBIG;
|
||||
} else if (!g_flags.output_crc32_digest) {
|
||||
return write(STDOUT_FD, ptr, len);
|
||||
}
|
||||
wuffs_crc32__ieee_hasher__update(
|
||||
&g_digest_hasher, wuffs_base__make_slice_u8((uint8_t*)ptr, len));
|
||||
return (ssize_t)len;
|
||||
}
|
||||
|
||||
const char* //
|
||||
read_more_src(uint64_t history_retain_length) {
|
||||
read_more_src() {
|
||||
if (g_src.meta.closed) {
|
||||
return "main: unexpected end of file";
|
||||
}
|
||||
wuffs_base__io_buffer__compact_retaining(&g_src, history_retain_length);
|
||||
wuffs_base__io_buffer__compact(&g_src);
|
||||
if (g_src.meta.wi == g_src.data.len) {
|
||||
return "main: internal error: no I/O progress possible";
|
||||
}
|
||||
ssize_t n = read(STDIN_FD, g_src.data.ptr + g_src.meta.wi,
|
||||
g_src.data.len - g_src.meta.wi);
|
||||
if (n > 0) {
|
||||
@@ -281,7 +330,7 @@ load_image_type() {
|
||||
(wuffs_base__io_buffer__reader_length(&g_src) == g_src.data.len)) {
|
||||
break;
|
||||
}
|
||||
TRY(read_more_src(0));
|
||||
TRY(read_more_src());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -350,6 +399,16 @@ initialize_image_decoder() {
|
||||
&g_potential_decoders.png);
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__FOURCC__QOI:
|
||||
status = wuffs_qoi__decoder__initialize(
|
||||
&g_potential_decoders.qoi, sizeof g_potential_decoders.qoi,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
TRY(wuffs_base__status__message(&status));
|
||||
g_image_decoder =
|
||||
wuffs_qoi__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
&g_potential_decoders.qoi);
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
status = wuffs_tga__decoder__initialize(
|
||||
&g_potential_decoders.tga, sizeof g_potential_decoders.tga,
|
||||
@@ -369,6 +428,16 @@ initialize_image_decoder() {
|
||||
wuffs_wbmp__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
&g_potential_decoders.wbmp);
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__FOURCC__WEBP:
|
||||
status = wuffs_webp__decoder__initialize(
|
||||
&g_potential_decoders.webp, sizeof g_potential_decoders.webp,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
TRY(wuffs_base__status__message(&status));
|
||||
g_image_decoder =
|
||||
wuffs_webp__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
&g_potential_decoders.webp);
|
||||
return NULL;
|
||||
}
|
||||
return "main: unsupported file format";
|
||||
}
|
||||
@@ -406,7 +475,7 @@ advance_for_redirect() {
|
||||
break;
|
||||
}
|
||||
g_src.meta.ri = g_src.meta.wi;
|
||||
TRY(read_more_src(0));
|
||||
TRY(read_more_src());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -433,8 +502,7 @@ redirect:
|
||||
} else if (status.repr != wuffs_base__suspension__short_read) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
TRY(read_more_src(
|
||||
wuffs_base__image_decoder__history_retain_length(g_image_decoder)));
|
||||
TRY(read_more_src());
|
||||
}
|
||||
|
||||
// Read the dimensions.
|
||||
@@ -526,7 +594,7 @@ print_nix_header(uint32_t magic_u32le) {
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x04, version1_bn4_u32le);
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x08, g_width);
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x0C, g_height);
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], 16));
|
||||
ignore_return_value(write_to_stdout(&data[0], 16));
|
||||
}
|
||||
|
||||
void //
|
||||
@@ -534,14 +602,14 @@ print_netpbm_header() {
|
||||
char data[256];
|
||||
int n = snprintf(data, sizeof(data), "P%c\n%" PRIu32 " %" PRIu32 "\n255\n",
|
||||
(g_pixfmt_is_gray ? '5' : '6'), g_width, g_height);
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], n));
|
||||
ignore_return_value(write_to_stdout(&data[0], n));
|
||||
}
|
||||
|
||||
void //
|
||||
print_nia_duration(wuffs_base__flicks duration) {
|
||||
uint8_t data[8];
|
||||
wuffs_base__poke_u64le__no_bounds_check(data + 0x00, duration);
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], 8));
|
||||
ignore_return_value(write_to_stdout(&data[0], 8));
|
||||
}
|
||||
|
||||
void //
|
||||
@@ -550,11 +618,11 @@ print_nie_frame() {
|
||||
print_nix_header(0x45AFC36E); // "nïE" as a u32le.
|
||||
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
|
||||
if (tab.width == tab.stride) {
|
||||
ignore_return_value(write(STDOUT_FD, tab.ptr, tab.width * tab.height));
|
||||
ignore_return_value(write_to_stdout(tab.ptr, tab.width * tab.height));
|
||||
} else {
|
||||
for (size_t y = 0; y < tab.height; y++) {
|
||||
ignore_return_value(
|
||||
write(STDOUT_FD, tab.ptr + (y * tab.stride), tab.width));
|
||||
write_to_stdout(tab.ptr + (y * tab.stride), tab.width));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -574,13 +642,13 @@ print_netpbm_frame() {
|
||||
data[o + 2] = row[x + 0];
|
||||
o += o_increment;
|
||||
if ((o + 3) > sizeof(data)) {
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], o));
|
||||
ignore_return_value(write_to_stdout(&data[0], o));
|
||||
o = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (o > 0) {
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], o));
|
||||
ignore_return_value(write_to_stdout(&data[0], o));
|
||||
o = 0;
|
||||
}
|
||||
}
|
||||
@@ -590,7 +658,7 @@ print_nia_padding() {
|
||||
if (g_width & g_height & 1) {
|
||||
uint8_t data[4];
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x00, 0);
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], 4));
|
||||
ignore_return_value(write_to_stdout(&data[0], 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,7 +682,7 @@ print_nia_footer() {
|
||||
uint8_t data[8];
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x00, n);
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x04, 0x80000000);
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], 8));
|
||||
ignore_return_value(write_to_stdout(&data[0], 8));
|
||||
}
|
||||
|
||||
const char* //
|
||||
@@ -633,8 +701,7 @@ convert_frames() {
|
||||
} else if (dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return wuffs_base__status__message(&dfc_status);
|
||||
}
|
||||
TRY(read_more_src(
|
||||
wuffs_base__image_decoder__history_retain_length(g_image_decoder)));
|
||||
TRY(read_more_src());
|
||||
}
|
||||
|
||||
wuffs_base__flicks duration =
|
||||
@@ -676,8 +743,7 @@ convert_frames() {
|
||||
if (df_status.repr != wuffs_base__suspension__short_read) {
|
||||
break;
|
||||
}
|
||||
decode_frame_io_error_message = read_more_src(
|
||||
wuffs_base__image_decoder__history_retain_length(g_image_decoder));
|
||||
decode_frame_io_error_message = read_more_src();
|
||||
if (decode_frame_io_error_message != NULL) {
|
||||
// Neuter the "short read" df_status so that convert_frames returns the
|
||||
// I/O error message instead.
|
||||
@@ -761,6 +827,15 @@ main1(int argc, char** argv) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
if (g_flags.output_crc32_digest) {
|
||||
wuffs_base__status status = wuffs_crc32__ieee_hasher__initialize(
|
||||
&g_digest_hasher, sizeof g_digest_hasher, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
if (status.repr) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
}
|
||||
|
||||
g_src.data.ptr = g_src_buffer_array;
|
||||
g_src.data.len = SRC_BUFFER_ARRAY_SIZE;
|
||||
|
||||
@@ -809,6 +884,21 @@ compute_exit_code(const char* status_msg) {
|
||||
return strstr(status_msg, "internal error:") ? 2 : 1;
|
||||
}
|
||||
|
||||
void //
|
||||
print_crc32_digest(bool bad) {
|
||||
const char* hex = "0123456789abcdef";
|
||||
uint32_t hash = wuffs_crc32__ieee_hasher__checksum_u32(&g_digest_hasher);
|
||||
char buf[13];
|
||||
memcpy(buf + 0, bad ? "BAD " : "OK. ", 4);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
buf[4 + i] = hex[hash >> 28];
|
||||
hash <<= 4;
|
||||
}
|
||||
buf[12] = '\n';
|
||||
const int stdout_fd = 1;
|
||||
ignore_return_value(write(stdout_fd, buf, 13));
|
||||
}
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
#if !defined(ALLOW_GIGABYTES_OF_PIXEL_BUFFERS)
|
||||
@@ -843,6 +933,9 @@ main(int argc, char** argv) {
|
||||
#endif
|
||||
|
||||
int exit_code = compute_exit_code(main1(argc, argv));
|
||||
if (g_flags.output_crc32_digest) {
|
||||
print_crc32_digest(exit_code != 0);
|
||||
}
|
||||
|
||||
#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
|
||||
// Call SYS_exit explicitly, instead of calling SYS_exit_group implicitly by
|
||||
|
||||
@@ -88,6 +88,21 @@ micros_since_start(struct timespec* now) {
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__GIF
|
||||
|
||||
// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the
|
||||
// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller
|
||||
// programs (in terms of binary size). By default (without these macros),
|
||||
// Wuffs' standard library can decode images to a variety of pixel formats,
|
||||
// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format
|
||||
// is selectable at runtime. Using these macros essentially makes the selection
|
||||
// at compile time, by narrowing the list of supported destination pixel
|
||||
// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as
|
||||
// part of the wuffs_base__image_config argument) to the decode_frame method.
|
||||
//
|
||||
// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method,
|
||||
// the implicit destination pixel format is BGRA_PREMUL.
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL
|
||||
|
||||
// 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.
|
||||
@@ -299,13 +314,12 @@ try_allocate(wuffs_gif__decoder* dec) {
|
||||
|
||||
uint64_t workbuf_len_max_incl = wuffs_gif__decoder__workbuf_len(dec).max_incl;
|
||||
if (workbuf_len_max_incl > 0) {
|
||||
g_workbuf = wuffs_base__malloc_slice_u8(
|
||||
malloc, wuffs_gif__decoder__workbuf_len(dec).max_incl);
|
||||
g_workbuf = wuffs_base__malloc_slice_u8(malloc, workbuf_len_max_incl);
|
||||
if (!g_workbuf.ptr) {
|
||||
return "could not allocate work buffer";
|
||||
}
|
||||
} else {
|
||||
g_workbuf = wuffs_base__make_slice_u8(NULL, 0);
|
||||
g_workbuf = wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
uint64_t plen = 1 + ((uint64_t)(width) + 1) * (uint64_t)(height);
|
||||
@@ -326,9 +340,9 @@ allocate(wuffs_gif__decoder* dec) {
|
||||
const char* status_msg = try_allocate(dec);
|
||||
if (status_msg) {
|
||||
free(g_printbuf.ptr);
|
||||
g_printbuf = wuffs_base__make_slice_u8(NULL, 0);
|
||||
g_printbuf = wuffs_base__empty_slice_u8();
|
||||
free(g_workbuf.ptr);
|
||||
g_workbuf = wuffs_base__make_slice_u8(NULL, 0);
|
||||
g_workbuf = wuffs_base__empty_slice_u8();
|
||||
free(g_prev_dst_buffer);
|
||||
g_prev_dst_buffer = NULL;
|
||||
free(g_curr_dst_buffer);
|
||||
|
||||
@@ -79,10 +79,28 @@ The Escape key quits.
|
||||
#define WUFFS_CONFIG__MODULE__NETPBM
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__QOI
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__VP8
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__WEBP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the
|
||||
// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller
|
||||
// programs (in terms of binary size). By default (without these macros),
|
||||
// Wuffs' standard library can decode images to a variety of pixel formats,
|
||||
// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format
|
||||
// is selectable at runtime. Using these macros essentially makes the selection
|
||||
// at compile time, by narrowing the list of supported destination pixel
|
||||
// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as
|
||||
// part of the wuffs_base__image_config argument) to the decode_frame method.
|
||||
//
|
||||
// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method,
|
||||
// the implicit destination pixel format is BGRA_PREMUL.
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL
|
||||
|
||||
// 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.
|
||||
@@ -115,6 +133,7 @@ struct {
|
||||
int remaining_argc;
|
||||
char** remaining_argv;
|
||||
|
||||
bool lower_quality;
|
||||
double screen_gamma;
|
||||
} g_flags = {0};
|
||||
|
||||
@@ -122,7 +141,8 @@ static const char* g_usage =
|
||||
"Usage: imageviewer -flags input0.gif input1.png\n"
|
||||
"\n"
|
||||
"Flags:\n"
|
||||
" -screen_gamma=N.N (default 2.2; 0 disables gamma correction)";
|
||||
" -lower-quality (exercise lower-image-quality code paths)\n"
|
||||
" -screen-gamma=N.N (default 2.2; 0 disables gamma correction)";
|
||||
|
||||
const char* //
|
||||
parse_flags(int argc, char** argv) {
|
||||
@@ -148,7 +168,11 @@ parse_flags(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!strncmp(arg, "screen_gamma=", 13)) {
|
||||
if (!strcmp(arg, "lower-quality")) {
|
||||
g_flags.lower_quality = true;
|
||||
continue;
|
||||
}
|
||||
if (!strncmp(arg, "screen-gamma=", 13)) {
|
||||
g_flags.screen_gamma = atof(arg + 13);
|
||||
continue;
|
||||
}
|
||||
@@ -248,10 +272,17 @@ load_image(const char* filename) {
|
||||
dia_flags |= wuffs_aux::DecodeImageArgFlags::REPORT_METADATA_GAMA;
|
||||
}
|
||||
|
||||
const wuffs_aux::QuirkKeyValuePair wuffs_base__quirk_quality = {
|
||||
WUFFS_BASE__QUIRK_QUALITY,
|
||||
WUFFS_BASE__QUIRK_QUALITY__VALUE__LOWER_QUALITY,
|
||||
};
|
||||
|
||||
MyDecodeImageCallbacks callbacks;
|
||||
wuffs_aux::sync_io::FileInput input(file);
|
||||
wuffs_aux::DecodeImageResult res = wuffs_aux::DecodeImage(
|
||||
callbacks, input, wuffs_aux::DecodeImageArgQuirks::DefaultValue(),
|
||||
callbacks, input,
|
||||
wuffs_aux::DecodeImageArgQuirks(&wuffs_base__quirk_quality,
|
||||
g_flags.lower_quality ? 1 : 0),
|
||||
wuffs_aux::DecodeImageArgFlags(dia_flags),
|
||||
// Use PIXEL_BLEND__SRC_OVER, not the default PIXEL_BLEND__SRC, because
|
||||
// we also pass a background color.
|
||||
|
||||
@@ -139,7 +139,7 @@ static const char* g_usage =
|
||||
uint8_t g_dst_array[DST_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__io_buffer g_dst;
|
||||
|
||||
std::vector<uint32_t> g_quirks;
|
||||
std::vector<wuffs_aux::QuirkKeyValuePair> g_quirks;
|
||||
|
||||
struct {
|
||||
int remaining_argc;
|
||||
@@ -149,9 +149,9 @@ struct {
|
||||
std::string //
|
||||
parse_flags(int argc, char** argv) {
|
||||
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, 1});
|
||||
#endif
|
||||
|
||||
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
|
||||
@@ -175,22 +175,22 @@ parse_flags(int argc, char** argv) {
|
||||
}
|
||||
|
||||
if (!strcmp(arg, "input-allow-comments")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, 1});
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "input-allow-extra-comma")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, 1});
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "input-allow-inf-nan-numbers")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS, 1});
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "input-jwcc") || !strcmp(arg, "jwcc")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, 1});
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ static const char* g_usage =
|
||||
|
||||
// ----
|
||||
|
||||
std::vector<uint32_t> g_quirks;
|
||||
std::vector<wuffs_aux::QuirkKeyValuePair> g_quirks;
|
||||
|
||||
std::string g_dst;
|
||||
|
||||
@@ -239,9 +239,9 @@ parse_flags(int argc, char** argv) {
|
||||
g_flags.max_output_depth = 0xFFFFFFFF;
|
||||
|
||||
#if defined(WUFFS_EXAMPLE_SPEAK_JWCC_NOT_JSON)
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, 1});
|
||||
#endif
|
||||
|
||||
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
|
||||
@@ -281,22 +281,22 @@ parse_flags(int argc, char** argv) {
|
||||
return g_usage;
|
||||
}
|
||||
if (!strcmp(arg, "input-allow-comments")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, 1});
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "input-allow-extra-comma")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, 1});
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "input-allow-inf-nan-numbers")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS, 1});
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(arg, "input-jwcc") || !strcmp(arg, "jwcc")) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE);
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA);
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, 1});
|
||||
g_quirks.push_back({WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, 1});
|
||||
continue;
|
||||
}
|
||||
if (!strncmp(arg, "q=", 2) || !strncmp(arg, "query=", 6)) {
|
||||
@@ -547,7 +547,7 @@ main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
if (!g_flags.strict_json_pointer_syntax) {
|
||||
g_quirks.push_back(
|
||||
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T);
|
||||
{WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T, 1});
|
||||
}
|
||||
|
||||
FILE* in = stdin;
|
||||
|
||||
@@ -997,11 +997,11 @@ static void //
|
||||
ignore_return_value(int ignored) {}
|
||||
|
||||
const char* //
|
||||
read_src(uint64_t history_retain_length) {
|
||||
read_src() {
|
||||
if (g_src.meta.closed) {
|
||||
return "main: internal error: read requested on a closed source";
|
||||
}
|
||||
g_src.compact_retaining(history_retain_length);
|
||||
g_src.compact();
|
||||
if (g_src.meta.wi >= g_src.data.len) {
|
||||
return "main: g_src buffer is full";
|
||||
}
|
||||
@@ -1394,7 +1394,7 @@ main1(int argc, char** argv) {
|
||||
}
|
||||
// Check that we've exhausted the input.
|
||||
if ((g_src.meta.ri == g_src.meta.wi) && !g_src.meta.closed) {
|
||||
TRY(read_src(g_dec.history_retain_length()));
|
||||
TRY(read_src());
|
||||
}
|
||||
if ((g_src.meta.ri < g_src.meta.wi) || !g_src.meta.closed) {
|
||||
return "main: valid JSON followed by further (unexpected) data";
|
||||
@@ -1405,7 +1405,7 @@ main1(int argc, char** argv) {
|
||||
if (g_cursor_index != g_src.meta.ri) {
|
||||
return "main: internal error: inconsistent g_src indexes";
|
||||
}
|
||||
TRY(read_src(g_dec.history_retain_length()));
|
||||
TRY(read_src());
|
||||
g_cursor_index = g_src.meta.ri;
|
||||
} else if (status.repr == wuffs_base__suspension__short_write) {
|
||||
g_tok.compact();
|
||||
|
||||
@@ -11,13 +11,22 @@
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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:
|
||||
mzcat decompresses stdin to stdout. It is similar to the standard /bin/bzcat,
|
||||
/bin/lzcat or /bin/zcat programs but the single program speaks multiple file
|
||||
formats (listed below). 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
|
||||
$CC mzcat.c && ./a.out < ../../test/data/romeo.txt.bz2; rm -f a.out
|
||||
|
||||
for a C compiler $CC, such as clang or gcc.
|
||||
|
||||
Supported compression formats:
|
||||
- bzip2
|
||||
- gzip
|
||||
- lzip
|
||||
- lzma
|
||||
- xz
|
||||
- zlib
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@@ -49,8 +58,18 @@ for a C compiler $CC, such as clang or gcc.
|
||||
// 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__BZIP2
|
||||
#define WUFFS_CONFIG__MODULE__CRC32
|
||||
#define WUFFS_CONFIG__MODULE__CRC64
|
||||
#define WUFFS_CONFIG__MODULE__DEFLATE
|
||||
#define WUFFS_CONFIG__MODULE__GZIP
|
||||
#define WUFFS_CONFIG__MODULE__LZIP
|
||||
#define WUFFS_CONFIG__MODULE__LZMA
|
||||
#define WUFFS_CONFIG__MODULE__SHA256
|
||||
#define WUFFS_CONFIG__MODULE__XZ
|
||||
#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
|
||||
@@ -65,34 +84,49 @@ for a C compiler $CC, such as clang or gcc.
|
||||
#endif
|
||||
|
||||
#ifndef DST_BUFFER_ARRAY_SIZE
|
||||
#define DST_BUFFER_ARRAY_SIZE (128 * 1024)
|
||||
#define DST_BUFFER_ARRAY_SIZE (64 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef SRC_BUFFER_ARRAY_SIZE
|
||||
#define SRC_BUFFER_ARRAY_SIZE (128 * 1024)
|
||||
#define SRC_BUFFER_ARRAY_SIZE (64 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#define WORK_BUFFER_ARRAY_SIZE \
|
||||
WUFFS_BZIP2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
|
||||
// 80 MiB is big enough to decode files encoded with "xz -9".
|
||||
#ifndef WORKBUF_ARRAY_SIZE
|
||||
#define WORKBUF_ARRAY_SIZE (80 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
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
|
||||
uint8_t g_workbuf_array[WORKBUF_ARRAY_SIZE];
|
||||
|
||||
// ----
|
||||
|
||||
static bool g_sandboxed = false;
|
||||
|
||||
int32_t g_fourcc = 0;
|
||||
|
||||
wuffs_base__io_transformer* g_io_transformer = NULL;
|
||||
union {
|
||||
wuffs_bzip2__decoder bzip2;
|
||||
wuffs_gzip__decoder gzip;
|
||||
wuffs_lzip__decoder lzip;
|
||||
wuffs_lzma__decoder lzma;
|
||||
wuffs_xz__decoder xz;
|
||||
wuffs_zlib__decoder zlib;
|
||||
} g_potential_decoders;
|
||||
|
||||
wuffs_crc32__ieee_hasher g_digest_hasher;
|
||||
|
||||
// ----
|
||||
|
||||
struct {
|
||||
int remaining_argc;
|
||||
char** remaining_argv;
|
||||
|
||||
bool fail_if_unsandboxed;
|
||||
bool ignore_checksum;
|
||||
bool output_crc32_digest;
|
||||
} g_flags = {0};
|
||||
|
||||
const char* //
|
||||
@@ -120,6 +154,12 @@ parse_flags(int argc, char** argv) {
|
||||
if (!strcmp(arg, "fail-if-unsandboxed")) {
|
||||
g_flags.fail_if_unsandboxed = true;
|
||||
continue;
|
||||
} else if (!strcmp(arg, "ignore-checksum")) {
|
||||
g_flags.ignore_checksum = true;
|
||||
continue;
|
||||
} else if (!strcmp(arg, "output-crc32-digest")) {
|
||||
g_flags.output_crc32_digest = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
return "main: unrecognized flag argument";
|
||||
@@ -136,6 +176,82 @@ parse_flags(int argc, char** argv) {
|
||||
static void //
|
||||
ignore_return_value(int ignored) {}
|
||||
|
||||
const char* //
|
||||
initialize_io_transformer(uint8_t input_first_byte) {
|
||||
wuffs_base__status status =
|
||||
wuffs_base__make_status("main: unrecognized input compression format");
|
||||
wuffs_base__io_transformer* io_transformer = NULL;
|
||||
|
||||
switch (input_first_byte) {
|
||||
case 0x1F:
|
||||
status = wuffs_gzip__decoder__initialize(
|
||||
&g_potential_decoders.gzip, sizeof g_potential_decoders.gzip,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
io_transformer =
|
||||
wuffs_gzip__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
&g_potential_decoders.gzip);
|
||||
break;
|
||||
|
||||
case 0x42:
|
||||
status = wuffs_bzip2__decoder__initialize(
|
||||
&g_potential_decoders.bzip2, sizeof g_potential_decoders.bzip2,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
io_transformer =
|
||||
wuffs_bzip2__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
&g_potential_decoders.bzip2);
|
||||
break;
|
||||
|
||||
case 0x4C:
|
||||
status = wuffs_lzip__decoder__initialize(
|
||||
&g_potential_decoders.lzip, sizeof g_potential_decoders.lzip,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
io_transformer =
|
||||
wuffs_lzip__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
&g_potential_decoders.lzip);
|
||||
break;
|
||||
|
||||
case 0x5D:
|
||||
status = wuffs_lzma__decoder__initialize(
|
||||
&g_potential_decoders.lzma, sizeof g_potential_decoders.lzma,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
io_transformer =
|
||||
wuffs_lzma__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
&g_potential_decoders.lzma);
|
||||
break;
|
||||
|
||||
case 0x78:
|
||||
status = wuffs_zlib__decoder__initialize(
|
||||
&g_potential_decoders.zlib, sizeof g_potential_decoders.zlib,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
io_transformer =
|
||||
wuffs_zlib__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
&g_potential_decoders.zlib);
|
||||
break;
|
||||
|
||||
case 0xFD:
|
||||
status = wuffs_xz__decoder__initialize(
|
||||
&g_potential_decoders.xz, sizeof g_potential_decoders.xz,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
io_transformer = wuffs_xz__decoder__upcast_as__wuffs_base__io_transformer(
|
||||
&g_potential_decoders.xz);
|
||||
wuffs_base__io_transformer__set_quirk(
|
||||
io_transformer,
|
||||
WUFFS_XZ__QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_flags.ignore_checksum) {
|
||||
wuffs_base__io_transformer__set_quirk(io_transformer,
|
||||
WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, 1);
|
||||
}
|
||||
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
g_io_transformer = io_transformer;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
const char* z = parse_flags(argc, argv);
|
||||
@@ -147,13 +263,6 @@ main1(int argc, char** argv) {
|
||||
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;
|
||||
@@ -185,18 +294,49 @@ main1(int argc, char** argv) {
|
||||
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 (g_io_transformer) {
|
||||
// No-op.
|
||||
} else if (src.meta.ri == src.meta.wi) {
|
||||
return "main: invalid empty input";
|
||||
} else {
|
||||
const char* z = initialize_io_transformer(src.data.ptr[src.meta.ri]);
|
||||
if (z) {
|
||||
return z;
|
||||
} else if (g_flags.output_crc32_digest) {
|
||||
wuffs_base__status status = wuffs_crc32__ieee_hasher__initialize(
|
||||
&g_digest_hasher, sizeof g_digest_hasher, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
if (status.repr) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
while (true) {
|
||||
wuffs_base__status status = wuffs_base__io_transformer__transform_io(
|
||||
g_io_transformer, &dst, &src,
|
||||
wuffs_base__make_slice_u8(&g_workbuf_array[0],
|
||||
sizeof(g_workbuf_array)));
|
||||
|
||||
if (dst.meta.ri < dst.meta.wi) {
|
||||
if (g_flags.output_crc32_digest) {
|
||||
wuffs_crc32__ieee_hasher__update(
|
||||
&g_digest_hasher, wuffs_base__io_buffer__reader_slice(&dst));
|
||||
} else {
|
||||
// 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.ri,
|
||||
dst.meta.wi - dst.meta.ri));
|
||||
}
|
||||
dst.meta.ri = dst.meta.wi;
|
||||
wuffs_base__io_buffer__compact(&dst);
|
||||
wuffs_base__optional_u63 hrl =
|
||||
wuffs_base__io_transformer__dst_history_retain_length(
|
||||
g_io_transformer);
|
||||
wuffs_base__io_buffer__compact_retaining(
|
||||
&dst, wuffs_base__optional_u63__value_or(&hrl, UINT64_MAX));
|
||||
if (dst.meta.wi == dst.data.len) {
|
||||
return "main: unsupported history length (a.k.a. dictionary size)";
|
||||
}
|
||||
}
|
||||
|
||||
if (status.repr == wuffs_base__suspension__short_read) {
|
||||
@@ -208,11 +348,7 @@ main1(int argc, char** argv) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer__compact_retaining(
|
||||
&src, wuffs_bzip2__decoder__history_retain_length(&dec));
|
||||
if (src.meta.wi == src.data.len) {
|
||||
return "main: internal error: no I/O progress possible";
|
||||
}
|
||||
wuffs_base__io_buffer__compact(&src);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +379,21 @@ compute_exit_code(const char* status_msg) {
|
||||
return strstr(status_msg, "internal error:") ? 2 : 1;
|
||||
}
|
||||
|
||||
void //
|
||||
print_crc32_digest(bool bad) {
|
||||
const char* hex = "0123456789abcdef";
|
||||
uint32_t hash = wuffs_crc32__ieee_hasher__checksum_u32(&g_digest_hasher);
|
||||
char buf[13];
|
||||
memcpy(buf + 0, bad ? "BAD " : "OK. ", 4);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
buf[4 + i] = hex[hash >> 28];
|
||||
hash <<= 4;
|
||||
}
|
||||
buf[12] = '\n';
|
||||
const int stdout_fd = 1;
|
||||
ignore_return_value(write(stdout_fd, buf, 13));
|
||||
}
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
|
||||
@@ -251,6 +402,9 @@ main(int argc, char** argv) {
|
||||
#endif
|
||||
|
||||
int exit_code = compute_exit_code(main1(argc, argv));
|
||||
if (g_flags.output_crc32_digest) {
|
||||
print_crc32_digest(exit_code != 0);
|
||||
}
|
||||
|
||||
#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
|
||||
// Call SYS_exit explicitly, instead of calling SYS_exit_group implicitly by
|
||||
@@ -77,10 +77,28 @@ isn't otherwise doing anything.
|
||||
#define WUFFS_CONFIG__MODULE__NETPBM
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__QOI
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__VP8
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__WEBP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the
|
||||
// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller
|
||||
// programs (in terms of binary size). By default (without these macros),
|
||||
// Wuffs' standard library can decode images to a variety of pixel formats,
|
||||
// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format
|
||||
// is selectable at runtime. Using these macros essentially makes the selection
|
||||
// at compile time, by narrowing the list of supported destination pixel
|
||||
// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as
|
||||
// part of the wuffs_base__image_config argument) to the decode_frame method.
|
||||
//
|
||||
// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method,
|
||||
// the implicit destination pixel format is BGRA_PREMUL.
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL
|
||||
|
||||
// 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.
|
||||
@@ -189,7 +207,7 @@ class Wuffs_Load_RW_Input : public wuffs_aux::sync_io::Input {
|
||||
|
||||
private:
|
||||
std::string //
|
||||
CopyIn(wuffs_aux::IOBuffer* dst, uint64_t history_retain_length) override {
|
||||
CopyIn(wuffs_aux::IOBuffer* dst) override {
|
||||
if (!m_rw) {
|
||||
return "Wuffs_Load_RW_Input: NULL SDL_RWops";
|
||||
} else if (!dst) {
|
||||
@@ -197,7 +215,7 @@ class Wuffs_Load_RW_Input : public wuffs_aux::sync_io::Input {
|
||||
} else if (dst->meta.closed) {
|
||||
return "Wuffs_Load_RW_Input: end of file";
|
||||
}
|
||||
dst->compact_retaining(history_retain_length);
|
||||
dst->compact();
|
||||
if (dst->writer_length() == 0) {
|
||||
return "Wuffs_Load_RW_Input: full IOBuffer";
|
||||
}
|
||||
|
||||
@@ -77,6 +77,21 @@ OOOOXXXXXXXXXXOXXXXXXXXXXXXOOO
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__JPEG
|
||||
|
||||
// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the
|
||||
// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller
|
||||
// programs (in terms of binary size). By default (without these macros),
|
||||
// Wuffs' standard library can decode images to a variety of pixel formats,
|
||||
// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format
|
||||
// is selectable at runtime. Using these macros essentially makes the selection
|
||||
// at compile time, by narrowing the list of supported destination pixel
|
||||
// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as
|
||||
// part of the wuffs_base__image_config argument) to the decode_frame method.
|
||||
//
|
||||
// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method,
|
||||
// the implicit destination pixel format is BGRA_PREMUL.
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST
|
||||
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL
|
||||
|
||||
// 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.
|
||||
|
||||
+20
-8
@@ -95,6 +95,7 @@ struct {
|
||||
char** remaining_argv;
|
||||
|
||||
bool fail_if_unsandboxed;
|
||||
bool ignore_checksum;
|
||||
} g_flags = {0};
|
||||
|
||||
const char* //
|
||||
@@ -122,6 +123,9 @@ parse_flags(int argc, char** argv) {
|
||||
if (!strcmp(arg, "fail-if-unsandboxed")) {
|
||||
g_flags.fail_if_unsandboxed = true;
|
||||
continue;
|
||||
} else if (!strcmp(arg, "ignore-checksum")) {
|
||||
g_flags.ignore_checksum = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
return "main: unrecognized flag argument";
|
||||
@@ -156,6 +160,10 @@ main1(int argc, char** argv) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
if (g_flags.ignore_checksum) {
|
||||
wuffs_gzip__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, 1);
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer dst;
|
||||
dst.data.ptr = g_dst_buffer_array;
|
||||
dst.data.len = DST_BUFFER_ARRAY_SIZE;
|
||||
@@ -193,12 +201,20 @@ main1(int argc, char** argv) {
|
||||
wuffs_base__make_slice_u8(g_work_buffer_array,
|
||||
WORK_BUFFER_ARRAY_SIZE));
|
||||
|
||||
if (dst.meta.wi) {
|
||||
if (dst.meta.ri < 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));
|
||||
ignore_return_value(write(stdout_fd, g_dst_buffer_array + dst.meta.ri,
|
||||
dst.meta.wi - dst.meta.ri));
|
||||
dst.meta.ri = dst.meta.wi;
|
||||
wuffs_base__io_buffer__compact(&dst);
|
||||
|
||||
wuffs_base__optional_u63 hrl =
|
||||
wuffs_gzip__decoder__dst_history_retain_length(&dec);
|
||||
wuffs_base__io_buffer__compact_retaining(
|
||||
&dst, wuffs_base__optional_u63__value_or(&hrl, UINT64_MAX));
|
||||
if (dst.meta.wi == dst.data.len) {
|
||||
return "main: unsupported history length (a.k.a. dictionary size)";
|
||||
}
|
||||
}
|
||||
|
||||
if (status.repr == wuffs_base__suspension__short_read) {
|
||||
@@ -210,11 +226,7 @@ main1(int argc, char** argv) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer__compact_retaining(
|
||||
&src, wuffs_gzip__decoder__history_retain_length(&dec));
|
||||
if (src.meta.wi == src.data.len) {
|
||||
return "main: internal error: no I/O progress possible";
|
||||
}
|
||||
wuffs_base__io_buffer__compact(&src);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ It should print "PASS", amongst other information, and exit(0).
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
|
||||
// 64 KiB.
|
||||
#define DST_BUFFER_ARRAY_SIZE 65536
|
||||
|
||||
// Wuffs allows either statically or dynamically allocated work buffers. This
|
||||
@@ -96,7 +97,7 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_bzip2__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
|
||||
hash & 0xFFFE);
|
||||
|
||||
uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
|
||||
static uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__io_buffer dst =
|
||||
wuffs_base__ptr_u8__writer(&dst_buffer[0], DST_BUFFER_ARRAY_SIZE);
|
||||
|
||||
|
||||
@@ -499,11 +499,11 @@ fuzz_cpp(const uint8_t* in_ptr, size_t in_len, uint64_t hash) {
|
||||
const char* json_pointer = json_pointers[hash & 15];
|
||||
hash = wuffs_base__u64__rotate_right(hash, 4);
|
||||
|
||||
std::vector<uint32_t> quirks;
|
||||
std::vector<wuffs_aux::QuirkKeyValuePair> quirks;
|
||||
for (uint32_t i = 0; g_quirks[i]; i++) {
|
||||
uint64_t bit = 1 << (i & 63);
|
||||
if (hash & bit) {
|
||||
quirks.push_back(g_quirks[i]);
|
||||
quirks.push_back({g_quirks[i], 1});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ It should print "PASS", amongst other information, and exit(0).
|
||||
const uint32_t pixfmts[] = {
|
||||
WUFFS_BASE__PIXEL_FORMAT__Y,
|
||||
WUFFS_BASE__PIXEL_FORMAT__Y_16BE,
|
||||
WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL,
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL,
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
|
||||
WUFFS_BASE__PIXEL_FORMAT__BGR_565,
|
||||
@@ -123,13 +124,17 @@ const char* //
|
||||
fuzz_swizzle_interleaved_from_slice(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
uint8_t dst_palette_array[1024];
|
||||
uint8_t src_palette_array[1024];
|
||||
if ((src->meta.wi - src->meta.ri) < 2048) {
|
||||
return "fuzz: not enough data";
|
||||
if ((src->meta.wi - src->meta.ri) >= 2048) {
|
||||
memcpy(dst_palette_array, src->data.ptr + src->meta.ri, 1024);
|
||||
src->meta.ri += 1024;
|
||||
memcpy(src_palette_array, src->data.ptr + src->meta.ri, 1024);
|
||||
src->meta.ri += 1024;
|
||||
} else {
|
||||
for (uint32_t i = 0; i < 1024; i++) {
|
||||
dst_palette_array[i] = (uint8_t)i;
|
||||
src_palette_array[i] = (uint8_t)i;
|
||||
}
|
||||
}
|
||||
memcpy(dst_palette_array, src->data.ptr + src->meta.ri, 1024);
|
||||
src->meta.ri += 1024;
|
||||
memcpy(src_palette_array, src->data.ptr + src->meta.ri, 1024);
|
||||
src->meta.ri += 1024;
|
||||
wuffs_base__slice_u8 dst_palette =
|
||||
wuffs_base__make_slice_u8(&dst_palette_array[0], 1024);
|
||||
wuffs_base__slice_u8 src_palette =
|
||||
@@ -177,17 +182,25 @@ fuzz_swizzle_interleaved_from_slice(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
|
||||
// Position dst_slice and src_slice so that reading or writing one byte past
|
||||
// their end will cause a segmentation fault.
|
||||
if ((src->meta.wi - src->meta.ri) < (dst_len + src_len)) {
|
||||
return "fuzz: not enough data";
|
||||
}
|
||||
wuffs_base__slice_u8 dst_slice =
|
||||
wuffs_base__make_slice_u8(dst_alloc + alloc_size - dst_len, dst_len);
|
||||
memcpy(dst_slice.ptr, src->data.ptr + src->meta.ri, dst_len);
|
||||
src->meta.ri += dst_len;
|
||||
wuffs_base__slice_u8 src_slice =
|
||||
wuffs_base__make_slice_u8(src_alloc + alloc_size - src_len, src_len);
|
||||
memcpy(src_slice.ptr, src->data.ptr + src->meta.ri, src_len);
|
||||
src->meta.ri += src_len;
|
||||
|
||||
// Fill in dst_slice and src_slice.
|
||||
if ((src->meta.wi - src->meta.ri) >= (dst_len + src_len)) {
|
||||
memcpy(dst_slice.ptr, src->data.ptr + src->meta.ri, dst_len);
|
||||
src->meta.ri += dst_len;
|
||||
memcpy(src_slice.ptr, src->data.ptr + src->meta.ri, src_len);
|
||||
src->meta.ri += src_len;
|
||||
} else {
|
||||
for (size_t i = 0; i < dst_len; i++) {
|
||||
dst_slice.ptr[i] = (uint8_t)i;
|
||||
}
|
||||
for (size_t i = 0; i < src_len; i++) {
|
||||
src_slice.ptr[i] = (uint8_t)i;
|
||||
}
|
||||
}
|
||||
|
||||
// When manually testing this program, enabling this code should lead to a
|
||||
// segmentation fault.
|
||||
@@ -213,16 +226,34 @@ fuzz_swizzle_ycck(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_base__pixel_format dst_pixfmt = wuffs_base__make_pixel_format(
|
||||
pixfmts[(0xFF & (hash >> 0)) % num_pixfmts]);
|
||||
|
||||
uint32_t width = (63 & (hash >> 8)) + 1;
|
||||
uint32_t height = (63 & (hash >> 14)) + 1;
|
||||
uint32_t x_min_incl = (63 & (hash >> 8)) + 1;
|
||||
uint32_t x_max_excl = (63 & (hash >> 14)) + 1;
|
||||
uint32_t y_min_incl = (63 & (hash >> 20)) + 1;
|
||||
uint32_t y_max_excl = (63 & (hash >> 26)) + 1;
|
||||
|
||||
uint32_t width_in_mcus = (3 & (hash >> 20)) + 1;
|
||||
uint32_t height_in_mcus = (3 & (hash >> 22)) + 1;
|
||||
uint32_t width_in_mcus = (3 & (hash >> 32)) + 1;
|
||||
uint32_t height_in_mcus = (3 & (hash >> 34)) + 1;
|
||||
|
||||
uint32_t allow_hv3 = 1 & (hash >> 24);
|
||||
bool is_rgb_or_cmyk = 1 & (hash >> 25);
|
||||
bool triangle_filter_for_2to1 = 1 & (hash >> 26);
|
||||
bool use_4th_component = 1 & (hash >> 27);
|
||||
uint32_t allow_hv3 = 1 & (hash >> 36);
|
||||
bool is_rgb_or_cmyk = 1 & (hash >> 37);
|
||||
bool triangle_filter_for_2to1 = 1 & (hash >> 38);
|
||||
bool use_4th_component = 1 & (hash >> 39);
|
||||
|
||||
if (triangle_filter_for_2to1) {
|
||||
x_min_incl = 0;
|
||||
y_min_incl = 0;
|
||||
} else {
|
||||
if (x_min_incl > x_max_excl) {
|
||||
uint32_t a = x_min_incl;
|
||||
x_min_incl = x_max_excl;
|
||||
x_max_excl = a;
|
||||
}
|
||||
if (y_min_incl > y_max_excl) {
|
||||
uint32_t a = y_min_incl;
|
||||
y_min_incl = y_max_excl;
|
||||
y_max_excl = a;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t possible_hv_values[2][4] = {
|
||||
{1, 1, 2, 4},
|
||||
@@ -252,8 +283,10 @@ fuzz_swizzle_ycck(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
h0, wuffs_base__u32__max(h1, wuffs_base__u32__max(h2, h3)));
|
||||
uint32_t vmax = wuffs_base__u32__max(
|
||||
v0, wuffs_base__u32__max(v1, wuffs_base__u32__max(v2, v3)));
|
||||
width = wuffs_base__u32__min(width, 8 * width_in_mcus * hmax);
|
||||
height = wuffs_base__u32__min(height, 8 * height_in_mcus * vmax);
|
||||
x_max_excl = x_min_incl + wuffs_base__u32__min(x_max_excl - x_min_incl,
|
||||
8 * width_in_mcus * hmax);
|
||||
y_max_excl = y_min_incl + wuffs_base__u32__min(y_max_excl - y_min_incl,
|
||||
8 * height_in_mcus * vmax);
|
||||
|
||||
static size_t dst_alloc_size = 0;
|
||||
if (dst_alloc_size == 0) {
|
||||
@@ -270,7 +303,8 @@ fuzz_swizzle_ycck(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
|
||||
wuffs_base__pixel_buffer dst_pixbuf;
|
||||
wuffs_base__pixel_config dst_pixcfg;
|
||||
wuffs_base__pixel_config__set(&dst_pixcfg, dst_pixfmt.repr, 0, width, height);
|
||||
wuffs_base__pixel_config__set(&dst_pixcfg, dst_pixfmt.repr, 0, x_max_excl,
|
||||
y_max_excl);
|
||||
uint64_t dst_pixbuf_len = wuffs_base__pixel_config__pixbuf_len(&dst_pixcfg);
|
||||
if (dst_pixbuf_len > dst_alloc_size) {
|
||||
return "fuzz: internal error: dst_alloc_size is too small";
|
||||
@@ -367,7 +401,8 @@ fuzz_swizzle_ycck(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
uint8_t scratch_buffer[2048];
|
||||
wuffs_base__status status = wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
&swizzler, &dst_pixbuf, dst_palette, //
|
||||
width, height, //
|
||||
x_min_incl, x_max_excl, //
|
||||
y_min_incl, y_max_excl, //
|
||||
src0, src1, src2, src3, //
|
||||
width0, width1, width2, width3, //
|
||||
height0, height1, height2, height3, //
|
||||
|
||||
@@ -24,6 +24,7 @@ json: test/data/*.json ../rapidjson_corpus/* ../simdjson_corpus/* ../JSONTe
|
||||
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
|
||||
tga: test/data/*.tga
|
||||
wbmp: test/data/*.wbmp
|
||||
xz: test/data/*.xz ../xz_corpus/*.xz
|
||||
zlib: test/data/*.zlib
|
||||
|
||||
# Wuffs' pixel_swizzler doesn't process any particular file format. We just
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
// 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 xz_fuzzer.c
|
||||
./a.out ../../../test/data/*.xz
|
||||
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__CRC32
|
||||
#define WUFFS_CONFIG__MODULE__CRC64
|
||||
#define WUFFS_CONFIG__MODULE__LZMA
|
||||
#define WUFFS_CONFIG__MODULE__SHA256
|
||||
#define WUFFS_CONFIG__MODULE__XZ
|
||||
|
||||
// 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"
|
||||
|
||||
// 64 KiB.
|
||||
#define DST_BUFFER_ARRAY_SIZE 65536
|
||||
|
||||
// Wuffs allows either statically or dynamically allocated work buffers. This
|
||||
// program exercises static allocation.
|
||||
//
|
||||
// We hard-code 64 MiB, as WUFFS_XZ__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
|
||||
// can be over 4 GiB. Using it can cause "relocation truncated to fit:
|
||||
// R_X86_64_PC32 against symbol etc" compiler errors.
|
||||
#define WORK_BUFFER_ARRAY_SIZE 67108864
|
||||
#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_xz__decoder dec;
|
||||
wuffs_base__status status = wuffs_xz__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_xz__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
|
||||
hash & 0xFFFE);
|
||||
|
||||
static uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__io_buffer dst =
|
||||
wuffs_base__ptr_u8__writer(&dst_buffer[0], DST_BUFFER_ARRAY_SIZE);
|
||||
|
||||
while (true) {
|
||||
dst.meta.wi = 0;
|
||||
status = wuffs_xz__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_xz__decoder__transform_io made no progress\n");
|
||||
intentional_segfault();
|
||||
}
|
||||
}
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
@@ -69,6 +69,7 @@ It should print "PASS", amongst other information, and exit(0).
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
|
||||
// 64 KiB.
|
||||
#define DST_BUFFER_ARRAY_SIZE 65536
|
||||
|
||||
// Wuffs allows either statically or dynamically allocated work buffers. This
|
||||
@@ -98,7 +99,7 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_zlib__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
|
||||
hash & 0xFFFE);
|
||||
|
||||
uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
|
||||
static uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__io_buffer dst =
|
||||
wuffs_base__ptr_u8__writer(&dst_buffer[0], DST_BUFFER_ARRAY_SIZE);
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
module github.com/google/wuffs
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/pierrec/xxHash v0.1.5 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
golang.org/x/image v0.5.0 // indirect
|
||||
)
|
||||
@@ -1,33 +0,0 @@
|
||||
github.com/pierrec/xxHash v0.1.5 h1:n/jBpwTHiER4xYvK3/CdPVnLDPchj8eTJFFLUb4QHBo=
|
||||
github.com/pierrec/xxHash v0.1.5/go.mod h1:w2waW5Zoa/Wc4Yqe0wgrIYAGKqRMf7czn2HNKXmuL+I=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
|
||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
|
||||
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -37,7 +37,7 @@ pub func parser.parse?(src: base.io_reader) {
|
||||
// Uncomment this assertion to see what facts are known here.
|
||||
// assert false
|
||||
this.val = (10 * this.val) + (c as base.u32)
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pub func parser.value() base.u32 {
|
||||
|
||||
@@ -25,16 +25,12 @@ DynIOBuffer::DynIOBuffer(uint64_t max_incl)
|
||||
: m_buf(wuffs_base__empty_io_buffer()), m_max_incl(max_incl) {}
|
||||
|
||||
DynIOBuffer::~DynIOBuffer() {
|
||||
if (m_buf.data.ptr) {
|
||||
free(m_buf.data.ptr);
|
||||
}
|
||||
free(m_buf.data.ptr);
|
||||
}
|
||||
|
||||
void //
|
||||
DynIOBuffer::drop() {
|
||||
if (m_buf.data.ptr) {
|
||||
free(m_buf.data.ptr);
|
||||
}
|
||||
free(m_buf.data.ptr);
|
||||
m_buf = wuffs_base__empty_io_buffer();
|
||||
}
|
||||
|
||||
@@ -45,13 +41,16 @@ DynIOBuffer::grow(uint64_t min_incl) {
|
||||
return ((min_incl == 0) && (m_max_incl == 0))
|
||||
? DynIOBuffer::GrowResult::OK
|
||||
: DynIOBuffer::GrowResult::FailedMaxInclExceeded;
|
||||
} else if (n > SIZE_MAX) {
|
||||
return DynIOBuffer::GrowResult::FailedOutOfMemory;
|
||||
} else if (n > m_buf.data.len) {
|
||||
uint8_t* ptr = static_cast<uint8_t*>(realloc(m_buf.data.ptr, n));
|
||||
uint8_t* ptr =
|
||||
static_cast<uint8_t*>(realloc(m_buf.data.ptr, static_cast<size_t>(n)));
|
||||
if (!ptr) {
|
||||
return DynIOBuffer::GrowResult::FailedOutOfMemory;
|
||||
}
|
||||
m_buf.data.ptr = ptr;
|
||||
m_buf.data.len = n;
|
||||
m_buf.data.len = static_cast<size_t>(n);
|
||||
}
|
||||
return DynIOBuffer::GrowResult::OK;
|
||||
}
|
||||
@@ -98,7 +97,7 @@ Input::BringsItsOwnIOBuffer() {
|
||||
FileInput::FileInput(FILE* f) : m_f(f) {}
|
||||
|
||||
std::string //
|
||||
FileInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
|
||||
FileInput::CopyIn(IOBuffer* dst) {
|
||||
if (!m_f) {
|
||||
return "wuffs_aux::sync_io::FileInput: nullptr file";
|
||||
} else if (!dst) {
|
||||
@@ -106,7 +105,7 @@ FileInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
|
||||
} else if (dst->meta.closed) {
|
||||
return "wuffs_aux::sync_io::FileInput: end of file";
|
||||
} else {
|
||||
dst->compact_retaining(history_retain_length);
|
||||
dst->compact();
|
||||
size_t n = fread(dst->writer_pointer(), 1, dst->writer_length(), m_f);
|
||||
dst->meta.wi += n;
|
||||
dst->meta.closed = feof(m_f);
|
||||
@@ -134,7 +133,7 @@ MemoryInput::BringsItsOwnIOBuffer() {
|
||||
}
|
||||
|
||||
std::string //
|
||||
MemoryInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
|
||||
MemoryInput::CopyIn(IOBuffer* dst) {
|
||||
if (!dst) {
|
||||
return "wuffs_aux::sync_io::MemoryInput: nullptr IOBuffer";
|
||||
} else if (dst->meta.closed) {
|
||||
@@ -144,7 +143,7 @@ MemoryInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
|
||||
// to it.
|
||||
return "wuffs_aux::sync_io::MemoryInput: overlapping buffers";
|
||||
} else {
|
||||
dst->compact_retaining(history_retain_length);
|
||||
dst->compact();
|
||||
size_t nd = dst->writer_length();
|
||||
size_t ns = m_io.reader_length();
|
||||
size_t n = (nd < ns) ? nd : ns;
|
||||
@@ -199,7 +198,7 @@ AdvanceIOBufferTo(const ErrorMessages& error_messages,
|
||||
if (!input.BringsItsOwnIOBuffer()) {
|
||||
io_buf.compact();
|
||||
}
|
||||
std::string error_message = input.CopyIn(&io_buf, 0);
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return error_message;
|
||||
}
|
||||
@@ -282,7 +281,7 @@ HandleMetadata(
|
||||
} else if (!input.BringsItsOwnIOBuffer()) {
|
||||
io_buf.compact();
|
||||
}
|
||||
std::string error_message = input.CopyIn(&io_buf, 0);
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return error_message;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace wuffs_aux {
|
||||
|
||||
@@ -28,6 +29,8 @@ using IOBuffer = wuffs_base__io_buffer;
|
||||
// nullptr, since calling free(nullptr) is a no-op.
|
||||
using MemOwner = std::unique_ptr<void, decltype(&free)>;
|
||||
|
||||
using QuirkKeyValuePair = std::pair<uint32_t, uint64_t>;
|
||||
|
||||
namespace sync_io {
|
||||
|
||||
// --------
|
||||
@@ -94,7 +97,7 @@ class Input {
|
||||
virtual ~Input();
|
||||
|
||||
virtual IOBuffer* BringsItsOwnIOBuffer();
|
||||
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length) = 0;
|
||||
virtual std::string CopyIn(IOBuffer* dst) = 0;
|
||||
};
|
||||
|
||||
// --------
|
||||
@@ -106,7 +109,7 @@ class FileInput : public Input {
|
||||
public:
|
||||
FileInput(FILE* f);
|
||||
|
||||
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
|
||||
virtual std::string CopyIn(IOBuffer* dst);
|
||||
|
||||
private:
|
||||
FILE* m_f;
|
||||
@@ -127,7 +130,7 @@ class MemoryInput : public Input {
|
||||
MemoryInput(const uint8_t* ptr, size_t len);
|
||||
|
||||
virtual IOBuffer* BringsItsOwnIOBuffer();
|
||||
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
|
||||
virtual std::string CopyIn(IOBuffer* dst);
|
||||
|
||||
private:
|
||||
IOBuffer m_io;
|
||||
|
||||
@@ -28,15 +28,13 @@ DecodeCborCallbacks::Done(DecodeCborResult& result,
|
||||
sync_io::Input& input,
|
||||
IOBuffer& buffer) {}
|
||||
|
||||
DecodeCborArgQuirks::DecodeCborArgQuirks(wuffs_base__slice_u32 repr0)
|
||||
: repr(repr0) {}
|
||||
|
||||
DecodeCborArgQuirks::DecodeCborArgQuirks(uint32_t* ptr0, size_t len0)
|
||||
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
|
||||
DecodeCborArgQuirks::DecodeCborArgQuirks(const QuirkKeyValuePair* ptr0,
|
||||
const size_t len0)
|
||||
: ptr(ptr0), len(len0) {}
|
||||
|
||||
DecodeCborArgQuirks //
|
||||
DecodeCborArgQuirks::DefaultValue() {
|
||||
return DecodeCborArgQuirks(wuffs_base__empty_slice_u32());
|
||||
return DecodeCborArgQuirks(nullptr, 0);
|
||||
}
|
||||
|
||||
DecodeCborResult //
|
||||
@@ -65,8 +63,8 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
|
||||
goto done;
|
||||
}
|
||||
for (size_t i = 0; i < quirks.repr.len; i++) {
|
||||
dec->set_quirk(quirks.repr.ptr[i], 1);
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
dec->set_quirk(quirks.ptr[i].first, quirks.ptr[i].second);
|
||||
}
|
||||
|
||||
// Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.
|
||||
@@ -111,14 +109,14 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is closed";
|
||||
goto done;
|
||||
}
|
||||
io_buf->compact_retaining(dec->history_retain_length());
|
||||
io_buf->compact();
|
||||
if (io_buf->meta.wi >= io_buf->data.len) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is full";
|
||||
goto done;
|
||||
}
|
||||
cursor_index = io_buf->meta.ri;
|
||||
io_error_message = input.CopyIn(io_buf, dec->history_retain_length());
|
||||
io_error_message = input.CopyIn(io_buf);
|
||||
} else {
|
||||
ret_error_message = tok_status.message();
|
||||
goto done;
|
||||
@@ -197,7 +195,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_CBOR__DECODER_DEPTH_MAX_INCL) {
|
||||
if (depth > (int32_t)WUFFS_CBOR__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
|
||||
@@ -75,13 +75,14 @@ class DecodeCborCallbacks {
|
||||
|
||||
// DecodeCborArgQuirks wraps an optional argument to DecodeCbor.
|
||||
struct DecodeCborArgQuirks {
|
||||
explicit DecodeCborArgQuirks(wuffs_base__slice_u32 repr0);
|
||||
explicit DecodeCborArgQuirks(uint32_t* ptr, size_t len);
|
||||
explicit DecodeCborArgQuirks(const QuirkKeyValuePair* ptr0,
|
||||
const size_t len0);
|
||||
|
||||
// DefaultValue returns an empty slice.
|
||||
static DecodeCborArgQuirks DefaultValue();
|
||||
|
||||
wuffs_base__slice_u32 repr;
|
||||
const QuirkKeyValuePair* ptr;
|
||||
const size_t len;
|
||||
};
|
||||
|
||||
// DecodeCbor calls callbacks based on the CBOR-formatted data in input.
|
||||
|
||||
@@ -91,6 +91,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
|
||||
case WUFFS_BASE__FOURCC__QOI:
|
||||
return wuffs_qoi__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
@@ -100,6 +105,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WEBP)
|
||||
case WUFFS_BASE__FOURCC__WEBP:
|
||||
return wuffs_webp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
}
|
||||
|
||||
return wuffs_base__image_decoder::unique_ptr(nullptr);
|
||||
@@ -192,15 +202,13 @@ const char DecodeImage_UnsupportedPixelConfiguration[] = //
|
||||
const char DecodeImage_UnsupportedPixelFormat[] = //
|
||||
"wuffs_aux::DecodeImage: unsupported pixel format";
|
||||
|
||||
DecodeImageArgQuirks::DecodeImageArgQuirks(wuffs_base__slice_u32 repr0)
|
||||
: repr(repr0) {}
|
||||
|
||||
DecodeImageArgQuirks::DecodeImageArgQuirks(uint32_t* ptr0, size_t len0)
|
||||
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
|
||||
DecodeImageArgQuirks::DecodeImageArgQuirks(const QuirkKeyValuePair* ptr0,
|
||||
const size_t len0)
|
||||
: ptr(ptr0), len(len0) {}
|
||||
|
||||
DecodeImageArgQuirks //
|
||||
DecodeImageArgQuirks::DefaultValue() {
|
||||
return DecodeImageArgQuirks(wuffs_base__empty_slice_u32());
|
||||
return DecodeImageArgQuirks(nullptr, 0);
|
||||
}
|
||||
|
||||
DecodeImageArgFlags::DecodeImageArgFlags(uint64_t repr0) : repr(repr0) {}
|
||||
@@ -298,7 +306,8 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
|
||||
DecodeImageCallbacks& callbacks,
|
||||
sync_io::Input& input,
|
||||
wuffs_base__io_buffer& io_buf,
|
||||
wuffs_base__slice_u32 quirks,
|
||||
const QuirkKeyValuePair* quirks_ptr,
|
||||
const size_t quirks_len,
|
||||
uint64_t flags,
|
||||
wuffs_base__pixel_blend pixel_blend,
|
||||
wuffs_base__color_u32_argb_premul background_color,
|
||||
@@ -340,7 +349,7 @@ redirect:
|
||||
fourcc = 0;
|
||||
break;
|
||||
}
|
||||
std::string error_message = input.CopyIn(&io_buf, 0);
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
@@ -381,8 +390,8 @@ redirect:
|
||||
}
|
||||
|
||||
// Apply quirks.
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
image_decoder->set_quirk(quirks.ptr[i], 1);
|
||||
for (size_t i = 0; i < quirks_len; i++) {
|
||||
image_decoder->set_quirk(quirks_ptr[i].first, quirks_ptr[i].second);
|
||||
}
|
||||
|
||||
// Apply flags.
|
||||
@@ -436,8 +445,7 @@ redirect:
|
||||
} else if (io_buf.meta.closed) {
|
||||
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
|
||||
} else {
|
||||
std::string error_message =
|
||||
input.CopyIn(&io_buf, image_decoder->history_retain_length());
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
@@ -519,8 +527,7 @@ redirect:
|
||||
} else if (io_buf.meta.closed) {
|
||||
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
|
||||
} else {
|
||||
std::string error_message =
|
||||
input.CopyIn(&io_buf, image_decoder->history_retain_length());
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
@@ -549,8 +556,7 @@ redirect:
|
||||
message = DecodeImage_UnexpectedEndOfFile;
|
||||
break;
|
||||
} else {
|
||||
std::string error_message =
|
||||
input.CopyIn(&io_buf, image_decoder->history_retain_length());
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
message = std::move(error_message);
|
||||
break;
|
||||
@@ -578,8 +584,7 @@ redirect:
|
||||
} else if (io_buf.meta.closed) {
|
||||
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
|
||||
} else {
|
||||
std::string error_message =
|
||||
input.CopyIn(&io_buf, image_decoder->history_retain_length());
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return DecodeImageResult(std::move(error_message));
|
||||
}
|
||||
@@ -613,10 +618,10 @@ DecodeImage(DecodeImageCallbacks& callbacks,
|
||||
}
|
||||
|
||||
wuffs_base__image_decoder::unique_ptr image_decoder(nullptr);
|
||||
DecodeImageResult result =
|
||||
DecodeImage0(image_decoder, callbacks, input, *io_buf, quirks.repr,
|
||||
flags.repr, pixel_blend.repr, background_color.repr,
|
||||
max_incl_dimension.repr, max_incl_metadata_length.repr);
|
||||
DecodeImageResult result = DecodeImage0(
|
||||
image_decoder, callbacks, input, *io_buf, quirks.ptr, quirks.len,
|
||||
flags.repr, pixel_blend.repr, background_color.repr,
|
||||
max_incl_dimension.repr, max_incl_metadata_length.repr);
|
||||
callbacks.Done(result, input, *io_buf, std::move(image_decoder));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -89,8 +89,10 @@ class DecodeImageCallbacks {
|
||||
// - WUFFS_BASE__FOURCC__NIE
|
||||
// - WUFFS_BASE__FOURCC__NPBM
|
||||
// - WUFFS_BASE__FOURCC__PNG
|
||||
// - WUFFS_BASE__FOURCC__QOI
|
||||
// - WUFFS_BASE__FOURCC__TGA
|
||||
// - WUFFS_BASE__FOURCC__WBMP
|
||||
// - WUFFS_BASE__FOURCC__WEBP
|
||||
virtual wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
@@ -199,13 +201,14 @@ extern const char DecodeImage_UnsupportedPixelFormat[];
|
||||
|
||||
// DecodeImageArgQuirks wraps an optional argument to DecodeImage.
|
||||
struct DecodeImageArgQuirks {
|
||||
explicit DecodeImageArgQuirks(wuffs_base__slice_u32 repr0);
|
||||
explicit DecodeImageArgQuirks(uint32_t* ptr, size_t len);
|
||||
explicit DecodeImageArgQuirks(const QuirkKeyValuePair* ptr0,
|
||||
const size_t len0);
|
||||
|
||||
// DefaultValue returns an empty slice.
|
||||
static DecodeImageArgQuirks DefaultValue();
|
||||
|
||||
wuffs_base__slice_u32 repr;
|
||||
const QuirkKeyValuePair* ptr;
|
||||
const size_t len;
|
||||
};
|
||||
|
||||
// DecodeImageArgFlags wraps an optional argument to DecodeImage.
|
||||
|
||||
@@ -33,15 +33,13 @@ const char DecodeJson_BadJsonPointer[] = //
|
||||
const char DecodeJson_NoMatch[] = //
|
||||
"wuffs_aux::DecodeJson: no match";
|
||||
|
||||
DecodeJsonArgQuirks::DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0)
|
||||
: repr(repr0) {}
|
||||
|
||||
DecodeJsonArgQuirks::DecodeJsonArgQuirks(uint32_t* ptr0, size_t len0)
|
||||
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
|
||||
DecodeJsonArgQuirks::DecodeJsonArgQuirks(const QuirkKeyValuePair* ptr0,
|
||||
const size_t len0)
|
||||
: ptr(ptr0), len(len0) {}
|
||||
|
||||
DecodeJsonArgQuirks //
|
||||
DecodeJsonArgQuirks::DefaultValue() {
|
||||
return DecodeJsonArgQuirks(wuffs_base__empty_slice_u32());
|
||||
return DecodeJsonArgQuirks(nullptr, 0);
|
||||
}
|
||||
|
||||
DecodeJsonArgJsonPointer::DecodeJsonArgJsonPointer(std::string repr0)
|
||||
@@ -54,58 +52,58 @@ DecodeJsonArgJsonPointer::DefaultValue() {
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
goto done; \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact_retaining(dec->history_retain_length()); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf, dec->history_retain_length()); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
tok_status = \
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) || \
|
||||
(tok_buf.meta.wi > tok_buf.data.len) || \
|
||||
(io_buf->meta.ri > io_buf->meta.wi) || \
|
||||
(io_buf->meta.wi > io_buf->data.len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad buffer indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
goto done; \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact(); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
tok_status = \
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) || \
|
||||
(tok_buf.meta.wi > tok_buf.data.len) || \
|
||||
(io_buf->meta.ri > io_buf->meta.wi) || \
|
||||
(io_buf->meta.wi > io_buf->data.len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad buffer indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
cursor_index += static_cast<size_t>(token_len)
|
||||
|
||||
// --------
|
||||
@@ -386,11 +384,11 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
bool allow_tilde_n_tilde_r_tilde_t = false;
|
||||
for (size_t i = 0; i < quirks.repr.len; i++) {
|
||||
dec->set_quirk(quirks.repr.ptr[i], 1);
|
||||
if (quirks.repr.ptr[i] ==
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
dec->set_quirk(quirks.ptr[i].first, quirks.ptr[i].second);
|
||||
if (quirks.ptr[i].first ==
|
||||
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {
|
||||
allow_tilde_n_tilde_r_tilde_t = true;
|
||||
allow_tilde_n_tilde_r_tilde_t = (quirks.ptr[i].second != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,7 +444,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_JSON__DECODER_DEPTH_MAX_INCL) {
|
||||
if (depth > (int32_t)WUFFS_JSON__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad depth";
|
||||
goto done;
|
||||
|
||||
@@ -76,13 +76,14 @@ extern const char DecodeJson_NoMatch[];
|
||||
|
||||
// DecodeJsonArgQuirks wraps an optional argument to DecodeJson.
|
||||
struct DecodeJsonArgQuirks {
|
||||
explicit DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0);
|
||||
explicit DecodeJsonArgQuirks(uint32_t* ptr, size_t len);
|
||||
explicit DecodeJsonArgQuirks(const QuirkKeyValuePair* ptr0,
|
||||
const size_t len0);
|
||||
|
||||
// DefaultValue returns an empty slice.
|
||||
static DecodeJsonArgQuirks DefaultValue();
|
||||
|
||||
wuffs_base__slice_u32 repr;
|
||||
const QuirkKeyValuePair* ptr;
|
||||
const size_t len;
|
||||
};
|
||||
|
||||
// DecodeJsonArgJsonPointer wraps an optional argument to DecodeJson.
|
||||
|
||||
@@ -63,16 +63,16 @@ extern "C" {
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \
|
||||
defined(WUFFS_CONFIG__MODULE__BASE__CORE)
|
||||
|
||||
const uint8_t wuffs_base__low_bits_mask__u8[8] = {
|
||||
const uint8_t wuffs_private_impl__low_bits_mask__u8[8] = {
|
||||
0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F,
|
||||
};
|
||||
|
||||
const uint16_t wuffs_base__low_bits_mask__u16[16] = {
|
||||
const uint16_t wuffs_private_impl__low_bits_mask__u16[16] = {
|
||||
0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F,
|
||||
0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF,
|
||||
};
|
||||
|
||||
const uint32_t wuffs_base__low_bits_mask__u32[32] = {
|
||||
const uint32_t wuffs_private_impl__low_bits_mask__u32[32] = {
|
||||
0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F,
|
||||
0x0000003F, 0x0000007F, 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
|
||||
0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF, 0x0001FFFF,
|
||||
@@ -81,7 +81,7 @@ const uint32_t wuffs_base__low_bits_mask__u32[32] = {
|
||||
0x3FFFFFFF, 0x7FFFFFFF,
|
||||
};
|
||||
|
||||
const uint64_t wuffs_base__low_bits_mask__u64[64] = {
|
||||
const uint64_t wuffs_private_impl__low_bits_mask__u64[64] = {
|
||||
0x0000000000000000, 0x0000000000000001, 0x0000000000000003,
|
||||
0x0000000000000007, 0x000000000000000F, 0x000000000000001F,
|
||||
0x000000000000003F, 0x000000000000007F, 0x00000000000000FF,
|
||||
@@ -106,7 +106,7 @@ const uint64_t wuffs_base__low_bits_mask__u64[64] = {
|
||||
0x7FFFFFFFFFFFFFFF,
|
||||
};
|
||||
|
||||
const uint32_t wuffs_base__pixel_format__bits_per_channel[16] = {
|
||||
const uint32_t wuffs_private_impl__pixel_format__bits_per_channel[16] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x0A, 0x0C, 0x10, 0x18, 0x20, 0x30, 0x40,
|
||||
};
|
||||
|
||||
@@ -140,27 +140,27 @@ wuffs_base__ieee_754_bit_representation__from_f64_to_u32_truncate(double f) {
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE 2047
|
||||
#define WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION 800
|
||||
#define WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE 2047
|
||||
#define WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION 800
|
||||
|
||||
// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL is the largest N
|
||||
// such that ((10 << N) < (1 << 64)).
|
||||
#define WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL 60
|
||||
// WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL is the largest N such that
|
||||
// ((10 << N) < (1 << 64)).
|
||||
#define WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL 60
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec (abbreviated as HPD) is a
|
||||
// fixed precision floating point decimal number, augmented with ±infinity
|
||||
// values, but it cannot represent NaN (Not a Number).
|
||||
// wuffs_private_impl__high_prec_dec (abbreviated as HPD) is a fixed precision
|
||||
// floating point decimal number, augmented with ±infinity values, but it
|
||||
// cannot represent NaN (Not a Number).
|
||||
//
|
||||
// "High precision" means that the mantissa holds 800 decimal digits. 800 is
|
||||
// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION.
|
||||
// WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION.
|
||||
//
|
||||
// An HPD isn't for general purpose arithmetic, only for conversions to and
|
||||
// from IEEE 754 double-precision floating point, where the largest and
|
||||
// smallest positive, finite values are approximately 1.8e+308 and 4.9e-324.
|
||||
// HPD exponents above +2047 mean infinity, below -2047 mean zero. The ±2047
|
||||
// bounds are further away from zero than ±(324 + 800), where 800 and 2047 is
|
||||
// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION and
|
||||
// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE.
|
||||
// WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION and
|
||||
// WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE.
|
||||
//
|
||||
// digits[.. num_digits] are the number's digits in big-endian order. The
|
||||
// uint8_t values are in the range [0 ..= 9], not ['0' ..= '9'], where e.g. '7'
|
||||
@@ -186,43 +186,40 @@ wuffs_base__ieee_754_bit_representation__from_f64_to_u32_truncate(double f) {
|
||||
// negative is a sign bit. An HPD can distinguish positive and negative zero.
|
||||
//
|
||||
// truncated is whether there are more than
|
||||
// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION digits, and at
|
||||
// least one of those extra digits are non-zero. The existence of long-tail
|
||||
// digits can affect rounding.
|
||||
// WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION digits, and at least one of those
|
||||
// extra digits are non-zero. The existence of long-tail digits can affect
|
||||
// rounding.
|
||||
//
|
||||
// The "all fields are zero" value is valid, and represents the number +0.
|
||||
typedef struct wuffs_base__private_implementation__high_prec_dec__struct {
|
||||
typedef struct wuffs_private_impl__high_prec_dec__struct {
|
||||
uint32_t num_digits;
|
||||
int32_t decimal_point;
|
||||
bool negative;
|
||||
bool truncated;
|
||||
uint8_t digits[WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION];
|
||||
} wuffs_base__private_implementation__high_prec_dec;
|
||||
uint8_t digits[WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION];
|
||||
} wuffs_private_impl__high_prec_dec;
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec__trim trims trailing
|
||||
// zeroes from the h->digits[.. h->num_digits] slice. They have no benefit,
|
||||
// since we explicitly track h->decimal_point.
|
||||
// wuffs_private_impl__high_prec_dec__trim trims trailing zeroes from the
|
||||
// h->digits[.. h->num_digits] slice. They have no benefit, since we explicitly
|
||||
// track h->decimal_point.
|
||||
//
|
||||
// Preconditions:
|
||||
// - h is non-NULL.
|
||||
static inline void //
|
||||
wuffs_base__private_implementation__high_prec_dec__trim(
|
||||
wuffs_base__private_implementation__high_prec_dec* h) {
|
||||
wuffs_private_impl__high_prec_dec__trim(wuffs_private_impl__high_prec_dec* h) {
|
||||
while ((h->num_digits > 0) && (h->digits[h->num_digits - 1] == 0)) {
|
||||
h->num_digits--;
|
||||
}
|
||||
}
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec__assign sets h to
|
||||
// represent the number x.
|
||||
// wuffs_private_impl__high_prec_dec__assign sets h to represent the number x.
|
||||
//
|
||||
// Preconditions:
|
||||
// - h is non-NULL.
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__assign(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
uint64_t x,
|
||||
bool negative) {
|
||||
wuffs_private_impl__high_prec_dec__assign(wuffs_private_impl__high_prec_dec* h,
|
||||
uint64_t x,
|
||||
bool negative) {
|
||||
uint32_t n = 0;
|
||||
|
||||
// Set h->digits.
|
||||
@@ -252,14 +249,13 @@ wuffs_base__private_implementation__high_prec_dec__assign(
|
||||
h->decimal_point = (int32_t)n;
|
||||
h->negative = negative;
|
||||
h->truncated = false;
|
||||
wuffs_base__private_implementation__high_prec_dec__trim(h);
|
||||
wuffs_private_impl__high_prec_dec__trim(h);
|
||||
}
|
||||
|
||||
static wuffs_base__status //
|
||||
wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_base__slice_u8 s,
|
||||
uint32_t options) {
|
||||
wuffs_private_impl__high_prec_dec__parse(wuffs_private_impl__high_prec_dec* h,
|
||||
wuffs_base__slice_u8 s,
|
||||
uint32_t options) {
|
||||
if (!h) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
@@ -348,7 +344,7 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
if (p >= q) {
|
||||
goto after_all;
|
||||
} else if (('0' <= *p) && (*p <= '9')) {
|
||||
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
|
||||
if (nd < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) {
|
||||
h->digits[nd++] = (uint8_t)(*p - '0');
|
||||
dp = (int32_t)nd;
|
||||
} else if ('0' != *p) {
|
||||
@@ -390,12 +386,11 @@ after_sep:
|
||||
if (nd == 0) {
|
||||
// Track leading zeroes implicitly.
|
||||
dp--;
|
||||
} else if (nd <
|
||||
WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
|
||||
} else if (nd < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) {
|
||||
h->digits[nd++] = (uint8_t)(*p - '0');
|
||||
}
|
||||
} else if (('0' < *p) && (*p <= '9')) {
|
||||
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
|
||||
if (nd < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) {
|
||||
h->digits[nd++] = (uint8_t)(*p - '0');
|
||||
} else {
|
||||
// Long-tail non-zeroes set the truncated bit.
|
||||
@@ -431,9 +426,8 @@ after_exp:
|
||||
}
|
||||
|
||||
int32_t exp = 0;
|
||||
const int32_t exp_large =
|
||||
WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE +
|
||||
WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION;
|
||||
const int32_t exp_large = WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE +
|
||||
WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION;
|
||||
bool saw_exp_digits = false;
|
||||
for (; p < q; p++) {
|
||||
if ((*p == '_') &&
|
||||
@@ -464,44 +458,39 @@ after_all:
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
h->decimal_point = 0;
|
||||
} else if (dp <
|
||||
-WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {
|
||||
h->decimal_point =
|
||||
-WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE - 1;
|
||||
} else if (dp >
|
||||
+WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {
|
||||
h->decimal_point =
|
||||
+WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE + 1;
|
||||
} else if (dp < -WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) {
|
||||
h->decimal_point = -WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE - 1;
|
||||
} else if (dp > +WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) {
|
||||
h->decimal_point = +WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE + 1;
|
||||
} else {
|
||||
h->decimal_point = dp;
|
||||
}
|
||||
wuffs_base__private_implementation__high_prec_dec__trim(h);
|
||||
wuffs_private_impl__high_prec_dec__trim(h);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits
|
||||
// returns the number of additional decimal digits when left-shifting by shift.
|
||||
// wuffs_private_impl__high_prec_dec__lshift_num_new_digits returns the number
|
||||
// of additional decimal digits when left-shifting by shift.
|
||||
//
|
||||
// See below for preconditions.
|
||||
static uint32_t //
|
||||
wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec__lshift_num_new_digits(
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
uint32_t shift) {
|
||||
// Masking with 0x3F should be unnecessary (assuming the preconditions) but
|
||||
// it's cheap and ensures that we don't overflow the
|
||||
// wuffs_base__private_implementation__hpd_left_shift array.
|
||||
// wuffs_private_impl__hpd_left_shift array.
|
||||
shift &= 63;
|
||||
|
||||
uint32_t x_a = wuffs_base__private_implementation__hpd_left_shift[shift];
|
||||
uint32_t x_b = wuffs_base__private_implementation__hpd_left_shift[shift + 1];
|
||||
uint32_t x_a = wuffs_private_impl__hpd_left_shift[shift];
|
||||
uint32_t x_b = wuffs_private_impl__hpd_left_shift[shift + 1];
|
||||
uint32_t num_new_digits = x_a >> 11;
|
||||
uint32_t pow5_a = 0x7FF & x_a;
|
||||
uint32_t pow5_b = 0x7FF & x_b;
|
||||
|
||||
const uint8_t* pow5 =
|
||||
&wuffs_base__private_implementation__powers_of_5[pow5_a];
|
||||
const uint8_t* pow5 = &wuffs_private_impl__powers_of_5[pow5_a];
|
||||
uint32_t i = 0;
|
||||
uint32_t n = pow5_b - pow5_a;
|
||||
for (; i < n; i++) {
|
||||
@@ -520,9 +509,9 @@ wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec__rounded_integer returns
|
||||
// the integral (non-fractional) part of h, provided that it is 18 or fewer
|
||||
// decimal digits. For 19 or more digits, it returns UINT64_MAX. Note that:
|
||||
// wuffs_private_impl__high_prec_dec__rounded_integer returns the integral
|
||||
// (non-fractional) part of h, provided that it is 18 or fewer decimal digits.
|
||||
// For 19 or more digits, it returns UINT64_MAX. Note that:
|
||||
// - (1 << 53) is 9007199254740992, which has 16 decimal digits.
|
||||
// - (1 << 56) is 72057594037927936, which has 17 decimal digits.
|
||||
// - (1 << 59) is 576460752303423488, which has 18 decimal digits.
|
||||
@@ -535,8 +524,8 @@ wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(
|
||||
//
|
||||
// See below for preconditions.
|
||||
static uint64_t //
|
||||
wuffs_base__private_implementation__high_prec_dec__rounded_integer(
|
||||
wuffs_base__private_implementation__high_prec_dec* h) {
|
||||
wuffs_private_impl__high_prec_dec__rounded_integer(
|
||||
wuffs_private_impl__high_prec_dec* h) {
|
||||
if ((h->num_digits == 0) || (h->decimal_point < 0)) {
|
||||
return 0;
|
||||
} else if (h->decimal_point > 18) {
|
||||
@@ -567,8 +556,8 @@ wuffs_base__private_implementation__high_prec_dec__rounded_integer(
|
||||
return n;
|
||||
}
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec__small_xshift shifts h's
|
||||
// number (where 'x' is 'l' or 'r' for left or right) by a small shift value.
|
||||
// wuffs_private_impl__high_prec_dec__small_xshift shifts h's number (where 'x'
|
||||
// is 'l' or 'r' for left or right) by a small shift value.
|
||||
//
|
||||
// Preconditions:
|
||||
// - h is non-NULL.
|
||||
@@ -576,31 +565,29 @@ wuffs_base__private_implementation__high_prec_dec__rounded_integer(
|
||||
// - shift is non-zero.
|
||||
// - shift is "a small shift".
|
||||
//
|
||||
// "Not extreme" means within
|
||||
// ±WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE.
|
||||
// "Not extreme" means within ±WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE.
|
||||
//
|
||||
// "A small shift" means not more than
|
||||
// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
|
||||
// WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL.
|
||||
//
|
||||
// wuffs_base__private_implementation__high_prec_dec__rounded_integer and
|
||||
// wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits
|
||||
// have the same preconditions.
|
||||
// wuffs_private_impl__high_prec_dec__rounded_integer and
|
||||
// wuffs_private_impl__high_prec_dec__lshift_num_new_digits have the same
|
||||
// preconditions.
|
||||
//
|
||||
// wuffs_base__private_implementation__high_prec_dec__lshift keeps the first
|
||||
// two preconditions but not the last two. Its shift argument is signed and
|
||||
// does not need to be "small": zero is a no-op, positive means left shift and
|
||||
// negative means right shift.
|
||||
// wuffs_private_impl__high_prec_dec__lshift keeps the first two preconditions
|
||||
// but not the last two. Its shift argument is signed and does not need to be
|
||||
// "small": zero is a no-op, positive means left shift and negative means right
|
||||
// shift.
|
||||
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec__small_lshift(
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
uint32_t shift) {
|
||||
if (h->num_digits == 0) {
|
||||
return;
|
||||
}
|
||||
uint32_t num_new_digits =
|
||||
wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(
|
||||
h, shift);
|
||||
wuffs_private_impl__high_prec_dec__lshift_num_new_digits(h, shift);
|
||||
uint32_t rx = h->num_digits - 1; // Read index.
|
||||
uint32_t wx = h->num_digits - 1 + num_new_digits; // Write index.
|
||||
uint64_t n = 0;
|
||||
@@ -610,7 +597,7 @@ wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
n += ((uint64_t)(h->digits[rx])) << shift;
|
||||
uint64_t quo = n / 10;
|
||||
uint64_t rem = n - (10 * quo);
|
||||
if (wx < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
|
||||
if (wx < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) {
|
||||
h->digits[wx] = (uint8_t)rem;
|
||||
} else if (rem > 0) {
|
||||
h->truncated = true;
|
||||
@@ -624,7 +611,7 @@ wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
while (n > 0) {
|
||||
uint64_t quo = n / 10;
|
||||
uint64_t rem = n - (10 * quo);
|
||||
if (wx < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
|
||||
if (wx < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) {
|
||||
h->digits[wx] = (uint8_t)rem;
|
||||
} else if (rem > 0) {
|
||||
h->truncated = true;
|
||||
@@ -635,17 +622,16 @@ wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
|
||||
// Finish.
|
||||
h->num_digits += num_new_digits;
|
||||
if (h->num_digits >
|
||||
WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
|
||||
h->num_digits = WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION;
|
||||
if (h->num_digits > WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) {
|
||||
h->num_digits = WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION;
|
||||
}
|
||||
h->decimal_point += (int32_t)num_new_digits;
|
||||
wuffs_base__private_implementation__high_prec_dec__trim(h);
|
||||
wuffs_private_impl__high_prec_dec__trim(h);
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__small_rshift(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec__small_rshift(
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
uint32_t shift) {
|
||||
uint32_t rx = 0; // Read index.
|
||||
uint32_t wx = 0; // Write index.
|
||||
@@ -669,8 +655,7 @@ wuffs_base__private_implementation__high_prec_dec__small_rshift(
|
||||
}
|
||||
}
|
||||
h->decimal_point -= ((int32_t)(rx - 1));
|
||||
if (h->decimal_point <
|
||||
-WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {
|
||||
if (h->decimal_point < -WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) {
|
||||
// After the shift, h's number is effectively zero.
|
||||
h->num_digits = 0;
|
||||
h->decimal_point = 0;
|
||||
@@ -690,7 +675,7 @@ wuffs_base__private_implementation__high_prec_dec__small_rshift(
|
||||
while (n > 0) {
|
||||
uint8_t new_digit = ((uint8_t)(n >> shift));
|
||||
n = 10 * (n & mask);
|
||||
if (wx < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
|
||||
if (wx < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) {
|
||||
h->digits[wx++] = new_digit;
|
||||
} else if (new_digit > 0) {
|
||||
h->truncated = true;
|
||||
@@ -699,62 +684,58 @@ wuffs_base__private_implementation__high_prec_dec__small_rshift(
|
||||
|
||||
// Finish.
|
||||
h->num_digits = wx;
|
||||
wuffs_base__private_implementation__high_prec_dec__trim(h);
|
||||
wuffs_private_impl__high_prec_dec__trim(h);
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__lshift(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
int32_t shift) {
|
||||
wuffs_private_impl__high_prec_dec__lshift(wuffs_private_impl__high_prec_dec* h,
|
||||
int32_t shift) {
|
||||
if (shift > 0) {
|
||||
while (shift > +WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL) {
|
||||
wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
h, WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL);
|
||||
shift -= WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
|
||||
while (shift > +WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL) {
|
||||
wuffs_private_impl__high_prec_dec__small_lshift(
|
||||
h, WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL);
|
||||
shift -= WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL;
|
||||
}
|
||||
wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
h, ((uint32_t)(+shift)));
|
||||
wuffs_private_impl__high_prec_dec__small_lshift(h, ((uint32_t)(+shift)));
|
||||
} else if (shift < 0) {
|
||||
while (shift < -WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL) {
|
||||
wuffs_base__private_implementation__high_prec_dec__small_rshift(
|
||||
h, WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL);
|
||||
shift += WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
|
||||
while (shift < -WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL) {
|
||||
wuffs_private_impl__high_prec_dec__small_rshift(
|
||||
h, WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL);
|
||||
shift += WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL;
|
||||
}
|
||||
wuffs_base__private_implementation__high_prec_dec__small_rshift(
|
||||
h, ((uint32_t)(-shift)));
|
||||
wuffs_private_impl__high_prec_dec__small_rshift(h, ((uint32_t)(-shift)));
|
||||
}
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec__round_etc rounds h's
|
||||
// number. For those functions that take an n argument, rounding produces at
|
||||
// most n digits (which is not necessarily at most n decimal places). Negative
|
||||
// n values are ignored, as well as any n greater than or equal to h's number
|
||||
// of digits. The etc__round_just_enough function implicitly chooses an n to
|
||||
// implement WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION.
|
||||
// wuffs_private_impl__high_prec_dec__round_etc rounds h's number. For those
|
||||
// functions that take an n argument, rounding produces at most n digits (which
|
||||
// is not necessarily at most n decimal places). Negative n values are ignored,
|
||||
// as well as any n greater than or equal to h's number of digits. The
|
||||
// etc__round_just_enough function implicitly chooses an n to implement
|
||||
// WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION.
|
||||
//
|
||||
// Preconditions:
|
||||
// - h is non-NULL.
|
||||
// - h->decimal_point is "not extreme".
|
||||
//
|
||||
// "Not extreme" means within
|
||||
// ±WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE.
|
||||
// "Not extreme" means within ±WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE.
|
||||
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__round_down(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec__round_down(
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
int32_t n) {
|
||||
if ((n < 0) || (h->num_digits <= (uint32_t)n)) {
|
||||
return;
|
||||
}
|
||||
h->num_digits = (uint32_t)(n);
|
||||
wuffs_base__private_implementation__high_prec_dec__trim(h);
|
||||
wuffs_private_impl__high_prec_dec__trim(h);
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__round_up(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec__round_up(
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
int32_t n) {
|
||||
if ((n < 0) || (h->num_digits <= (uint32_t)n)) {
|
||||
return;
|
||||
@@ -775,8 +756,8 @@ wuffs_base__private_implementation__high_prec_dec__round_up(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__round_nearest(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec__round_nearest(
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
int32_t n) {
|
||||
if ((n < 0) || (h->num_digits <= (uint32_t)n)) {
|
||||
return;
|
||||
@@ -788,15 +769,15 @@ wuffs_base__private_implementation__high_prec_dec__round_nearest(
|
||||
}
|
||||
|
||||
if (up) {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_up(h, n);
|
||||
wuffs_private_impl__high_prec_dec__round_up(h, n);
|
||||
} else {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_down(h, n);
|
||||
wuffs_private_impl__high_prec_dec__round_down(h, n);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec__round_just_enough(
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
int32_t exp2,
|
||||
uint64_t mantissa) {
|
||||
// The magic numbers 52 and 53 in this function are because IEEE 754 double
|
||||
@@ -834,11 +815,10 @@ wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
l_exp2 = exp2 - 1;
|
||||
l_mantissa = (2 * mantissa) - 1;
|
||||
}
|
||||
wuffs_base__private_implementation__high_prec_dec lower;
|
||||
wuffs_base__private_implementation__high_prec_dec__assign(
|
||||
&lower, (2 * l_mantissa) + 1, false);
|
||||
wuffs_base__private_implementation__high_prec_dec__lshift(&lower,
|
||||
l_exp2 - 53);
|
||||
wuffs_private_impl__high_prec_dec lower;
|
||||
wuffs_private_impl__high_prec_dec__assign(&lower, (2 * l_mantissa) + 1,
|
||||
false);
|
||||
wuffs_private_impl__high_prec_dec__lshift(&lower, l_exp2 - 53);
|
||||
|
||||
// Next, the upper bound. Our number f is:
|
||||
// ((mantissa + 0) * (2 ** (exp2 - 52)))
|
||||
@@ -848,10 +828,9 @@ wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
//
|
||||
// The upper bound is halfway between them (noting that 52 became 53):
|
||||
// (((2 * mantissa) + 1) * (2 ** (exp2 - 53)))
|
||||
wuffs_base__private_implementation__high_prec_dec upper;
|
||||
wuffs_base__private_implementation__high_prec_dec__assign(
|
||||
&upper, (2 * mantissa) + 1, false);
|
||||
wuffs_base__private_implementation__high_prec_dec__lshift(&upper, exp2 - 53);
|
||||
wuffs_private_impl__high_prec_dec upper;
|
||||
wuffs_private_impl__high_prec_dec__assign(&upper, (2 * mantissa) + 1, false);
|
||||
wuffs_private_impl__high_prec_dec__lshift(&upper, exp2 - 53);
|
||||
|
||||
// The lower and upper bounds are possible outputs only if the original
|
||||
// mantissa is even, so that IEEE round-to-even would round to the original
|
||||
@@ -934,17 +913,15 @@ wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
// way, do it. If we can't round, continue the loop.
|
||||
if (can_round_down) {
|
||||
if (can_round_up) {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_nearest(
|
||||
h, hi + 1);
|
||||
wuffs_private_impl__high_prec_dec__round_nearest(h, hi + 1);
|
||||
return;
|
||||
} else {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_down(h,
|
||||
hi + 1);
|
||||
wuffs_private_impl__high_prec_dec__round_down(h, hi + 1);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (can_round_up) {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_up(h, hi + 1);
|
||||
wuffs_private_impl__high_prec_dec__round_up(h, hi + 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -953,9 +930,9 @@ wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__private_implementation__parse_number_f64_eisel_lemire produces
|
||||
// the IEEE 754 double-precision value for an exact mantissa and base-10
|
||||
// exponent. For example:
|
||||
// wuffs_private_impl__parse_number_f64_eisel_lemire produces the IEEE 754
|
||||
// double-precision value for an exact mantissa and base-10 exponent. For
|
||||
// example:
|
||||
// - when parsing "12345.678e+02", man is 12345678 and exp10 is -1.
|
||||
// - when parsing "-12", man is 12 and exp10 is 0. Processing the leading
|
||||
// minus sign is the responsibility of the caller, not this function.
|
||||
@@ -974,7 +951,7 @@ wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
// Preconditions:
|
||||
// - man is non-zero.
|
||||
// - exp10 is in the range [-307 ..= 288], the same range of the
|
||||
// wuffs_base__private_implementation__powers_of_10 array.
|
||||
// wuffs_private_impl__powers_of_10 array.
|
||||
//
|
||||
// The exp10 range (and the fact that man is in the range [1 ..= UINT64_MAX],
|
||||
// approximately [1 ..= 1.85e+19]) means that (man * (10 ** exp10)) is in the
|
||||
@@ -982,14 +959,11 @@ wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
// (neither subnormal nor non-finite) f64 values: DBL_MIN and DBL_MAX are
|
||||
// approximately 2.23e–308 and 1.80e+308.
|
||||
static int64_t //
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
uint64_t man,
|
||||
int32_t exp10) {
|
||||
wuffs_private_impl__parse_number_f64_eisel_lemire(uint64_t man, int32_t exp10) {
|
||||
// Look up the (possibly truncated) base-2 representation of (10 ** exp10).
|
||||
// The look-up table was constructed so that it is already normalized: the
|
||||
// table entry's mantissa's MSB (most significant bit) is on.
|
||||
const uint64_t* po10 =
|
||||
&wuffs_base__private_implementation__powers_of_10[exp10 + 307][0];
|
||||
const uint64_t* po10 = &wuffs_private_impl__powers_of_10[exp10 + 307][0];
|
||||
|
||||
// Normalize the man argument. The (man != 0) precondition means that a
|
||||
// non-zero bit exists.
|
||||
@@ -1147,9 +1121,8 @@ wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
// --------
|
||||
|
||||
static wuffs_base__result_f64 //
|
||||
wuffs_base__private_implementation__parse_number_f64_special(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint32_t options) {
|
||||
wuffs_private_impl__parse_number_f64_special(wuffs_base__slice_u8 s,
|
||||
uint32_t options) {
|
||||
do {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_FXX__REJECT_INF_AND_NAN) {
|
||||
goto fail;
|
||||
@@ -1253,17 +1226,16 @@ fail:
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //
|
||||
wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
uint32_t options) {
|
||||
wuffs_private_impl__high_prec_dec__to_f64(wuffs_private_impl__high_prec_dec* h,
|
||||
uint32_t options) {
|
||||
do {
|
||||
// powers converts decimal powers of 10 to binary powers of 2. For example,
|
||||
// (10000 >> 13) is 1. It stops before the elements exceed 60, also known
|
||||
// as WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
|
||||
// as WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL.
|
||||
//
|
||||
// This rounds down (1<<13 is a lower bound for 1e4). Adding 1 to the array
|
||||
// element value rounds up (1<<14 is an upper bound for 1e4) while staying
|
||||
// at or below WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
|
||||
// at or below WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL.
|
||||
//
|
||||
// When starting in the range [1e+1 .. 1e+2] (i.e. h->decimal_point == +2),
|
||||
// powers[2] == 6 and so:
|
||||
@@ -1318,14 +1290,12 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
}
|
||||
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
|
||||
int64_t r0 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man + 0, exp10);
|
||||
wuffs_private_impl__parse_number_f64_eisel_lemire(man + 0, exp10);
|
||||
if (r0 < 0) {
|
||||
break;
|
||||
} else if (h->num_digits > 19) {
|
||||
int64_t r1 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man + 1, exp10);
|
||||
wuffs_private_impl__parse_number_f64_eisel_lemire(man + 1, exp10);
|
||||
if (r1 != r0) {
|
||||
break;
|
||||
}
|
||||
@@ -1349,14 +1319,12 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
int32_t exp2 = 0;
|
||||
while (h->decimal_point > 1) {
|
||||
uint32_t n = (uint32_t)(+h->decimal_point);
|
||||
uint32_t shift =
|
||||
(n < num_powers)
|
||||
? powers[n]
|
||||
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
|
||||
uint32_t shift = (n < num_powers)
|
||||
? powers[n]
|
||||
: WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL;
|
||||
|
||||
wuffs_base__private_implementation__high_prec_dec__small_rshift(h, shift);
|
||||
if (h->decimal_point <
|
||||
-WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {
|
||||
wuffs_private_impl__high_prec_dec__small_rshift(h, shift);
|
||||
if (h->decimal_point < -WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) {
|
||||
goto zero;
|
||||
}
|
||||
exp2 += (int32_t)shift;
|
||||
@@ -1368,12 +1336,11 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
shift = (n < num_powers)
|
||||
// The +1 is per "when targeting h->decimal_point being +0 or
|
||||
// +1... when left shifting" in the powers comment above.
|
||||
? (powers[n] + 1)
|
||||
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
|
||||
? (powers[n] + 1u)
|
||||
: WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL;
|
||||
|
||||
wuffs_base__private_implementation__high_prec_dec__small_lshift(h, shift);
|
||||
if (h->decimal_point >
|
||||
+WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {
|
||||
wuffs_private_impl__high_prec_dec__small_lshift(h, shift);
|
||||
if (h->decimal_point > +WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) {
|
||||
goto infinity;
|
||||
}
|
||||
exp2 -= (int32_t)shift;
|
||||
@@ -1414,10 +1381,10 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
// The minimum normal exponent is (f64_bias + 1).
|
||||
while ((f64_bias + 1) > exp2) {
|
||||
uint32_t n = (uint32_t)((f64_bias + 1) - exp2);
|
||||
if (n > WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL) {
|
||||
n = WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
|
||||
if (n > WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL) {
|
||||
n = WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL;
|
||||
}
|
||||
wuffs_base__private_implementation__high_prec_dec__small_rshift(h, n);
|
||||
wuffs_private_impl__high_prec_dec__small_rshift(h, n);
|
||||
exp2 += (int32_t)n;
|
||||
}
|
||||
|
||||
@@ -1427,10 +1394,8 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
}
|
||||
|
||||
// Extract 53 bits for the mantissa (in base-2).
|
||||
wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
h, final_lshift);
|
||||
uint64_t man2 =
|
||||
wuffs_base__private_implementation__high_prec_dec__rounded_integer(h);
|
||||
wuffs_private_impl__high_prec_dec__small_lshift(h, final_lshift);
|
||||
uint64_t man2 = wuffs_private_impl__high_prec_dec__rounded_integer(h);
|
||||
|
||||
// Rounding might have added one bit. If so, shift and re-check overflow.
|
||||
if ((man2 >> 53) != 0) {
|
||||
@@ -1488,7 +1453,7 @@ infinity:
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__private_implementation__is_decimal_digit(uint8_t c) {
|
||||
wuffs_private_impl__is_decimal_digit(uint8_t c) {
|
||||
return ('0' <= c) && (c <= '9');
|
||||
}
|
||||
|
||||
@@ -1549,13 +1514,13 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
if (*p == '0') {
|
||||
man = 0;
|
||||
p++;
|
||||
if (wuffs_base__private_implementation__is_decimal_digit(*p)) {
|
||||
if (wuffs_private_impl__is_decimal_digit(*p)) {
|
||||
goto fallback;
|
||||
}
|
||||
} else if (wuffs_base__private_implementation__is_decimal_digit(*p)) {
|
||||
} else if (wuffs_private_impl__is_decimal_digit(*p)) {
|
||||
man = ((uint8_t)(*p - '0'));
|
||||
p++;
|
||||
for (; wuffs_base__private_implementation__is_decimal_digit(*p); p++) {
|
||||
for (; wuffs_private_impl__is_decimal_digit(*p); p++) {
|
||||
man = (10 * man) + ((uint8_t)(*p - '0'));
|
||||
}
|
||||
} else {
|
||||
@@ -1571,12 +1536,12 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
: '.')) {
|
||||
p++;
|
||||
const uint8_t* first_after_separator_ptr = p;
|
||||
if (!wuffs_base__private_implementation__is_decimal_digit(*p)) {
|
||||
if (!wuffs_private_impl__is_decimal_digit(*p)) {
|
||||
goto fallback;
|
||||
}
|
||||
man = (10 * man) + ((uint8_t)(*p - '0'));
|
||||
p++;
|
||||
for (; wuffs_base__private_implementation__is_decimal_digit(*p); p++) {
|
||||
for (; wuffs_private_impl__is_decimal_digit(*p); p++) {
|
||||
man = (10 * man) + ((uint8_t)(*p - '0'));
|
||||
}
|
||||
exp10 = ((int32_t)(first_after_separator_ptr - p));
|
||||
@@ -1601,7 +1566,7 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
} else if (*p == '+') {
|
||||
p++;
|
||||
}
|
||||
if (!wuffs_base__private_implementation__is_decimal_digit(*p)) {
|
||||
if (!wuffs_private_impl__is_decimal_digit(*p)) {
|
||||
goto fallback;
|
||||
}
|
||||
int32_t exp_num = ((uint8_t)(*p - '0'));
|
||||
@@ -1609,15 +1574,15 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
// The rest of the exp_num walking has a peculiar control flow but, once
|
||||
// again, the "script/process-json-numbers.c with -p" benchmark is
|
||||
// sensitive to alternative formulations.
|
||||
if (wuffs_base__private_implementation__is_decimal_digit(*p)) {
|
||||
if (wuffs_private_impl__is_decimal_digit(*p)) {
|
||||
exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));
|
||||
p++;
|
||||
}
|
||||
if (wuffs_base__private_implementation__is_decimal_digit(*p)) {
|
||||
if (wuffs_private_impl__is_decimal_digit(*p)) {
|
||||
exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));
|
||||
p++;
|
||||
}
|
||||
while (wuffs_base__private_implementation__is_decimal_digit(*p)) {
|
||||
while (wuffs_private_impl__is_decimal_digit(*p)) {
|
||||
if (exp_num > 0x1000000) {
|
||||
goto fallback;
|
||||
}
|
||||
@@ -1661,8 +1626,8 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
}
|
||||
}
|
||||
|
||||
// The wuffs_base__private_implementation__parse_number_f64_eisel_lemire
|
||||
// preconditions include that exp10 is in the range [-307 ..= 288].
|
||||
// The wuffs_private_impl__parse_number_f64_eisel_lemire preconditions
|
||||
// include that exp10 is in the range [-307 ..= 288].
|
||||
if ((exp10 < -307) || (288 < exp10)) {
|
||||
goto fallback;
|
||||
}
|
||||
@@ -1672,9 +1637,9 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
if ((-22 <= exp10) && (exp10 <= 22) && ((man >> 53) == 0)) {
|
||||
double d = (double)man;
|
||||
if (exp10 >= 0) {
|
||||
d *= wuffs_base__private_implementation__f64_powers_of_10[+exp10];
|
||||
d *= wuffs_private_impl__f64_powers_of_10[+exp10];
|
||||
} else {
|
||||
d /= wuffs_base__private_implementation__f64_powers_of_10[-exp10];
|
||||
d /= wuffs_private_impl__f64_powers_of_10[-exp10];
|
||||
}
|
||||
wuffs_base__result_f64 ret;
|
||||
ret.status.repr = NULL;
|
||||
@@ -1682,17 +1647,15 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// The wuffs_base__private_implementation__parse_number_f64_eisel_lemire
|
||||
// preconditions include that man is non-zero. Parsing "0" should be caught
|
||||
// by the "If both man and (10 ** exp10)" above, but "0e99" might not.
|
||||
// The wuffs_private_impl__parse_number_f64_eisel_lemire preconditions
|
||||
// include that man is non-zero. Parsing "0" should be caught by the "If
|
||||
// both man and (10 ** exp10)" above, but "0e99" might not.
|
||||
if (man == 0) {
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
// Our man and exp10 are in range. Run the Eisel-Lemire algorithm.
|
||||
int64_t r =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man, exp10);
|
||||
int64_t r = wuffs_private_impl__parse_number_f64_eisel_lemire(man, exp10);
|
||||
if (r < 0) {
|
||||
goto fallback;
|
||||
}
|
||||
@@ -1705,25 +1668,22 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
|
||||
fallback:
|
||||
do {
|
||||
wuffs_base__private_implementation__high_prec_dec h;
|
||||
wuffs_private_impl__high_prec_dec h;
|
||||
wuffs_base__status status =
|
||||
wuffs_base__private_implementation__high_prec_dec__parse(&h, s,
|
||||
options);
|
||||
wuffs_private_impl__high_prec_dec__parse(&h, s, options);
|
||||
if (status.repr) {
|
||||
return wuffs_base__private_implementation__parse_number_f64_special(
|
||||
s, options);
|
||||
return wuffs_private_impl__parse_number_f64_special(s, options);
|
||||
}
|
||||
return wuffs_base__private_implementation__high_prec_dec__to_f64(&h,
|
||||
options);
|
||||
return wuffs_private_impl__high_prec_dec__to_f64(&h, options);
|
||||
} while (0);
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static inline size_t //
|
||||
wuffs_base__private_implementation__render_inf(wuffs_base__slice_u8 dst,
|
||||
bool neg,
|
||||
uint32_t options) {
|
||||
wuffs_private_impl__render_inf(wuffs_base__slice_u8 dst,
|
||||
bool neg,
|
||||
uint32_t options) {
|
||||
if (neg) {
|
||||
if (dst.len < 4) {
|
||||
return 0;
|
||||
@@ -1748,7 +1708,7 @@ wuffs_base__private_implementation__render_inf(wuffs_base__slice_u8 dst,
|
||||
}
|
||||
|
||||
static inline size_t //
|
||||
wuffs_base__private_implementation__render_nan(wuffs_base__slice_u8 dst) {
|
||||
wuffs_private_impl__render_nan(wuffs_base__slice_u8 dst) {
|
||||
if (dst.len < 3) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1757,9 +1717,9 @@ wuffs_base__private_implementation__render_nan(wuffs_base__slice_u8 dst) {
|
||||
}
|
||||
|
||||
static size_t //
|
||||
wuffs_base__private_implementation__high_prec_dec__render_exponent_absent(
|
||||
wuffs_private_impl__high_prec_dec__render_exponent_absent(
|
||||
wuffs_base__slice_u8 dst,
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
uint32_t precision,
|
||||
uint32_t options) {
|
||||
size_t n = (h->negative ||
|
||||
@@ -1824,9 +1784,9 @@ wuffs_base__private_implementation__high_prec_dec__render_exponent_absent(
|
||||
}
|
||||
|
||||
static size_t //
|
||||
wuffs_base__private_implementation__high_prec_dec__render_exponent_present(
|
||||
wuffs_private_impl__high_prec_dec__render_exponent_present(
|
||||
wuffs_base__slice_u8 dst,
|
||||
wuffs_base__private_implementation__high_prec_dec* h,
|
||||
wuffs_private_impl__high_prec_dec* h,
|
||||
uint32_t precision,
|
||||
uint32_t options) {
|
||||
int32_t exp = 0;
|
||||
@@ -1923,9 +1883,9 @@ wuffs_base__render_number_f64(wuffs_base__slice_u8 dst,
|
||||
// unless x is subnormal. Also take care of Inf and NaN.
|
||||
if (exp2 == 0x7FF) {
|
||||
if (man != 0) {
|
||||
return wuffs_base__private_implementation__render_nan(dst);
|
||||
return wuffs_private_impl__render_nan(dst);
|
||||
}
|
||||
return wuffs_base__private_implementation__render_inf(dst, neg, options);
|
||||
return wuffs_private_impl__render_inf(dst, neg, options);
|
||||
} else if (exp2 == 0) {
|
||||
exp2 = -1022;
|
||||
} else {
|
||||
@@ -1939,11 +1899,11 @@ wuffs_base__render_number_f64(wuffs_base__slice_u8 dst,
|
||||
}
|
||||
|
||||
// Convert from the (neg, exp2, man) tuple to an HPD.
|
||||
wuffs_base__private_implementation__high_prec_dec h;
|
||||
wuffs_base__private_implementation__high_prec_dec__assign(&h, man, neg);
|
||||
wuffs_private_impl__high_prec_dec h;
|
||||
wuffs_private_impl__high_prec_dec__assign(&h, man, neg);
|
||||
if (h.num_digits > 0) {
|
||||
wuffs_base__private_implementation__high_prec_dec__lshift(
|
||||
&h, exp2 - 52); // 52 mantissa bits.
|
||||
wuffs_private_impl__high_prec_dec__lshift(&h,
|
||||
exp2 - 52); // 52 mantissa bits.
|
||||
}
|
||||
|
||||
// Handle the "%e" and "%f" formats.
|
||||
@@ -1951,27 +1911,25 @@ wuffs_base__render_number_f64(wuffs_base__slice_u8 dst,
|
||||
WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_PRESENT)) {
|
||||
case WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_ABSENT: // The "%"f" format.
|
||||
if (options & WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION) {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
&h, exp2, man);
|
||||
wuffs_private_impl__high_prec_dec__round_just_enough(&h, exp2, man);
|
||||
int32_t p = ((int32_t)(h.num_digits)) - h.decimal_point;
|
||||
precision = ((uint32_t)(wuffs_base__i32__max(0, p)));
|
||||
} else {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_nearest(
|
||||
wuffs_private_impl__high_prec_dec__round_nearest(
|
||||
&h, ((int32_t)precision) + h.decimal_point);
|
||||
}
|
||||
return wuffs_base__private_implementation__high_prec_dec__render_exponent_absent(
|
||||
return wuffs_private_impl__high_prec_dec__render_exponent_absent(
|
||||
dst, &h, precision, options);
|
||||
|
||||
case WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_PRESENT: // The "%e" format.
|
||||
if (options & WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION) {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
&h, exp2, man);
|
||||
wuffs_private_impl__high_prec_dec__round_just_enough(&h, exp2, man);
|
||||
precision = (h.num_digits > 0) ? (h.num_digits - 1) : 0;
|
||||
} else {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_nearest(
|
||||
wuffs_private_impl__high_prec_dec__round_nearest(
|
||||
&h, ((int32_t)precision) + 1);
|
||||
}
|
||||
return wuffs_base__private_implementation__high_prec_dec__render_exponent_present(
|
||||
return wuffs_private_impl__high_prec_dec__render_exponent_present(
|
||||
dst, &h, precision, options);
|
||||
}
|
||||
|
||||
@@ -1980,16 +1938,14 @@ wuffs_base__render_number_f64(wuffs_base__slice_u8 dst,
|
||||
// rounding and determine whether to use "%e" or "%f".
|
||||
int32_t e_threshold = 0;
|
||||
if (options & WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION) {
|
||||
wuffs_base__private_implementation__high_prec_dec__round_just_enough(
|
||||
&h, exp2, man);
|
||||
wuffs_private_impl__high_prec_dec__round_just_enough(&h, exp2, man);
|
||||
precision = h.num_digits;
|
||||
e_threshold = 6;
|
||||
} else {
|
||||
if (precision == 0) {
|
||||
precision = 1;
|
||||
}
|
||||
wuffs_base__private_implementation__high_prec_dec__round_nearest(
|
||||
&h, ((int32_t)precision));
|
||||
wuffs_private_impl__high_prec_dec__round_nearest(&h, ((int32_t)precision));
|
||||
e_threshold = ((int32_t)precision);
|
||||
int32_t nd = ((int32_t)(h.num_digits));
|
||||
if ((e_threshold > nd) && (nd >= h.decimal_point)) {
|
||||
@@ -2001,7 +1957,7 @@ wuffs_base__render_number_f64(wuffs_base__slice_u8 dst,
|
||||
int32_t e = h.decimal_point - 1;
|
||||
if ((e < -4) || (e_threshold <= e)) {
|
||||
uint32_t p = wuffs_base__u32__min(precision, h.num_digits);
|
||||
return wuffs_base__private_implementation__high_prec_dec__render_exponent_present(
|
||||
return wuffs_private_impl__high_prec_dec__render_exponent_present(
|
||||
dst, &h, (p > 0) ? (p - 1) : 0, options);
|
||||
}
|
||||
|
||||
@@ -2011,6 +1967,6 @@ wuffs_base__render_number_f64(wuffs_base__slice_u8 dst,
|
||||
p = ((int32_t)(h.num_digits));
|
||||
}
|
||||
precision = ((uint32_t)(wuffs_base__i32__max(0, p - h.decimal_point)));
|
||||
return wuffs_base__private_implementation__high_prec_dec__render_exponent_absent(
|
||||
return wuffs_private_impl__high_prec_dec__render_exponent_absent(
|
||||
dst, &h, precision, options);
|
||||
}
|
||||
@@ -15,14 +15,14 @@
|
||||
// whose output is not copied here, which prints further detail.
|
||||
//
|
||||
// These tables are used in
|
||||
// wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits.
|
||||
// wuffs_private_impl__high_prec_dec__lshift_num_new_digits.
|
||||
|
||||
// wuffs_base__private_implementation__hpd_left_shift[i] encodes the number of
|
||||
// new digits created after multiplying a positive integer by (1 << i): the
|
||||
// additional length in the decimal representation. For example, shifting "234"
|
||||
// by 3 (equivalent to multiplying by 8) will produce "1872". Going from a
|
||||
// 3-length string to a 4-length string means that 1 new digit was added (and
|
||||
// existing digits may have changed).
|
||||
// wuffs_private_impl__hpd_left_shift[i] encodes the number of new digits
|
||||
// created after multiplying a positive integer by (1 << i): the additional
|
||||
// length in the decimal representation. For example, shifting "234" by 3
|
||||
// (equivalent to multiplying by 8) will produce "1872". Going from a 3-length
|
||||
// string to a 4-length string means that 1 new digit was added (and existing
|
||||
// digits may have changed).
|
||||
//
|
||||
// Shifting by i can add either N or N-1 new digits, depending on whether the
|
||||
// original positive integer compares >= or < to the i'th power of 5 (as 10
|
||||
@@ -52,7 +52,7 @@
|
||||
// is the string "\x06\x02\x05", so the relevant power of 5 is "625".
|
||||
//
|
||||
// Thanks to Ken Thompson for the original idea.
|
||||
static const uint16_t wuffs_base__private_implementation__hpd_left_shift[65] = {
|
||||
static const uint16_t wuffs_private_impl__hpd_left_shift[65] = {
|
||||
0x0000, 0x0800, 0x0801, 0x0803, 0x1006, 0x1009, 0x100D, 0x1812, 0x1817,
|
||||
0x181D, 0x2024, 0x202B, 0x2033, 0x203C, 0x2846, 0x2850, 0x285B, 0x3067,
|
||||
0x3073, 0x3080, 0x388E, 0x389C, 0x38AB, 0x38BB, 0x40CC, 0x40DD, 0x40EF,
|
||||
@@ -63,9 +63,9 @@ static const uint16_t wuffs_base__private_implementation__hpd_left_shift[65] = {
|
||||
0x051C, 0x051C,
|
||||
};
|
||||
|
||||
// wuffs_base__private_implementation__powers_of_5 contains the powers of 5,
|
||||
// concatenated together: "5", "25", "125", "625", "3125", etc.
|
||||
static const uint8_t wuffs_base__private_implementation__powers_of_5[0x051C] = {
|
||||
// wuffs_private_impl__powers_of_5 contains the powers of 5, concatenated
|
||||
// together: "5", "25", "125", "625", "3125", etc.
|
||||
static const uint8_t wuffs_private_impl__powers_of_5[0x051C] = {
|
||||
5, 2, 5, 1, 2, 5, 6, 2, 5, 3, 1, 2, 5, 1, 5, 6, 2, 5, 7, 8, 1, 2, 5, 3, 9,
|
||||
0, 6, 2, 5, 1, 9, 5, 3, 1, 2, 5, 9, 7, 6, 5, 6, 2, 5, 4, 8, 8, 2, 8, 1, 2,
|
||||
5, 2, 4, 4, 1, 4, 0, 6, 2, 5, 1, 2, 2, 0, 7, 0, 3, 1, 2, 5, 6, 1, 0, 3, 5,
|
||||
@@ -123,15 +123,15 @@ static const uint8_t wuffs_base__private_implementation__powers_of_5[0x051C] = {
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__private_implementation__powers_of_10 contains truncated
|
||||
// approximations to the powers of 10, ranging from 1e-307 to 1e+288 inclusive,
|
||||
// as 596 pairs of uint64_t values (a 128-bit mantissa).
|
||||
// wuffs_private_impl__powers_of_10 contains truncated approximations to the
|
||||
// powers of 10, ranging from 1e-307 to 1e+288 inclusive, as 596 pairs of
|
||||
// uint64_t values (a 128-bit mantissa).
|
||||
//
|
||||
// There's also an implicit third column (implied by a linear formula involving
|
||||
// the base-10 exponent) that is the base-2 exponent, biased by a magic
|
||||
// constant. That constant (1214 or 0x04BE) equals 1023 + 191. 1023 is the bias
|
||||
// for IEEE 754 double-precision floating point. 191 is ((3 * 64) - 1) and
|
||||
// wuffs_base__private_implementation__parse_number_f64_eisel_lemire works with
|
||||
// wuffs_private_impl__parse_number_f64_eisel_lemire works with
|
||||
// multiples-of-64-bit mantissas.
|
||||
//
|
||||
// For example, the third row holds the approximation to 1e-305:
|
||||
@@ -144,609 +144,608 @@ static const uint8_t wuffs_base__private_implementation__powers_of_5[0x051C] = {
|
||||
// 0xED63A231_D4C4FB27_4CA7AAA8_63EE4BDD * (2 ** (0x0520 - 0x04BE))
|
||||
//
|
||||
// This table was generated by by script/print-mpb-powers-of-10.go
|
||||
static const uint64_t wuffs_base__private_implementation__powers_of_10[596][2] =
|
||||
{
|
||||
{0xA5D3B6D479F8E056, 0x8FD0C16206306BAB}, // 1e-307
|
||||
{0x8F48A4899877186C, 0xB3C4F1BA87BC8696}, // 1e-306
|
||||
{0x331ACDABFE94DE87, 0xE0B62E2929ABA83C}, // 1e-305
|
||||
{0x9FF0C08B7F1D0B14, 0x8C71DCD9BA0B4925}, // 1e-304
|
||||
{0x07ECF0AE5EE44DD9, 0xAF8E5410288E1B6F}, // 1e-303
|
||||
{0xC9E82CD9F69D6150, 0xDB71E91432B1A24A}, // 1e-302
|
||||
{0xBE311C083A225CD2, 0x892731AC9FAF056E}, // 1e-301
|
||||
{0x6DBD630A48AAF406, 0xAB70FE17C79AC6CA}, // 1e-300
|
||||
{0x092CBBCCDAD5B108, 0xD64D3D9DB981787D}, // 1e-299
|
||||
{0x25BBF56008C58EA5, 0x85F0468293F0EB4E}, // 1e-298
|
||||
{0xAF2AF2B80AF6F24E, 0xA76C582338ED2621}, // 1e-297
|
||||
{0x1AF5AF660DB4AEE1, 0xD1476E2C07286FAA}, // 1e-296
|
||||
{0x50D98D9FC890ED4D, 0x82CCA4DB847945CA}, // 1e-295
|
||||
{0xE50FF107BAB528A0, 0xA37FCE126597973C}, // 1e-294
|
||||
{0x1E53ED49A96272C8, 0xCC5FC196FEFD7D0C}, // 1e-293
|
||||
{0x25E8E89C13BB0F7A, 0xFF77B1FCBEBCDC4F}, // 1e-292
|
||||
{0x77B191618C54E9AC, 0x9FAACF3DF73609B1}, // 1e-291
|
||||
{0xD59DF5B9EF6A2417, 0xC795830D75038C1D}, // 1e-290
|
||||
{0x4B0573286B44AD1D, 0xF97AE3D0D2446F25}, // 1e-289
|
||||
{0x4EE367F9430AEC32, 0x9BECCE62836AC577}, // 1e-288
|
||||
{0x229C41F793CDA73F, 0xC2E801FB244576D5}, // 1e-287
|
||||
{0x6B43527578C1110F, 0xF3A20279ED56D48A}, // 1e-286
|
||||
{0x830A13896B78AAA9, 0x9845418C345644D6}, // 1e-285
|
||||
{0x23CC986BC656D553, 0xBE5691EF416BD60C}, // 1e-284
|
||||
{0x2CBFBE86B7EC8AA8, 0xEDEC366B11C6CB8F}, // 1e-283
|
||||
{0x7BF7D71432F3D6A9, 0x94B3A202EB1C3F39}, // 1e-282
|
||||
{0xDAF5CCD93FB0CC53, 0xB9E08A83A5E34F07}, // 1e-281
|
||||
{0xD1B3400F8F9CFF68, 0xE858AD248F5C22C9}, // 1e-280
|
||||
{0x23100809B9C21FA1, 0x91376C36D99995BE}, // 1e-279
|
||||
{0xABD40A0C2832A78A, 0xB58547448FFFFB2D}, // 1e-278
|
||||
{0x16C90C8F323F516C, 0xE2E69915B3FFF9F9}, // 1e-277
|
||||
{0xAE3DA7D97F6792E3, 0x8DD01FAD907FFC3B}, // 1e-276
|
||||
{0x99CD11CFDF41779C, 0xB1442798F49FFB4A}, // 1e-275
|
||||
{0x40405643D711D583, 0xDD95317F31C7FA1D}, // 1e-274
|
||||
{0x482835EA666B2572, 0x8A7D3EEF7F1CFC52}, // 1e-273
|
||||
{0xDA3243650005EECF, 0xAD1C8EAB5EE43B66}, // 1e-272
|
||||
{0x90BED43E40076A82, 0xD863B256369D4A40}, // 1e-271
|
||||
{0x5A7744A6E804A291, 0x873E4F75E2224E68}, // 1e-270
|
||||
{0x711515D0A205CB36, 0xA90DE3535AAAE202}, // 1e-269
|
||||
{0x0D5A5B44CA873E03, 0xD3515C2831559A83}, // 1e-268
|
||||
{0xE858790AFE9486C2, 0x8412D9991ED58091}, // 1e-267
|
||||
{0x626E974DBE39A872, 0xA5178FFF668AE0B6}, // 1e-266
|
||||
{0xFB0A3D212DC8128F, 0xCE5D73FF402D98E3}, // 1e-265
|
||||
{0x7CE66634BC9D0B99, 0x80FA687F881C7F8E}, // 1e-264
|
||||
{0x1C1FFFC1EBC44E80, 0xA139029F6A239F72}, // 1e-263
|
||||
{0xA327FFB266B56220, 0xC987434744AC874E}, // 1e-262
|
||||
{0x4BF1FF9F0062BAA8, 0xFBE9141915D7A922}, // 1e-261
|
||||
{0x6F773FC3603DB4A9, 0x9D71AC8FADA6C9B5}, // 1e-260
|
||||
{0xCB550FB4384D21D3, 0xC4CE17B399107C22}, // 1e-259
|
||||
{0x7E2A53A146606A48, 0xF6019DA07F549B2B}, // 1e-258
|
||||
{0x2EDA7444CBFC426D, 0x99C102844F94E0FB}, // 1e-257
|
||||
{0xFA911155FEFB5308, 0xC0314325637A1939}, // 1e-256
|
||||
{0x793555AB7EBA27CA, 0xF03D93EEBC589F88}, // 1e-255
|
||||
{0x4BC1558B2F3458DE, 0x96267C7535B763B5}, // 1e-254
|
||||
{0x9EB1AAEDFB016F16, 0xBBB01B9283253CA2}, // 1e-253
|
||||
{0x465E15A979C1CADC, 0xEA9C227723EE8BCB}, // 1e-252
|
||||
{0x0BFACD89EC191EC9, 0x92A1958A7675175F}, // 1e-251
|
||||
{0xCEF980EC671F667B, 0xB749FAED14125D36}, // 1e-250
|
||||
{0x82B7E12780E7401A, 0xE51C79A85916F484}, // 1e-249
|
||||
{0xD1B2ECB8B0908810, 0x8F31CC0937AE58D2}, // 1e-248
|
||||
{0x861FA7E6DCB4AA15, 0xB2FE3F0B8599EF07}, // 1e-247
|
||||
{0x67A791E093E1D49A, 0xDFBDCECE67006AC9}, // 1e-246
|
||||
{0xE0C8BB2C5C6D24E0, 0x8BD6A141006042BD}, // 1e-245
|
||||
{0x58FAE9F773886E18, 0xAECC49914078536D}, // 1e-244
|
||||
{0xAF39A475506A899E, 0xDA7F5BF590966848}, // 1e-243
|
||||
{0x6D8406C952429603, 0x888F99797A5E012D}, // 1e-242
|
||||
{0xC8E5087BA6D33B83, 0xAAB37FD7D8F58178}, // 1e-241
|
||||
{0xFB1E4A9A90880A64, 0xD5605FCDCF32E1D6}, // 1e-240
|
||||
{0x5CF2EEA09A55067F, 0x855C3BE0A17FCD26}, // 1e-239
|
||||
{0xF42FAA48C0EA481E, 0xA6B34AD8C9DFC06F}, // 1e-238
|
||||
{0xF13B94DAF124DA26, 0xD0601D8EFC57B08B}, // 1e-237
|
||||
{0x76C53D08D6B70858, 0x823C12795DB6CE57}, // 1e-236
|
||||
{0x54768C4B0C64CA6E, 0xA2CB1717B52481ED}, // 1e-235
|
||||
{0xA9942F5DCF7DFD09, 0xCB7DDCDDA26DA268}, // 1e-234
|
||||
{0xD3F93B35435D7C4C, 0xFE5D54150B090B02}, // 1e-233
|
||||
{0xC47BC5014A1A6DAF, 0x9EFA548D26E5A6E1}, // 1e-232
|
||||
{0x359AB6419CA1091B, 0xC6B8E9B0709F109A}, // 1e-231
|
||||
{0xC30163D203C94B62, 0xF867241C8CC6D4C0}, // 1e-230
|
||||
{0x79E0DE63425DCF1D, 0x9B407691D7FC44F8}, // 1e-229
|
||||
{0x985915FC12F542E4, 0xC21094364DFB5636}, // 1e-228
|
||||
{0x3E6F5B7B17B2939D, 0xF294B943E17A2BC4}, // 1e-227
|
||||
{0xA705992CEECF9C42, 0x979CF3CA6CEC5B5A}, // 1e-226
|
||||
{0x50C6FF782A838353, 0xBD8430BD08277231}, // 1e-225
|
||||
{0xA4F8BF5635246428, 0xECE53CEC4A314EBD}, // 1e-224
|
||||
{0x871B7795E136BE99, 0x940F4613AE5ED136}, // 1e-223
|
||||
{0x28E2557B59846E3F, 0xB913179899F68584}, // 1e-222
|
||||
{0x331AEADA2FE589CF, 0xE757DD7EC07426E5}, // 1e-221
|
||||
{0x3FF0D2C85DEF7621, 0x9096EA6F3848984F}, // 1e-220
|
||||
{0x0FED077A756B53A9, 0xB4BCA50B065ABE63}, // 1e-219
|
||||
{0xD3E8495912C62894, 0xE1EBCE4DC7F16DFB}, // 1e-218
|
||||
{0x64712DD7ABBBD95C, 0x8D3360F09CF6E4BD}, // 1e-217
|
||||
{0xBD8D794D96AACFB3, 0xB080392CC4349DEC}, // 1e-216
|
||||
{0xECF0D7A0FC5583A0, 0xDCA04777F541C567}, // 1e-215
|
||||
{0xF41686C49DB57244, 0x89E42CAAF9491B60}, // 1e-214
|
||||
{0x311C2875C522CED5, 0xAC5D37D5B79B6239}, // 1e-213
|
||||
{0x7D633293366B828B, 0xD77485CB25823AC7}, // 1e-212
|
||||
{0xAE5DFF9C02033197, 0x86A8D39EF77164BC}, // 1e-211
|
||||
{0xD9F57F830283FDFC, 0xA8530886B54DBDEB}, // 1e-210
|
||||
{0xD072DF63C324FD7B, 0xD267CAA862A12D66}, // 1e-209
|
||||
{0x4247CB9E59F71E6D, 0x8380DEA93DA4BC60}, // 1e-208
|
||||
{0x52D9BE85F074E608, 0xA46116538D0DEB78}, // 1e-207
|
||||
{0x67902E276C921F8B, 0xCD795BE870516656}, // 1e-206
|
||||
{0x00BA1CD8A3DB53B6, 0x806BD9714632DFF6}, // 1e-205
|
||||
{0x80E8A40ECCD228A4, 0xA086CFCD97BF97F3}, // 1e-204
|
||||
{0x6122CD128006B2CD, 0xC8A883C0FDAF7DF0}, // 1e-203
|
||||
{0x796B805720085F81, 0xFAD2A4B13D1B5D6C}, // 1e-202
|
||||
{0xCBE3303674053BB0, 0x9CC3A6EEC6311A63}, // 1e-201
|
||||
{0xBEDBFC4411068A9C, 0xC3F490AA77BD60FC}, // 1e-200
|
||||
{0xEE92FB5515482D44, 0xF4F1B4D515ACB93B}, // 1e-199
|
||||
{0x751BDD152D4D1C4A, 0x991711052D8BF3C5}, // 1e-198
|
||||
{0xD262D45A78A0635D, 0xBF5CD54678EEF0B6}, // 1e-197
|
||||
{0x86FB897116C87C34, 0xEF340A98172AACE4}, // 1e-196
|
||||
{0xD45D35E6AE3D4DA0, 0x9580869F0E7AAC0E}, // 1e-195
|
||||
{0x8974836059CCA109, 0xBAE0A846D2195712}, // 1e-194
|
||||
{0x2BD1A438703FC94B, 0xE998D258869FACD7}, // 1e-193
|
||||
{0x7B6306A34627DDCF, 0x91FF83775423CC06}, // 1e-192
|
||||
{0x1A3BC84C17B1D542, 0xB67F6455292CBF08}, // 1e-191
|
||||
{0x20CABA5F1D9E4A93, 0xE41F3D6A7377EECA}, // 1e-190
|
||||
{0x547EB47B7282EE9C, 0x8E938662882AF53E}, // 1e-189
|
||||
{0xE99E619A4F23AA43, 0xB23867FB2A35B28D}, // 1e-188
|
||||
{0x6405FA00E2EC94D4, 0xDEC681F9F4C31F31}, // 1e-187
|
||||
{0xDE83BC408DD3DD04, 0x8B3C113C38F9F37E}, // 1e-186
|
||||
{0x9624AB50B148D445, 0xAE0B158B4738705E}, // 1e-185
|
||||
{0x3BADD624DD9B0957, 0xD98DDAEE19068C76}, // 1e-184
|
||||
{0xE54CA5D70A80E5D6, 0x87F8A8D4CFA417C9}, // 1e-183
|
||||
{0x5E9FCF4CCD211F4C, 0xA9F6D30A038D1DBC}, // 1e-182
|
||||
{0x7647C3200069671F, 0xD47487CC8470652B}, // 1e-181
|
||||
{0x29ECD9F40041E073, 0x84C8D4DFD2C63F3B}, // 1e-180
|
||||
{0xF468107100525890, 0xA5FB0A17C777CF09}, // 1e-179
|
||||
{0x7182148D4066EEB4, 0xCF79CC9DB955C2CC}, // 1e-178
|
||||
{0xC6F14CD848405530, 0x81AC1FE293D599BF}, // 1e-177
|
||||
{0xB8ADA00E5A506A7C, 0xA21727DB38CB002F}, // 1e-176
|
||||
{0xA6D90811F0E4851C, 0xCA9CF1D206FDC03B}, // 1e-175
|
||||
{0x908F4A166D1DA663, 0xFD442E4688BD304A}, // 1e-174
|
||||
{0x9A598E4E043287FE, 0x9E4A9CEC15763E2E}, // 1e-173
|
||||
{0x40EFF1E1853F29FD, 0xC5DD44271AD3CDBA}, // 1e-172
|
||||
{0xD12BEE59E68EF47C, 0xF7549530E188C128}, // 1e-171
|
||||
{0x82BB74F8301958CE, 0x9A94DD3E8CF578B9}, // 1e-170
|
||||
{0xE36A52363C1FAF01, 0xC13A148E3032D6E7}, // 1e-169
|
||||
{0xDC44E6C3CB279AC1, 0xF18899B1BC3F8CA1}, // 1e-168
|
||||
{0x29AB103A5EF8C0B9, 0x96F5600F15A7B7E5}, // 1e-167
|
||||
{0x7415D448F6B6F0E7, 0xBCB2B812DB11A5DE}, // 1e-166
|
||||
{0x111B495B3464AD21, 0xEBDF661791D60F56}, // 1e-165
|
||||
{0xCAB10DD900BEEC34, 0x936B9FCEBB25C995}, // 1e-164
|
||||
{0x3D5D514F40EEA742, 0xB84687C269EF3BFB}, // 1e-163
|
||||
{0x0CB4A5A3112A5112, 0xE65829B3046B0AFA}, // 1e-162
|
||||
{0x47F0E785EABA72AB, 0x8FF71A0FE2C2E6DC}, // 1e-161
|
||||
{0x59ED216765690F56, 0xB3F4E093DB73A093}, // 1e-160
|
||||
{0x306869C13EC3532C, 0xE0F218B8D25088B8}, // 1e-159
|
||||
{0x1E414218C73A13FB, 0x8C974F7383725573}, // 1e-158
|
||||
{0xE5D1929EF90898FA, 0xAFBD2350644EEACF}, // 1e-157
|
||||
{0xDF45F746B74ABF39, 0xDBAC6C247D62A583}, // 1e-156
|
||||
{0x6B8BBA8C328EB783, 0x894BC396CE5DA772}, // 1e-155
|
||||
{0x066EA92F3F326564, 0xAB9EB47C81F5114F}, // 1e-154
|
||||
{0xC80A537B0EFEFEBD, 0xD686619BA27255A2}, // 1e-153
|
||||
{0xBD06742CE95F5F36, 0x8613FD0145877585}, // 1e-152
|
||||
{0x2C48113823B73704, 0xA798FC4196E952E7}, // 1e-151
|
||||
{0xF75A15862CA504C5, 0xD17F3B51FCA3A7A0}, // 1e-150
|
||||
{0x9A984D73DBE722FB, 0x82EF85133DE648C4}, // 1e-149
|
||||
{0xC13E60D0D2E0EBBA, 0xA3AB66580D5FDAF5}, // 1e-148
|
||||
{0x318DF905079926A8, 0xCC963FEE10B7D1B3}, // 1e-147
|
||||
{0xFDF17746497F7052, 0xFFBBCFE994E5C61F}, // 1e-146
|
||||
{0xFEB6EA8BEDEFA633, 0x9FD561F1FD0F9BD3}, // 1e-145
|
||||
{0xFE64A52EE96B8FC0, 0xC7CABA6E7C5382C8}, // 1e-144
|
||||
{0x3DFDCE7AA3C673B0, 0xF9BD690A1B68637B}, // 1e-143
|
||||
{0x06BEA10CA65C084E, 0x9C1661A651213E2D}, // 1e-142
|
||||
{0x486E494FCFF30A62, 0xC31BFA0FE5698DB8}, // 1e-141
|
||||
{0x5A89DBA3C3EFCCFA, 0xF3E2F893DEC3F126}, // 1e-140
|
||||
{0xF89629465A75E01C, 0x986DDB5C6B3A76B7}, // 1e-139
|
||||
{0xF6BBB397F1135823, 0xBE89523386091465}, // 1e-138
|
||||
{0x746AA07DED582E2C, 0xEE2BA6C0678B597F}, // 1e-137
|
||||
{0xA8C2A44EB4571CDC, 0x94DB483840B717EF}, // 1e-136
|
||||
{0x92F34D62616CE413, 0xBA121A4650E4DDEB}, // 1e-135
|
||||
{0x77B020BAF9C81D17, 0xE896A0D7E51E1566}, // 1e-134
|
||||
{0x0ACE1474DC1D122E, 0x915E2486EF32CD60}, // 1e-133
|
||||
{0x0D819992132456BA, 0xB5B5ADA8AAFF80B8}, // 1e-132
|
||||
{0x10E1FFF697ED6C69, 0xE3231912D5BF60E6}, // 1e-131
|
||||
{0xCA8D3FFA1EF463C1, 0x8DF5EFABC5979C8F}, // 1e-130
|
||||
{0xBD308FF8A6B17CB2, 0xB1736B96B6FD83B3}, // 1e-129
|
||||
{0xAC7CB3F6D05DDBDE, 0xDDD0467C64BCE4A0}, // 1e-128
|
||||
{0x6BCDF07A423AA96B, 0x8AA22C0DBEF60EE4}, // 1e-127
|
||||
{0x86C16C98D2C953C6, 0xAD4AB7112EB3929D}, // 1e-126
|
||||
{0xE871C7BF077BA8B7, 0xD89D64D57A607744}, // 1e-125
|
||||
{0x11471CD764AD4972, 0x87625F056C7C4A8B}, // 1e-124
|
||||
{0xD598E40D3DD89BCF, 0xA93AF6C6C79B5D2D}, // 1e-123
|
||||
{0x4AFF1D108D4EC2C3, 0xD389B47879823479}, // 1e-122
|
||||
{0xCEDF722A585139BA, 0x843610CB4BF160CB}, // 1e-121
|
||||
{0xC2974EB4EE658828, 0xA54394FE1EEDB8FE}, // 1e-120
|
||||
{0x733D226229FEEA32, 0xCE947A3DA6A9273E}, // 1e-119
|
||||
{0x0806357D5A3F525F, 0x811CCC668829B887}, // 1e-118
|
||||
{0xCA07C2DCB0CF26F7, 0xA163FF802A3426A8}, // 1e-117
|
||||
{0xFC89B393DD02F0B5, 0xC9BCFF6034C13052}, // 1e-116
|
||||
{0xBBAC2078D443ACE2, 0xFC2C3F3841F17C67}, // 1e-115
|
||||
{0xD54B944B84AA4C0D, 0x9D9BA7832936EDC0}, // 1e-114
|
||||
{0x0A9E795E65D4DF11, 0xC5029163F384A931}, // 1e-113
|
||||
{0x4D4617B5FF4A16D5, 0xF64335BCF065D37D}, // 1e-112
|
||||
{0x504BCED1BF8E4E45, 0x99EA0196163FA42E}, // 1e-111
|
||||
{0xE45EC2862F71E1D6, 0xC06481FB9BCF8D39}, // 1e-110
|
||||
{0x5D767327BB4E5A4C, 0xF07DA27A82C37088}, // 1e-109
|
||||
{0x3A6A07F8D510F86F, 0x964E858C91BA2655}, // 1e-108
|
||||
{0x890489F70A55368B, 0xBBE226EFB628AFEA}, // 1e-107
|
||||
{0x2B45AC74CCEA842E, 0xEADAB0ABA3B2DBE5}, // 1e-106
|
||||
{0x3B0B8BC90012929D, 0x92C8AE6B464FC96F}, // 1e-105
|
||||
{0x09CE6EBB40173744, 0xB77ADA0617E3BBCB}, // 1e-104
|
||||
{0xCC420A6A101D0515, 0xE55990879DDCAABD}, // 1e-103
|
||||
{0x9FA946824A12232D, 0x8F57FA54C2A9EAB6}, // 1e-102
|
||||
{0x47939822DC96ABF9, 0xB32DF8E9F3546564}, // 1e-101
|
||||
{0x59787E2B93BC56F7, 0xDFF9772470297EBD}, // 1e-100
|
||||
{0x57EB4EDB3C55B65A, 0x8BFBEA76C619EF36}, // 1e-99
|
||||
{0xEDE622920B6B23F1, 0xAEFAE51477A06B03}, // 1e-98
|
||||
{0xE95FAB368E45ECED, 0xDAB99E59958885C4}, // 1e-97
|
||||
{0x11DBCB0218EBB414, 0x88B402F7FD75539B}, // 1e-96
|
||||
{0xD652BDC29F26A119, 0xAAE103B5FCD2A881}, // 1e-95
|
||||
{0x4BE76D3346F0495F, 0xD59944A37C0752A2}, // 1e-94
|
||||
{0x6F70A4400C562DDB, 0x857FCAE62D8493A5}, // 1e-93
|
||||
{0xCB4CCD500F6BB952, 0xA6DFBD9FB8E5B88E}, // 1e-92
|
||||
{0x7E2000A41346A7A7, 0xD097AD07A71F26B2}, // 1e-91
|
||||
{0x8ED400668C0C28C8, 0x825ECC24C873782F}, // 1e-90
|
||||
{0x728900802F0F32FA, 0xA2F67F2DFA90563B}, // 1e-89
|
||||
{0x4F2B40A03AD2FFB9, 0xCBB41EF979346BCA}, // 1e-88
|
||||
{0xE2F610C84987BFA8, 0xFEA126B7D78186BC}, // 1e-87
|
||||
{0x0DD9CA7D2DF4D7C9, 0x9F24B832E6B0F436}, // 1e-86
|
||||
{0x91503D1C79720DBB, 0xC6EDE63FA05D3143}, // 1e-85
|
||||
{0x75A44C6397CE912A, 0xF8A95FCF88747D94}, // 1e-84
|
||||
{0xC986AFBE3EE11ABA, 0x9B69DBE1B548CE7C}, // 1e-83
|
||||
{0xFBE85BADCE996168, 0xC24452DA229B021B}, // 1e-82
|
||||
{0xFAE27299423FB9C3, 0xF2D56790AB41C2A2}, // 1e-81
|
||||
{0xDCCD879FC967D41A, 0x97C560BA6B0919A5}, // 1e-80
|
||||
{0x5400E987BBC1C920, 0xBDB6B8E905CB600F}, // 1e-79
|
||||
{0x290123E9AAB23B68, 0xED246723473E3813}, // 1e-78
|
||||
{0xF9A0B6720AAF6521, 0x9436C0760C86E30B}, // 1e-77
|
||||
{0xF808E40E8D5B3E69, 0xB94470938FA89BCE}, // 1e-76
|
||||
{0xB60B1D1230B20E04, 0xE7958CB87392C2C2}, // 1e-75
|
||||
{0xB1C6F22B5E6F48C2, 0x90BD77F3483BB9B9}, // 1e-74
|
||||
{0x1E38AEB6360B1AF3, 0xB4ECD5F01A4AA828}, // 1e-73
|
||||
{0x25C6DA63C38DE1B0, 0xE2280B6C20DD5232}, // 1e-72
|
||||
{0x579C487E5A38AD0E, 0x8D590723948A535F}, // 1e-71
|
||||
{0x2D835A9DF0C6D851, 0xB0AF48EC79ACE837}, // 1e-70
|
||||
{0xF8E431456CF88E65, 0xDCDB1B2798182244}, // 1e-69
|
||||
{0x1B8E9ECB641B58FF, 0x8A08F0F8BF0F156B}, // 1e-68
|
||||
{0xE272467E3D222F3F, 0xAC8B2D36EED2DAC5}, // 1e-67
|
||||
{0x5B0ED81DCC6ABB0F, 0xD7ADF884AA879177}, // 1e-66
|
||||
{0x98E947129FC2B4E9, 0x86CCBB52EA94BAEA}, // 1e-65
|
||||
{0x3F2398D747B36224, 0xA87FEA27A539E9A5}, // 1e-64
|
||||
{0x8EEC7F0D19A03AAD, 0xD29FE4B18E88640E}, // 1e-63
|
||||
{0x1953CF68300424AC, 0x83A3EEEEF9153E89}, // 1e-62
|
||||
{0x5FA8C3423C052DD7, 0xA48CEAAAB75A8E2B}, // 1e-61
|
||||
{0x3792F412CB06794D, 0xCDB02555653131B6}, // 1e-60
|
||||
{0xE2BBD88BBEE40BD0, 0x808E17555F3EBF11}, // 1e-59
|
||||
{0x5B6ACEAEAE9D0EC4, 0xA0B19D2AB70E6ED6}, // 1e-58
|
||||
{0xF245825A5A445275, 0xC8DE047564D20A8B}, // 1e-57
|
||||
{0xEED6E2F0F0D56712, 0xFB158592BE068D2E}, // 1e-56
|
||||
{0x55464DD69685606B, 0x9CED737BB6C4183D}, // 1e-55
|
||||
{0xAA97E14C3C26B886, 0xC428D05AA4751E4C}, // 1e-54
|
||||
{0xD53DD99F4B3066A8, 0xF53304714D9265DF}, // 1e-53
|
||||
{0xE546A8038EFE4029, 0x993FE2C6D07B7FAB}, // 1e-52
|
||||
{0xDE98520472BDD033, 0xBF8FDB78849A5F96}, // 1e-51
|
||||
{0x963E66858F6D4440, 0xEF73D256A5C0F77C}, // 1e-50
|
||||
{0xDDE7001379A44AA8, 0x95A8637627989AAD}, // 1e-49
|
||||
{0x5560C018580D5D52, 0xBB127C53B17EC159}, // 1e-48
|
||||
{0xAAB8F01E6E10B4A6, 0xE9D71B689DDE71AF}, // 1e-47
|
||||
{0xCAB3961304CA70E8, 0x9226712162AB070D}, // 1e-46
|
||||
{0x3D607B97C5FD0D22, 0xB6B00D69BB55C8D1}, // 1e-45
|
||||
{0x8CB89A7DB77C506A, 0xE45C10C42A2B3B05}, // 1e-44
|
||||
{0x77F3608E92ADB242, 0x8EB98A7A9A5B04E3}, // 1e-43
|
||||
{0x55F038B237591ED3, 0xB267ED1940F1C61C}, // 1e-42
|
||||
{0x6B6C46DEC52F6688, 0xDF01E85F912E37A3}, // 1e-41
|
||||
{0x2323AC4B3B3DA015, 0x8B61313BBABCE2C6}, // 1e-40
|
||||
{0xABEC975E0A0D081A, 0xAE397D8AA96C1B77}, // 1e-39
|
||||
{0x96E7BD358C904A21, 0xD9C7DCED53C72255}, // 1e-38
|
||||
{0x7E50D64177DA2E54, 0x881CEA14545C7575}, // 1e-37
|
||||
{0xDDE50BD1D5D0B9E9, 0xAA242499697392D2}, // 1e-36
|
||||
{0x955E4EC64B44E864, 0xD4AD2DBFC3D07787}, // 1e-35
|
||||
{0xBD5AF13BEF0B113E, 0x84EC3C97DA624AB4}, // 1e-34
|
||||
{0xECB1AD8AEACDD58E, 0xA6274BBDD0FADD61}, // 1e-33
|
||||
{0x67DE18EDA5814AF2, 0xCFB11EAD453994BA}, // 1e-32
|
||||
{0x80EACF948770CED7, 0x81CEB32C4B43FCF4}, // 1e-31
|
||||
{0xA1258379A94D028D, 0xA2425FF75E14FC31}, // 1e-30
|
||||
{0x096EE45813A04330, 0xCAD2F7F5359A3B3E}, // 1e-29
|
||||
{0x8BCA9D6E188853FC, 0xFD87B5F28300CA0D}, // 1e-28
|
||||
{0x775EA264CF55347D, 0x9E74D1B791E07E48}, // 1e-27
|
||||
{0x95364AFE032A819D, 0xC612062576589DDA}, // 1e-26
|
||||
{0x3A83DDBD83F52204, 0xF79687AED3EEC551}, // 1e-25
|
||||
{0xC4926A9672793542, 0x9ABE14CD44753B52}, // 1e-24
|
||||
{0x75B7053C0F178293, 0xC16D9A0095928A27}, // 1e-23
|
||||
{0x5324C68B12DD6338, 0xF1C90080BAF72CB1}, // 1e-22
|
||||
{0xD3F6FC16EBCA5E03, 0x971DA05074DA7BEE}, // 1e-21
|
||||
{0x88F4BB1CA6BCF584, 0xBCE5086492111AEA}, // 1e-20
|
||||
{0x2B31E9E3D06C32E5, 0xEC1E4A7DB69561A5}, // 1e-19
|
||||
{0x3AFF322E62439FCF, 0x9392EE8E921D5D07}, // 1e-18
|
||||
{0x09BEFEB9FAD487C2, 0xB877AA3236A4B449}, // 1e-17
|
||||
{0x4C2EBE687989A9B3, 0xE69594BEC44DE15B}, // 1e-16
|
||||
{0x0F9D37014BF60A10, 0x901D7CF73AB0ACD9}, // 1e-15
|
||||
{0x538484C19EF38C94, 0xB424DC35095CD80F}, // 1e-14
|
||||
{0x2865A5F206B06FB9, 0xE12E13424BB40E13}, // 1e-13
|
||||
{0xF93F87B7442E45D3, 0x8CBCCC096F5088CB}, // 1e-12
|
||||
{0xF78F69A51539D748, 0xAFEBFF0BCB24AAFE}, // 1e-11
|
||||
{0xB573440E5A884D1B, 0xDBE6FECEBDEDD5BE}, // 1e-10
|
||||
{0x31680A88F8953030, 0x89705F4136B4A597}, // 1e-9
|
||||
{0xFDC20D2B36BA7C3D, 0xABCC77118461CEFC}, // 1e-8
|
||||
{0x3D32907604691B4C, 0xD6BF94D5E57A42BC}, // 1e-7
|
||||
{0xA63F9A49C2C1B10F, 0x8637BD05AF6C69B5}, // 1e-6
|
||||
{0x0FCF80DC33721D53, 0xA7C5AC471B478423}, // 1e-5
|
||||
{0xD3C36113404EA4A8, 0xD1B71758E219652B}, // 1e-4
|
||||
{0x645A1CAC083126E9, 0x83126E978D4FDF3B}, // 1e-3
|
||||
{0x3D70A3D70A3D70A3, 0xA3D70A3D70A3D70A}, // 1e-2
|
||||
{0xCCCCCCCCCCCCCCCC, 0xCCCCCCCCCCCCCCCC}, // 1e-1
|
||||
{0x0000000000000000, 0x8000000000000000}, // 1e0
|
||||
{0x0000000000000000, 0xA000000000000000}, // 1e1
|
||||
{0x0000000000000000, 0xC800000000000000}, // 1e2
|
||||
{0x0000000000000000, 0xFA00000000000000}, // 1e3
|
||||
{0x0000000000000000, 0x9C40000000000000}, // 1e4
|
||||
{0x0000000000000000, 0xC350000000000000}, // 1e5
|
||||
{0x0000000000000000, 0xF424000000000000}, // 1e6
|
||||
{0x0000000000000000, 0x9896800000000000}, // 1e7
|
||||
{0x0000000000000000, 0xBEBC200000000000}, // 1e8
|
||||
{0x0000000000000000, 0xEE6B280000000000}, // 1e9
|
||||
{0x0000000000000000, 0x9502F90000000000}, // 1e10
|
||||
{0x0000000000000000, 0xBA43B74000000000}, // 1e11
|
||||
{0x0000000000000000, 0xE8D4A51000000000}, // 1e12
|
||||
{0x0000000000000000, 0x9184E72A00000000}, // 1e13
|
||||
{0x0000000000000000, 0xB5E620F480000000}, // 1e14
|
||||
{0x0000000000000000, 0xE35FA931A0000000}, // 1e15
|
||||
{0x0000000000000000, 0x8E1BC9BF04000000}, // 1e16
|
||||
{0x0000000000000000, 0xB1A2BC2EC5000000}, // 1e17
|
||||
{0x0000000000000000, 0xDE0B6B3A76400000}, // 1e18
|
||||
{0x0000000000000000, 0x8AC7230489E80000}, // 1e19
|
||||
{0x0000000000000000, 0xAD78EBC5AC620000}, // 1e20
|
||||
{0x0000000000000000, 0xD8D726B7177A8000}, // 1e21
|
||||
{0x0000000000000000, 0x878678326EAC9000}, // 1e22
|
||||
{0x0000000000000000, 0xA968163F0A57B400}, // 1e23
|
||||
{0x0000000000000000, 0xD3C21BCECCEDA100}, // 1e24
|
||||
{0x0000000000000000, 0x84595161401484A0}, // 1e25
|
||||
{0x0000000000000000, 0xA56FA5B99019A5C8}, // 1e26
|
||||
{0x0000000000000000, 0xCECB8F27F4200F3A}, // 1e27
|
||||
{0x4000000000000000, 0x813F3978F8940984}, // 1e28
|
||||
{0x5000000000000000, 0xA18F07D736B90BE5}, // 1e29
|
||||
{0xA400000000000000, 0xC9F2C9CD04674EDE}, // 1e30
|
||||
{0x4D00000000000000, 0xFC6F7C4045812296}, // 1e31
|
||||
{0xF020000000000000, 0x9DC5ADA82B70B59D}, // 1e32
|
||||
{0x6C28000000000000, 0xC5371912364CE305}, // 1e33
|
||||
{0xC732000000000000, 0xF684DF56C3E01BC6}, // 1e34
|
||||
{0x3C7F400000000000, 0x9A130B963A6C115C}, // 1e35
|
||||
{0x4B9F100000000000, 0xC097CE7BC90715B3}, // 1e36
|
||||
{0x1E86D40000000000, 0xF0BDC21ABB48DB20}, // 1e37
|
||||
{0x1314448000000000, 0x96769950B50D88F4}, // 1e38
|
||||
{0x17D955A000000000, 0xBC143FA4E250EB31}, // 1e39
|
||||
{0x5DCFAB0800000000, 0xEB194F8E1AE525FD}, // 1e40
|
||||
{0x5AA1CAE500000000, 0x92EFD1B8D0CF37BE}, // 1e41
|
||||
{0xF14A3D9E40000000, 0xB7ABC627050305AD}, // 1e42
|
||||
{0x6D9CCD05D0000000, 0xE596B7B0C643C719}, // 1e43
|
||||
{0xE4820023A2000000, 0x8F7E32CE7BEA5C6F}, // 1e44
|
||||
{0xDDA2802C8A800000, 0xB35DBF821AE4F38B}, // 1e45
|
||||
{0xD50B2037AD200000, 0xE0352F62A19E306E}, // 1e46
|
||||
{0x4526F422CC340000, 0x8C213D9DA502DE45}, // 1e47
|
||||
{0x9670B12B7F410000, 0xAF298D050E4395D6}, // 1e48
|
||||
{0x3C0CDD765F114000, 0xDAF3F04651D47B4C}, // 1e49
|
||||
{0xA5880A69FB6AC800, 0x88D8762BF324CD0F}, // 1e50
|
||||
{0x8EEA0D047A457A00, 0xAB0E93B6EFEE0053}, // 1e51
|
||||
{0x72A4904598D6D880, 0xD5D238A4ABE98068}, // 1e52
|
||||
{0x47A6DA2B7F864750, 0x85A36366EB71F041}, // 1e53
|
||||
{0x999090B65F67D924, 0xA70C3C40A64E6C51}, // 1e54
|
||||
{0xFFF4B4E3F741CF6D, 0xD0CF4B50CFE20765}, // 1e55
|
||||
{0xBFF8F10E7A8921A4, 0x82818F1281ED449F}, // 1e56
|
||||
{0xAFF72D52192B6A0D, 0xA321F2D7226895C7}, // 1e57
|
||||
{0x9BF4F8A69F764490, 0xCBEA6F8CEB02BB39}, // 1e58
|
||||
{0x02F236D04753D5B4, 0xFEE50B7025C36A08}, // 1e59
|
||||
{0x01D762422C946590, 0x9F4F2726179A2245}, // 1e60
|
||||
{0x424D3AD2B7B97EF5, 0xC722F0EF9D80AAD6}, // 1e61
|
||||
{0xD2E0898765A7DEB2, 0xF8EBAD2B84E0D58B}, // 1e62
|
||||
{0x63CC55F49F88EB2F, 0x9B934C3B330C8577}, // 1e63
|
||||
{0x3CBF6B71C76B25FB, 0xC2781F49FFCFA6D5}, // 1e64
|
||||
{0x8BEF464E3945EF7A, 0xF316271C7FC3908A}, // 1e65
|
||||
{0x97758BF0E3CBB5AC, 0x97EDD871CFDA3A56}, // 1e66
|
||||
{0x3D52EEED1CBEA317, 0xBDE94E8E43D0C8EC}, // 1e67
|
||||
{0x4CA7AAA863EE4BDD, 0xED63A231D4C4FB27}, // 1e68
|
||||
{0x8FE8CAA93E74EF6A, 0x945E455F24FB1CF8}, // 1e69
|
||||
{0xB3E2FD538E122B44, 0xB975D6B6EE39E436}, // 1e70
|
||||
{0x60DBBCA87196B616, 0xE7D34C64A9C85D44}, // 1e71
|
||||
{0xBC8955E946FE31CD, 0x90E40FBEEA1D3A4A}, // 1e72
|
||||
{0x6BABAB6398BDBE41, 0xB51D13AEA4A488DD}, // 1e73
|
||||
{0xC696963C7EED2DD1, 0xE264589A4DCDAB14}, // 1e74
|
||||
{0xFC1E1DE5CF543CA2, 0x8D7EB76070A08AEC}, // 1e75
|
||||
{0x3B25A55F43294BCB, 0xB0DE65388CC8ADA8}, // 1e76
|
||||
{0x49EF0EB713F39EBE, 0xDD15FE86AFFAD912}, // 1e77
|
||||
{0x6E3569326C784337, 0x8A2DBF142DFCC7AB}, // 1e78
|
||||
{0x49C2C37F07965404, 0xACB92ED9397BF996}, // 1e79
|
||||
{0xDC33745EC97BE906, 0xD7E77A8F87DAF7FB}, // 1e80
|
||||
{0x69A028BB3DED71A3, 0x86F0AC99B4E8DAFD}, // 1e81
|
||||
{0xC40832EA0D68CE0C, 0xA8ACD7C0222311BC}, // 1e82
|
||||
{0xF50A3FA490C30190, 0xD2D80DB02AABD62B}, // 1e83
|
||||
{0x792667C6DA79E0FA, 0x83C7088E1AAB65DB}, // 1e84
|
||||
{0x577001B891185938, 0xA4B8CAB1A1563F52}, // 1e85
|
||||
{0xED4C0226B55E6F86, 0xCDE6FD5E09ABCF26}, // 1e86
|
||||
{0x544F8158315B05B4, 0x80B05E5AC60B6178}, // 1e87
|
||||
{0x696361AE3DB1C721, 0xA0DC75F1778E39D6}, // 1e88
|
||||
{0x03BC3A19CD1E38E9, 0xC913936DD571C84C}, // 1e89
|
||||
{0x04AB48A04065C723, 0xFB5878494ACE3A5F}, // 1e90
|
||||
{0x62EB0D64283F9C76, 0x9D174B2DCEC0E47B}, // 1e91
|
||||
{0x3BA5D0BD324F8394, 0xC45D1DF942711D9A}, // 1e92
|
||||
{0xCA8F44EC7EE36479, 0xF5746577930D6500}, // 1e93
|
||||
{0x7E998B13CF4E1ECB, 0x9968BF6ABBE85F20}, // 1e94
|
||||
{0x9E3FEDD8C321A67E, 0xBFC2EF456AE276E8}, // 1e95
|
||||
{0xC5CFE94EF3EA101E, 0xEFB3AB16C59B14A2}, // 1e96
|
||||
{0xBBA1F1D158724A12, 0x95D04AEE3B80ECE5}, // 1e97
|
||||
{0x2A8A6E45AE8EDC97, 0xBB445DA9CA61281F}, // 1e98
|
||||
{0xF52D09D71A3293BD, 0xEA1575143CF97226}, // 1e99
|
||||
{0x593C2626705F9C56, 0x924D692CA61BE758}, // 1e100
|
||||
{0x6F8B2FB00C77836C, 0xB6E0C377CFA2E12E}, // 1e101
|
||||
{0x0B6DFB9C0F956447, 0xE498F455C38B997A}, // 1e102
|
||||
{0x4724BD4189BD5EAC, 0x8EDF98B59A373FEC}, // 1e103
|
||||
{0x58EDEC91EC2CB657, 0xB2977EE300C50FE7}, // 1e104
|
||||
{0x2F2967B66737E3ED, 0xDF3D5E9BC0F653E1}, // 1e105
|
||||
{0xBD79E0D20082EE74, 0x8B865B215899F46C}, // 1e106
|
||||
{0xECD8590680A3AA11, 0xAE67F1E9AEC07187}, // 1e107
|
||||
{0xE80E6F4820CC9495, 0xDA01EE641A708DE9}, // 1e108
|
||||
{0x3109058D147FDCDD, 0x884134FE908658B2}, // 1e109
|
||||
{0xBD4B46F0599FD415, 0xAA51823E34A7EEDE}, // 1e110
|
||||
{0x6C9E18AC7007C91A, 0xD4E5E2CDC1D1EA96}, // 1e111
|
||||
{0x03E2CF6BC604DDB0, 0x850FADC09923329E}, // 1e112
|
||||
{0x84DB8346B786151C, 0xA6539930BF6BFF45}, // 1e113
|
||||
{0xE612641865679A63, 0xCFE87F7CEF46FF16}, // 1e114
|
||||
{0x4FCB7E8F3F60C07E, 0x81F14FAE158C5F6E}, // 1e115
|
||||
{0xE3BE5E330F38F09D, 0xA26DA3999AEF7749}, // 1e116
|
||||
{0x5CADF5BFD3072CC5, 0xCB090C8001AB551C}, // 1e117
|
||||
{0x73D9732FC7C8F7F6, 0xFDCB4FA002162A63}, // 1e118
|
||||
{0x2867E7FDDCDD9AFA, 0x9E9F11C4014DDA7E}, // 1e119
|
||||
{0xB281E1FD541501B8, 0xC646D63501A1511D}, // 1e120
|
||||
{0x1F225A7CA91A4226, 0xF7D88BC24209A565}, // 1e121
|
||||
{0x3375788DE9B06958, 0x9AE757596946075F}, // 1e122
|
||||
{0x0052D6B1641C83AE, 0xC1A12D2FC3978937}, // 1e123
|
||||
{0xC0678C5DBD23A49A, 0xF209787BB47D6B84}, // 1e124
|
||||
{0xF840B7BA963646E0, 0x9745EB4D50CE6332}, // 1e125
|
||||
{0xB650E5A93BC3D898, 0xBD176620A501FBFF}, // 1e126
|
||||
{0xA3E51F138AB4CEBE, 0xEC5D3FA8CE427AFF}, // 1e127
|
||||
{0xC66F336C36B10137, 0x93BA47C980E98CDF}, // 1e128
|
||||
{0xB80B0047445D4184, 0xB8A8D9BBE123F017}, // 1e129
|
||||
{0xA60DC059157491E5, 0xE6D3102AD96CEC1D}, // 1e130
|
||||
{0x87C89837AD68DB2F, 0x9043EA1AC7E41392}, // 1e131
|
||||
{0x29BABE4598C311FB, 0xB454E4A179DD1877}, // 1e132
|
||||
{0xF4296DD6FEF3D67A, 0xE16A1DC9D8545E94}, // 1e133
|
||||
{0x1899E4A65F58660C, 0x8CE2529E2734BB1D}, // 1e134
|
||||
{0x5EC05DCFF72E7F8F, 0xB01AE745B101E9E4}, // 1e135
|
||||
{0x76707543F4FA1F73, 0xDC21A1171D42645D}, // 1e136
|
||||
{0x6A06494A791C53A8, 0x899504AE72497EBA}, // 1e137
|
||||
{0x0487DB9D17636892, 0xABFA45DA0EDBDE69}, // 1e138
|
||||
{0x45A9D2845D3C42B6, 0xD6F8D7509292D603}, // 1e139
|
||||
{0x0B8A2392BA45A9B2, 0x865B86925B9BC5C2}, // 1e140
|
||||
{0x8E6CAC7768D7141E, 0xA7F26836F282B732}, // 1e141
|
||||
{0x3207D795430CD926, 0xD1EF0244AF2364FF}, // 1e142
|
||||
{0x7F44E6BD49E807B8, 0x8335616AED761F1F}, // 1e143
|
||||
{0x5F16206C9C6209A6, 0xA402B9C5A8D3A6E7}, // 1e144
|
||||
{0x36DBA887C37A8C0F, 0xCD036837130890A1}, // 1e145
|
||||
{0xC2494954DA2C9789, 0x802221226BE55A64}, // 1e146
|
||||
{0xF2DB9BAA10B7BD6C, 0xA02AA96B06DEB0FD}, // 1e147
|
||||
{0x6F92829494E5ACC7, 0xC83553C5C8965D3D}, // 1e148
|
||||
{0xCB772339BA1F17F9, 0xFA42A8B73ABBF48C}, // 1e149
|
||||
{0xFF2A760414536EFB, 0x9C69A97284B578D7}, // 1e150
|
||||
{0xFEF5138519684ABA, 0xC38413CF25E2D70D}, // 1e151
|
||||
{0x7EB258665FC25D69, 0xF46518C2EF5B8CD1}, // 1e152
|
||||
{0xEF2F773FFBD97A61, 0x98BF2F79D5993802}, // 1e153
|
||||
{0xAAFB550FFACFD8FA, 0xBEEEFB584AFF8603}, // 1e154
|
||||
{0x95BA2A53F983CF38, 0xEEAABA2E5DBF6784}, // 1e155
|
||||
{0xDD945A747BF26183, 0x952AB45CFA97A0B2}, // 1e156
|
||||
{0x94F971119AEEF9E4, 0xBA756174393D88DF}, // 1e157
|
||||
{0x7A37CD5601AAB85D, 0xE912B9D1478CEB17}, // 1e158
|
||||
{0xAC62E055C10AB33A, 0x91ABB422CCB812EE}, // 1e159
|
||||
{0x577B986B314D6009, 0xB616A12B7FE617AA}, // 1e160
|
||||
{0xED5A7E85FDA0B80B, 0xE39C49765FDF9D94}, // 1e161
|
||||
{0x14588F13BE847307, 0x8E41ADE9FBEBC27D}, // 1e162
|
||||
{0x596EB2D8AE258FC8, 0xB1D219647AE6B31C}, // 1e163
|
||||
{0x6FCA5F8ED9AEF3BB, 0xDE469FBD99A05FE3}, // 1e164
|
||||
{0x25DE7BB9480D5854, 0x8AEC23D680043BEE}, // 1e165
|
||||
{0xAF561AA79A10AE6A, 0xADA72CCC20054AE9}, // 1e166
|
||||
{0x1B2BA1518094DA04, 0xD910F7FF28069DA4}, // 1e167
|
||||
{0x90FB44D2F05D0842, 0x87AA9AFF79042286}, // 1e168
|
||||
{0x353A1607AC744A53, 0xA99541BF57452B28}, // 1e169
|
||||
{0x42889B8997915CE8, 0xD3FA922F2D1675F2}, // 1e170
|
||||
{0x69956135FEBADA11, 0x847C9B5D7C2E09B7}, // 1e171
|
||||
{0x43FAB9837E699095, 0xA59BC234DB398C25}, // 1e172
|
||||
{0x94F967E45E03F4BB, 0xCF02B2C21207EF2E}, // 1e173
|
||||
{0x1D1BE0EEBAC278F5, 0x8161AFB94B44F57D}, // 1e174
|
||||
{0x6462D92A69731732, 0xA1BA1BA79E1632DC}, // 1e175
|
||||
{0x7D7B8F7503CFDCFE, 0xCA28A291859BBF93}, // 1e176
|
||||
{0x5CDA735244C3D43E, 0xFCB2CB35E702AF78}, // 1e177
|
||||
{0x3A0888136AFA64A7, 0x9DEFBF01B061ADAB}, // 1e178
|
||||
{0x088AAA1845B8FDD0, 0xC56BAEC21C7A1916}, // 1e179
|
||||
{0x8AAD549E57273D45, 0xF6C69A72A3989F5B}, // 1e180
|
||||
{0x36AC54E2F678864B, 0x9A3C2087A63F6399}, // 1e181
|
||||
{0x84576A1BB416A7DD, 0xC0CB28A98FCF3C7F}, // 1e182
|
||||
{0x656D44A2A11C51D5, 0xF0FDF2D3F3C30B9F}, // 1e183
|
||||
{0x9F644AE5A4B1B325, 0x969EB7C47859E743}, // 1e184
|
||||
{0x873D5D9F0DDE1FEE, 0xBC4665B596706114}, // 1e185
|
||||
{0xA90CB506D155A7EA, 0xEB57FF22FC0C7959}, // 1e186
|
||||
{0x09A7F12442D588F2, 0x9316FF75DD87CBD8}, // 1e187
|
||||
{0x0C11ED6D538AEB2F, 0xB7DCBF5354E9BECE}, // 1e188
|
||||
{0x8F1668C8A86DA5FA, 0xE5D3EF282A242E81}, // 1e189
|
||||
{0xF96E017D694487BC, 0x8FA475791A569D10}, // 1e190
|
||||
{0x37C981DCC395A9AC, 0xB38D92D760EC4455}, // 1e191
|
||||
{0x85BBE253F47B1417, 0xE070F78D3927556A}, // 1e192
|
||||
{0x93956D7478CCEC8E, 0x8C469AB843B89562}, // 1e193
|
||||
{0x387AC8D1970027B2, 0xAF58416654A6BABB}, // 1e194
|
||||
{0x06997B05FCC0319E, 0xDB2E51BFE9D0696A}, // 1e195
|
||||
{0x441FECE3BDF81F03, 0x88FCF317F22241E2}, // 1e196
|
||||
{0xD527E81CAD7626C3, 0xAB3C2FDDEEAAD25A}, // 1e197
|
||||
{0x8A71E223D8D3B074, 0xD60B3BD56A5586F1}, // 1e198
|
||||
{0xF6872D5667844E49, 0x85C7056562757456}, // 1e199
|
||||
{0xB428F8AC016561DB, 0xA738C6BEBB12D16C}, // 1e200
|
||||
{0xE13336D701BEBA52, 0xD106F86E69D785C7}, // 1e201
|
||||
{0xECC0024661173473, 0x82A45B450226B39C}, // 1e202
|
||||
{0x27F002D7F95D0190, 0xA34D721642B06084}, // 1e203
|
||||
{0x31EC038DF7B441F4, 0xCC20CE9BD35C78A5}, // 1e204
|
||||
{0x7E67047175A15271, 0xFF290242C83396CE}, // 1e205
|
||||
{0x0F0062C6E984D386, 0x9F79A169BD203E41}, // 1e206
|
||||
{0x52C07B78A3E60868, 0xC75809C42C684DD1}, // 1e207
|
||||
{0xA7709A56CCDF8A82, 0xF92E0C3537826145}, // 1e208
|
||||
{0x88A66076400BB691, 0x9BBCC7A142B17CCB}, // 1e209
|
||||
{0x6ACFF893D00EA435, 0xC2ABF989935DDBFE}, // 1e210
|
||||
{0x0583F6B8C4124D43, 0xF356F7EBF83552FE}, // 1e211
|
||||
{0xC3727A337A8B704A, 0x98165AF37B2153DE}, // 1e212
|
||||
{0x744F18C0592E4C5C, 0xBE1BF1B059E9A8D6}, // 1e213
|
||||
{0x1162DEF06F79DF73, 0xEDA2EE1C7064130C}, // 1e214
|
||||
{0x8ADDCB5645AC2BA8, 0x9485D4D1C63E8BE7}, // 1e215
|
||||
{0x6D953E2BD7173692, 0xB9A74A0637CE2EE1}, // 1e216
|
||||
{0xC8FA8DB6CCDD0437, 0xE8111C87C5C1BA99}, // 1e217
|
||||
{0x1D9C9892400A22A2, 0x910AB1D4DB9914A0}, // 1e218
|
||||
{0x2503BEB6D00CAB4B, 0xB54D5E4A127F59C8}, // 1e219
|
||||
{0x2E44AE64840FD61D, 0xE2A0B5DC971F303A}, // 1e220
|
||||
{0x5CEAECFED289E5D2, 0x8DA471A9DE737E24}, // 1e221
|
||||
{0x7425A83E872C5F47, 0xB10D8E1456105DAD}, // 1e222
|
||||
{0xD12F124E28F77719, 0xDD50F1996B947518}, // 1e223
|
||||
{0x82BD6B70D99AAA6F, 0x8A5296FFE33CC92F}, // 1e224
|
||||
{0x636CC64D1001550B, 0xACE73CBFDC0BFB7B}, // 1e225
|
||||
{0x3C47F7E05401AA4E, 0xD8210BEFD30EFA5A}, // 1e226
|
||||
{0x65ACFAEC34810A71, 0x8714A775E3E95C78}, // 1e227
|
||||
{0x7F1839A741A14D0D, 0xA8D9D1535CE3B396}, // 1e228
|
||||
{0x1EDE48111209A050, 0xD31045A8341CA07C}, // 1e229
|
||||
{0x934AED0AAB460432, 0x83EA2B892091E44D}, // 1e230
|
||||
{0xF81DA84D5617853F, 0xA4E4B66B68B65D60}, // 1e231
|
||||
{0x36251260AB9D668E, 0xCE1DE40642E3F4B9}, // 1e232
|
||||
{0xC1D72B7C6B426019, 0x80D2AE83E9CE78F3}, // 1e233
|
||||
{0xB24CF65B8612F81F, 0xA1075A24E4421730}, // 1e234
|
||||
{0xDEE033F26797B627, 0xC94930AE1D529CFC}, // 1e235
|
||||
{0x169840EF017DA3B1, 0xFB9B7CD9A4A7443C}, // 1e236
|
||||
{0x8E1F289560EE864E, 0x9D412E0806E88AA5}, // 1e237
|
||||
{0xF1A6F2BAB92A27E2, 0xC491798A08A2AD4E}, // 1e238
|
||||
{0xAE10AF696774B1DB, 0xF5B5D7EC8ACB58A2}, // 1e239
|
||||
{0xACCA6DA1E0A8EF29, 0x9991A6F3D6BF1765}, // 1e240
|
||||
{0x17FD090A58D32AF3, 0xBFF610B0CC6EDD3F}, // 1e241
|
||||
{0xDDFC4B4CEF07F5B0, 0xEFF394DCFF8A948E}, // 1e242
|
||||
{0x4ABDAF101564F98E, 0x95F83D0A1FB69CD9}, // 1e243
|
||||
{0x9D6D1AD41ABE37F1, 0xBB764C4CA7A4440F}, // 1e244
|
||||
{0x84C86189216DC5ED, 0xEA53DF5FD18D5513}, // 1e245
|
||||
{0x32FD3CF5B4E49BB4, 0x92746B9BE2F8552C}, // 1e246
|
||||
{0x3FBC8C33221DC2A1, 0xB7118682DBB66A77}, // 1e247
|
||||
{0x0FABAF3FEAA5334A, 0xE4D5E82392A40515}, // 1e248
|
||||
{0x29CB4D87F2A7400E, 0x8F05B1163BA6832D}, // 1e249
|
||||
{0x743E20E9EF511012, 0xB2C71D5BCA9023F8}, // 1e250
|
||||
{0x914DA9246B255416, 0xDF78E4B2BD342CF6}, // 1e251
|
||||
{0x1AD089B6C2F7548E, 0x8BAB8EEFB6409C1A}, // 1e252
|
||||
{0xA184AC2473B529B1, 0xAE9672ABA3D0C320}, // 1e253
|
||||
{0xC9E5D72D90A2741E, 0xDA3C0F568CC4F3E8}, // 1e254
|
||||
{0x7E2FA67C7A658892, 0x8865899617FB1871}, // 1e255
|
||||
{0xDDBB901B98FEEAB7, 0xAA7EEBFB9DF9DE8D}, // 1e256
|
||||
{0x552A74227F3EA565, 0xD51EA6FA85785631}, // 1e257
|
||||
{0xD53A88958F87275F, 0x8533285C936B35DE}, // 1e258
|
||||
{0x8A892ABAF368F137, 0xA67FF273B8460356}, // 1e259
|
||||
{0x2D2B7569B0432D85, 0xD01FEF10A657842C}, // 1e260
|
||||
{0x9C3B29620E29FC73, 0x8213F56A67F6B29B}, // 1e261
|
||||
{0x8349F3BA91B47B8F, 0xA298F2C501F45F42}, // 1e262
|
||||
{0x241C70A936219A73, 0xCB3F2F7642717713}, // 1e263
|
||||
{0xED238CD383AA0110, 0xFE0EFB53D30DD4D7}, // 1e264
|
||||
{0xF4363804324A40AA, 0x9EC95D1463E8A506}, // 1e265
|
||||
{0xB143C6053EDCD0D5, 0xC67BB4597CE2CE48}, // 1e266
|
||||
{0xDD94B7868E94050A, 0xF81AA16FDC1B81DA}, // 1e267
|
||||
{0xCA7CF2B4191C8326, 0x9B10A4E5E9913128}, // 1e268
|
||||
{0xFD1C2F611F63A3F0, 0xC1D4CE1F63F57D72}, // 1e269
|
||||
{0xBC633B39673C8CEC, 0xF24A01A73CF2DCCF}, // 1e270
|
||||
{0xD5BE0503E085D813, 0x976E41088617CA01}, // 1e271
|
||||
{0x4B2D8644D8A74E18, 0xBD49D14AA79DBC82}, // 1e272
|
||||
{0xDDF8E7D60ED1219E, 0xEC9C459D51852BA2}, // 1e273
|
||||
{0xCABB90E5C942B503, 0x93E1AB8252F33B45}, // 1e274
|
||||
{0x3D6A751F3B936243, 0xB8DA1662E7B00A17}, // 1e275
|
||||
{0x0CC512670A783AD4, 0xE7109BFBA19C0C9D}, // 1e276
|
||||
{0x27FB2B80668B24C5, 0x906A617D450187E2}, // 1e277
|
||||
{0xB1F9F660802DEDF6, 0xB484F9DC9641E9DA}, // 1e278
|
||||
{0x5E7873F8A0396973, 0xE1A63853BBD26451}, // 1e279
|
||||
{0xDB0B487B6423E1E8, 0x8D07E33455637EB2}, // 1e280
|
||||
{0x91CE1A9A3D2CDA62, 0xB049DC016ABC5E5F}, // 1e281
|
||||
{0x7641A140CC7810FB, 0xDC5C5301C56B75F7}, // 1e282
|
||||
{0xA9E904C87FCB0A9D, 0x89B9B3E11B6329BA}, // 1e283
|
||||
{0x546345FA9FBDCD44, 0xAC2820D9623BF429}, // 1e284
|
||||
{0xA97C177947AD4095, 0xD732290FBACAF133}, // 1e285
|
||||
{0x49ED8EABCCCC485D, 0x867F59A9D4BED6C0}, // 1e286
|
||||
{0x5C68F256BFFF5A74, 0xA81F301449EE8C70}, // 1e287
|
||||
{0x73832EEC6FFF3111, 0xD226FC195C6A2F8C}, // 1e288
|
||||
static const uint64_t wuffs_private_impl__powers_of_10[596][2] = {
|
||||
{0xA5D3B6D479F8E056, 0x8FD0C16206306BAB}, // 1e-307
|
||||
{0x8F48A4899877186C, 0xB3C4F1BA87BC8696}, // 1e-306
|
||||
{0x331ACDABFE94DE87, 0xE0B62E2929ABA83C}, // 1e-305
|
||||
{0x9FF0C08B7F1D0B14, 0x8C71DCD9BA0B4925}, // 1e-304
|
||||
{0x07ECF0AE5EE44DD9, 0xAF8E5410288E1B6F}, // 1e-303
|
||||
{0xC9E82CD9F69D6150, 0xDB71E91432B1A24A}, // 1e-302
|
||||
{0xBE311C083A225CD2, 0x892731AC9FAF056E}, // 1e-301
|
||||
{0x6DBD630A48AAF406, 0xAB70FE17C79AC6CA}, // 1e-300
|
||||
{0x092CBBCCDAD5B108, 0xD64D3D9DB981787D}, // 1e-299
|
||||
{0x25BBF56008C58EA5, 0x85F0468293F0EB4E}, // 1e-298
|
||||
{0xAF2AF2B80AF6F24E, 0xA76C582338ED2621}, // 1e-297
|
||||
{0x1AF5AF660DB4AEE1, 0xD1476E2C07286FAA}, // 1e-296
|
||||
{0x50D98D9FC890ED4D, 0x82CCA4DB847945CA}, // 1e-295
|
||||
{0xE50FF107BAB528A0, 0xA37FCE126597973C}, // 1e-294
|
||||
{0x1E53ED49A96272C8, 0xCC5FC196FEFD7D0C}, // 1e-293
|
||||
{0x25E8E89C13BB0F7A, 0xFF77B1FCBEBCDC4F}, // 1e-292
|
||||
{0x77B191618C54E9AC, 0x9FAACF3DF73609B1}, // 1e-291
|
||||
{0xD59DF5B9EF6A2417, 0xC795830D75038C1D}, // 1e-290
|
||||
{0x4B0573286B44AD1D, 0xF97AE3D0D2446F25}, // 1e-289
|
||||
{0x4EE367F9430AEC32, 0x9BECCE62836AC577}, // 1e-288
|
||||
{0x229C41F793CDA73F, 0xC2E801FB244576D5}, // 1e-287
|
||||
{0x6B43527578C1110F, 0xF3A20279ED56D48A}, // 1e-286
|
||||
{0x830A13896B78AAA9, 0x9845418C345644D6}, // 1e-285
|
||||
{0x23CC986BC656D553, 0xBE5691EF416BD60C}, // 1e-284
|
||||
{0x2CBFBE86B7EC8AA8, 0xEDEC366B11C6CB8F}, // 1e-283
|
||||
{0x7BF7D71432F3D6A9, 0x94B3A202EB1C3F39}, // 1e-282
|
||||
{0xDAF5CCD93FB0CC53, 0xB9E08A83A5E34F07}, // 1e-281
|
||||
{0xD1B3400F8F9CFF68, 0xE858AD248F5C22C9}, // 1e-280
|
||||
{0x23100809B9C21FA1, 0x91376C36D99995BE}, // 1e-279
|
||||
{0xABD40A0C2832A78A, 0xB58547448FFFFB2D}, // 1e-278
|
||||
{0x16C90C8F323F516C, 0xE2E69915B3FFF9F9}, // 1e-277
|
||||
{0xAE3DA7D97F6792E3, 0x8DD01FAD907FFC3B}, // 1e-276
|
||||
{0x99CD11CFDF41779C, 0xB1442798F49FFB4A}, // 1e-275
|
||||
{0x40405643D711D583, 0xDD95317F31C7FA1D}, // 1e-274
|
||||
{0x482835EA666B2572, 0x8A7D3EEF7F1CFC52}, // 1e-273
|
||||
{0xDA3243650005EECF, 0xAD1C8EAB5EE43B66}, // 1e-272
|
||||
{0x90BED43E40076A82, 0xD863B256369D4A40}, // 1e-271
|
||||
{0x5A7744A6E804A291, 0x873E4F75E2224E68}, // 1e-270
|
||||
{0x711515D0A205CB36, 0xA90DE3535AAAE202}, // 1e-269
|
||||
{0x0D5A5B44CA873E03, 0xD3515C2831559A83}, // 1e-268
|
||||
{0xE858790AFE9486C2, 0x8412D9991ED58091}, // 1e-267
|
||||
{0x626E974DBE39A872, 0xA5178FFF668AE0B6}, // 1e-266
|
||||
{0xFB0A3D212DC8128F, 0xCE5D73FF402D98E3}, // 1e-265
|
||||
{0x7CE66634BC9D0B99, 0x80FA687F881C7F8E}, // 1e-264
|
||||
{0x1C1FFFC1EBC44E80, 0xA139029F6A239F72}, // 1e-263
|
||||
{0xA327FFB266B56220, 0xC987434744AC874E}, // 1e-262
|
||||
{0x4BF1FF9F0062BAA8, 0xFBE9141915D7A922}, // 1e-261
|
||||
{0x6F773FC3603DB4A9, 0x9D71AC8FADA6C9B5}, // 1e-260
|
||||
{0xCB550FB4384D21D3, 0xC4CE17B399107C22}, // 1e-259
|
||||
{0x7E2A53A146606A48, 0xF6019DA07F549B2B}, // 1e-258
|
||||
{0x2EDA7444CBFC426D, 0x99C102844F94E0FB}, // 1e-257
|
||||
{0xFA911155FEFB5308, 0xC0314325637A1939}, // 1e-256
|
||||
{0x793555AB7EBA27CA, 0xF03D93EEBC589F88}, // 1e-255
|
||||
{0x4BC1558B2F3458DE, 0x96267C7535B763B5}, // 1e-254
|
||||
{0x9EB1AAEDFB016F16, 0xBBB01B9283253CA2}, // 1e-253
|
||||
{0x465E15A979C1CADC, 0xEA9C227723EE8BCB}, // 1e-252
|
||||
{0x0BFACD89EC191EC9, 0x92A1958A7675175F}, // 1e-251
|
||||
{0xCEF980EC671F667B, 0xB749FAED14125D36}, // 1e-250
|
||||
{0x82B7E12780E7401A, 0xE51C79A85916F484}, // 1e-249
|
||||
{0xD1B2ECB8B0908810, 0x8F31CC0937AE58D2}, // 1e-248
|
||||
{0x861FA7E6DCB4AA15, 0xB2FE3F0B8599EF07}, // 1e-247
|
||||
{0x67A791E093E1D49A, 0xDFBDCECE67006AC9}, // 1e-246
|
||||
{0xE0C8BB2C5C6D24E0, 0x8BD6A141006042BD}, // 1e-245
|
||||
{0x58FAE9F773886E18, 0xAECC49914078536D}, // 1e-244
|
||||
{0xAF39A475506A899E, 0xDA7F5BF590966848}, // 1e-243
|
||||
{0x6D8406C952429603, 0x888F99797A5E012D}, // 1e-242
|
||||
{0xC8E5087BA6D33B83, 0xAAB37FD7D8F58178}, // 1e-241
|
||||
{0xFB1E4A9A90880A64, 0xD5605FCDCF32E1D6}, // 1e-240
|
||||
{0x5CF2EEA09A55067F, 0x855C3BE0A17FCD26}, // 1e-239
|
||||
{0xF42FAA48C0EA481E, 0xA6B34AD8C9DFC06F}, // 1e-238
|
||||
{0xF13B94DAF124DA26, 0xD0601D8EFC57B08B}, // 1e-237
|
||||
{0x76C53D08D6B70858, 0x823C12795DB6CE57}, // 1e-236
|
||||
{0x54768C4B0C64CA6E, 0xA2CB1717B52481ED}, // 1e-235
|
||||
{0xA9942F5DCF7DFD09, 0xCB7DDCDDA26DA268}, // 1e-234
|
||||
{0xD3F93B35435D7C4C, 0xFE5D54150B090B02}, // 1e-233
|
||||
{0xC47BC5014A1A6DAF, 0x9EFA548D26E5A6E1}, // 1e-232
|
||||
{0x359AB6419CA1091B, 0xC6B8E9B0709F109A}, // 1e-231
|
||||
{0xC30163D203C94B62, 0xF867241C8CC6D4C0}, // 1e-230
|
||||
{0x79E0DE63425DCF1D, 0x9B407691D7FC44F8}, // 1e-229
|
||||
{0x985915FC12F542E4, 0xC21094364DFB5636}, // 1e-228
|
||||
{0x3E6F5B7B17B2939D, 0xF294B943E17A2BC4}, // 1e-227
|
||||
{0xA705992CEECF9C42, 0x979CF3CA6CEC5B5A}, // 1e-226
|
||||
{0x50C6FF782A838353, 0xBD8430BD08277231}, // 1e-225
|
||||
{0xA4F8BF5635246428, 0xECE53CEC4A314EBD}, // 1e-224
|
||||
{0x871B7795E136BE99, 0x940F4613AE5ED136}, // 1e-223
|
||||
{0x28E2557B59846E3F, 0xB913179899F68584}, // 1e-222
|
||||
{0x331AEADA2FE589CF, 0xE757DD7EC07426E5}, // 1e-221
|
||||
{0x3FF0D2C85DEF7621, 0x9096EA6F3848984F}, // 1e-220
|
||||
{0x0FED077A756B53A9, 0xB4BCA50B065ABE63}, // 1e-219
|
||||
{0xD3E8495912C62894, 0xE1EBCE4DC7F16DFB}, // 1e-218
|
||||
{0x64712DD7ABBBD95C, 0x8D3360F09CF6E4BD}, // 1e-217
|
||||
{0xBD8D794D96AACFB3, 0xB080392CC4349DEC}, // 1e-216
|
||||
{0xECF0D7A0FC5583A0, 0xDCA04777F541C567}, // 1e-215
|
||||
{0xF41686C49DB57244, 0x89E42CAAF9491B60}, // 1e-214
|
||||
{0x311C2875C522CED5, 0xAC5D37D5B79B6239}, // 1e-213
|
||||
{0x7D633293366B828B, 0xD77485CB25823AC7}, // 1e-212
|
||||
{0xAE5DFF9C02033197, 0x86A8D39EF77164BC}, // 1e-211
|
||||
{0xD9F57F830283FDFC, 0xA8530886B54DBDEB}, // 1e-210
|
||||
{0xD072DF63C324FD7B, 0xD267CAA862A12D66}, // 1e-209
|
||||
{0x4247CB9E59F71E6D, 0x8380DEA93DA4BC60}, // 1e-208
|
||||
{0x52D9BE85F074E608, 0xA46116538D0DEB78}, // 1e-207
|
||||
{0x67902E276C921F8B, 0xCD795BE870516656}, // 1e-206
|
||||
{0x00BA1CD8A3DB53B6, 0x806BD9714632DFF6}, // 1e-205
|
||||
{0x80E8A40ECCD228A4, 0xA086CFCD97BF97F3}, // 1e-204
|
||||
{0x6122CD128006B2CD, 0xC8A883C0FDAF7DF0}, // 1e-203
|
||||
{0x796B805720085F81, 0xFAD2A4B13D1B5D6C}, // 1e-202
|
||||
{0xCBE3303674053BB0, 0x9CC3A6EEC6311A63}, // 1e-201
|
||||
{0xBEDBFC4411068A9C, 0xC3F490AA77BD60FC}, // 1e-200
|
||||
{0xEE92FB5515482D44, 0xF4F1B4D515ACB93B}, // 1e-199
|
||||
{0x751BDD152D4D1C4A, 0x991711052D8BF3C5}, // 1e-198
|
||||
{0xD262D45A78A0635D, 0xBF5CD54678EEF0B6}, // 1e-197
|
||||
{0x86FB897116C87C34, 0xEF340A98172AACE4}, // 1e-196
|
||||
{0xD45D35E6AE3D4DA0, 0x9580869F0E7AAC0E}, // 1e-195
|
||||
{0x8974836059CCA109, 0xBAE0A846D2195712}, // 1e-194
|
||||
{0x2BD1A438703FC94B, 0xE998D258869FACD7}, // 1e-193
|
||||
{0x7B6306A34627DDCF, 0x91FF83775423CC06}, // 1e-192
|
||||
{0x1A3BC84C17B1D542, 0xB67F6455292CBF08}, // 1e-191
|
||||
{0x20CABA5F1D9E4A93, 0xE41F3D6A7377EECA}, // 1e-190
|
||||
{0x547EB47B7282EE9C, 0x8E938662882AF53E}, // 1e-189
|
||||
{0xE99E619A4F23AA43, 0xB23867FB2A35B28D}, // 1e-188
|
||||
{0x6405FA00E2EC94D4, 0xDEC681F9F4C31F31}, // 1e-187
|
||||
{0xDE83BC408DD3DD04, 0x8B3C113C38F9F37E}, // 1e-186
|
||||
{0x9624AB50B148D445, 0xAE0B158B4738705E}, // 1e-185
|
||||
{0x3BADD624DD9B0957, 0xD98DDAEE19068C76}, // 1e-184
|
||||
{0xE54CA5D70A80E5D6, 0x87F8A8D4CFA417C9}, // 1e-183
|
||||
{0x5E9FCF4CCD211F4C, 0xA9F6D30A038D1DBC}, // 1e-182
|
||||
{0x7647C3200069671F, 0xD47487CC8470652B}, // 1e-181
|
||||
{0x29ECD9F40041E073, 0x84C8D4DFD2C63F3B}, // 1e-180
|
||||
{0xF468107100525890, 0xA5FB0A17C777CF09}, // 1e-179
|
||||
{0x7182148D4066EEB4, 0xCF79CC9DB955C2CC}, // 1e-178
|
||||
{0xC6F14CD848405530, 0x81AC1FE293D599BF}, // 1e-177
|
||||
{0xB8ADA00E5A506A7C, 0xA21727DB38CB002F}, // 1e-176
|
||||
{0xA6D90811F0E4851C, 0xCA9CF1D206FDC03B}, // 1e-175
|
||||
{0x908F4A166D1DA663, 0xFD442E4688BD304A}, // 1e-174
|
||||
{0x9A598E4E043287FE, 0x9E4A9CEC15763E2E}, // 1e-173
|
||||
{0x40EFF1E1853F29FD, 0xC5DD44271AD3CDBA}, // 1e-172
|
||||
{0xD12BEE59E68EF47C, 0xF7549530E188C128}, // 1e-171
|
||||
{0x82BB74F8301958CE, 0x9A94DD3E8CF578B9}, // 1e-170
|
||||
{0xE36A52363C1FAF01, 0xC13A148E3032D6E7}, // 1e-169
|
||||
{0xDC44E6C3CB279AC1, 0xF18899B1BC3F8CA1}, // 1e-168
|
||||
{0x29AB103A5EF8C0B9, 0x96F5600F15A7B7E5}, // 1e-167
|
||||
{0x7415D448F6B6F0E7, 0xBCB2B812DB11A5DE}, // 1e-166
|
||||
{0x111B495B3464AD21, 0xEBDF661791D60F56}, // 1e-165
|
||||
{0xCAB10DD900BEEC34, 0x936B9FCEBB25C995}, // 1e-164
|
||||
{0x3D5D514F40EEA742, 0xB84687C269EF3BFB}, // 1e-163
|
||||
{0x0CB4A5A3112A5112, 0xE65829B3046B0AFA}, // 1e-162
|
||||
{0x47F0E785EABA72AB, 0x8FF71A0FE2C2E6DC}, // 1e-161
|
||||
{0x59ED216765690F56, 0xB3F4E093DB73A093}, // 1e-160
|
||||
{0x306869C13EC3532C, 0xE0F218B8D25088B8}, // 1e-159
|
||||
{0x1E414218C73A13FB, 0x8C974F7383725573}, // 1e-158
|
||||
{0xE5D1929EF90898FA, 0xAFBD2350644EEACF}, // 1e-157
|
||||
{0xDF45F746B74ABF39, 0xDBAC6C247D62A583}, // 1e-156
|
||||
{0x6B8BBA8C328EB783, 0x894BC396CE5DA772}, // 1e-155
|
||||
{0x066EA92F3F326564, 0xAB9EB47C81F5114F}, // 1e-154
|
||||
{0xC80A537B0EFEFEBD, 0xD686619BA27255A2}, // 1e-153
|
||||
{0xBD06742CE95F5F36, 0x8613FD0145877585}, // 1e-152
|
||||
{0x2C48113823B73704, 0xA798FC4196E952E7}, // 1e-151
|
||||
{0xF75A15862CA504C5, 0xD17F3B51FCA3A7A0}, // 1e-150
|
||||
{0x9A984D73DBE722FB, 0x82EF85133DE648C4}, // 1e-149
|
||||
{0xC13E60D0D2E0EBBA, 0xA3AB66580D5FDAF5}, // 1e-148
|
||||
{0x318DF905079926A8, 0xCC963FEE10B7D1B3}, // 1e-147
|
||||
{0xFDF17746497F7052, 0xFFBBCFE994E5C61F}, // 1e-146
|
||||
{0xFEB6EA8BEDEFA633, 0x9FD561F1FD0F9BD3}, // 1e-145
|
||||
{0xFE64A52EE96B8FC0, 0xC7CABA6E7C5382C8}, // 1e-144
|
||||
{0x3DFDCE7AA3C673B0, 0xF9BD690A1B68637B}, // 1e-143
|
||||
{0x06BEA10CA65C084E, 0x9C1661A651213E2D}, // 1e-142
|
||||
{0x486E494FCFF30A62, 0xC31BFA0FE5698DB8}, // 1e-141
|
||||
{0x5A89DBA3C3EFCCFA, 0xF3E2F893DEC3F126}, // 1e-140
|
||||
{0xF89629465A75E01C, 0x986DDB5C6B3A76B7}, // 1e-139
|
||||
{0xF6BBB397F1135823, 0xBE89523386091465}, // 1e-138
|
||||
{0x746AA07DED582E2C, 0xEE2BA6C0678B597F}, // 1e-137
|
||||
{0xA8C2A44EB4571CDC, 0x94DB483840B717EF}, // 1e-136
|
||||
{0x92F34D62616CE413, 0xBA121A4650E4DDEB}, // 1e-135
|
||||
{0x77B020BAF9C81D17, 0xE896A0D7E51E1566}, // 1e-134
|
||||
{0x0ACE1474DC1D122E, 0x915E2486EF32CD60}, // 1e-133
|
||||
{0x0D819992132456BA, 0xB5B5ADA8AAFF80B8}, // 1e-132
|
||||
{0x10E1FFF697ED6C69, 0xE3231912D5BF60E6}, // 1e-131
|
||||
{0xCA8D3FFA1EF463C1, 0x8DF5EFABC5979C8F}, // 1e-130
|
||||
{0xBD308FF8A6B17CB2, 0xB1736B96B6FD83B3}, // 1e-129
|
||||
{0xAC7CB3F6D05DDBDE, 0xDDD0467C64BCE4A0}, // 1e-128
|
||||
{0x6BCDF07A423AA96B, 0x8AA22C0DBEF60EE4}, // 1e-127
|
||||
{0x86C16C98D2C953C6, 0xAD4AB7112EB3929D}, // 1e-126
|
||||
{0xE871C7BF077BA8B7, 0xD89D64D57A607744}, // 1e-125
|
||||
{0x11471CD764AD4972, 0x87625F056C7C4A8B}, // 1e-124
|
||||
{0xD598E40D3DD89BCF, 0xA93AF6C6C79B5D2D}, // 1e-123
|
||||
{0x4AFF1D108D4EC2C3, 0xD389B47879823479}, // 1e-122
|
||||
{0xCEDF722A585139BA, 0x843610CB4BF160CB}, // 1e-121
|
||||
{0xC2974EB4EE658828, 0xA54394FE1EEDB8FE}, // 1e-120
|
||||
{0x733D226229FEEA32, 0xCE947A3DA6A9273E}, // 1e-119
|
||||
{0x0806357D5A3F525F, 0x811CCC668829B887}, // 1e-118
|
||||
{0xCA07C2DCB0CF26F7, 0xA163FF802A3426A8}, // 1e-117
|
||||
{0xFC89B393DD02F0B5, 0xC9BCFF6034C13052}, // 1e-116
|
||||
{0xBBAC2078D443ACE2, 0xFC2C3F3841F17C67}, // 1e-115
|
||||
{0xD54B944B84AA4C0D, 0x9D9BA7832936EDC0}, // 1e-114
|
||||
{0x0A9E795E65D4DF11, 0xC5029163F384A931}, // 1e-113
|
||||
{0x4D4617B5FF4A16D5, 0xF64335BCF065D37D}, // 1e-112
|
||||
{0x504BCED1BF8E4E45, 0x99EA0196163FA42E}, // 1e-111
|
||||
{0xE45EC2862F71E1D6, 0xC06481FB9BCF8D39}, // 1e-110
|
||||
{0x5D767327BB4E5A4C, 0xF07DA27A82C37088}, // 1e-109
|
||||
{0x3A6A07F8D510F86F, 0x964E858C91BA2655}, // 1e-108
|
||||
{0x890489F70A55368B, 0xBBE226EFB628AFEA}, // 1e-107
|
||||
{0x2B45AC74CCEA842E, 0xEADAB0ABA3B2DBE5}, // 1e-106
|
||||
{0x3B0B8BC90012929D, 0x92C8AE6B464FC96F}, // 1e-105
|
||||
{0x09CE6EBB40173744, 0xB77ADA0617E3BBCB}, // 1e-104
|
||||
{0xCC420A6A101D0515, 0xE55990879DDCAABD}, // 1e-103
|
||||
{0x9FA946824A12232D, 0x8F57FA54C2A9EAB6}, // 1e-102
|
||||
{0x47939822DC96ABF9, 0xB32DF8E9F3546564}, // 1e-101
|
||||
{0x59787E2B93BC56F7, 0xDFF9772470297EBD}, // 1e-100
|
||||
{0x57EB4EDB3C55B65A, 0x8BFBEA76C619EF36}, // 1e-99
|
||||
{0xEDE622920B6B23F1, 0xAEFAE51477A06B03}, // 1e-98
|
||||
{0xE95FAB368E45ECED, 0xDAB99E59958885C4}, // 1e-97
|
||||
{0x11DBCB0218EBB414, 0x88B402F7FD75539B}, // 1e-96
|
||||
{0xD652BDC29F26A119, 0xAAE103B5FCD2A881}, // 1e-95
|
||||
{0x4BE76D3346F0495F, 0xD59944A37C0752A2}, // 1e-94
|
||||
{0x6F70A4400C562DDB, 0x857FCAE62D8493A5}, // 1e-93
|
||||
{0xCB4CCD500F6BB952, 0xA6DFBD9FB8E5B88E}, // 1e-92
|
||||
{0x7E2000A41346A7A7, 0xD097AD07A71F26B2}, // 1e-91
|
||||
{0x8ED400668C0C28C8, 0x825ECC24C873782F}, // 1e-90
|
||||
{0x728900802F0F32FA, 0xA2F67F2DFA90563B}, // 1e-89
|
||||
{0x4F2B40A03AD2FFB9, 0xCBB41EF979346BCA}, // 1e-88
|
||||
{0xE2F610C84987BFA8, 0xFEA126B7D78186BC}, // 1e-87
|
||||
{0x0DD9CA7D2DF4D7C9, 0x9F24B832E6B0F436}, // 1e-86
|
||||
{0x91503D1C79720DBB, 0xC6EDE63FA05D3143}, // 1e-85
|
||||
{0x75A44C6397CE912A, 0xF8A95FCF88747D94}, // 1e-84
|
||||
{0xC986AFBE3EE11ABA, 0x9B69DBE1B548CE7C}, // 1e-83
|
||||
{0xFBE85BADCE996168, 0xC24452DA229B021B}, // 1e-82
|
||||
{0xFAE27299423FB9C3, 0xF2D56790AB41C2A2}, // 1e-81
|
||||
{0xDCCD879FC967D41A, 0x97C560BA6B0919A5}, // 1e-80
|
||||
{0x5400E987BBC1C920, 0xBDB6B8E905CB600F}, // 1e-79
|
||||
{0x290123E9AAB23B68, 0xED246723473E3813}, // 1e-78
|
||||
{0xF9A0B6720AAF6521, 0x9436C0760C86E30B}, // 1e-77
|
||||
{0xF808E40E8D5B3E69, 0xB94470938FA89BCE}, // 1e-76
|
||||
{0xB60B1D1230B20E04, 0xE7958CB87392C2C2}, // 1e-75
|
||||
{0xB1C6F22B5E6F48C2, 0x90BD77F3483BB9B9}, // 1e-74
|
||||
{0x1E38AEB6360B1AF3, 0xB4ECD5F01A4AA828}, // 1e-73
|
||||
{0x25C6DA63C38DE1B0, 0xE2280B6C20DD5232}, // 1e-72
|
||||
{0x579C487E5A38AD0E, 0x8D590723948A535F}, // 1e-71
|
||||
{0x2D835A9DF0C6D851, 0xB0AF48EC79ACE837}, // 1e-70
|
||||
{0xF8E431456CF88E65, 0xDCDB1B2798182244}, // 1e-69
|
||||
{0x1B8E9ECB641B58FF, 0x8A08F0F8BF0F156B}, // 1e-68
|
||||
{0xE272467E3D222F3F, 0xAC8B2D36EED2DAC5}, // 1e-67
|
||||
{0x5B0ED81DCC6ABB0F, 0xD7ADF884AA879177}, // 1e-66
|
||||
{0x98E947129FC2B4E9, 0x86CCBB52EA94BAEA}, // 1e-65
|
||||
{0x3F2398D747B36224, 0xA87FEA27A539E9A5}, // 1e-64
|
||||
{0x8EEC7F0D19A03AAD, 0xD29FE4B18E88640E}, // 1e-63
|
||||
{0x1953CF68300424AC, 0x83A3EEEEF9153E89}, // 1e-62
|
||||
{0x5FA8C3423C052DD7, 0xA48CEAAAB75A8E2B}, // 1e-61
|
||||
{0x3792F412CB06794D, 0xCDB02555653131B6}, // 1e-60
|
||||
{0xE2BBD88BBEE40BD0, 0x808E17555F3EBF11}, // 1e-59
|
||||
{0x5B6ACEAEAE9D0EC4, 0xA0B19D2AB70E6ED6}, // 1e-58
|
||||
{0xF245825A5A445275, 0xC8DE047564D20A8B}, // 1e-57
|
||||
{0xEED6E2F0F0D56712, 0xFB158592BE068D2E}, // 1e-56
|
||||
{0x55464DD69685606B, 0x9CED737BB6C4183D}, // 1e-55
|
||||
{0xAA97E14C3C26B886, 0xC428D05AA4751E4C}, // 1e-54
|
||||
{0xD53DD99F4B3066A8, 0xF53304714D9265DF}, // 1e-53
|
||||
{0xE546A8038EFE4029, 0x993FE2C6D07B7FAB}, // 1e-52
|
||||
{0xDE98520472BDD033, 0xBF8FDB78849A5F96}, // 1e-51
|
||||
{0x963E66858F6D4440, 0xEF73D256A5C0F77C}, // 1e-50
|
||||
{0xDDE7001379A44AA8, 0x95A8637627989AAD}, // 1e-49
|
||||
{0x5560C018580D5D52, 0xBB127C53B17EC159}, // 1e-48
|
||||
{0xAAB8F01E6E10B4A6, 0xE9D71B689DDE71AF}, // 1e-47
|
||||
{0xCAB3961304CA70E8, 0x9226712162AB070D}, // 1e-46
|
||||
{0x3D607B97C5FD0D22, 0xB6B00D69BB55C8D1}, // 1e-45
|
||||
{0x8CB89A7DB77C506A, 0xE45C10C42A2B3B05}, // 1e-44
|
||||
{0x77F3608E92ADB242, 0x8EB98A7A9A5B04E3}, // 1e-43
|
||||
{0x55F038B237591ED3, 0xB267ED1940F1C61C}, // 1e-42
|
||||
{0x6B6C46DEC52F6688, 0xDF01E85F912E37A3}, // 1e-41
|
||||
{0x2323AC4B3B3DA015, 0x8B61313BBABCE2C6}, // 1e-40
|
||||
{0xABEC975E0A0D081A, 0xAE397D8AA96C1B77}, // 1e-39
|
||||
{0x96E7BD358C904A21, 0xD9C7DCED53C72255}, // 1e-38
|
||||
{0x7E50D64177DA2E54, 0x881CEA14545C7575}, // 1e-37
|
||||
{0xDDE50BD1D5D0B9E9, 0xAA242499697392D2}, // 1e-36
|
||||
{0x955E4EC64B44E864, 0xD4AD2DBFC3D07787}, // 1e-35
|
||||
{0xBD5AF13BEF0B113E, 0x84EC3C97DA624AB4}, // 1e-34
|
||||
{0xECB1AD8AEACDD58E, 0xA6274BBDD0FADD61}, // 1e-33
|
||||
{0x67DE18EDA5814AF2, 0xCFB11EAD453994BA}, // 1e-32
|
||||
{0x80EACF948770CED7, 0x81CEB32C4B43FCF4}, // 1e-31
|
||||
{0xA1258379A94D028D, 0xA2425FF75E14FC31}, // 1e-30
|
||||
{0x096EE45813A04330, 0xCAD2F7F5359A3B3E}, // 1e-29
|
||||
{0x8BCA9D6E188853FC, 0xFD87B5F28300CA0D}, // 1e-28
|
||||
{0x775EA264CF55347D, 0x9E74D1B791E07E48}, // 1e-27
|
||||
{0x95364AFE032A819D, 0xC612062576589DDA}, // 1e-26
|
||||
{0x3A83DDBD83F52204, 0xF79687AED3EEC551}, // 1e-25
|
||||
{0xC4926A9672793542, 0x9ABE14CD44753B52}, // 1e-24
|
||||
{0x75B7053C0F178293, 0xC16D9A0095928A27}, // 1e-23
|
||||
{0x5324C68B12DD6338, 0xF1C90080BAF72CB1}, // 1e-22
|
||||
{0xD3F6FC16EBCA5E03, 0x971DA05074DA7BEE}, // 1e-21
|
||||
{0x88F4BB1CA6BCF584, 0xBCE5086492111AEA}, // 1e-20
|
||||
{0x2B31E9E3D06C32E5, 0xEC1E4A7DB69561A5}, // 1e-19
|
||||
{0x3AFF322E62439FCF, 0x9392EE8E921D5D07}, // 1e-18
|
||||
{0x09BEFEB9FAD487C2, 0xB877AA3236A4B449}, // 1e-17
|
||||
{0x4C2EBE687989A9B3, 0xE69594BEC44DE15B}, // 1e-16
|
||||
{0x0F9D37014BF60A10, 0x901D7CF73AB0ACD9}, // 1e-15
|
||||
{0x538484C19EF38C94, 0xB424DC35095CD80F}, // 1e-14
|
||||
{0x2865A5F206B06FB9, 0xE12E13424BB40E13}, // 1e-13
|
||||
{0xF93F87B7442E45D3, 0x8CBCCC096F5088CB}, // 1e-12
|
||||
{0xF78F69A51539D748, 0xAFEBFF0BCB24AAFE}, // 1e-11
|
||||
{0xB573440E5A884D1B, 0xDBE6FECEBDEDD5BE}, // 1e-10
|
||||
{0x31680A88F8953030, 0x89705F4136B4A597}, // 1e-9
|
||||
{0xFDC20D2B36BA7C3D, 0xABCC77118461CEFC}, // 1e-8
|
||||
{0x3D32907604691B4C, 0xD6BF94D5E57A42BC}, // 1e-7
|
||||
{0xA63F9A49C2C1B10F, 0x8637BD05AF6C69B5}, // 1e-6
|
||||
{0x0FCF80DC33721D53, 0xA7C5AC471B478423}, // 1e-5
|
||||
{0xD3C36113404EA4A8, 0xD1B71758E219652B}, // 1e-4
|
||||
{0x645A1CAC083126E9, 0x83126E978D4FDF3B}, // 1e-3
|
||||
{0x3D70A3D70A3D70A3, 0xA3D70A3D70A3D70A}, // 1e-2
|
||||
{0xCCCCCCCCCCCCCCCC, 0xCCCCCCCCCCCCCCCC}, // 1e-1
|
||||
{0x0000000000000000, 0x8000000000000000}, // 1e0
|
||||
{0x0000000000000000, 0xA000000000000000}, // 1e1
|
||||
{0x0000000000000000, 0xC800000000000000}, // 1e2
|
||||
{0x0000000000000000, 0xFA00000000000000}, // 1e3
|
||||
{0x0000000000000000, 0x9C40000000000000}, // 1e4
|
||||
{0x0000000000000000, 0xC350000000000000}, // 1e5
|
||||
{0x0000000000000000, 0xF424000000000000}, // 1e6
|
||||
{0x0000000000000000, 0x9896800000000000}, // 1e7
|
||||
{0x0000000000000000, 0xBEBC200000000000}, // 1e8
|
||||
{0x0000000000000000, 0xEE6B280000000000}, // 1e9
|
||||
{0x0000000000000000, 0x9502F90000000000}, // 1e10
|
||||
{0x0000000000000000, 0xBA43B74000000000}, // 1e11
|
||||
{0x0000000000000000, 0xE8D4A51000000000}, // 1e12
|
||||
{0x0000000000000000, 0x9184E72A00000000}, // 1e13
|
||||
{0x0000000000000000, 0xB5E620F480000000}, // 1e14
|
||||
{0x0000000000000000, 0xE35FA931A0000000}, // 1e15
|
||||
{0x0000000000000000, 0x8E1BC9BF04000000}, // 1e16
|
||||
{0x0000000000000000, 0xB1A2BC2EC5000000}, // 1e17
|
||||
{0x0000000000000000, 0xDE0B6B3A76400000}, // 1e18
|
||||
{0x0000000000000000, 0x8AC7230489E80000}, // 1e19
|
||||
{0x0000000000000000, 0xAD78EBC5AC620000}, // 1e20
|
||||
{0x0000000000000000, 0xD8D726B7177A8000}, // 1e21
|
||||
{0x0000000000000000, 0x878678326EAC9000}, // 1e22
|
||||
{0x0000000000000000, 0xA968163F0A57B400}, // 1e23
|
||||
{0x0000000000000000, 0xD3C21BCECCEDA100}, // 1e24
|
||||
{0x0000000000000000, 0x84595161401484A0}, // 1e25
|
||||
{0x0000000000000000, 0xA56FA5B99019A5C8}, // 1e26
|
||||
{0x0000000000000000, 0xCECB8F27F4200F3A}, // 1e27
|
||||
{0x4000000000000000, 0x813F3978F8940984}, // 1e28
|
||||
{0x5000000000000000, 0xA18F07D736B90BE5}, // 1e29
|
||||
{0xA400000000000000, 0xC9F2C9CD04674EDE}, // 1e30
|
||||
{0x4D00000000000000, 0xFC6F7C4045812296}, // 1e31
|
||||
{0xF020000000000000, 0x9DC5ADA82B70B59D}, // 1e32
|
||||
{0x6C28000000000000, 0xC5371912364CE305}, // 1e33
|
||||
{0xC732000000000000, 0xF684DF56C3E01BC6}, // 1e34
|
||||
{0x3C7F400000000000, 0x9A130B963A6C115C}, // 1e35
|
||||
{0x4B9F100000000000, 0xC097CE7BC90715B3}, // 1e36
|
||||
{0x1E86D40000000000, 0xF0BDC21ABB48DB20}, // 1e37
|
||||
{0x1314448000000000, 0x96769950B50D88F4}, // 1e38
|
||||
{0x17D955A000000000, 0xBC143FA4E250EB31}, // 1e39
|
||||
{0x5DCFAB0800000000, 0xEB194F8E1AE525FD}, // 1e40
|
||||
{0x5AA1CAE500000000, 0x92EFD1B8D0CF37BE}, // 1e41
|
||||
{0xF14A3D9E40000000, 0xB7ABC627050305AD}, // 1e42
|
||||
{0x6D9CCD05D0000000, 0xE596B7B0C643C719}, // 1e43
|
||||
{0xE4820023A2000000, 0x8F7E32CE7BEA5C6F}, // 1e44
|
||||
{0xDDA2802C8A800000, 0xB35DBF821AE4F38B}, // 1e45
|
||||
{0xD50B2037AD200000, 0xE0352F62A19E306E}, // 1e46
|
||||
{0x4526F422CC340000, 0x8C213D9DA502DE45}, // 1e47
|
||||
{0x9670B12B7F410000, 0xAF298D050E4395D6}, // 1e48
|
||||
{0x3C0CDD765F114000, 0xDAF3F04651D47B4C}, // 1e49
|
||||
{0xA5880A69FB6AC800, 0x88D8762BF324CD0F}, // 1e50
|
||||
{0x8EEA0D047A457A00, 0xAB0E93B6EFEE0053}, // 1e51
|
||||
{0x72A4904598D6D880, 0xD5D238A4ABE98068}, // 1e52
|
||||
{0x47A6DA2B7F864750, 0x85A36366EB71F041}, // 1e53
|
||||
{0x999090B65F67D924, 0xA70C3C40A64E6C51}, // 1e54
|
||||
{0xFFF4B4E3F741CF6D, 0xD0CF4B50CFE20765}, // 1e55
|
||||
{0xBFF8F10E7A8921A4, 0x82818F1281ED449F}, // 1e56
|
||||
{0xAFF72D52192B6A0D, 0xA321F2D7226895C7}, // 1e57
|
||||
{0x9BF4F8A69F764490, 0xCBEA6F8CEB02BB39}, // 1e58
|
||||
{0x02F236D04753D5B4, 0xFEE50B7025C36A08}, // 1e59
|
||||
{0x01D762422C946590, 0x9F4F2726179A2245}, // 1e60
|
||||
{0x424D3AD2B7B97EF5, 0xC722F0EF9D80AAD6}, // 1e61
|
||||
{0xD2E0898765A7DEB2, 0xF8EBAD2B84E0D58B}, // 1e62
|
||||
{0x63CC55F49F88EB2F, 0x9B934C3B330C8577}, // 1e63
|
||||
{0x3CBF6B71C76B25FB, 0xC2781F49FFCFA6D5}, // 1e64
|
||||
{0x8BEF464E3945EF7A, 0xF316271C7FC3908A}, // 1e65
|
||||
{0x97758BF0E3CBB5AC, 0x97EDD871CFDA3A56}, // 1e66
|
||||
{0x3D52EEED1CBEA317, 0xBDE94E8E43D0C8EC}, // 1e67
|
||||
{0x4CA7AAA863EE4BDD, 0xED63A231D4C4FB27}, // 1e68
|
||||
{0x8FE8CAA93E74EF6A, 0x945E455F24FB1CF8}, // 1e69
|
||||
{0xB3E2FD538E122B44, 0xB975D6B6EE39E436}, // 1e70
|
||||
{0x60DBBCA87196B616, 0xE7D34C64A9C85D44}, // 1e71
|
||||
{0xBC8955E946FE31CD, 0x90E40FBEEA1D3A4A}, // 1e72
|
||||
{0x6BABAB6398BDBE41, 0xB51D13AEA4A488DD}, // 1e73
|
||||
{0xC696963C7EED2DD1, 0xE264589A4DCDAB14}, // 1e74
|
||||
{0xFC1E1DE5CF543CA2, 0x8D7EB76070A08AEC}, // 1e75
|
||||
{0x3B25A55F43294BCB, 0xB0DE65388CC8ADA8}, // 1e76
|
||||
{0x49EF0EB713F39EBE, 0xDD15FE86AFFAD912}, // 1e77
|
||||
{0x6E3569326C784337, 0x8A2DBF142DFCC7AB}, // 1e78
|
||||
{0x49C2C37F07965404, 0xACB92ED9397BF996}, // 1e79
|
||||
{0xDC33745EC97BE906, 0xD7E77A8F87DAF7FB}, // 1e80
|
||||
{0x69A028BB3DED71A3, 0x86F0AC99B4E8DAFD}, // 1e81
|
||||
{0xC40832EA0D68CE0C, 0xA8ACD7C0222311BC}, // 1e82
|
||||
{0xF50A3FA490C30190, 0xD2D80DB02AABD62B}, // 1e83
|
||||
{0x792667C6DA79E0FA, 0x83C7088E1AAB65DB}, // 1e84
|
||||
{0x577001B891185938, 0xA4B8CAB1A1563F52}, // 1e85
|
||||
{0xED4C0226B55E6F86, 0xCDE6FD5E09ABCF26}, // 1e86
|
||||
{0x544F8158315B05B4, 0x80B05E5AC60B6178}, // 1e87
|
||||
{0x696361AE3DB1C721, 0xA0DC75F1778E39D6}, // 1e88
|
||||
{0x03BC3A19CD1E38E9, 0xC913936DD571C84C}, // 1e89
|
||||
{0x04AB48A04065C723, 0xFB5878494ACE3A5F}, // 1e90
|
||||
{0x62EB0D64283F9C76, 0x9D174B2DCEC0E47B}, // 1e91
|
||||
{0x3BA5D0BD324F8394, 0xC45D1DF942711D9A}, // 1e92
|
||||
{0xCA8F44EC7EE36479, 0xF5746577930D6500}, // 1e93
|
||||
{0x7E998B13CF4E1ECB, 0x9968BF6ABBE85F20}, // 1e94
|
||||
{0x9E3FEDD8C321A67E, 0xBFC2EF456AE276E8}, // 1e95
|
||||
{0xC5CFE94EF3EA101E, 0xEFB3AB16C59B14A2}, // 1e96
|
||||
{0xBBA1F1D158724A12, 0x95D04AEE3B80ECE5}, // 1e97
|
||||
{0x2A8A6E45AE8EDC97, 0xBB445DA9CA61281F}, // 1e98
|
||||
{0xF52D09D71A3293BD, 0xEA1575143CF97226}, // 1e99
|
||||
{0x593C2626705F9C56, 0x924D692CA61BE758}, // 1e100
|
||||
{0x6F8B2FB00C77836C, 0xB6E0C377CFA2E12E}, // 1e101
|
||||
{0x0B6DFB9C0F956447, 0xE498F455C38B997A}, // 1e102
|
||||
{0x4724BD4189BD5EAC, 0x8EDF98B59A373FEC}, // 1e103
|
||||
{0x58EDEC91EC2CB657, 0xB2977EE300C50FE7}, // 1e104
|
||||
{0x2F2967B66737E3ED, 0xDF3D5E9BC0F653E1}, // 1e105
|
||||
{0xBD79E0D20082EE74, 0x8B865B215899F46C}, // 1e106
|
||||
{0xECD8590680A3AA11, 0xAE67F1E9AEC07187}, // 1e107
|
||||
{0xE80E6F4820CC9495, 0xDA01EE641A708DE9}, // 1e108
|
||||
{0x3109058D147FDCDD, 0x884134FE908658B2}, // 1e109
|
||||
{0xBD4B46F0599FD415, 0xAA51823E34A7EEDE}, // 1e110
|
||||
{0x6C9E18AC7007C91A, 0xD4E5E2CDC1D1EA96}, // 1e111
|
||||
{0x03E2CF6BC604DDB0, 0x850FADC09923329E}, // 1e112
|
||||
{0x84DB8346B786151C, 0xA6539930BF6BFF45}, // 1e113
|
||||
{0xE612641865679A63, 0xCFE87F7CEF46FF16}, // 1e114
|
||||
{0x4FCB7E8F3F60C07E, 0x81F14FAE158C5F6E}, // 1e115
|
||||
{0xE3BE5E330F38F09D, 0xA26DA3999AEF7749}, // 1e116
|
||||
{0x5CADF5BFD3072CC5, 0xCB090C8001AB551C}, // 1e117
|
||||
{0x73D9732FC7C8F7F6, 0xFDCB4FA002162A63}, // 1e118
|
||||
{0x2867E7FDDCDD9AFA, 0x9E9F11C4014DDA7E}, // 1e119
|
||||
{0xB281E1FD541501B8, 0xC646D63501A1511D}, // 1e120
|
||||
{0x1F225A7CA91A4226, 0xF7D88BC24209A565}, // 1e121
|
||||
{0x3375788DE9B06958, 0x9AE757596946075F}, // 1e122
|
||||
{0x0052D6B1641C83AE, 0xC1A12D2FC3978937}, // 1e123
|
||||
{0xC0678C5DBD23A49A, 0xF209787BB47D6B84}, // 1e124
|
||||
{0xF840B7BA963646E0, 0x9745EB4D50CE6332}, // 1e125
|
||||
{0xB650E5A93BC3D898, 0xBD176620A501FBFF}, // 1e126
|
||||
{0xA3E51F138AB4CEBE, 0xEC5D3FA8CE427AFF}, // 1e127
|
||||
{0xC66F336C36B10137, 0x93BA47C980E98CDF}, // 1e128
|
||||
{0xB80B0047445D4184, 0xB8A8D9BBE123F017}, // 1e129
|
||||
{0xA60DC059157491E5, 0xE6D3102AD96CEC1D}, // 1e130
|
||||
{0x87C89837AD68DB2F, 0x9043EA1AC7E41392}, // 1e131
|
||||
{0x29BABE4598C311FB, 0xB454E4A179DD1877}, // 1e132
|
||||
{0xF4296DD6FEF3D67A, 0xE16A1DC9D8545E94}, // 1e133
|
||||
{0x1899E4A65F58660C, 0x8CE2529E2734BB1D}, // 1e134
|
||||
{0x5EC05DCFF72E7F8F, 0xB01AE745B101E9E4}, // 1e135
|
||||
{0x76707543F4FA1F73, 0xDC21A1171D42645D}, // 1e136
|
||||
{0x6A06494A791C53A8, 0x899504AE72497EBA}, // 1e137
|
||||
{0x0487DB9D17636892, 0xABFA45DA0EDBDE69}, // 1e138
|
||||
{0x45A9D2845D3C42B6, 0xD6F8D7509292D603}, // 1e139
|
||||
{0x0B8A2392BA45A9B2, 0x865B86925B9BC5C2}, // 1e140
|
||||
{0x8E6CAC7768D7141E, 0xA7F26836F282B732}, // 1e141
|
||||
{0x3207D795430CD926, 0xD1EF0244AF2364FF}, // 1e142
|
||||
{0x7F44E6BD49E807B8, 0x8335616AED761F1F}, // 1e143
|
||||
{0x5F16206C9C6209A6, 0xA402B9C5A8D3A6E7}, // 1e144
|
||||
{0x36DBA887C37A8C0F, 0xCD036837130890A1}, // 1e145
|
||||
{0xC2494954DA2C9789, 0x802221226BE55A64}, // 1e146
|
||||
{0xF2DB9BAA10B7BD6C, 0xA02AA96B06DEB0FD}, // 1e147
|
||||
{0x6F92829494E5ACC7, 0xC83553C5C8965D3D}, // 1e148
|
||||
{0xCB772339BA1F17F9, 0xFA42A8B73ABBF48C}, // 1e149
|
||||
{0xFF2A760414536EFB, 0x9C69A97284B578D7}, // 1e150
|
||||
{0xFEF5138519684ABA, 0xC38413CF25E2D70D}, // 1e151
|
||||
{0x7EB258665FC25D69, 0xF46518C2EF5B8CD1}, // 1e152
|
||||
{0xEF2F773FFBD97A61, 0x98BF2F79D5993802}, // 1e153
|
||||
{0xAAFB550FFACFD8FA, 0xBEEEFB584AFF8603}, // 1e154
|
||||
{0x95BA2A53F983CF38, 0xEEAABA2E5DBF6784}, // 1e155
|
||||
{0xDD945A747BF26183, 0x952AB45CFA97A0B2}, // 1e156
|
||||
{0x94F971119AEEF9E4, 0xBA756174393D88DF}, // 1e157
|
||||
{0x7A37CD5601AAB85D, 0xE912B9D1478CEB17}, // 1e158
|
||||
{0xAC62E055C10AB33A, 0x91ABB422CCB812EE}, // 1e159
|
||||
{0x577B986B314D6009, 0xB616A12B7FE617AA}, // 1e160
|
||||
{0xED5A7E85FDA0B80B, 0xE39C49765FDF9D94}, // 1e161
|
||||
{0x14588F13BE847307, 0x8E41ADE9FBEBC27D}, // 1e162
|
||||
{0x596EB2D8AE258FC8, 0xB1D219647AE6B31C}, // 1e163
|
||||
{0x6FCA5F8ED9AEF3BB, 0xDE469FBD99A05FE3}, // 1e164
|
||||
{0x25DE7BB9480D5854, 0x8AEC23D680043BEE}, // 1e165
|
||||
{0xAF561AA79A10AE6A, 0xADA72CCC20054AE9}, // 1e166
|
||||
{0x1B2BA1518094DA04, 0xD910F7FF28069DA4}, // 1e167
|
||||
{0x90FB44D2F05D0842, 0x87AA9AFF79042286}, // 1e168
|
||||
{0x353A1607AC744A53, 0xA99541BF57452B28}, // 1e169
|
||||
{0x42889B8997915CE8, 0xD3FA922F2D1675F2}, // 1e170
|
||||
{0x69956135FEBADA11, 0x847C9B5D7C2E09B7}, // 1e171
|
||||
{0x43FAB9837E699095, 0xA59BC234DB398C25}, // 1e172
|
||||
{0x94F967E45E03F4BB, 0xCF02B2C21207EF2E}, // 1e173
|
||||
{0x1D1BE0EEBAC278F5, 0x8161AFB94B44F57D}, // 1e174
|
||||
{0x6462D92A69731732, 0xA1BA1BA79E1632DC}, // 1e175
|
||||
{0x7D7B8F7503CFDCFE, 0xCA28A291859BBF93}, // 1e176
|
||||
{0x5CDA735244C3D43E, 0xFCB2CB35E702AF78}, // 1e177
|
||||
{0x3A0888136AFA64A7, 0x9DEFBF01B061ADAB}, // 1e178
|
||||
{0x088AAA1845B8FDD0, 0xC56BAEC21C7A1916}, // 1e179
|
||||
{0x8AAD549E57273D45, 0xF6C69A72A3989F5B}, // 1e180
|
||||
{0x36AC54E2F678864B, 0x9A3C2087A63F6399}, // 1e181
|
||||
{0x84576A1BB416A7DD, 0xC0CB28A98FCF3C7F}, // 1e182
|
||||
{0x656D44A2A11C51D5, 0xF0FDF2D3F3C30B9F}, // 1e183
|
||||
{0x9F644AE5A4B1B325, 0x969EB7C47859E743}, // 1e184
|
||||
{0x873D5D9F0DDE1FEE, 0xBC4665B596706114}, // 1e185
|
||||
{0xA90CB506D155A7EA, 0xEB57FF22FC0C7959}, // 1e186
|
||||
{0x09A7F12442D588F2, 0x9316FF75DD87CBD8}, // 1e187
|
||||
{0x0C11ED6D538AEB2F, 0xB7DCBF5354E9BECE}, // 1e188
|
||||
{0x8F1668C8A86DA5FA, 0xE5D3EF282A242E81}, // 1e189
|
||||
{0xF96E017D694487BC, 0x8FA475791A569D10}, // 1e190
|
||||
{0x37C981DCC395A9AC, 0xB38D92D760EC4455}, // 1e191
|
||||
{0x85BBE253F47B1417, 0xE070F78D3927556A}, // 1e192
|
||||
{0x93956D7478CCEC8E, 0x8C469AB843B89562}, // 1e193
|
||||
{0x387AC8D1970027B2, 0xAF58416654A6BABB}, // 1e194
|
||||
{0x06997B05FCC0319E, 0xDB2E51BFE9D0696A}, // 1e195
|
||||
{0x441FECE3BDF81F03, 0x88FCF317F22241E2}, // 1e196
|
||||
{0xD527E81CAD7626C3, 0xAB3C2FDDEEAAD25A}, // 1e197
|
||||
{0x8A71E223D8D3B074, 0xD60B3BD56A5586F1}, // 1e198
|
||||
{0xF6872D5667844E49, 0x85C7056562757456}, // 1e199
|
||||
{0xB428F8AC016561DB, 0xA738C6BEBB12D16C}, // 1e200
|
||||
{0xE13336D701BEBA52, 0xD106F86E69D785C7}, // 1e201
|
||||
{0xECC0024661173473, 0x82A45B450226B39C}, // 1e202
|
||||
{0x27F002D7F95D0190, 0xA34D721642B06084}, // 1e203
|
||||
{0x31EC038DF7B441F4, 0xCC20CE9BD35C78A5}, // 1e204
|
||||
{0x7E67047175A15271, 0xFF290242C83396CE}, // 1e205
|
||||
{0x0F0062C6E984D386, 0x9F79A169BD203E41}, // 1e206
|
||||
{0x52C07B78A3E60868, 0xC75809C42C684DD1}, // 1e207
|
||||
{0xA7709A56CCDF8A82, 0xF92E0C3537826145}, // 1e208
|
||||
{0x88A66076400BB691, 0x9BBCC7A142B17CCB}, // 1e209
|
||||
{0x6ACFF893D00EA435, 0xC2ABF989935DDBFE}, // 1e210
|
||||
{0x0583F6B8C4124D43, 0xF356F7EBF83552FE}, // 1e211
|
||||
{0xC3727A337A8B704A, 0x98165AF37B2153DE}, // 1e212
|
||||
{0x744F18C0592E4C5C, 0xBE1BF1B059E9A8D6}, // 1e213
|
||||
{0x1162DEF06F79DF73, 0xEDA2EE1C7064130C}, // 1e214
|
||||
{0x8ADDCB5645AC2BA8, 0x9485D4D1C63E8BE7}, // 1e215
|
||||
{0x6D953E2BD7173692, 0xB9A74A0637CE2EE1}, // 1e216
|
||||
{0xC8FA8DB6CCDD0437, 0xE8111C87C5C1BA99}, // 1e217
|
||||
{0x1D9C9892400A22A2, 0x910AB1D4DB9914A0}, // 1e218
|
||||
{0x2503BEB6D00CAB4B, 0xB54D5E4A127F59C8}, // 1e219
|
||||
{0x2E44AE64840FD61D, 0xE2A0B5DC971F303A}, // 1e220
|
||||
{0x5CEAECFED289E5D2, 0x8DA471A9DE737E24}, // 1e221
|
||||
{0x7425A83E872C5F47, 0xB10D8E1456105DAD}, // 1e222
|
||||
{0xD12F124E28F77719, 0xDD50F1996B947518}, // 1e223
|
||||
{0x82BD6B70D99AAA6F, 0x8A5296FFE33CC92F}, // 1e224
|
||||
{0x636CC64D1001550B, 0xACE73CBFDC0BFB7B}, // 1e225
|
||||
{0x3C47F7E05401AA4E, 0xD8210BEFD30EFA5A}, // 1e226
|
||||
{0x65ACFAEC34810A71, 0x8714A775E3E95C78}, // 1e227
|
||||
{0x7F1839A741A14D0D, 0xA8D9D1535CE3B396}, // 1e228
|
||||
{0x1EDE48111209A050, 0xD31045A8341CA07C}, // 1e229
|
||||
{0x934AED0AAB460432, 0x83EA2B892091E44D}, // 1e230
|
||||
{0xF81DA84D5617853F, 0xA4E4B66B68B65D60}, // 1e231
|
||||
{0x36251260AB9D668E, 0xCE1DE40642E3F4B9}, // 1e232
|
||||
{0xC1D72B7C6B426019, 0x80D2AE83E9CE78F3}, // 1e233
|
||||
{0xB24CF65B8612F81F, 0xA1075A24E4421730}, // 1e234
|
||||
{0xDEE033F26797B627, 0xC94930AE1D529CFC}, // 1e235
|
||||
{0x169840EF017DA3B1, 0xFB9B7CD9A4A7443C}, // 1e236
|
||||
{0x8E1F289560EE864E, 0x9D412E0806E88AA5}, // 1e237
|
||||
{0xF1A6F2BAB92A27E2, 0xC491798A08A2AD4E}, // 1e238
|
||||
{0xAE10AF696774B1DB, 0xF5B5D7EC8ACB58A2}, // 1e239
|
||||
{0xACCA6DA1E0A8EF29, 0x9991A6F3D6BF1765}, // 1e240
|
||||
{0x17FD090A58D32AF3, 0xBFF610B0CC6EDD3F}, // 1e241
|
||||
{0xDDFC4B4CEF07F5B0, 0xEFF394DCFF8A948E}, // 1e242
|
||||
{0x4ABDAF101564F98E, 0x95F83D0A1FB69CD9}, // 1e243
|
||||
{0x9D6D1AD41ABE37F1, 0xBB764C4CA7A4440F}, // 1e244
|
||||
{0x84C86189216DC5ED, 0xEA53DF5FD18D5513}, // 1e245
|
||||
{0x32FD3CF5B4E49BB4, 0x92746B9BE2F8552C}, // 1e246
|
||||
{0x3FBC8C33221DC2A1, 0xB7118682DBB66A77}, // 1e247
|
||||
{0x0FABAF3FEAA5334A, 0xE4D5E82392A40515}, // 1e248
|
||||
{0x29CB4D87F2A7400E, 0x8F05B1163BA6832D}, // 1e249
|
||||
{0x743E20E9EF511012, 0xB2C71D5BCA9023F8}, // 1e250
|
||||
{0x914DA9246B255416, 0xDF78E4B2BD342CF6}, // 1e251
|
||||
{0x1AD089B6C2F7548E, 0x8BAB8EEFB6409C1A}, // 1e252
|
||||
{0xA184AC2473B529B1, 0xAE9672ABA3D0C320}, // 1e253
|
||||
{0xC9E5D72D90A2741E, 0xDA3C0F568CC4F3E8}, // 1e254
|
||||
{0x7E2FA67C7A658892, 0x8865899617FB1871}, // 1e255
|
||||
{0xDDBB901B98FEEAB7, 0xAA7EEBFB9DF9DE8D}, // 1e256
|
||||
{0x552A74227F3EA565, 0xD51EA6FA85785631}, // 1e257
|
||||
{0xD53A88958F87275F, 0x8533285C936B35DE}, // 1e258
|
||||
{0x8A892ABAF368F137, 0xA67FF273B8460356}, // 1e259
|
||||
{0x2D2B7569B0432D85, 0xD01FEF10A657842C}, // 1e260
|
||||
{0x9C3B29620E29FC73, 0x8213F56A67F6B29B}, // 1e261
|
||||
{0x8349F3BA91B47B8F, 0xA298F2C501F45F42}, // 1e262
|
||||
{0x241C70A936219A73, 0xCB3F2F7642717713}, // 1e263
|
||||
{0xED238CD383AA0110, 0xFE0EFB53D30DD4D7}, // 1e264
|
||||
{0xF4363804324A40AA, 0x9EC95D1463E8A506}, // 1e265
|
||||
{0xB143C6053EDCD0D5, 0xC67BB4597CE2CE48}, // 1e266
|
||||
{0xDD94B7868E94050A, 0xF81AA16FDC1B81DA}, // 1e267
|
||||
{0xCA7CF2B4191C8326, 0x9B10A4E5E9913128}, // 1e268
|
||||
{0xFD1C2F611F63A3F0, 0xC1D4CE1F63F57D72}, // 1e269
|
||||
{0xBC633B39673C8CEC, 0xF24A01A73CF2DCCF}, // 1e270
|
||||
{0xD5BE0503E085D813, 0x976E41088617CA01}, // 1e271
|
||||
{0x4B2D8644D8A74E18, 0xBD49D14AA79DBC82}, // 1e272
|
||||
{0xDDF8E7D60ED1219E, 0xEC9C459D51852BA2}, // 1e273
|
||||
{0xCABB90E5C942B503, 0x93E1AB8252F33B45}, // 1e274
|
||||
{0x3D6A751F3B936243, 0xB8DA1662E7B00A17}, // 1e275
|
||||
{0x0CC512670A783AD4, 0xE7109BFBA19C0C9D}, // 1e276
|
||||
{0x27FB2B80668B24C5, 0x906A617D450187E2}, // 1e277
|
||||
{0xB1F9F660802DEDF6, 0xB484F9DC9641E9DA}, // 1e278
|
||||
{0x5E7873F8A0396973, 0xE1A63853BBD26451}, // 1e279
|
||||
{0xDB0B487B6423E1E8, 0x8D07E33455637EB2}, // 1e280
|
||||
{0x91CE1A9A3D2CDA62, 0xB049DC016ABC5E5F}, // 1e281
|
||||
{0x7641A140CC7810FB, 0xDC5C5301C56B75F7}, // 1e282
|
||||
{0xA9E904C87FCB0A9D, 0x89B9B3E11B6329BA}, // 1e283
|
||||
{0x546345FA9FBDCD44, 0xAC2820D9623BF429}, // 1e284
|
||||
{0xA97C177947AD4095, 0xD732290FBACAF133}, // 1e285
|
||||
{0x49ED8EABCCCC485D, 0x867F59A9D4BED6C0}, // 1e286
|
||||
{0x5C68F256BFFF5A74, 0xA81F301449EE8C70}, // 1e287
|
||||
{0x73832EEC6FFF3111, 0xD226FC195C6A2F8C}, // 1e288
|
||||
};
|
||||
|
||||
// wuffs_base__private_implementation__f64_powers_of_10 holds powers of 10 that
|
||||
// can be exactly represented by a float64 (what C calls a double).
|
||||
static const double wuffs_base__private_implementation__f64_powers_of_10[23] = {
|
||||
// wuffs_private_impl__f64_powers_of_10 holds powers of 10 that can be exactly
|
||||
// represented by a float64 (what C calls a double).
|
||||
static const double wuffs_private_impl__f64_powers_of_10[23] = {
|
||||
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
|
||||
1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22,
|
||||
};
|
||||
@@ -57,27 +57,13 @@
|
||||
|
||||
// --------
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
static inline uint8_t* //
|
||||
wuffs_base__strip_const_from_u8_ptr(const uint8_t* ptr) {
|
||||
return (uint8_t*)ptr;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// --------
|
||||
|
||||
static inline wuffs_base__empty_struct //
|
||||
wuffs_base__ignore_status(wuffs_base__status z) {
|
||||
wuffs_private_impl__ignore_status(wuffs_base__status z) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
static inline wuffs_base__status //
|
||||
wuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) {
|
||||
wuffs_private_impl__status__ensure_not_a_suspension(wuffs_base__status z) {
|
||||
if (z.repr && (*z.repr == '$')) {
|
||||
z.repr = wuffs_base__error__cannot_return_a_suspension;
|
||||
}
|
||||
@@ -86,9 +72,10 @@ wuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) {
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__iterate_total_advance returns the exclusive pointer-offset at
|
||||
// which iteration should stop. The overall slice has length total_len, each
|
||||
// iteration's sub-slice has length iter_len and are placed iter_advance apart.
|
||||
// wuffs_private_impl__iterate_total_advance returns the exclusive
|
||||
// pointer-offset at which iteration should stop. The overall slice has length
|
||||
// total_len, each iteration's sub-slice has length iter_len and are placed
|
||||
// iter_advance apart.
|
||||
//
|
||||
// The iter_advance may not be larger than iter_len. The iter_advance may be
|
||||
// smaller than iter_len, in which case the sub-slices will overlap.
|
||||
@@ -116,9 +103,9 @@ wuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) {
|
||||
// $
|
||||
// 0123456789012345
|
||||
static inline size_t //
|
||||
wuffs_base__iterate_total_advance(size_t total_len,
|
||||
size_t iter_len,
|
||||
size_t iter_advance) {
|
||||
wuffs_private_impl__iterate_total_advance(size_t total_len,
|
||||
size_t iter_len,
|
||||
size_t iter_advance) {
|
||||
if (total_len >= iter_len) {
|
||||
size_t n = total_len - iter_len;
|
||||
return ((n / iter_advance) * iter_advance) + iter_advance;
|
||||
@@ -128,60 +115,67 @@ wuffs_base__iterate_total_advance(size_t total_len,
|
||||
|
||||
// ---------------- Numeric Types
|
||||
|
||||
extern const uint8_t wuffs_base__low_bits_mask__u8[8];
|
||||
extern const uint16_t wuffs_base__low_bits_mask__u16[16];
|
||||
extern const uint32_t wuffs_base__low_bits_mask__u32[32];
|
||||
extern const uint64_t wuffs_base__low_bits_mask__u64[64];
|
||||
extern const uint8_t wuffs_private_impl__low_bits_mask__u8[8];
|
||||
extern const uint16_t wuffs_private_impl__low_bits_mask__u16[16];
|
||||
extern const uint32_t wuffs_private_impl__low_bits_mask__u32[32];
|
||||
extern const uint64_t wuffs_private_impl__low_bits_mask__u64[64];
|
||||
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U8(n) (wuffs_base__low_bits_mask__u8[n])
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U16(n) (wuffs_base__low_bits_mask__u16[n])
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U32(n) (wuffs_base__low_bits_mask__u32[n])
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U64(n) (wuffs_base__low_bits_mask__u64[n])
|
||||
#define WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U8(n) \
|
||||
(wuffs_private_impl__low_bits_mask__u8[n])
|
||||
#define WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U16(n) \
|
||||
(wuffs_private_impl__low_bits_mask__u16[n])
|
||||
#define WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U32(n) \
|
||||
(wuffs_private_impl__low_bits_mask__u32[n])
|
||||
#define WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U64(n) \
|
||||
(wuffs_private_impl__low_bits_mask__u64[n])
|
||||
|
||||
// --------
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) {
|
||||
wuffs_private_impl__u8__sat_add_indirect(uint8_t* x, uint8_t y) {
|
||||
*x = wuffs_base__u8__sat_add(*x, y);
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u8__sat_sub_indirect(uint8_t* x, uint8_t y) {
|
||||
wuffs_private_impl__u8__sat_sub_indirect(uint8_t* x, uint8_t y) {
|
||||
*x = wuffs_base__u8__sat_sub(*x, y);
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u16__sat_add_indirect(uint16_t* x, uint16_t y) {
|
||||
wuffs_private_impl__u16__sat_add_indirect(uint16_t* x, uint16_t y) {
|
||||
*x = wuffs_base__u16__sat_add(*x, y);
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u16__sat_sub_indirect(uint16_t* x, uint16_t y) {
|
||||
wuffs_private_impl__u16__sat_sub_indirect(uint16_t* x, uint16_t y) {
|
||||
*x = wuffs_base__u16__sat_sub(*x, y);
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u32__sat_add_indirect(uint32_t* x, uint32_t y) {
|
||||
wuffs_private_impl__u32__sat_add_indirect(uint32_t* x, uint32_t y) {
|
||||
*x = wuffs_base__u32__sat_add(*x, y);
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u32__sat_sub_indirect(uint32_t* x, uint32_t y) {
|
||||
wuffs_private_impl__u32__sat_sub_indirect(uint32_t* x, uint32_t y) {
|
||||
*x = wuffs_base__u32__sat_sub(*x, y);
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u64__sat_add_indirect(uint64_t* x, uint64_t y) {
|
||||
wuffs_private_impl__u64__sat_add_indirect(uint64_t* x, uint64_t y) {
|
||||
*x = wuffs_base__u64__sat_add(*x, y);
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {
|
||||
wuffs_private_impl__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {
|
||||
*x = wuffs_base__u64__sat_sub(*x, y);
|
||||
}
|
||||
|
||||
// ---------------- Numeric Types (Utility)
|
||||
|
||||
#define wuffs_base__utility__sign_extend_convert_u8_u32(a) \
|
||||
((uint32_t)(int32_t)(int8_t)(a))
|
||||
|
||||
#define wuffs_base__utility__sign_extend_convert_u16_u32(a) \
|
||||
((uint32_t)(int32_t)(int16_t)(a))
|
||||
|
||||
@@ -191,20 +185,39 @@ wuffs_base__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {
|
||||
#define wuffs_base__utility__sign_extend_rshift_u64(a, n) \
|
||||
((uint64_t)(((int64_t)(a)) >> (n)))
|
||||
|
||||
#define wuffs_base__utility__make_bitvec256(e00, e01, e02, e03) \
|
||||
wuffs_base__make_bitvec256(e00, e01, e02, e03)
|
||||
|
||||
#define wuffs_base__utility__make_optional_u63(h, v) \
|
||||
wuffs_base__make_optional_u63(h, v)
|
||||
|
||||
// ---------------- Slices and Tables
|
||||
|
||||
// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
|
||||
// This function basically returns (ptr + len), except that that expression is
|
||||
// Undefined Behavior in C (but not C++) when ptr is NULL, even if len is zero.
|
||||
//
|
||||
// Precondition: (ptr != NULL) || (len == 0).
|
||||
static inline const uint8_t* //
|
||||
wuffs_private_impl__ptr_u8_plus_len(const uint8_t* ptr, size_t len) {
|
||||
return ptr ? (ptr + len) : NULL;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_private_impl__slice_u8__prefix returns up to the first up_to bytes of
|
||||
// s.
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__slice_u8__prefix(wuffs_base__slice_u8 s, uint64_t up_to) {
|
||||
wuffs_private_impl__slice_u8__prefix(wuffs_base__slice_u8 s, uint64_t up_to) {
|
||||
if (((uint64_t)(s.len)) > up_to) {
|
||||
s.len = ((size_t)up_to);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// wuffs_base__slice_u8__suffix returns up to the last up_to bytes of s.
|
||||
// wuffs_private_impl__slice_u8__suffix returns up to the last up_to bytes of
|
||||
// s.
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__slice_u8__suffix(wuffs_base__slice_u8 s, uint64_t up_to) {
|
||||
wuffs_private_impl__slice_u8__suffix(wuffs_base__slice_u8 s, uint64_t up_to) {
|
||||
if (((uint64_t)(s.len)) > up_to) {
|
||||
s.ptr += ((uint64_t)(s.len)) - up_to;
|
||||
s.len = ((size_t)up_to);
|
||||
@@ -212,14 +225,14 @@ wuffs_base__slice_u8__suffix(wuffs_base__slice_u8 s, uint64_t up_to) {
|
||||
return s;
|
||||
}
|
||||
|
||||
// wuffs_base__slice_u8__copy_from_slice calls memmove(dst.ptr, src.ptr, len)
|
||||
// where len is the minimum of dst.len and src.len.
|
||||
// wuffs_private_impl__slice_u8__copy_from_slice calls memmove(dst.ptr,
|
||||
// src.ptr, len) where len is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a wuffs_base__slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t //
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,
|
||||
wuffs_base__slice_u8 src) {
|
||||
wuffs_private_impl__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,
|
||||
wuffs_base__slice_u8 src) {
|
||||
size_t len = dst.len < src.len ? dst.len : src.len;
|
||||
if (len > 0) {
|
||||
memmove(dst.ptr, src.ptr, len);
|
||||
@@ -228,9 +241,9 @@ wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,
|
||||
}
|
||||
|
||||
static inline wuffs_base__empty_struct //
|
||||
wuffs_base__bulk_load_host_endian(void* ptr,
|
||||
size_t len,
|
||||
wuffs_base__slice_u8 src) {
|
||||
wuffs_private_impl__bulk_load_host_endian(void* ptr,
|
||||
size_t len,
|
||||
wuffs_base__slice_u8 src) {
|
||||
if (len && (len <= src.len)) {
|
||||
memmove(ptr, src.ptr, len);
|
||||
}
|
||||
@@ -238,7 +251,7 @@ wuffs_base__bulk_load_host_endian(void* ptr,
|
||||
}
|
||||
|
||||
static inline wuffs_base__empty_struct //
|
||||
wuffs_base__bulk_memset(void* ptr, size_t len, uint8_t byte_value) {
|
||||
wuffs_private_impl__bulk_memset(void* ptr, size_t len, uint8_t byte_value) {
|
||||
if (len) {
|
||||
memset(ptr, byte_value, len);
|
||||
}
|
||||
@@ -246,9 +259,9 @@ wuffs_base__bulk_memset(void* ptr, size_t len, uint8_t byte_value) {
|
||||
}
|
||||
|
||||
static inline wuffs_base__empty_struct //
|
||||
wuffs_base__bulk_save_host_endian(void* ptr,
|
||||
size_t len,
|
||||
wuffs_base__slice_u8 dst) {
|
||||
wuffs_private_impl__bulk_save_host_endian(void* ptr,
|
||||
size_t len,
|
||||
wuffs_base__slice_u8 dst) {
|
||||
if (len && (len <= dst.len)) {
|
||||
memmove(dst.ptr, ptr, len);
|
||||
}
|
||||
@@ -258,11 +271,11 @@ wuffs_base__bulk_save_host_endian(void* ptr,
|
||||
// --------
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__table_u8__row_u32(wuffs_base__table_u8 t, uint32_t y) {
|
||||
if (y < t.height) {
|
||||
wuffs_private_impl__table_u8__row_u32(wuffs_base__table_u8 t, uint32_t y) {
|
||||
if (t.ptr && (y < t.height)) {
|
||||
return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);
|
||||
}
|
||||
return wuffs_base__make_slice_u8(NULL, 0);
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
// ---------------- Slices and Tables (Utility)
|
||||
|
||||
@@ -34,6 +34,34 @@
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0
|
||||
#define WUFFS_VERSION_STRING "0.0.0+0.00000000"
|
||||
|
||||
// ---------------- Private Implementation Macros Re-definition Check
|
||||
|
||||
// Users (those who #include the "wuffs-vM.N.c" file) should not define any
|
||||
// WUFFS_PRIVATE_IMPL__ETC macros, only WUFFS_CONFIG__ETC macros (and
|
||||
// WUFFS_IMPLEMENTATION). Mucking about with the private implementation macros
|
||||
// is not supported and may break when upgrading to newer Wuffs versions.
|
||||
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_CRC32) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__HPD__SHIFT__MAX_INCL) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U16) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U32) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U64) || \
|
||||
defined(WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U8)
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#warning "Defining WUFFS_PRIVATE_IMPL__ETC yourself is not supported"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message("Defining WUFFS_PRIVATE_IMPL__ETC yourself is not supported")
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU
|
||||
@@ -60,11 +88,11 @@
|
||||
// intrinsics. Look for __ARM_FEATURE_CRC32 instead.
|
||||
#if defined(__ARM_FEATURE_CRC32)
|
||||
#include <arm_acle.h>
|
||||
#define WUFFS_BASE__CPU_ARCH__ARM_CRC32
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_CRC32
|
||||
#endif // defined(__ARM_FEATURE_CRC32)
|
||||
#if defined(__ARM_NEON)
|
||||
#include <arm_neon.h>
|
||||
#define WUFFS_BASE__CPU_ARCH__ARM_NEON
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON
|
||||
#endif // defined(__ARM_NEON)
|
||||
#endif // defined(__ARM_FEATURE_UNALIGNED) etc
|
||||
|
||||
@@ -72,26 +100,82 @@
|
||||
// POPCNT. This is checked at runtime via cpuid, not at compile time.
|
||||
//
|
||||
// Likewise, "cpu_arch >= x86_avx2" also requires PCLMUL, POPCNT and SSE4.2.
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
//
|
||||
// ----
|
||||
//
|
||||
// Technically, we could use the SSE family on 32-bit x86, not just 64-bit x86.
|
||||
// But some intrinsics don't compile in 32-bit mode. It's not worth the hassle.
|
||||
// https://github.com/google/wuffs/issues/145
|
||||
#if defined(__x86_64__)
|
||||
#if !defined(__native_client__)
|
||||
#include <cpuid.h>
|
||||
#include <x86intrin.h>
|
||||
// X86_FAMILY means X86 (32-bit) or X86_64 (64-bit, obviously).
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_FAMILY
|
||||
#if defined(__x86_64__)
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_64
|
||||
#endif // defined(__x86_64__)
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3
|
||||
#endif // !defined(__native_client__)
|
||||
#endif // defined(__i386__) || defined(__x86_64__)
|
||||
#endif // defined(__x86_64__)
|
||||
|
||||
#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
|
||||
#if defined(_M_IX86) || defined(_M_X64)
|
||||
#if defined(__AVX__) || defined(__clang__)
|
||||
#if defined(_M_X64)
|
||||
|
||||
// On X86_64, Microsoft Visual C/C++ (MSVC) only supports SSE2 by default.
|
||||
// There are /arch:SSE2, /arch:AVX and /arch:AVX2 compiler flags (the AVX2 one
|
||||
// is roughly equivalent to X86_64_V3), but there is no /arch:SSE42 compiler
|
||||
// flag that's equivalent to X86_64_V2.
|
||||
//
|
||||
// For getting maximum performance with X86_64 MSVC and Wuffs, pass /arch:AVX2
|
||||
// (and then test on the oldest hardware you intend to support).
|
||||
//
|
||||
// Absent that compiler flag, either define one of the three macros listed
|
||||
// below or else the X86_64 SIMD code will be disabled and you'll get a #pragma
|
||||
// message stating this library "performs best with /arch:AVX2". This message
|
||||
// is harmless and ignorable, in that the non-SIMD code is still correct and
|
||||
// reasonably performant, but is a reminder that when combining Wuffs and MSVC,
|
||||
// some compiler configuration is required for maximum performance.
|
||||
//
|
||||
// - WUFFS_CONFIG__DISABLE_MSVC_CPU_ARCH__X86_64_FAMILY
|
||||
// - WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V2 (enables SSE4.2 and below)
|
||||
// - WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V3 (enables AVX2 and below)
|
||||
//
|
||||
// Defining the first one (WUFFS_CONFIG__DISABLE_MSVC_CPU_ARCH__X86_64_FAMILY)
|
||||
// or defining none of those three (the default state) are equivalent (in that
|
||||
// both disable the SIMD code paths), other than that pragma message.
|
||||
//
|
||||
// When defining these WUFFS_CONFIG__ENABLE_ETC macros with MSVC, be aware that
|
||||
// some users report it leading to ICEs (Internal Compiler Errors), but other
|
||||
// users report no problems at all (and improved performance). It's unclear
|
||||
// exactly what combination of SIMD code and MSVC configuration lead to ICEs.
|
||||
// Do your own testing with your own MSVC version and configuration.
|
||||
//
|
||||
// https://github.com/google/wuffs/issues/148
|
||||
// https://github.com/google/wuffs/issues/151
|
||||
// https://developercommunity.visualstudio.com/t/fatal--error-C1001:-Internal-compiler-er/10703305
|
||||
//
|
||||
// Clang (including clang-cl) and GCC don't need this WUFFS_CONFIG__ETC macro
|
||||
// machinery, or having the Wuffs-the-library user to fiddle with compiler
|
||||
// flags, because they support "__attribute__((target(arg)))".
|
||||
#if defined(__AVX2__) || defined(__clang__) || \
|
||||
defined(WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V3)
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3
|
||||
#elif defined(WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V2)
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64
|
||||
#define WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2
|
||||
#elif !defined(WUFFS_CONFIG__DISABLE_MSVC_CPU_ARCH__X86_64_FAMILY)
|
||||
#pragma message("Wuffs with MSVC+X64 performs best with /arch:AVX2")
|
||||
#endif // defined(__AVX2__) || defined(__clang__) || etc
|
||||
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
|
||||
#if defined(WUFFS_CONFIG__DISABLE_MSVC_CPU_ARCH__X86_64_FAMILY)
|
||||
#error "MSVC_CPU_ARCH simultaneously enabled and disabled"
|
||||
#endif
|
||||
|
||||
// We need <intrin.h> for the __cpuid function.
|
||||
#include <intrin.h>
|
||||
// That's not enough for X64 SIMD, with clang-cl, if we want to use
|
||||
// intrin.h isn't enough for X64 SIMD, with clang-cl, if we want to use
|
||||
// "__attribute__((target(arg)))" without e.g. "/arch:AVX".
|
||||
//
|
||||
// Some web pages suggest that <immintrin.h> is all you need, as it pulls in
|
||||
@@ -100,25 +184,9 @@
|
||||
#include <immintrin.h> // AVX, AVX2, FMA, POPCNT
|
||||
#include <nmmintrin.h> // SSE4.2
|
||||
#include <wmmintrin.h> // AES, PCLMUL
|
||||
// X86_FAMILY means X86 (32-bit) or X86_64 (64-bit, obviously).
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_FAMILY
|
||||
#if defined(_M_X64)
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_64
|
||||
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
#endif // defined(_M_X64)
|
||||
|
||||
#else // defined(__AVX__) || defined(__clang__)
|
||||
|
||||
// clang-cl (which defines both __clang__ and _MSC_VER) supports
|
||||
// "__attribute__((target(arg)))".
|
||||
//
|
||||
// For MSVC's cl.exe (unlike clang or gcc), SIMD capability is a compile-time
|
||||
// property of the source file (e.g. a /arch:AVX or -mavx compiler flag), not
|
||||
// of individual functions (that can be conditionally selected at runtime).
|
||||
#pragma message("Wuffs with MSVC+IX86/X64 needs /arch:AVX for best performance")
|
||||
|
||||
#endif // defined(__AVX__) || defined(__clang__)
|
||||
#endif // defined(_M_IX86) || defined(_M_X64)
|
||||
|
||||
#endif // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
#endif // (#if-chain ref AVOID_CPU_ARCH_0)
|
||||
|
||||
@@ -141,20 +209,20 @@
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_arm_crc32(void) {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_CRC32)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_CRC32)
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_arm_neon(void) {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__ARM_NEON)
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
@@ -163,7 +231,7 @@ wuffs_base__cpu_arch__have_x86_avx2(void) {
|
||||
defined(__AVX2__)
|
||||
return true;
|
||||
#else
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_AVX2 = (1 << 5)
|
||||
const unsigned int avx2_ebx7 = 0x00000020;
|
||||
@@ -201,9 +269,9 @@ wuffs_base__cpu_arch__have_x86_avx2(void) {
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#error "WUFFS_PRIVATE_IMPL__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
#endif // defined(__PCLMUL__) && defined(__POPCNT__) && defined(__SSE4_2__) &&
|
||||
// defined(__AVX2__)
|
||||
@@ -214,7 +282,7 @@ wuffs_base__cpu_arch__have_x86_bmi2(void) {
|
||||
#if defined(__BMI2__)
|
||||
return true;
|
||||
#else
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_BMI2 = (1 << 8)
|
||||
const unsigned int bmi2_ebx7 = 0x00000100;
|
||||
@@ -236,9 +304,9 @@ wuffs_base__cpu_arch__have_x86_bmi2(void) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#error "WUFFS_PRIVATE_IMPL__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
#endif // defined(__BMI2__)
|
||||
}
|
||||
@@ -248,7 +316,7 @@ wuffs_base__cpu_arch__have_x86_sse42(void) {
|
||||
#if defined(__PCLMUL__) && defined(__POPCNT__) && defined(__SSE4_2__)
|
||||
return true;
|
||||
#else
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_PCLMUL = (1 << 1)
|
||||
// - bit_POPCNT = (1 << 23)
|
||||
@@ -272,9 +340,9 @@ wuffs_base__cpu_arch__have_x86_sse42(void) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#error "WUFFS_PRIVATE_IMPL__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
#endif // defined(__PCLMUL__) && defined(__POPCNT__) && defined(__SSE4_2__)
|
||||
}
|
||||
@@ -293,9 +361,15 @@ wuffs_base__cpu_arch__have_x86_sse42(void) {
|
||||
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define WUFFS_BASE__FORCE_INLINE __attribute__((__always_inline__))
|
||||
#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))
|
||||
#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
||||
#elif defined(_MSC_VER)
|
||||
#define WUFFS_BASE__FORCE_INLINE __forceinline
|
||||
#define WUFFS_BASE__POTENTIALLY_UNUSED
|
||||
#define WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
#else
|
||||
#define WUFFS_BASE__FORCE_INLINE
|
||||
#define WUFFS_BASE__POTENTIALLY_UNUSED
|
||||
#define WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
#endif
|
||||
@@ -358,6 +432,37 @@ struct wuffs_unique_ptr_deleter {
|
||||
|
||||
// --------
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
|
||||
static inline uint8_t* //
|
||||
wuffs_base__strip_const_from_u8_ptr(const uint8_t* ptr) {
|
||||
return (uint8_t*)ptr;
|
||||
}
|
||||
|
||||
static inline uint16_t* //
|
||||
wuffs_base__strip_const_from_u16_ptr(const uint16_t* ptr) {
|
||||
return (uint16_t*)ptr;
|
||||
}
|
||||
|
||||
static inline uint32_t* //
|
||||
wuffs_base__strip_const_from_u32_ptr(const uint32_t* ptr) {
|
||||
return (uint32_t*)ptr;
|
||||
}
|
||||
|
||||
static inline uint64_t* //
|
||||
wuffs_base__strip_const_from_u64_ptr(const uint64_t* ptr) {
|
||||
return (uint64_t*)ptr;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__empty_struct is used when a Wuffs function returns an empty
|
||||
// struct. In C, if a function f returns void, you can't say "x = f()", but in
|
||||
// Wuffs, if a function g returns empty, you can say "y = g()".
|
||||
@@ -820,6 +925,96 @@ wuffs_base__multiply_u64(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
typedef struct wuffs_base__bitvec256__struct {
|
||||
// elements_u64[0] holds the LSBs (least significant bits) and
|
||||
// elements_u64[3] holds the MSBs (most significant bits).
|
||||
uint64_t elements_u64[4];
|
||||
} wuffs_base__bitvec256;
|
||||
|
||||
static inline wuffs_base__bitvec256 //
|
||||
wuffs_base__make_bitvec256(uint64_t e00,
|
||||
uint64_t e01,
|
||||
uint64_t e02,
|
||||
uint64_t e03) {
|
||||
wuffs_base__bitvec256 res;
|
||||
res.elements_u64[0] = e00;
|
||||
res.elements_u64[1] = e01;
|
||||
res.elements_u64[2] = e02;
|
||||
res.elements_u64[3] = e03;
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__bitvec256__get_u64(const wuffs_base__bitvec256* b, uint32_t i) {
|
||||
return b->elements_u64[i & 3];
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__optional_u63 is like a std::optional<uint64_t>, but for C (not
|
||||
// just C++) and the value can only hold 63 bits (not 64).
|
||||
//
|
||||
// Do not manipulate repr directly; it is a private implementation detail.
|
||||
typedef struct wuffs_base__optional_u63__struct {
|
||||
uint64_t repr;
|
||||
|
||||
#ifdef __cplusplus
|
||||
inline bool has_value() const;
|
||||
inline uint64_t value() const;
|
||||
inline uint64_t value_or(uint64_t default_value) const;
|
||||
#endif // __cplusplus
|
||||
|
||||
} wuffs_base__optional_u63;
|
||||
|
||||
// wuffs_base__make_optional_u63 ignores value when has_value is false.
|
||||
//
|
||||
// Preconditions:
|
||||
// - value < (1 << 63).
|
||||
static inline wuffs_base__optional_u63 //
|
||||
wuffs_base__make_optional_u63(bool has_value, uint64_t value) {
|
||||
wuffs_base__optional_u63 res;
|
||||
res.repr = has_value ? ((value << 1u) | 1u) : 0u;
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__optional_u63__has_value(const wuffs_base__optional_u63* o) {
|
||||
return o->repr;
|
||||
}
|
||||
|
||||
// wuffs_base__optional_u63__value returns zero when o does not have a value.
|
||||
static inline uint64_t //
|
||||
wuffs_base__optional_u63__value(const wuffs_base__optional_u63* o) {
|
||||
return o->repr >> 1u;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__optional_u63__value_or(const wuffs_base__optional_u63* o,
|
||||
uint64_t default_value) {
|
||||
return o->repr ? (o->repr >> 1u) : default_value;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
inline bool //
|
||||
wuffs_base__optional_u63::has_value() const {
|
||||
return wuffs_base__optional_u63__has_value(this);
|
||||
}
|
||||
|
||||
inline uint64_t //
|
||||
wuffs_base__optional_u63::value() const {
|
||||
return wuffs_base__optional_u63__value(this);
|
||||
}
|
||||
|
||||
inline uint64_t //
|
||||
wuffs_base__optional_u63::value_or(uint64_t default_value) const {
|
||||
return wuffs_base__optional_u63__value_or(this, default_value);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
// --------
|
||||
|
||||
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && (__SIZEOF_LONG__ == 8)
|
||||
@@ -1257,7 +1452,7 @@ wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
|
||||
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.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1265,7 +1460,7 @@ wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
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.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1273,7 +1468,7 @@ wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
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.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1281,7 +1476,7 @@ wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
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.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1424,7 +1619,7 @@ wuffs_base__slice_u8__subslice_i(wuffs_base__slice_u8 s, uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return wuffs_base__make_slice_u8(s.ptr + i, ((size_t)(s.len - i)));
|
||||
}
|
||||
return wuffs_base__make_slice_u8(NULL, 0);
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
// wuffs_base__slice_u8__subslice_j returns s[:j].
|
||||
@@ -1435,7 +1630,7 @@ wuffs_base__slice_u8__subslice_j(wuffs_base__slice_u8 s, uint64_t j) {
|
||||
if ((j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return wuffs_base__make_slice_u8(s.ptr, ((size_t)j));
|
||||
}
|
||||
return wuffs_base__make_slice_u8(NULL, 0);
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
// wuffs_base__slice_u8__subslice_ij returns s[i:j].
|
||||
@@ -1448,7 +1643,7 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
|
||||
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return wuffs_base__make_slice_u8(s.ptr + i, ((size_t)(j - i)));
|
||||
}
|
||||
return wuffs_base__make_slice_u8(NULL, 0);
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
// wuffs_base__table_u8__subtable_ij returns t[ix:jx, iy:jy].
|
||||
@@ -1541,3 +1736,17 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// ---------------- Quirk Values
|
||||
|
||||
// These constants are the value half of a key-value pair, where the key is
|
||||
// WUFFS_BASE__QUIRK_QUALITY.
|
||||
//
|
||||
// In the Wuffs API, set_quirk takes a u64 value. These macro definitions are
|
||||
// likewise unsigned values (uint64_t) but for this particular key, they are
|
||||
// best interpreted as signed values (int64_t). "Lower-than-default quality"
|
||||
// and "higher-than-default quality", as signed values, are -1 and +1.
|
||||
//
|
||||
// See doc/note/quirks.md for some more discussion about trade-offs.
|
||||
#define WUFFS_BASE__QUIRK_QUALITY__VALUE__LOWER_QUALITY UINT64_MAX
|
||||
#define WUFFS_BASE__QUIRK_QUALITY__VALUE__HIGHER_QUALITY ((uint64_t)1)
|
||||
@@ -39,8 +39,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
const wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t x_min_incl,
|
||||
uint32_t x_max_excl,
|
||||
uint32_t y_min_incl,
|
||||
uint32_t y_max_excl,
|
||||
wuffs_base__slice_u8 src0,
|
||||
wuffs_base__slice_u8 src1,
|
||||
wuffs_base__slice_u8 src2,
|
||||
|
||||
@@ -69,6 +69,26 @@ wuffs_base__color_u32_argb_premul__as__color_u8_gray(
|
||||
return (uint8_t)(weighted_average >> 24);
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_alpha_gray_nonpremul(
|
||||
wuffs_base__color_u32_argb_premul c) {
|
||||
uint32_t a = 0xFF & (c >> 24);
|
||||
if (a == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t a16 = a * 0x101;
|
||||
|
||||
uint32_t cr = 0xFF & (c >> 16);
|
||||
cr = (cr * (0x101 * 0xFFFF)) / a16;
|
||||
uint32_t cg = 0xFF & (c >> 8);
|
||||
cg = (cg * (0x101 * 0xFFFF)) / a16;
|
||||
uint32_t cb = 0xFF & (c >> 0);
|
||||
cb = (cb * (0x101 * 0xFFFF)) / a16;
|
||||
|
||||
uint32_t weighted_average = (19595 * cr) + (38470 * cg) + (7471 * cb) + 32768;
|
||||
return (uint16_t)((a16 & 0xFF00) | (weighted_average >> 24));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_gray(
|
||||
wuffs_base__color_u32_argb_premul c) {
|
||||
@@ -345,49 +365,53 @@ wuffs_base__make_pixel_format(uint32_t repr) {
|
||||
// Common 8-bit-depth pixel formats. This list is not exhaustive; not all valid
|
||||
// wuffs_base__pixel_format values are present.
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INVALID 0x00000000
|
||||
// clang-format off
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__A 0x02000008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INVALID 0x00000000
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__Y 0x20000008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__Y_16LE 0x2000000B
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__Y_16BE 0x2010000B
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL 0x21000008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL 0x22000008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__A 0x02000008
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCR 0x40020888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRA_NONPREMUL 0x41038888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRK 0x50038888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__Y 0x20000008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__Y_16LE 0x2000000B
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__Y_16BE 0x2010000B
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL 0x21000088
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL 0x22000088
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCG 0x60020888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGA_NONPREMUL 0x61038888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGK 0x70038888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCR 0x40020888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRA_NONPREMUL 0x41038888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRK 0x50038888
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL 0x81040008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL 0x82040008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY 0x83040008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCG 0x60020888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGA_NONPREMUL 0x61038888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGK 0x70038888
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR_565 0x80000565
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR 0x80000888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL 0x81008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE 0x8100BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL 0x82008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE 0x8200BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY 0x83008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRX 0x90008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL 0x81040008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL 0x82040008
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY 0x83040008
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGB 0xA0000888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL 0xA1008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE 0xA100BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL 0xA2008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL_4X16LE 0xA200BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY 0xA3008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBX 0xB0008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR_565 0x80000565
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR 0x80000888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL 0x81008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE 0x8100BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL 0x82008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE 0x8200BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY 0x83008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRX 0x90008888
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMY 0xC0020888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMYK 0xD0038888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGB 0xA0000888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL 0xA1008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE 0xA100BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL 0xA2008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL_4X16LE 0xA200BBBB
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY 0xA3008888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBX 0xB0008888
|
||||
|
||||
extern const uint32_t wuffs_base__pixel_format__bits_per_channel[16];
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMY 0xC0020888
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMYK 0xD0038888
|
||||
|
||||
// clang-format on
|
||||
|
||||
extern const uint32_t wuffs_private_impl__pixel_format__bits_per_channel[16];
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__pixel_format__is_valid(const wuffs_base__pixel_format* f) {
|
||||
@@ -401,10 +425,14 @@ wuffs_base__pixel_format__bits_per_pixel(const wuffs_base__pixel_format* f) {
|
||||
if (((f->repr >> 16) & 0x03) != 0) {
|
||||
return 0;
|
||||
}
|
||||
return wuffs_base__pixel_format__bits_per_channel[0x0F & (f->repr >> 0)] +
|
||||
wuffs_base__pixel_format__bits_per_channel[0x0F & (f->repr >> 4)] +
|
||||
wuffs_base__pixel_format__bits_per_channel[0x0F & (f->repr >> 8)] +
|
||||
wuffs_base__pixel_format__bits_per_channel[0x0F & (f->repr >> 12)];
|
||||
return wuffs_private_impl__pixel_format__bits_per_channel[0x0F &
|
||||
(f->repr >> 0)] +
|
||||
wuffs_private_impl__pixel_format__bits_per_channel[0x0F &
|
||||
(f->repr >> 4)] +
|
||||
wuffs_private_impl__pixel_format__bits_per_channel[0x0F &
|
||||
(f->repr >> 8)] +
|
||||
wuffs_private_impl__pixel_format__bits_per_channel[0x0F &
|
||||
(f->repr >> 12)];
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
@@ -622,15 +650,20 @@ wuffs_base__pixel_config__set(wuffs_base__pixel_config* c,
|
||||
return;
|
||||
}
|
||||
if (pixfmt_repr) {
|
||||
uint64_t wh = ((uint64_t)width) * ((uint64_t)height);
|
||||
// TODO: handle things other than 1 byte per pixel.
|
||||
if (wh <= ((uint64_t)SIZE_MAX)) {
|
||||
do {
|
||||
#if SIZE_MAX < UINT64_MAX
|
||||
uint64_t wh = ((uint64_t)width) * ((uint64_t)height);
|
||||
// TODO: handle things other than 1 byte per pixel.
|
||||
if (wh > ((uint64_t)SIZE_MAX)) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
c->private_impl.pixfmt.repr = pixfmt_repr;
|
||||
c->private_impl.pixsub.repr = pixsub_repr;
|
||||
c->private_impl.width = width;
|
||||
c->private_impl.height = height;
|
||||
return;
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
|
||||
c->private_impl.pixfmt.repr = 0;
|
||||
@@ -1348,7 +1381,7 @@ wuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* pb) {
|
||||
tab->ptr, WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_slice_u8(NULL, 0);
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
|
||||
@@ -97,7 +97,7 @@ static const uint8_t wuffs_base__parse_number__hexadecimal_digits[256] = {
|
||||
// 8 9 A B C D E F
|
||||
};
|
||||
|
||||
static const uint8_t wuffs_base__private_implementation__encode_base16[16] = {
|
||||
static const uint8_t wuffs_private_impl__encode_base16[16] = {
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x00 ..= 0x07.
|
||||
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // 0x08 ..= 0x0F.
|
||||
};
|
||||
@@ -350,10 +350,10 @@ static const uint8_t wuffs_base__render_number__first_hundred[200] = {
|
||||
};
|
||||
|
||||
static size_t //
|
||||
wuffs_base__private_implementation__render_number_u64(wuffs_base__slice_u8 dst,
|
||||
uint64_t x,
|
||||
uint32_t options,
|
||||
bool neg) {
|
||||
wuffs_private_impl__render_number_u64(wuffs_base__slice_u8 dst,
|
||||
uint64_t x,
|
||||
uint32_t options,
|
||||
bool neg) {
|
||||
uint8_t buf[WUFFS_BASE__U64__BYTE_LENGTH__MAX_INCL];
|
||||
uint8_t* ptr = &buf[0] + sizeof(buf);
|
||||
|
||||
@@ -407,16 +407,14 @@ wuffs_base__render_number_i64(wuffs_base__slice_u8 dst,
|
||||
if (neg) {
|
||||
u = 1 + ~u;
|
||||
}
|
||||
return wuffs_base__private_implementation__render_number_u64(dst, u, options,
|
||||
neg);
|
||||
return wuffs_private_impl__render_number_u64(dst, u, options, neg);
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC size_t //
|
||||
wuffs_base__render_number_u64(wuffs_base__slice_u8 dst,
|
||||
uint64_t x,
|
||||
uint32_t options) {
|
||||
return wuffs_base__private_implementation__render_number_u64(dst, x, options,
|
||||
false);
|
||||
return wuffs_private_impl__render_number_u64(dst, x, options, false);
|
||||
}
|
||||
|
||||
// ---------------- Base-16
|
||||
@@ -523,8 +521,8 @@ wuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,
|
||||
|
||||
while (n--) {
|
||||
uint8_t c = *s;
|
||||
d[0] = wuffs_base__private_implementation__encode_base16[c >> 4];
|
||||
d[1] = wuffs_base__private_implementation__encode_base16[c & 0x0F];
|
||||
d[0] = wuffs_private_impl__encode_base16[c >> 4];
|
||||
d[1] = wuffs_private_impl__encode_base16[c & 0x0F];
|
||||
d += 2;
|
||||
s += 1;
|
||||
}
|
||||
@@ -562,8 +560,8 @@ wuffs_base__base_16__encode4(wuffs_base__slice_u8 dst,
|
||||
uint8_t c = *s;
|
||||
d[0] = '\\';
|
||||
d[1] = 'x';
|
||||
d[2] = wuffs_base__private_implementation__encode_base16[c >> 4];
|
||||
d[3] = wuffs_base__private_implementation__encode_base16[c & 0x0F];
|
||||
d[2] = wuffs_private_impl__encode_base16[c >> 4];
|
||||
d[3] = wuffs_private_impl__encode_base16[c & 0x0F];
|
||||
d += 4;
|
||||
s += 1;
|
||||
}
|
||||
|
||||
+203
-65
@@ -11,7 +11,7 @@
|
||||
// ---------------- I/O
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__io__count_since(uint64_t mark, uint64_t index) {
|
||||
wuffs_private_impl__io__count_since(uint64_t mark, uint64_t index) {
|
||||
if (index >= mark) {
|
||||
return index - mark;
|
||||
}
|
||||
@@ -25,12 +25,14 @@ wuffs_base__io__count_since(uint64_t mark, uint64_t index) {
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__io__since(uint64_t mark, uint64_t index, const uint8_t* ptr) {
|
||||
wuffs_private_impl__io__since(uint64_t mark,
|
||||
uint64_t index,
|
||||
const uint8_t* ptr) {
|
||||
if (index >= mark) {
|
||||
return wuffs_base__make_slice_u8(((uint8_t*)ptr) + mark,
|
||||
((size_t)(index - mark)));
|
||||
}
|
||||
return wuffs_base__make_slice_u8(NULL, 0);
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
@@ -39,19 +41,20 @@ wuffs_base__io__since(uint64_t mark, uint64_t index, const uint8_t* ptr) {
|
||||
// --------
|
||||
|
||||
static inline void //
|
||||
wuffs_base__io_reader__limit(const uint8_t** ptr_io2_r,
|
||||
const uint8_t* iop_r,
|
||||
uint64_t limit) {
|
||||
wuffs_private_impl__io_reader__limit(const uint8_t** ptr_io2_r,
|
||||
const uint8_t* iop_r,
|
||||
uint64_t limit) {
|
||||
if (((uint64_t)(*ptr_io2_r - iop_r)) > limit) {
|
||||
*ptr_io2_r = iop_r + limit;
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_reader__limited_copy_u32_to_slice(const uint8_t** ptr_iop_r,
|
||||
const uint8_t* io2_r,
|
||||
uint32_t length,
|
||||
wuffs_base__slice_u8 dst) {
|
||||
wuffs_private_impl__io_reader__limited_copy_u32_to_slice(
|
||||
const uint8_t** ptr_iop_r,
|
||||
const uint8_t* io2_r,
|
||||
uint32_t length,
|
||||
wuffs_base__slice_u8 dst) {
|
||||
const uint8_t* iop_r = *ptr_iop_r;
|
||||
size_t n = dst.len;
|
||||
if (n > length) {
|
||||
@@ -67,9 +70,9 @@ wuffs_base__io_reader__limited_copy_u32_to_slice(const uint8_t** ptr_iop_r,
|
||||
return (uint32_t)(n);
|
||||
}
|
||||
|
||||
// wuffs_base__io_reader__match7 returns whether the io_reader's upcoming bytes
|
||||
// start with the given prefix (up to 7 bytes long). It is peek-like, not
|
||||
// read-like, in that there are no side-effects.
|
||||
// wuffs_private_impl__io_reader__match7 returns whether the io_reader's
|
||||
// upcoming bytes start with the given prefix (up to 7 bytes long). It is
|
||||
// peek-like, not read-like, in that there are no side-effects.
|
||||
//
|
||||
// The low 3 bits of a hold the prefix length, n.
|
||||
//
|
||||
@@ -82,10 +85,10 @@ wuffs_base__io_reader__limited_copy_u32_to_slice(const uint8_t** ptr_iop_r,
|
||||
// - 1 means inconclusive, equivalent to "$short read".
|
||||
// - 2 means failure.
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_reader__match7(const uint8_t* iop_r,
|
||||
const uint8_t* io2_r,
|
||||
wuffs_base__io_buffer* r,
|
||||
uint64_t a) {
|
||||
wuffs_private_impl__io_reader__match7(const uint8_t* iop_r,
|
||||
const uint8_t* io2_r,
|
||||
wuffs_base__io_buffer* r,
|
||||
uint64_t a) {
|
||||
uint32_t n = a & 7;
|
||||
a >>= 8;
|
||||
if ((io2_r - iop_r) >= 8) {
|
||||
@@ -106,13 +109,13 @@ wuffs_base__io_reader__match7(const uint8_t* iop_r,
|
||||
}
|
||||
|
||||
static inline wuffs_base__io_buffer* //
|
||||
wuffs_base__io_reader__set(wuffs_base__io_buffer* b,
|
||||
const uint8_t** ptr_iop_r,
|
||||
const uint8_t** ptr_io0_r,
|
||||
const uint8_t** ptr_io1_r,
|
||||
const uint8_t** ptr_io2_r,
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
wuffs_private_impl__io_reader__set(wuffs_base__io_buffer* b,
|
||||
const uint8_t** ptr_iop_r,
|
||||
const uint8_t** ptr_io0_r,
|
||||
const uint8_t** ptr_io1_r,
|
||||
const uint8_t** ptr_io2_r,
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = data.len;
|
||||
b->meta.ri = 0;
|
||||
@@ -130,9 +133,9 @@ wuffs_base__io_reader__set(wuffs_base__io_buffer* b,
|
||||
// --------
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
wuffs_base__slice_u8 src) {
|
||||
wuffs_private_impl__io_writer__copy_from_slice(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
wuffs_base__slice_u8 src) {
|
||||
uint8_t* iop_w = *ptr_iop_w;
|
||||
size_t n = src.len;
|
||||
if (n > ((size_t)(io2_w - iop_w))) {
|
||||
@@ -146,20 +149,21 @@ wuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
uint8_t* iop_w,
|
||||
uint64_t limit) {
|
||||
wuffs_private_impl__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
uint8_t* iop_w,
|
||||
uint64_t limit) {
|
||||
if (((uint64_t)(*ptr_io2_w - iop_w)) > limit) {
|
||||
*ptr_io2_w = iop_w + limit;
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_history(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
if (!distance) {
|
||||
return 0;
|
||||
}
|
||||
@@ -181,7 +185,8 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
// argument, and the cgen can look if that argument is the constant
|
||||
// expression '3'.
|
||||
//
|
||||
// See also wuffs_base__io_writer__limited_copy_u32_from_history_fast below.
|
||||
// See also wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast
|
||||
// below.
|
||||
for (; n >= 3; n -= 3) {
|
||||
*p++ = *q++;
|
||||
*p++ = *q++;
|
||||
@@ -194,20 +199,22 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_fast is like the
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history function above, but has
|
||||
// stronger pre-conditions.
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast is like
|
||||
// the wuffs_private_impl__io_writer__limited_copy_u32_from_history function
|
||||
// above, but has stronger pre-conditions.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - length >= 1
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
uint8_t* q = p - distance;
|
||||
uint32_t n = length;
|
||||
@@ -223,7 +230,44 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast_return_cusp
|
||||
// is like the
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast function,
|
||||
// but also returns the cusp: a byte pair (as a u16le) being the last byte of
|
||||
// and next byte after the copied history.
|
||||
//
|
||||
// For example, if history was [10, 11, 12, 13, 14, 15, 16, 17, 18] then:
|
||||
// - copying l=3, d=8 produces [11, 12, 13] and the cusp is (13, 14).
|
||||
// - copying l=3, d=2 produces [17, 18, 17] and the cusp is (17, 18).
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - length >= 1
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast_return_cusp(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
uint8_t* q = p - distance;
|
||||
uint32_t n = length;
|
||||
for (; n >= 3; n -= 3) {
|
||||
*p++ = *q++;
|
||||
*p++ = *q++;
|
||||
*p++ = *q++;
|
||||
}
|
||||
for (; n; n--) {
|
||||
*p++ = *q++;
|
||||
}
|
||||
*ptr_iop_w = p;
|
||||
return (uint32_t)wuffs_base__peek_u16le__no_bounds_check(q - 1);
|
||||
}
|
||||
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast
|
||||
// copies the previous byte (the one immediately before *ptr_iop_w), copying 8
|
||||
// byte chunks at a time. Each chunk contains 8 repetitions of the same byte.
|
||||
//
|
||||
@@ -234,11 +278,12 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
// In terms of advancing *ptr_iop_w, length is not rounded up.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - length >= 1
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
@@ -263,8 +308,55 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast is
|
||||
// like the wuffs_base__io_writer__limited_copy_u32_from_history_fast function
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp
|
||||
// copies the previous byte (the one immediately before *ptr_iop_w), copying 8
|
||||
// byte chunks at a time. Each chunk contains 8 repetitions of the same byte.
|
||||
// It also returns the cusp: a byte pair (as a u16le) being the last byte of
|
||||
// and next byte after the copied history.
|
||||
//
|
||||
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
|
||||
// As a special case, a zero length rounds up to 8 (even though 0 is already a
|
||||
// multiple of 8), since there is always at least one 8 byte chunk copied.
|
||||
//
|
||||
// In terms of advancing *ptr_iop_w, length is not rounded up.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - length >= 1
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
uint8_t* q = p - distance;
|
||||
uint64_t x = p[-1];
|
||||
x |= x << 8;
|
||||
x |= x << 16;
|
||||
x |= x << 32;
|
||||
uint32_t n = length;
|
||||
while (1) {
|
||||
wuffs_base__poke_u64le__no_bounds_check(p, x);
|
||||
if (n <= 8) {
|
||||
p += n;
|
||||
q += n;
|
||||
break;
|
||||
}
|
||||
p += 8;
|
||||
q += 8;
|
||||
n -= 8;
|
||||
}
|
||||
*ptr_iop_w = p;
|
||||
return (uint32_t)wuffs_base__peek_u16le__no_bounds_check(q - 1);
|
||||
}
|
||||
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast
|
||||
// is like the
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast function
|
||||
// above, but copies 8 byte chunks at a time.
|
||||
//
|
||||
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
|
||||
@@ -274,11 +366,12 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
// In terms of advancing *ptr_iop_w, length is not rounded up.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - length >= 1
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
@@ -301,12 +394,56 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast_return_cusp
|
||||
// is like the
|
||||
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast function
|
||||
// above, but copies 8 byte chunks at a time. It also returns the cusp: a byte
|
||||
// pair (as a u16le) being the last byte of and next byte after the copied
|
||||
// history.
|
||||
//
|
||||
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
|
||||
// As a special case, a zero length rounds up to 8 (even though 0 is already a
|
||||
// multiple of 8), since there is always at least one 8 byte chunk copied.
|
||||
//
|
||||
// In terms of advancing *ptr_iop_w, length is not rounded up.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - length >= 1
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_reader(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
const uint8_t** ptr_iop_r,
|
||||
const uint8_t* io2_r) {
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast_return_cusp(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
uint8_t* q = p - distance;
|
||||
uint32_t n = length;
|
||||
while (1) {
|
||||
memcpy(p, q, 8);
|
||||
if (n <= 8) {
|
||||
p += n;
|
||||
q += n;
|
||||
break;
|
||||
}
|
||||
p += 8;
|
||||
q += 8;
|
||||
n -= 8;
|
||||
}
|
||||
*ptr_iop_w = p;
|
||||
return (uint32_t)wuffs_base__peek_u16le__no_bounds_check(q - 1);
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_reader(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
const uint8_t** ptr_iop_r,
|
||||
const uint8_t* io2_r) {
|
||||
uint8_t* iop_w = *ptr_iop_w;
|
||||
size_t n = length;
|
||||
if (n > ((size_t)(io2_w - iop_w))) {
|
||||
@@ -325,10 +462,11 @@ wuffs_base__io_writer__limited_copy_u32_from_reader(uint8_t** ptr_iop_w,
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
wuffs_base__slice_u8 src) {
|
||||
wuffs_private_impl__io_writer__limited_copy_u32_from_slice(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
wuffs_base__slice_u8 src) {
|
||||
uint8_t* iop_w = *ptr_iop_w;
|
||||
size_t n = src.len;
|
||||
if (n > length) {
|
||||
@@ -345,13 +483,13 @@ wuffs_base__io_writer__limited_copy_u32_from_slice(uint8_t** ptr_iop_w,
|
||||
}
|
||||
|
||||
static inline wuffs_base__io_buffer* //
|
||||
wuffs_base__io_writer__set(wuffs_base__io_buffer* b,
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t** ptr_io0_w,
|
||||
uint8_t** ptr_io1_w,
|
||||
uint8_t** ptr_io2_w,
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
wuffs_private_impl__io_writer__set(wuffs_base__io_buffer* b,
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t** ptr_io0_w,
|
||||
uint8_t** ptr_io1_w,
|
||||
uint8_t** ptr_io2_w,
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = 0;
|
||||
b->meta.ri = 0;
|
||||
|
||||
@@ -168,7 +168,8 @@ wuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {
|
||||
// wuffs_base__io_buffer__compact_retaining moves any written but unread bytes
|
||||
// closer to the start of the buffer. It retains H bytes of history (the most
|
||||
// recently read bytes), where H is min(buf->meta.ri, history_retain_length).
|
||||
// A postcondition is that buf->meta.ri == H.
|
||||
// It is therefore a no-op if history_retain_length is UINT64_MAX. A
|
||||
// postcondition is that buf->meta.ri == H.
|
||||
//
|
||||
// wuffs_base__io_buffer__compact_retaining(0) is equivalent to
|
||||
// wuffs_base__io_buffer__compact().
|
||||
@@ -213,7 +214,7 @@ wuffs_base__io_buffer__reader_length(const wuffs_base__io_buffer* buf) {
|
||||
|
||||
static inline uint8_t* //
|
||||
wuffs_base__io_buffer__reader_pointer(const wuffs_base__io_buffer* buf) {
|
||||
return buf ? (buf->data.ptr + buf->meta.ri) : NULL;
|
||||
return (buf && buf->data.ptr) ? (buf->data.ptr + buf->meta.ri) : NULL;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
@@ -223,7 +224,8 @@ wuffs_base__io_buffer__reader_position(const wuffs_base__io_buffer* buf) {
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__io_buffer__reader_slice(const wuffs_base__io_buffer* buf) {
|
||||
return buf ? wuffs_base__make_slice_u8(buf->data.ptr + buf->meta.ri,
|
||||
return (buf && buf->data.ptr)
|
||||
? wuffs_base__make_slice_u8(buf->data.ptr + buf->meta.ri,
|
||||
buf->meta.wi - buf->meta.ri)
|
||||
: wuffs_base__empty_slice_u8();
|
||||
}
|
||||
@@ -235,7 +237,7 @@ wuffs_base__io_buffer__writer_length(const wuffs_base__io_buffer* buf) {
|
||||
|
||||
static inline uint8_t* //
|
||||
wuffs_base__io_buffer__writer_pointer(const wuffs_base__io_buffer* buf) {
|
||||
return buf ? (buf->data.ptr + buf->meta.wi) : NULL;
|
||||
return (buf && buf->data.ptr) ? (buf->data.ptr + buf->meta.wi) : NULL;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
@@ -245,7 +247,8 @@ wuffs_base__io_buffer__writer_position(const wuffs_base__io_buffer* buf) {
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__io_buffer__writer_slice(const wuffs_base__io_buffer* buf) {
|
||||
return buf ? wuffs_base__make_slice_u8(buf->data.ptr + buf->meta.wi,
|
||||
return (buf && buf->data.ptr)
|
||||
? wuffs_base__make_slice_u8(buf->data.ptr + buf->meta.wi,
|
||||
buf->data.len - buf->meta.wi)
|
||||
: wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
{+0x424D5020, "\x01\x42\x4D"}, // BMP
|
||||
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
||||
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
||||
{+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP
|
||||
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
|
||||
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
|
||||
|
||||
@@ -20,49 +20,49 @@
|
||||
//
|
||||
// You can pass the C stdlib's malloc as the malloc_func.
|
||||
//
|
||||
// It returns an empty slice (containing a NULL ptr field) if (num_uxx *
|
||||
// sizeof(uintxx_t)) would overflow SIZE_MAX.
|
||||
// It returns an empty slice (containing a NULL ptr field) if num_uxx is zero
|
||||
// or if (num_uxx * sizeof(uintxx_t)) would overflow SIZE_MAX.
|
||||
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__malloc_slice_u8(void* (*malloc_func)(size_t), uint64_t num_u8) {
|
||||
if (malloc_func && (num_u8 <= (SIZE_MAX / sizeof(uint8_t)))) {
|
||||
if (malloc_func && num_u8 && (num_u8 <= (SIZE_MAX / sizeof(uint8_t)))) {
|
||||
void* p = (*malloc_func)((size_t)(num_u8 * sizeof(uint8_t)));
|
||||
if (p) {
|
||||
return wuffs_base__make_slice_u8((uint8_t*)(p), (size_t)num_u8);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_slice_u8(NULL, 0);
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u16 //
|
||||
wuffs_base__malloc_slice_u16(void* (*malloc_func)(size_t), uint64_t num_u16) {
|
||||
if (malloc_func && (num_u16 <= (SIZE_MAX / sizeof(uint16_t)))) {
|
||||
if (malloc_func && num_u16 && (num_u16 <= (SIZE_MAX / sizeof(uint16_t)))) {
|
||||
void* p = (*malloc_func)((size_t)(num_u16 * sizeof(uint16_t)));
|
||||
if (p) {
|
||||
return wuffs_base__make_slice_u16((uint16_t*)(p), (size_t)num_u16);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_slice_u16(NULL, 0);
|
||||
return wuffs_base__empty_slice_u16();
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u32 //
|
||||
wuffs_base__malloc_slice_u32(void* (*malloc_func)(size_t), uint64_t num_u32) {
|
||||
if (malloc_func && (num_u32 <= (SIZE_MAX / sizeof(uint32_t)))) {
|
||||
if (malloc_func && num_u32 && (num_u32 <= (SIZE_MAX / sizeof(uint32_t)))) {
|
||||
void* p = (*malloc_func)((size_t)(num_u32 * sizeof(uint32_t)));
|
||||
if (p) {
|
||||
return wuffs_base__make_slice_u32((uint32_t*)(p), (size_t)num_u32);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_slice_u32(NULL, 0);
|
||||
return wuffs_base__empty_slice_u32();
|
||||
}
|
||||
|
||||
static inline wuffs_base__slice_u64 //
|
||||
wuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) {
|
||||
if (malloc_func && (num_u64 <= (SIZE_MAX / sizeof(uint64_t)))) {
|
||||
if (malloc_func && num_u64 && (num_u64 <= (SIZE_MAX / sizeof(uint64_t)))) {
|
||||
void* p = (*malloc_func)((size_t)(num_u64 * sizeof(uint64_t)));
|
||||
if (p) {
|
||||
return wuffs_base__make_slice_u64((uint64_t*)(p), (size_t)num_u64);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_slice_u64(NULL, 0);
|
||||
return wuffs_base__empty_slice_u64();
|
||||
}
|
||||
@@ -10,10 +10,18 @@
|
||||
|
||||
// ---------------- Pixel Swizzler
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw__bgr__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len);
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgrw__rgb__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -22,7 +30,7 @@ wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42(uint8_t* dst_ptr,
|
||||
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -31,18 +39,18 @@ wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42(uint8_t* dst_ptr,
|
||||
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxx__y__x86_sse42(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxx__y__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len);
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__swap_u32_argb_abgr(uint32_t u) {
|
||||
wuffs_private_impl__swap_u32_argb_abgr(uint32_t u) {
|
||||
uint32_t o = u & 0xFF00FF00ul;
|
||||
uint32_t r = u & 0x00FF0000ul;
|
||||
uint32_t b = u & 0x000000FFul;
|
||||
@@ -50,7 +58,7 @@ wuffs_base__swap_u32_argb_abgr(uint32_t u) {
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__swap_u64_argb_abgr(uint64_t u) {
|
||||
wuffs_private_impl__swap_u64_argb_abgr(uint64_t u) {
|
||||
uint64_t o = u & 0xFFFF0000FFFF0000ull;
|
||||
uint64_t r = u & 0x0000FFFF00000000ull;
|
||||
uint64_t b = u & 0x000000000000FFFFull;
|
||||
@@ -58,7 +66,7 @@ wuffs_base__swap_u64_argb_abgr(uint64_t u) {
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__color_u64__as__color_u32__swap_u32_argb_abgr(uint64_t c) {
|
||||
wuffs_private_impl__color_u64__as__color_u32__swap_u32_argb_abgr(uint64_t c) {
|
||||
uint32_t a = ((uint32_t)(0xFF & (c >> 56)));
|
||||
uint32_t r = ((uint32_t)(0xFF & (c >> 40)));
|
||||
uint32_t g = ((uint32_t)(0xFF & (c >> 24)));
|
||||
@@ -105,6 +113,10 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
return 0xFF000000 | (0x00010101 * ((uint32_t)(row[(2 * x) + 1])));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
return 0xFF000000 | (0x00010101 * ((uint32_t)(row[(2 * x) + 0])));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
|
||||
return wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
(((uint32_t)(row[(2 * x) + 1])) << 24) |
|
||||
(((uint32_t)(row[(2 * x) + 0])) * 0x00010101));
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL: {
|
||||
uint8_t* palette = pb->private_impl.planes[3].ptr;
|
||||
@@ -130,20 +142,20 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__peek_u32le__no_bounds_check(row + (4 * ((size_t)x)));
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__swap_u32_argb_abgr(
|
||||
return wuffs_private_impl__swap_u32_argb_abgr(
|
||||
0xFF000000 |
|
||||
wuffs_base__peek_u24le__no_bounds_check(row + (3 * ((size_t)x))));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
return wuffs_base__swap_u32_argb_abgr(
|
||||
return wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u32le__no_bounds_check(row +
|
||||
(4 * ((size_t)x)))));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
return wuffs_base__swap_u32_argb_abgr(
|
||||
return wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(row + (4 * ((size_t)x))));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
return wuffs_base__swap_u32_argb_abgr(
|
||||
return wuffs_private_impl__swap_u32_argb_abgr(
|
||||
0xFF000000 |
|
||||
wuffs_base__peek_u32le__no_bounds_check(row + (4 * ((size_t)x))));
|
||||
|
||||
@@ -202,6 +214,12 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_gray(color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_alpha_gray_nonpremul(
|
||||
color));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
|
||||
@@ -235,18 +253,20 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
row + (3 * ((size_t)x)), wuffs_base__swap_u32_argb_abgr(color));
|
||||
row + (3 * ((size_t)x)),
|
||||
wuffs_private_impl__swap_u32_argb_abgr(color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(
|
||||
wuffs_base__swap_u32_argb_abgr(color)));
|
||||
wuffs_private_impl__swap_u32_argb_abgr(color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)), wuffs_base__swap_u32_argb_abgr(color));
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_private_impl__swap_u32_argb_abgr(color));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -260,7 +280,7 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
// --------
|
||||
|
||||
static inline void //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xx(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
uint16_t color) {
|
||||
@@ -291,7 +311,7 @@ wuffs_base__pixel_buffer__set_color_u32_fill_rect__xx(
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxx(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
uint32_t color) {
|
||||
@@ -322,7 +342,7 @@ wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxx(
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
uint32_t color) {
|
||||
@@ -353,7 +373,7 @@ wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
}
|
||||
|
||||
static inline void //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxxxxxx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxxxxxx(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
uint64_t color) {
|
||||
@@ -407,46 +427,48 @@ wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
switch (pb->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxx(pb, rect, color);
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxx(pb, rect,
|
||||
color);
|
||||
return wuffs_base__make_status(NULL);
|
||||
|
||||
// Common formats above. Rarer formats below.
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xx(
|
||||
pb, rect,
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(color));
|
||||
return wuffs_base__make_status(NULL);
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxx(pb, rect, color);
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxx(pb, rect,
|
||||
color);
|
||||
return wuffs_base__make_status(NULL);
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
pb, rect,
|
||||
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(
|
||||
color));
|
||||
return wuffs_base__make_status(NULL);
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxxxxxx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxxxxxx(
|
||||
pb, rect,
|
||||
wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul(
|
||||
color));
|
||||
return wuffs_base__make_status(NULL);
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
pb, rect,
|
||||
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(
|
||||
wuffs_base__swap_u32_argb_abgr(color)));
|
||||
wuffs_private_impl__swap_u32_argb_abgr(color)));
|
||||
return wuffs_base__make_status(NULL);
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
pb, rect, wuffs_base__swap_u32_argb_abgr(color));
|
||||
wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxx(
|
||||
pb, rect, wuffs_private_impl__swap_u32_argb_abgr(color));
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
@@ -525,8 +547,9 @@ wuffs_base__pixel_palette__closest_element(
|
||||
// --------
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(
|
||||
uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
@@ -578,8 +601,9 @@ wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(
|
||||
uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
@@ -625,8 +649,8 @@ wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
wuffs_private_impl__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
@@ -669,8 +693,8 @@ wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
wuffs_private_impl__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
// Extract components.
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
@@ -707,8 +731,9 @@ wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
@@ -739,8 +764,9 @@ wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
wuffs_private_impl__composite_premul_nonpremul_u64_axxx(
|
||||
uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
uint64_t da = 0xFFFF & (dst_premul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_premul >> 32);
|
||||
@@ -765,8 +791,8 @@ wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
wuffs_private_impl__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
@@ -799,7 +825,7 @@ wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__squash_align4_bgr_565_8888(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_squash_align4_bgr_565_8888(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len,
|
||||
@@ -830,7 +856,7 @@ wuffs_base__pixel_swizzler__squash_align4_bgr_565_8888(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__swap_rgb_bgr(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_swap_rgb_bgr(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -855,10 +881,10 @@ wuffs_base__pixel_swizzler__swap_rgb_bgr(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_sse42
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -899,11 +925,11 @@ wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42(uint8_t* dst_ptr,
|
||||
}
|
||||
return len;
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_sse42
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__swap_rgbx_bgrx(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_swap_rgbx_bgrx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -932,7 +958,7 @@ wuffs_base__pixel_swizzler__swap_rgbx_bgrx(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__copy_1_1(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_copy_1_1(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -946,7 +972,7 @@ wuffs_base__pixel_swizzler__copy_1_1(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__copy_2_2(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_copy_2_2(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -962,7 +988,7 @@ wuffs_base__pixel_swizzler__copy_2_2(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__copy_3_3(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_copy_3_3(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -978,7 +1004,7 @@ wuffs_base__pixel_swizzler__copy_3_3(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__copy_4_4(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_copy_4_4(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -994,7 +1020,7 @@ wuffs_base__pixel_swizzler__copy_4_4(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__copy_8_8(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_copy_8_8(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1012,7 +1038,7 @@ wuffs_base__pixel_swizzler__copy_8_8(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgr(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__bgr(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1028,9 +1054,9 @@ wuffs_base__pixel_swizzler__bgr_565__bgr(uint8_t* dst_ptr,
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t b5 = s[0] >> 3;
|
||||
uint32_t g6 = s[1] >> 2;
|
||||
uint32_t r5 = s[2] >> 3;
|
||||
uint32_t b5 = (uint32_t)(s[0] >> 3);
|
||||
uint32_t g6 = (uint32_t)(s[1] >> 2);
|
||||
uint32_t r5 = (uint32_t)(s[2] >> 3);
|
||||
uint32_t rgb_565 = (r5 << 11) | (g6 << 5) | (b5 << 0);
|
||||
wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)rgb_565);
|
||||
|
||||
@@ -1043,7 +1069,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgr(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgrx(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__bgrx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1059,9 +1085,9 @@ wuffs_base__pixel_swizzler__bgr_565__bgrx(uint8_t* dst_ptr,
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t b5 = s[0] >> 3;
|
||||
uint32_t g6 = s[1] >> 2;
|
||||
uint32_t r5 = s[2] >> 3;
|
||||
uint32_t b5 = (uint32_t)(s[0] >> 3);
|
||||
uint32_t g6 = (uint32_t)(s[1] >> 2);
|
||||
uint32_t r5 = (uint32_t)(s[2] >> 3);
|
||||
uint32_t rgb_565 = (r5 << 11) | (g6 << 5) | (b5 << 0);
|
||||
wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)rgb_565);
|
||||
|
||||
@@ -1074,7 +1100,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgrx(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src(
|
||||
wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1106,7 +1132,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src(
|
||||
wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul_4x16le__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1138,7 +1164,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1194,7 +1220,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1250,7 +1276,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__bgra_premul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1279,7 +1305,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgr_565__bgra_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1335,7 +1361,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__rgb(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__rgb(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1351,9 +1377,9 @@ wuffs_base__pixel_swizzler__bgr_565__rgb(uint8_t* dst_ptr,
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t r5 = s[0] >> 3;
|
||||
uint32_t g6 = s[1] >> 2;
|
||||
uint32_t b5 = s[2] >> 3;
|
||||
uint32_t r5 = (uint32_t)(s[0] >> 3);
|
||||
uint32_t g6 = (uint32_t)(s[1] >> 2);
|
||||
uint32_t b5 = (uint32_t)(s[2] >> 3);
|
||||
uint32_t rgb_565 = (r5 << 11) | (g6 << 5) | (b5 << 0);
|
||||
wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)rgb_565);
|
||||
|
||||
@@ -1366,7 +1392,7 @@ wuffs_base__pixel_swizzler__bgr_565__rgb(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src(
|
||||
wuffs_private_impl__swizzle_bgr_565__rgba_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1386,7 +1412,7 @@ wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src(
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
d + (0 * 2),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
wuffs_base__swap_u32_argb_abgr(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))))));
|
||||
|
||||
@@ -1399,7 +1425,7 @@ wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgr_565__rgba_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1455,7 +1481,7 @@ wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__rgba_premul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1474,7 +1500,7 @@ wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src(uint8_t* dst_ptr,
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
d + (0 * 2),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
wuffs_base__swap_u32_argb_abgr(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)))));
|
||||
|
||||
s += 1 * 4;
|
||||
@@ -1486,7 +1512,7 @@ wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgr_565__rgba_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1542,7 +1568,7 @@ wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__y(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__y(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1557,8 +1583,8 @@ wuffs_base__pixel_swizzler__bgr_565__y(uint8_t* dst_ptr,
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t y5 = s[0] >> 3;
|
||||
uint32_t y6 = s[0] >> 2;
|
||||
uint32_t y5 = (uint32_t)(s[0] >> 3);
|
||||
uint32_t y6 = (uint32_t)(s[0] >> 2);
|
||||
uint32_t rgb_565 = (y5 << 11) | (y6 << 5) | (y5 << 0);
|
||||
wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)rgb_565);
|
||||
|
||||
@@ -1571,7 +1597,7 @@ wuffs_base__pixel_swizzler__bgr_565__y(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__y_16be(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1587,8 +1613,8 @@ wuffs_base__pixel_swizzler__bgr_565__y_16be(uint8_t* dst_ptr,
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t y5 = s[0] >> 3;
|
||||
uint32_t y6 = s[0] >> 2;
|
||||
uint32_t y5 = (uint32_t)(s[0] >> 3);
|
||||
uint32_t y6 = (uint32_t)(s[0] >> 2);
|
||||
uint32_t rgb_565 = (y5 << 11) | (y6 << 5) | (y5 << 0);
|
||||
wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)rgb_565);
|
||||
|
||||
@@ -1601,7 +1627,94 @@ wuffs_base__pixel_swizzler__bgr_565__y_16be(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__index__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr_565__ya_nonpremul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len2 = dst_len / 2;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
d + (0 * 2),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
s0)));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 2;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgr_565__ya_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len2 = dst_len / 2;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sy = 0x101 * ((uint32_t)s[0]);
|
||||
|
||||
// Convert from 565 color to 16-bit color.
|
||||
uint32_t old_rgb_565 = wuffs_base__peek_u16le__no_bounds_check(d + (0 * 2));
|
||||
uint32_t old_r5 = 0x1F & (old_rgb_565 >> 11);
|
||||
uint32_t dr = (0x8421 * old_r5) >> 4;
|
||||
uint32_t old_g6 = 0x3F & (old_rgb_565 >> 5);
|
||||
uint32_t dg = (0x1041 * old_g6) >> 2;
|
||||
uint32_t old_b5 = 0x1F & (old_rgb_565 >> 0);
|
||||
uint32_t db = (0x8421 * old_b5) >> 4;
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
|
||||
// Composite src (nonpremul) over dst (premul).
|
||||
dr = ((sy * sa) + (dr * ia)) / 0xFFFF;
|
||||
dg = ((sy * sa) + (dg * ia)) / 0xFFFF;
|
||||
db = ((sy * sa) + (db * ia)) / 0xFFFF;
|
||||
|
||||
// Convert from 16-bit color to 565 color and combine the components.
|
||||
uint32_t new_r5 = 0x1F & (dr >> 11);
|
||||
uint32_t new_g6 = 0x3F & (dg >> 10);
|
||||
uint32_t new_b5 = 0x1F & (db >> 11);
|
||||
uint32_t new_rgb_565 = (new_r5 << 11) | (new_g6 << 5) | (new_b5 << 0);
|
||||
wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)new_rgb_565);
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 2;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgr_565__index__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1652,7 +1765,7 @@ wuffs_base__pixel_swizzler__bgr_565__index__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__index_bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgr_565__index_bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1679,7 +1792,7 @@ wuffs_base__pixel_swizzler__bgr_565__index_bgra_nonpremul__src_over(
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
d + (0 * 2),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(d0, s0)));
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0)));
|
||||
|
||||
s += 1 * 1;
|
||||
d += 1 * 2;
|
||||
@@ -1690,7 +1803,7 @@ wuffs_base__pixel_swizzler__bgr_565__index_bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr_565__index_binary_alpha__src_over(
|
||||
wuffs_private_impl__swizzle_bgr_565__index_binary_alpha__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1727,7 +1840,7 @@ wuffs_base__pixel_swizzler__bgr_565__index_binary_alpha__src_over(
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__bgr_565(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__bgr_565(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1756,7 +1869,7 @@ wuffs_base__pixel_swizzler__bgr__bgr_565(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__bgra_nonpremul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1786,7 +1899,7 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src(
|
||||
wuffs_private_impl__swizzle_bgr__bgra_nonpremul_4x16le__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1817,7 +1930,7 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgr__bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1865,7 +1978,7 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_bgr__bgra_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -1913,7 +2026,7 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__bgra_premul__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__bgra_premul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1943,7 +2056,7 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -1988,7 +2101,7 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__rgba_nonpremul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -2004,7 +2117,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src(uint8_t* dst_ptr,
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))));
|
||||
wuffs_base__poke_u24le__no_bounds_check(d + (0 * 3), s0);
|
||||
@@ -2018,7 +2131,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src(
|
||||
wuffs_private_impl__swizzle_bgr__rgba_nonpremul_4x16le__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2035,7 +2148,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src(
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8))));
|
||||
wuffs_base__poke_u24le__no_bounds_check(d + (0 * 3), s0);
|
||||
@@ -2049,7 +2162,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgr__rgba_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2097,7 +2210,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_bgr__rgba_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2145,7 +2258,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__rgba_premul__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__rgba_premul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -2175,7 +2288,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -2220,7 +2333,7 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgr__rgbx(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgr__rgbx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -2254,7 +2367,7 @@ wuffs_base__pixel_swizzler__bgr__rgbx(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2273,7 +2386,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over(
|
||||
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(d0, s0));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -2284,7 +2397,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__bgra_nonpremul_4x16le__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2311,7 +2424,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2332,7 +2445,8 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__color_u64__as__color_u32(
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(d0, s0)));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(d0,
|
||||
s0)));
|
||||
|
||||
s += 1 * 8;
|
||||
d += 1 * 4;
|
||||
@@ -2343,7 +2457,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2372,7 +2486,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2390,7 +2504,8 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over(
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__composite_nonpremul_premul_u32_axxx(d0, s0));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_nonpremul_premul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -2401,7 +2516,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__index_bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2426,7 +2541,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over(
|
||||
((size_t)s[0] * 4));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(d0, s0));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 1;
|
||||
d += 1 * 4;
|
||||
@@ -2437,7 +2552,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__rgba_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2453,11 +2568,11 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(d0, s0));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -2468,7 +2583,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2483,7 +2598,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src(
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
@@ -2498,7 +2613,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2514,10 +2629,11 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__composite_nonpremul_premul_u32_axxx(d0, s0));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_nonpremul_premul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -2527,10 +2643,71 @@ wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over(
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__ya_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len4 = dst_len / 4;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len4 < src_len2) ? dst_len4 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
wuffs_base__poke_u32le__no_bounds_check(d + (0 * 4), s0);
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 4;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul__ya_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len4 = dst_len / 4;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len4 < src_len2) ? dst_len4 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 4;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2566,7 +2743,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2586,7 +2763,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src_over(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
d + (0 * 8),
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 8;
|
||||
@@ -2596,7 +2773,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2615,7 +2792,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul_4x16le__src_ov
|
||||
uint64_t s0 = wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8));
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
d + (0 * 8),
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
|
||||
s += 1 * 8;
|
||||
d += 1 * 8;
|
||||
@@ -2625,7 +2802,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul_4x16le__src_ov
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2653,7 +2830,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2672,7 +2849,8 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src_over(
|
||||
uint64_t s0 = wuffs_base__color_u32__as__color_u64(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
d + (0 * 8), wuffs_base__composite_nonpremul_premul_u64_axxx(d0, s0));
|
||||
d + (0 * 8),
|
||||
wuffs_private_impl__composite_nonpremul_premul_u64_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 8;
|
||||
@@ -2682,7 +2860,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__index_bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__index_bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2706,7 +2884,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__index_bgra_nonpremul__src_ove
|
||||
((size_t)s[0] * 4)));
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
d + (0 * 8),
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
|
||||
s += 1 * 1;
|
||||
d += 1 * 8;
|
||||
@@ -2717,7 +2895,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__index_bgra_nonpremul__src_ove
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2753,7 +2931,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2769,12 +2947,12 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src_over(
|
||||
size_t n = len;
|
||||
while (n >= 1) {
|
||||
uint64_t d0 = wuffs_base__peek_u64le__no_bounds_check(d + (0 * 8));
|
||||
uint64_t s0 =
|
||||
wuffs_base__color_u32__as__color_u64(wuffs_base__swap_u32_argb_abgr(
|
||||
uint64_t s0 = wuffs_base__color_u32__as__color_u64(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))));
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
d + (0 * 8),
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 8;
|
||||
@@ -2784,7 +2962,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_premul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2801,7 +2979,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src(
|
||||
while (n >= 1) {
|
||||
uint64_t s0 = wuffs_base__color_u32__as__color_u64(
|
||||
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(
|
||||
wuffs_base__swap_u32_argb_abgr(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)))));
|
||||
wuffs_base__poke_u64le__no_bounds_check(d + (0 * 8), s0);
|
||||
|
||||
@@ -2813,7 +2991,7 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2829,11 +3007,12 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src_over(
|
||||
size_t n = len;
|
||||
while (n >= 1) {
|
||||
uint64_t d0 = wuffs_base__peek_u64le__no_bounds_check(d + (0 * 8));
|
||||
uint64_t s0 =
|
||||
wuffs_base__color_u32__as__color_u64(wuffs_base__swap_u32_argb_abgr(
|
||||
uint64_t s0 = wuffs_base__color_u32__as__color_u64(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))));
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
d + (0 * 8), wuffs_base__composite_nonpremul_premul_u64_axxx(d0, s0));
|
||||
d + (0 * 8),
|
||||
wuffs_private_impl__composite_nonpremul_premul_u64_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 8;
|
||||
@@ -2842,10 +3021,67 @@ wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src_over(
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__ya_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len8 = dst_len / 8;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len8 < src_len2) ? dst_len8 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
|
||||
size_t n = len;
|
||||
while (n >= 1) {
|
||||
uint64_t s0 = ((uint64_t)(s[1]) * 0x0101000000000000) |
|
||||
((uint64_t)(s[0]) * 0x0000010101010101);
|
||||
wuffs_base__poke_u64le__no_bounds_check(d + (0 * 8), s0);
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 8;
|
||||
n -= 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__ya_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len8 = dst_len / 8;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len8 < src_len2) ? dst_len8 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
|
||||
size_t n = len;
|
||||
while (n >= 1) {
|
||||
uint64_t d0 = wuffs_base__peek_u64le__no_bounds_check(d + (0 * 8));
|
||||
uint64_t s0 = ((uint64_t)(s[1]) * 0x0101000000000000) |
|
||||
((uint64_t)(s[0]) * 0x0000010101010101);
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
d + (0 * 8),
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(d0, s0));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 8;
|
||||
n -= 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(
|
||||
wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2876,7 +3112,7 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src(
|
||||
wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul_4x16le__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2907,7 +3143,7 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2927,7 +3163,8 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over(
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -2938,7 +3175,7 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2961,7 +3198,7 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__color_u64__as__color_u32(
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(d0, s0)));
|
||||
wuffs_private_impl__composite_premul_nonpremul_u64_axxx(d0, s0)));
|
||||
|
||||
s += 1 * 8;
|
||||
d += 1 * 4;
|
||||
@@ -2972,7 +3209,7 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_premul__bgra_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -2992,7 +3229,8 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over(
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__composite_premul_premul_u32_axxx(d0, s0));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_premul_premul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -3003,7 +3241,7 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_premul__index_bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3027,7 +3265,8 @@ wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over(
|
||||
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
|
||||
((size_t)s[0] * 4));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 1;
|
||||
d += 1 * 4;
|
||||
@@ -3038,7 +3277,7 @@ wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src(
|
||||
wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3055,7 +3294,7 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src(
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
@@ -3070,7 +3309,7 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3088,10 +3327,11 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -3102,7 +3342,7 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src(
|
||||
wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul_4x16le__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3122,7 +3362,7 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src(
|
||||
uint64_t s0 = wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__swap_u32_argb_abgr(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u32_argb_premul(
|
||||
s0)));
|
||||
|
||||
@@ -3135,7 +3375,7 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3154,12 +3394,12 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src_over(
|
||||
while (n >= 1) {
|
||||
uint64_t d0 = wuffs_base__color_u32__as__color_u64(
|
||||
wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4)));
|
||||
uint64_t s0 = wuffs_base__swap_u64_argb_abgr(
|
||||
uint64_t s0 = wuffs_private_impl__swap_u64_argb_abgr(
|
||||
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__color_u64__as__color_u32(
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(d0, s0)));
|
||||
wuffs_private_impl__composite_premul_nonpremul_u64_axxx(d0, s0)));
|
||||
|
||||
s += 1 * 8;
|
||||
d += 1 * 4;
|
||||
@@ -3170,7 +3410,7 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over(
|
||||
wuffs_private_impl__swizzle_bgra_premul__rgba_premul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3186,10 +3426,11 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = wuffs_base__swap_u32_argb_abgr(
|
||||
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__composite_premul_premul_u32_axxx(d0, s0));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_premul_premul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
@@ -3199,10 +3440,73 @@ wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over(
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgra_premul__ya_nonpremul__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len4 = dst_len / 4;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len4 < src_len2) ? dst_len4 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(s0));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 4;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgra_premul__ya_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len4 = dst_len / 4;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len4 < src_len2) ? dst_len4 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4));
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 4;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__bgr(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw__bgr(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3231,7 +3535,7 @@ wuffs_base__pixel_swizzler__bgrw__bgr(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__bgr_565(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw__bgr_565(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3260,7 +3564,7 @@ wuffs_base__pixel_swizzler__bgrw__bgr_565(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__bgrx(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw__bgrx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3289,10 +3593,63 @@ wuffs_base__pixel_swizzler__bgrw__bgrx(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_sse42
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw__bgr__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len4 = dst_len / 4;
|
||||
size_t src_len3 = src_len / 3;
|
||||
size_t len = (dst_len4 < src_len3) ? dst_len4 : src_len3;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
__m128i shuffle = _mm_set_epi8(+0x00, +0x0B, +0x0A, +0x09, //
|
||||
+0x00, +0x08, +0x07, +0x06, //
|
||||
+0x00, +0x05, +0x04, +0x03, //
|
||||
+0x00, +0x02, +0x01, +0x00);
|
||||
__m128i or_ff = _mm_set_epi8(-0x01, +0x00, +0x00, +0x00, //
|
||||
-0x01, +0x00, +0x00, +0x00, //
|
||||
-0x01, +0x00, +0x00, +0x00, //
|
||||
-0x01, +0x00, +0x00, +0x00);
|
||||
|
||||
while (n >= 6) {
|
||||
__m128i x;
|
||||
x = _mm_lddqu_si128((const __m128i*)(const void*)s);
|
||||
x = _mm_shuffle_epi8(x, shuffle);
|
||||
x = _mm_or_si128(x, or_ff);
|
||||
_mm_storeu_si128((__m128i*)(void*)d, x);
|
||||
|
||||
s += 4 * 3;
|
||||
d += 4 * 4;
|
||||
n -= 4;
|
||||
}
|
||||
|
||||
while (n >= 1) {
|
||||
uint8_t b0 = s[0];
|
||||
uint8_t b1 = s[1];
|
||||
uint8_t b2 = s[2];
|
||||
d[0] = b0;
|
||||
d[1] = b1;
|
||||
d[2] = b2;
|
||||
d[3] = 0xFF;
|
||||
|
||||
s += 1 * 3;
|
||||
d += 1 * 4;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_bgrw__rgb__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3342,11 +3699,11 @@ wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42(uint8_t* dst_ptr,
|
||||
|
||||
return len;
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_sse42
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__rgb(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw__rgb(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3377,7 +3734,7 @@ wuffs_base__pixel_swizzler__bgrw__rgb(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__rgbx(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw__rgbx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3412,7 +3769,7 @@ wuffs_base__pixel_swizzler__bgrw__rgbx(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw_4x16le__bgr(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw_4x16le__bgr(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3447,7 +3804,7 @@ wuffs_base__pixel_swizzler__bgrw_4x16le__bgr(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw_4x16le__bgr_565(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw_4x16le__bgr_565(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3476,7 +3833,7 @@ wuffs_base__pixel_swizzler__bgrw_4x16le__bgr_565(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw_4x16le__bgrx(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw_4x16le__bgrx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3511,7 +3868,7 @@ wuffs_base__pixel_swizzler__bgrw_4x16le__bgrx(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw_4x16le__rgb(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_bgrw_4x16le__rgb(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3548,7 +3905,7 @@ wuffs_base__pixel_swizzler__bgrw_4x16le__rgb(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__rgb__bgr_565(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_rgb__bgr_565(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3566,7 +3923,7 @@ wuffs_base__pixel_swizzler__rgb__bgr_565(uint8_t* dst_ptr,
|
||||
while (n >= 1) {
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
d + (0 * 3),
|
||||
wuffs_base__swap_u32_argb_abgr(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u16le__no_bounds_check(s + (0 * 2)))));
|
||||
|
||||
@@ -3581,7 +3938,7 @@ wuffs_base__pixel_swizzler__rgb__bgr_565(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src(
|
||||
wuffs_private_impl__swizzle_rgba_nonpremul__bgra_nonpremul_4x16le__src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3597,8 +3954,9 @@ wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src(
|
||||
size_t n = len;
|
||||
while (n >= 1) {
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4), wuffs_base__color_u64__as__color_u32__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8))));
|
||||
d + (0 * 4),
|
||||
wuffs_private_impl__color_u64__as__color_u32__swap_u32_argb_abgr(
|
||||
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8))));
|
||||
|
||||
s += 1 * 8;
|
||||
d += 1 * 4;
|
||||
@@ -3608,7 +3966,7 @@ wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
wuffs_private_impl__swizzle_rgba_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3625,12 +3983,13 @@ wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
while (n >= 1) {
|
||||
uint64_t d0 = wuffs_base__color_u32__as__color_u64(
|
||||
wuffs_base__peek_u32le__no_bounds_check(d + (0 * 4)));
|
||||
uint64_t s0 = wuffs_base__swap_u64_argb_abgr(
|
||||
uint64_t s0 = wuffs_private_impl__swap_u64_argb_abgr(
|
||||
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8)));
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__color_u64__as__color_u32(
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(d0, s0)));
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(d0,
|
||||
s0)));
|
||||
|
||||
s += 1 * 8;
|
||||
d += 1 * 4;
|
||||
@@ -3643,7 +4002,7 @@ wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src_over(
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__rgbw__bgr_565(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_rgbw__bgr_565(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3661,7 +4020,7 @@ wuffs_base__pixel_swizzler__rgbw__bgr_565(uint8_t* dst_ptr,
|
||||
while (n >= 1) {
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__swap_u32_argb_abgr(
|
||||
wuffs_private_impl__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u16le__no_bounds_check(s + (0 * 2)))));
|
||||
|
||||
@@ -3676,7 +4035,7 @@ wuffs_base__pixel_swizzler__rgbw__bgr_565(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxx__index__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxx__index__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3734,7 +4093,7 @@ wuffs_base__pixel_swizzler__xxx__index__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxx__index_bgra_nonpremul__src_over(
|
||||
wuffs_private_impl__swizzle_xxx__index_bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3759,7 +4118,8 @@ wuffs_base__pixel_swizzler__xxx__index_bgra_nonpremul__src_over(
|
||||
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
|
||||
((size_t)s[0] * 4));
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
d + (0 * 3), wuffs_base__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
d + (0 * 3),
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 1;
|
||||
d += 1 * 3;
|
||||
@@ -3770,7 +4130,7 @@ wuffs_base__pixel_swizzler__xxx__index_bgra_nonpremul__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over(
|
||||
wuffs_private_impl__swizzle_xxx__index_binary_alpha__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -3832,7 +4192,7 @@ wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxx__xxxx(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxx__xxxx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3860,7 +4220,7 @@ wuffs_base__pixel_swizzler__xxx__xxxx(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxx__y(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxx__y(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3889,7 +4249,7 @@ wuffs_base__pixel_swizzler__xxx__y(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxx__y_16be(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxx__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3918,10 +4278,73 @@ wuffs_base__pixel_swizzler__xxx__y_16be(uint8_t* dst_ptr,
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_xxx__ya_nonpremul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len3 = dst_len / 3;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len3 < src_len2) ? dst_len3 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
d + (0 * 3),
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(s0));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 3;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_xxx__ya_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len3 = dst_len / 3;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len3 < src_len2) ? dst_len3 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 =
|
||||
wuffs_base__peek_u24le__no_bounds_check(d + (0 * 3)) | 0xFF000000;
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
d + (0 * 3),
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 3;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxx__index__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxx__index__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -3972,7 +4395,7 @@ wuffs_base__pixel_swizzler__xxxx__index__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over(
|
||||
wuffs_private_impl__swizzle_xxxx__index_binary_alpha__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -4034,10 +4457,10 @@ wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over(
|
||||
}
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_sse42
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxx__y__x86_sse42(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxx__y__x86_sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4081,11 +4504,11 @@ wuffs_base__pixel_swizzler__xxxx__y__x86_sse42(uint8_t* dst_ptr,
|
||||
|
||||
return len;
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_sse42
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxx__y(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxx__y(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4110,7 +4533,7 @@ wuffs_base__pixel_swizzler__xxxx__y(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxx__y_16be(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxx__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4138,7 +4561,7 @@ wuffs_base__pixel_swizzler__xxxx__y_16be(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxxxxxx__index__src(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxxxxxx__index__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4169,7 +4592,7 @@ wuffs_base__pixel_swizzler__xxxxxxxx__index__src(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxxxxxx__index_binary_alpha__src_over(
|
||||
wuffs_private_impl__swizzle_xxxxxxxx__index_binary_alpha__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -4203,7 +4626,7 @@ wuffs_base__pixel_swizzler__xxxxxxxx__index_binary_alpha__src_over(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxxxxxx__y(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxxxxxx__y(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4228,7 +4651,7 @@ wuffs_base__pixel_swizzler__xxxxxxxx__y(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxxxxxx__y_16be(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_xxxxxxxx__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4258,7 +4681,88 @@ wuffs_base__pixel_swizzler__xxxxxxxx__y_16be(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__y__y_16be(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t src_len4 = src_len / 4;
|
||||
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 =
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
|
||||
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 1;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t src_len4 = src_len / 4;
|
||||
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
|
||||
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
|
||||
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 1;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t src_len4 = src_len / 4;
|
||||
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 =
|
||||
0xFF000000 | wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
|
||||
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 1;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4282,7 +4786,7 @@ wuffs_base__pixel_swizzler__y__y_16be(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__y_16le__y_16be(uint8_t* dst_ptr,
|
||||
wuffs_private_impl__swizzle_y_16le__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
@@ -4312,7 +4816,39 @@ wuffs_base__pixel_swizzler__y_16le__y_16be(uint8_t* dst_ptr,
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__transparent_black_src(
|
||||
wuffs_private_impl__swizzle_ya_nonpremul__ya_nonpremul__src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len2 = dst_len / 2;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t d0 = ((uint32_t)(d[1]) << 24) | ((uint32_t)(d[0]) * 0x010101);
|
||||
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
|
||||
uint32_t c0 =
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(d0, s0);
|
||||
wuffs_base__poke_u16le__no_bounds_check(d + (0 * 2), (uint16_t)(c0 >> 16));
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 2;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
wuffs_private_impl__swizzle_transparent_black_src(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -4328,7 +4864,7 @@ wuffs_base__pixel_swizzler__transparent_black_src(
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__transparent_black_src_over(
|
||||
wuffs_private_impl__swizzle_transparent_black_src_over(
|
||||
uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
@@ -4344,22 +4880,23 @@ wuffs_base__pixel_swizzler__transparent_black_src_over(
|
||||
|
||||
// --------
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__y(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
return wuffs_base__pixel_swizzler__copy_1_1;
|
||||
return wuffs_private_impl__swizzle_copy_1_1;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__y;
|
||||
return wuffs_private_impl__swizzle_bgr_565__y;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__xxx__y;
|
||||
return wuffs_private_impl__swizzle_xxx__y;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
@@ -4369,44 +4906,45 @@ wuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p,
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_base__pixel_swizzler__xxxx__y__x86_sse42;
|
||||
return wuffs_private_impl__swizzle_xxxx__y__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_base__pixel_swizzler__xxxx__y;
|
||||
return wuffs_private_impl__swizzle_xxxx__y;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL_4X16LE:
|
||||
return wuffs_base__pixel_swizzler__xxxxxxxx__y;
|
||||
return wuffs_private_impl__swizzle_xxxxxxxx__y;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__y_16be(wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__y_16be(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
return wuffs_base__pixel_swizzler__y__y_16be;
|
||||
return wuffs_private_impl__swizzle_y__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
||||
return wuffs_base__pixel_swizzler__y_16le__y_16be;
|
||||
return wuffs_private_impl__swizzle_y_16le__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
return wuffs_base__pixel_swizzler__copy_2_2;
|
||||
return wuffs_private_impl__swizzle_copy_2_2;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__y_16be;
|
||||
return wuffs_private_impl__swizzle_bgr_565__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__xxx__y_16be;
|
||||
return wuffs_private_impl__swizzle_xxx__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
@@ -4416,19 +4954,88 @@ wuffs_base__pixel_swizzler__prepare__y_16be(wuffs_base__pixel_swizzler* p,
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
return wuffs_base__pixel_swizzler__xxxx__y_16be;
|
||||
return wuffs_private_impl__swizzle_xxxx__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL_4X16LE:
|
||||
return wuffs_base__pixel_swizzler__xxxxxxxx__y_16be;
|
||||
return wuffs_private_impl__swizzle_xxxxxxxx__y_16be;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__ya_nonpremul(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_private_impl__swizzle_copy_2_2;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_private_impl__swizzle_ya_nonpremul__ya_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_private_impl__swizzle_bgr_565__ya_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_private_impl__swizzle_bgr_565__ya_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_private_impl__swizzle_xxx__ya_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_private_impl__swizzle_xxx__ya_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__ya_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__ya_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_private_impl__swizzle_bgra_premul__ya_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_private_impl__swizzle_bgra_premul__ya_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__ya_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__ya_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_nonpremul(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
@@ -4436,122 +5043,128 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__copy_1_1;
|
||||
return wuffs_private_impl__swizzle_copy_1_1;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
if (wuffs_base__pixel_swizzler__squash_align4_bgr_565_8888(
|
||||
if (wuffs_private_impl__swizzle_squash_align4_bgr_565_8888(
|
||||
dst_palette.ptr, dst_palette.len, src_palette.ptr,
|
||||
src_palette.len, true) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__bgr_565__index__src;
|
||||
return wuffs_private_impl__swizzle_bgr_565__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__bgr_565__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr_565__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
if (wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(
|
||||
if (wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__xxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__xxx__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_xxx__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxxxxxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxxxxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
if (wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(
|
||||
if (wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__xxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
if (wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src(
|
||||
if (wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__xxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(
|
||||
if (wuffs_private_impl__swizzle_swap_rgbx_bgrx(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__xxx__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_xxx__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(
|
||||
if (wuffs_private_impl__swizzle_swap_rgbx_bgrx(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
@@ -4559,30 +5172,30 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
if (wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src(
|
||||
if (wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__xxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(
|
||||
if (wuffs_private_impl__swizzle_swap_rgbx_bgrx(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
return NULL;
|
||||
}
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__index_bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -4593,8 +5206,8 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
@@ -4604,18 +5217,19 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__copy_1_1;
|
||||
return wuffs_private_impl__swizzle_copy_1_1;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
if (wuffs_base__pixel_swizzler__squash_align4_bgr_565_8888(
|
||||
if (wuffs_private_impl__swizzle_squash_align4_bgr_565_8888(
|
||||
dst_palette.ptr, dst_palette.len, src_palette.ptr,
|
||||
src_palette.len, false) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
@@ -4623,56 +5237,59 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__index__src;
|
||||
return wuffs_private_impl__swizzle_bgr_565__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__index_binary_alpha__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr_565__index_binary_alpha__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over;
|
||||
return wuffs_private_impl__swizzle_xxx__index_binary_alpha__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over;
|
||||
return wuffs_private_impl__swizzle_xxxx__index_binary_alpha__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
|
||||
if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=
|
||||
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
|
||||
src_palette) !=
|
||||
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxxxxxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxxxxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__xxxxxxxx__index_binary_alpha__src_over;
|
||||
return wuffs_private_impl__swizzle_xxxxxxxx__index_binary_alpha__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(
|
||||
if (wuffs_private_impl__swizzle_swap_rgbx_bgrx(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
@@ -4680,16 +5297,16 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over;
|
||||
return wuffs_private_impl__swizzle_xxx__index_binary_alpha__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(
|
||||
if (wuffs_private_impl__swizzle_swap_rgbx_bgrx(
|
||||
dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,
|
||||
src_palette.len) !=
|
||||
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
|
||||
@@ -4697,17 +5314,17 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
}
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__xxxx__index__src;
|
||||
return wuffs_private_impl__swizzle_xxxx__index__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over;
|
||||
return wuffs_private_impl__swizzle_xxxx__index_binary_alpha__src_over;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__bgr_565(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__bgr_565(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
@@ -4715,123 +5332,138 @@ wuffs_base__pixel_swizzler__prepare__bgr_565(
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__copy_2_2;
|
||||
return wuffs_private_impl__swizzle_copy_2_2;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgr_565;
|
||||
return wuffs_private_impl__swizzle_bgr__bgr_565;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
return wuffs_base__pixel_swizzler__bgrw__bgr_565;
|
||||
return wuffs_private_impl__swizzle_bgrw__bgr_565;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
|
||||
return wuffs_base__pixel_swizzler__bgrw_4x16le__bgr_565;
|
||||
return wuffs_private_impl__swizzle_bgrw_4x16le__bgr_565;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__rgb__bgr_565;
|
||||
return wuffs_private_impl__swizzle_rgb__bgr_565;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
return wuffs_base__pixel_swizzler__rgbw__bgr_565;
|
||||
return wuffs_private_impl__swizzle_rgbw__bgr_565;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__bgr(wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__bgr(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgr;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgr;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
return wuffs_base__pixel_swizzler__copy_3_3;
|
||||
return wuffs_private_impl__swizzle_copy_3_3;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
return wuffs_base__pixel_swizzler__bgrw__bgr;
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_private_impl__swizzle_bgrw__bgr__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_private_impl__swizzle_bgrw__bgr;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
|
||||
return wuffs_base__pixel_swizzler__bgrw_4x16le__bgr;
|
||||
return wuffs_private_impl__swizzle_bgrw_4x16le__bgr;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__swap_rgb_bgr;
|
||||
return wuffs_private_impl__swizzle_swap_rgb_bgr;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42;
|
||||
return wuffs_private_impl__swizzle_bgrw__rgb__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_base__pixel_swizzler__bgrw__rgb;
|
||||
return wuffs_private_impl__swizzle_bgrw__rgb;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__bgra_nonpremul(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_private_impl__swizzle_y__bgra_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__copy_4_4;
|
||||
return wuffs_private_impl__swizzle_copy_4_4;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -4843,32 +5475,32 @@ wuffs_base__pixel_swizzler__prepare__bgra_nonpremul(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -4880,8 +5512,8 @@ wuffs_base__pixel_swizzler__prepare__bgra_nonpremul(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
@@ -4891,45 +5523,45 @@ wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul_4x16le__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgra_nonpremul_4x16le__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_nonpremul_4x16le__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_nonpremul_4x16le__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_nonpremul_4x16le__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_nonpremul_4x16le__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__copy_8_8;
|
||||
return wuffs_private_impl__swizzle_copy_8_8;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_nonpremul_4x16le__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul_4x16le__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul_4x16le__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -4941,27 +5573,27 @@ wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_nonpremul_4x16le__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_nonpremul_4x16le__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src;
|
||||
return wuffs_private_impl__swizzle_rgba_nonpremul__bgra_nonpremul_4x16le__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_rgba_nonpremul__bgra_nonpremul_4x16le__src_over;
|
||||
}
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul_4x16le__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul_4x16le__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -4973,8 +5605,8 @@ wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__bgra_premul(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
@@ -4984,160 +5616,170 @@ wuffs_base__pixel_swizzler__prepare__bgra_premul(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__copy_4_4;
|
||||
return wuffs_private_impl__swizzle_copy_4_4;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__bgrx(wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__bgrx(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
return wuffs_private_impl__swizzle_y__bgrx;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__bgrx;
|
||||
return wuffs_private_impl__swizzle_bgr_565__bgrx;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
return wuffs_base__pixel_swizzler__xxx__xxxx;
|
||||
return wuffs_private_impl__swizzle_xxx__xxxx;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
|
||||
return wuffs_base__pixel_swizzler__bgrw__bgrx;
|
||||
return wuffs_private_impl__swizzle_bgrw__bgrx;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
return wuffs_base__pixel_swizzler__bgrw_4x16le__bgrx;
|
||||
return wuffs_private_impl__swizzle_bgrw_4x16le__bgrx;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
return wuffs_base__pixel_swizzler__copy_4_4;
|
||||
return wuffs_private_impl__swizzle_copy_4_4;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgbx;
|
||||
return wuffs_private_impl__swizzle_bgr__rgbx;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
return wuffs_base__pixel_swizzler__bgrw__rgbx;
|
||||
return wuffs_private_impl__swizzle_bgrw__rgbx;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__rgb(wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__rgb(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
wuffs_base__slice_u8 src_palette,
|
||||
wuffs_base__pixel_blend blend) {
|
||||
switch (dst_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__rgb;
|
||||
return wuffs_private_impl__swizzle_bgr_565__rgb;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
return wuffs_base__pixel_swizzler__swap_rgb_bgr;
|
||||
return wuffs_private_impl__swizzle_swap_rgb_bgr;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42;
|
||||
return wuffs_private_impl__swizzle_bgrw__rgb__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_base__pixel_swizzler__bgrw__rgb;
|
||||
return wuffs_private_impl__swizzle_bgrw__rgb;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
return wuffs_base__pixel_swizzler__bgrw_4x16le__rgb;
|
||||
return wuffs_private_impl__swizzle_bgrw_4x16le__rgb;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__copy_3_3;
|
||||
return wuffs_private_impl__swizzle_copy_3_3;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
return wuffs_base__pixel_swizzler__bgrw__bgr;
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_private_impl__swizzle_bgrw__bgr__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_private_impl__swizzle_bgrw__bgr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__rgba_nonpremul(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__rgba_nonpremul(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
@@ -5147,50 +5789,50 @@ wuffs_base__pixel_swizzler__prepare__rgba_nonpremul(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgr_565__rgba_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr_565__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -5202,27 +5844,27 @@ wuffs_base__pixel_swizzler__prepare__rgba_nonpremul(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__copy_4_4;
|
||||
return wuffs_private_impl__swizzle_copy_4_4;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_nonpremul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -5234,8 +5876,8 @@ wuffs_base__pixel_swizzler__prepare__rgba_nonpremul(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static wuffs_base__pixel_swizzler__func //
|
||||
wuffs_base__pixel_swizzler__prepare__rgba_premul(
|
||||
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
|
||||
wuffs_private_impl__pixel_swizzler__prepare__rgba_premul(
|
||||
wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_format dst_pixfmt,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
@@ -5245,77 +5887,77 @@ wuffs_base__pixel_swizzler__prepare__rgba_premul(
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgr_565__rgba_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr_565__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
|
||||
if (wuffs_base__cpu_arch__have_x86_sse42()) {
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
|
||||
}
|
||||
#endif
|
||||
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
|
||||
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__rgba_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgr__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
return wuffs_base__pixel_swizzler__copy_4_4;
|
||||
return wuffs_private_impl__swizzle_copy_4_4;
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
return wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over;
|
||||
return wuffs_private_impl__swizzle_bgra_premul__bgra_premul__src_over;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -5339,6 +5981,50 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
|
||||
p->private_impl.dst_pixfmt_bytes_per_pixel = 0;
|
||||
p->private_impl.src_pixfmt_bytes_per_pixel = 0;
|
||||
|
||||
// ----
|
||||
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
|
||||
switch (dst_pixfmt.repr) {
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL_4X16LE)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGB)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_PREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist);
|
||||
}
|
||||
#endif // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
|
||||
|
||||
// ----
|
||||
|
||||
wuffs_base__pixel_swizzler__func func = NULL;
|
||||
wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func =
|
||||
NULL;
|
||||
@@ -5364,78 +6050,84 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
|
||||
switch (blend) {
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC:
|
||||
transparent_black_func =
|
||||
wuffs_base__pixel_swizzler__transparent_black_src;
|
||||
wuffs_private_impl__swizzle_transparent_black_src;
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
|
||||
transparent_black_func =
|
||||
wuffs_base__pixel_swizzler__transparent_black_src_over;
|
||||
wuffs_private_impl__swizzle_transparent_black_src_over;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (src_pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
func = wuffs_base__pixel_swizzler__prepare__y(p, dst_pixfmt, dst_palette,
|
||||
src_palette, blend);
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__y(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
func = wuffs_base__pixel_swizzler__prepare__y_16be(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__y_16be(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__ya_nonpremul(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
|
||||
func = wuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
func =
|
||||
wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_nonpremul(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
|
||||
func = wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_binary(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
func = wuffs_base__pixel_swizzler__prepare__bgr_565(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__bgr_565(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
func = wuffs_base__pixel_swizzler__prepare__bgr(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__bgr(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
func = wuffs_base__pixel_swizzler__prepare__bgra_nonpremul(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
func = wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
func = wuffs_base__pixel_swizzler__prepare__bgra_premul(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
func = wuffs_base__pixel_swizzler__prepare__bgrx(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__bgrx(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
func = wuffs_base__pixel_swizzler__prepare__rgb(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__rgb(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
func = wuffs_base__pixel_swizzler__prepare__rgba_nonpremul(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__rgba_nonpremul(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
func = wuffs_base__pixel_swizzler__prepare__rgba_premul(
|
||||
func = wuffs_private_impl__pixel_swizzler__prepare__rgba_premul(
|
||||
p, dst_pixfmt, dst_palette, src_palette, blend);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
// --------
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_avx2
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2(
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_bgrx_x86_avx2(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -23,7 +23,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2(
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
if ((x + 32u) > x_end) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx( //
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_bgrx( //
|
||||
dst, x, x_end, y, up0, up1, up2);
|
||||
return;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2(
|
||||
// except for the lines marked with a § and that comments were stripped.
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2(
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_rgbx_x86_avx2(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -296,7 +296,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2(
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
if ((x + 32u) > x_end) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx( //
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_bgrx( //
|
||||
dst, x, x_end, y, up0, up1, up2);
|
||||
return;
|
||||
}
|
||||
@@ -438,7 +438,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2(
|
||||
#else
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
@@ -636,5 +636,5 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
return dst_ptr;
|
||||
}
|
||||
#endif
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_avx2
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
// --------
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2(
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_bgrx_x86_avx2(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -24,7 +24,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2(
|
||||
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2(
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_rgbx_x86_avx2(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -38,7 +38,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2(
|
||||
#else
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
@@ -47,23 +47,26 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2(
|
||||
bool first_column,
|
||||
bool last_column);
|
||||
#endif
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__max_of_4(uint32_t a, uint32_t b, uint32_t c, uint32_t d) {
|
||||
wuffs_private_impl__u32__max_of_4(uint32_t a,
|
||||
uint32_t b,
|
||||
uint32_t c,
|
||||
uint32_t d) {
|
||||
return wuffs_base__u32__max( //
|
||||
wuffs_base__u32__max(a, b), //
|
||||
wuffs_base__u32__max(c, d));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__min_of_5(uint32_t a,
|
||||
uint32_t b,
|
||||
uint32_t c,
|
||||
uint32_t d,
|
||||
uint32_t e) {
|
||||
wuffs_private_impl__u32__min_of_5(uint32_t a,
|
||||
uint32_t b,
|
||||
uint32_t c,
|
||||
uint32_t d,
|
||||
uint32_t e) {
|
||||
return wuffs_base__u32__min( //
|
||||
wuffs_base__u32__min( //
|
||||
wuffs_base__u32__min(a, b), //
|
||||
@@ -73,7 +76,7 @@ wuffs_base__u32__min_of_5(uint32_t a,
|
||||
|
||||
// --------
|
||||
|
||||
typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_4_func)(
|
||||
typedef void (*wuffs_private_impl__swizzle_ycc__convert_4_func)(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -84,7 +87,7 @@ typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_4_func)(
|
||||
const uint8_t* up3);
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_cmyk__convert_4_general(
|
||||
wuffs_private_impl__swizzle_cmyk__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -110,7 +113,7 @@ wuffs_base__pixel_swizzler__swizzle_cmyk__convert_4_general(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycck__convert_4_general(
|
||||
wuffs_private_impl__swizzle_ycck__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -138,7 +141,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck__convert_4_general(
|
||||
|
||||
// --------
|
||||
|
||||
typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func)(
|
||||
typedef void (*wuffs_private_impl__swizzle_ycc__convert_3_func)(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -148,7 +151,7 @@ typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func)(
|
||||
const uint8_t* up2);
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_rgb__convert_3_general(
|
||||
wuffs_private_impl__swizzle_rgb__convert_3_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -166,7 +169,7 @@ wuffs_base__pixel_swizzler__swizzle_rgb__convert_3_general(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_general(
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
@@ -183,14 +186,13 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_general(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_bgrx(wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
size_t dst_stride = dst->private_impl.planes[0].stride;
|
||||
uint8_t* dst_iter = dst->private_impl.planes[0].ptr +
|
||||
(dst_stride * ((size_t)y)) + (4u * ((size_t)x));
|
||||
@@ -205,14 +207,13 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_rgbx(wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
size_t dst_stride = dst->private_impl.planes[0].stride;
|
||||
uint8_t* dst_iter = dst->private_impl.planes[0].ptr +
|
||||
(dst_stride * ((size_t)y)) + (4u * ((size_t)x));
|
||||
@@ -228,11 +229,11 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx(
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upsamples to a
|
||||
// destination slice at least 480 (YCCK) or 672 (YCC) bytes long and whose
|
||||
// src_len (multiplied by 1, 2, 3 or 4) is positive but no more than that. This
|
||||
// 480 or 672 length is just under 1/4 or 1/3 of the scratch_buffer_2k slice
|
||||
// length. Both (480 * 4) = 1920 and (672 * 3) = 2016 are less than 2048.
|
||||
// wuffs_private_impl__swizzle_ycc__upsample_func upsamples to a destination
|
||||
// slice at least 480 (YCCK) or 672 (YCC) bytes long and whose src_len
|
||||
// (multiplied by 1, 2, 3 or 4) is positive but no more than that. This 480 or
|
||||
// 672 length is just under 1/4 or 1/3 of the scratch_buffer_2k slice length.
|
||||
// Both (480 * 4) = 1920 and (672 * 3) = 2016 are less than 2048.
|
||||
//
|
||||
// 480 and 672 are nice round numbers because a JPEG MCU is 1, 2, 3 or 4 blocks
|
||||
// wide and each block is 8 pixels wide. We have:
|
||||
@@ -252,8 +253,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx(
|
||||
// In practice, matching libjpeg-turbo, we only implement it for the common
|
||||
// chroma subsampling ratios (YCC420, YCC422 or YCC440), corresponding to an
|
||||
// (inv_h, inv_v) pair of (2, 2), (2, 1) or (1, 2).
|
||||
typedef const uint8_t* (
|
||||
*wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func)(
|
||||
typedef const uint8_t* (*wuffs_private_impl__swizzle_ycc__upsample_func)(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major, // Nearest row.
|
||||
const uint8_t* src_ptr_minor, // Adjacent row, alternating above or below.
|
||||
@@ -263,7 +263,7 @@ typedef const uint8_t* (
|
||||
bool last_column);
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1vn_box(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h1vn_box(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor_ignored,
|
||||
@@ -275,7 +275,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1vn_box(
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2vn_box(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2vn_box(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor_ignored,
|
||||
@@ -294,7 +294,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2vn_box(
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h3vn_box(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h3vn_box(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor_ignored,
|
||||
@@ -314,7 +314,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h3vn_box(
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h4vn_box(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h4vn_box(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor_ignored,
|
||||
@@ -335,7 +335,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h4vn_box(
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1v2_triangle(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h1v2_triangle(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
@@ -356,7 +356,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1v2_triangle(
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v1_triangle(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v1_triangle(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
@@ -407,7 +407,7 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v1_triangle(
|
||||
}
|
||||
|
||||
static const uint8_t* //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
uint8_t* dst_ptr,
|
||||
const uint8_t* src_ptr_major,
|
||||
const uint8_t* src_ptr_minor,
|
||||
@@ -474,38 +474,38 @@ wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle(
|
||||
return dst_ptr;
|
||||
}
|
||||
|
||||
// wuffs_base__pixel_swizzler__swizzle_ycc__upsample_funcs is indexed by inv_h
|
||||
// and then inv_v.
|
||||
static const wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_funcs[4][4] = {
|
||||
// wuffs_private_impl__swizzle_ycc__upsample_funcs is indexed by inv_h and then
|
||||
// inv_v.
|
||||
static const wuffs_private_impl__swizzle_ycc__upsample_func
|
||||
wuffs_private_impl__swizzle_ycc__upsample_funcs[4][4] = {
|
||||
{
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h1vn_box,
|
||||
},
|
||||
{
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2vn_box,
|
||||
},
|
||||
{
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h3vn_box,
|
||||
},
|
||||
{
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h4vn_box,
|
||||
},
|
||||
};
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__pixel_swizzler__has_triangle_upsampler(uint32_t inv_h,
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(uint32_t inv_h,
|
||||
uint32_t inv_v) {
|
||||
if (inv_h == 1u) {
|
||||
return inv_v == 2u;
|
||||
@@ -517,13 +517,13 @@ wuffs_base__pixel_swizzler__has_triangle_upsampler(uint32_t inv_h,
|
||||
|
||||
// --------
|
||||
|
||||
// All of the wuffs_base__pixel_swizzler__swizzle_ycc__etc functions have
|
||||
// All of the wuffs_private_impl__swizzle_ycc__etc functions have
|
||||
// preconditions. See all of the checks made in
|
||||
// wuffs_base__pixel_swizzler__swizzle_ycck before calling these functions. For
|
||||
// example, (width > 0) is a precondition, but there are many more.
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
wuffs_private_impl__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t width,
|
||||
uint32_t y,
|
||||
@@ -546,11 +546,11 @@ wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
uint32_t half_width_for_2to1,
|
||||
uint32_t h1v2_bias,
|
||||
uint8_t* scratch_buffer_2k_ptr,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc0,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc3,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_4_func conv4func) {
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc0,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc1,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc2,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc3,
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func) {
|
||||
const uint8_t* src0 = src_ptr0 + ((y / inv_v0) * (size_t)stride0);
|
||||
const uint8_t* src1 = src_ptr1 + ((y / inv_v1) * (size_t)stride1);
|
||||
const uint8_t* src2 = src_ptr2 + ((y / inv_v2) * (size_t)stride2);
|
||||
@@ -623,10 +623,12 @@ wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter(
|
||||
wuffs_private_impl__swizzle_ycck__general__triangle_filter(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t x_min_incl,
|
||||
uint32_t x_max_excl,
|
||||
uint32_t y_min_incl,
|
||||
uint32_t y_max_excl,
|
||||
const uint8_t* src_ptr0,
|
||||
const uint8_t* src_ptr1,
|
||||
const uint8_t* src_ptr2,
|
||||
@@ -646,21 +648,25 @@ wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter(
|
||||
uint32_t half_width_for_2to1,
|
||||
uint32_t half_height_for_2to1,
|
||||
uint8_t* scratch_buffer_2k_ptr,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4],
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_4_func conv4func) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc0 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func (*upfuncs)[4][4],
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func) {
|
||||
if ((x_min_incl != 0) || (y_min_incl != 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc0 =
|
||||
(*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u];
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc1 =
|
||||
(*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u];
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc2 =
|
||||
(*upfuncs)[(inv_h2 - 1u) & 3u][(inv_v2 - 1u) & 3u];
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc3 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc3 =
|
||||
(*upfuncs)[(inv_h3 - 1u) & 3u][(inv_v3 - 1u) & 3u];
|
||||
|
||||
// First row.
|
||||
uint32_t h1v2_bias = 1u;
|
||||
wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
dst, width, 0u, //
|
||||
wuffs_private_impl__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
dst, x_max_excl, 0u, //
|
||||
src_ptr0, src_ptr1, src_ptr2, src_ptr3, //
|
||||
stride0, stride1, stride2, stride3, //
|
||||
inv_h0, inv_h1, inv_h2, inv_h3, //
|
||||
@@ -672,10 +678,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter(
|
||||
h1v2_bias = 2u;
|
||||
|
||||
// Middle rows.
|
||||
bool last_row = height == 2u * half_height_for_2to1;
|
||||
uint32_t y_max_excl = last_row ? (height - 1u) : height;
|
||||
bool last_row = y_max_excl == 2u * half_height_for_2to1;
|
||||
uint32_t middle_y_max_excl = last_row ? (y_max_excl - 1u) : y_max_excl;
|
||||
uint32_t y;
|
||||
for (y = 1u; y < y_max_excl; y++) {
|
||||
for (y = 1u; y < middle_y_max_excl; y++) {
|
||||
const uint8_t* src0_major = src_ptr0 + ((y / inv_v0) * (size_t)stride0);
|
||||
const uint8_t* src0_minor =
|
||||
(inv_v0 != 2u)
|
||||
@@ -702,11 +708,11 @@ wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter(
|
||||
uint32_t total_src_len3 = 0u;
|
||||
|
||||
uint32_t x = 0u;
|
||||
while (x < width) {
|
||||
while (x < x_max_excl) {
|
||||
bool first_column = x == 0u;
|
||||
uint32_t end = x + 480u;
|
||||
if (end > width) {
|
||||
end = width;
|
||||
if (end > x_max_excl) {
|
||||
end = x_max_excl;
|
||||
}
|
||||
|
||||
uint32_t src_len0 = ((end - x) + inv_h0 - 1u) / inv_h0;
|
||||
@@ -762,9 +768,9 @@ wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter(
|
||||
}
|
||||
|
||||
// Last row.
|
||||
if (y_max_excl != height) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
dst, width, height - 1u, //
|
||||
if (middle_y_max_excl != y_max_excl) {
|
||||
wuffs_private_impl__swizzle_ycck__general__triangle_filter_edge_row(
|
||||
dst, x_max_excl, middle_y_max_excl, //
|
||||
src_ptr0, src_ptr1, src_ptr2, src_ptr3, //
|
||||
stride0, stride1, stride2, stride3, //
|
||||
inv_h0, inv_h1, inv_h2, inv_h3, //
|
||||
@@ -777,7 +783,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
wuffs_private_impl__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t width,
|
||||
uint32_t y,
|
||||
@@ -796,10 +802,10 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
uint32_t half_width_for_2to1,
|
||||
uint32_t h1v2_bias,
|
||||
uint8_t* scratch_buffer_2k_ptr,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc0,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func conv3func) {
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc0,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc1,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc2,
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_func conv3func) {
|
||||
const uint8_t* src0 = src_ptr0 + ((y / inv_v0) * (size_t)stride0);
|
||||
const uint8_t* src1 = src_ptr1 + ((y / inv_v1) * (size_t)stride1);
|
||||
const uint8_t* src2 = src_ptr2 + ((y / inv_v2) * (size_t)stride2);
|
||||
@@ -858,10 +864,12 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter(
|
||||
wuffs_private_impl__swizzle_ycc__general__triangle_filter(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t x_min_incl,
|
||||
uint32_t x_max_excl,
|
||||
uint32_t y_min_incl,
|
||||
uint32_t y_max_excl,
|
||||
const uint8_t* src_ptr0,
|
||||
const uint8_t* src_ptr1,
|
||||
const uint8_t* src_ptr2,
|
||||
@@ -877,19 +885,23 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter(
|
||||
uint32_t half_width_for_2to1,
|
||||
uint32_t half_height_for_2to1,
|
||||
uint8_t* scratch_buffer_2k_ptr,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4],
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func conv3func) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc0 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func (*upfuncs)[4][4],
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_func conv3func) {
|
||||
if ((x_min_incl != 0) || (y_min_incl != 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc0 =
|
||||
(*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u];
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc1 =
|
||||
(*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u];
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc2 =
|
||||
(*upfuncs)[(inv_h2 - 1u) & 3u][(inv_v2 - 1u) & 3u];
|
||||
|
||||
// First row.
|
||||
uint32_t h1v2_bias = 1u;
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
dst, width, 0u, //
|
||||
wuffs_private_impl__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
dst, x_max_excl, 0u, //
|
||||
src_ptr0, src_ptr1, src_ptr2, //
|
||||
stride0, stride1, stride2, //
|
||||
inv_h0, inv_h1, inv_h2, //
|
||||
@@ -901,10 +913,10 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter(
|
||||
h1v2_bias = 2u;
|
||||
|
||||
// Middle rows.
|
||||
bool last_row = height == 2u * half_height_for_2to1;
|
||||
uint32_t y_max_excl = last_row ? (height - 1u) : height;
|
||||
bool last_row = y_max_excl == 2u * half_height_for_2to1;
|
||||
uint32_t middle_y_max_excl = last_row ? (y_max_excl - 1u) : y_max_excl;
|
||||
uint32_t y;
|
||||
for (y = 1u; y < y_max_excl; y++) {
|
||||
for (y = 1u; y < middle_y_max_excl; y++) {
|
||||
const uint8_t* src0_major = src_ptr0 + ((y / inv_v0) * (size_t)stride0);
|
||||
const uint8_t* src0_minor =
|
||||
(inv_v0 != 2u)
|
||||
@@ -925,11 +937,11 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter(
|
||||
uint32_t total_src_len2 = 0u;
|
||||
|
||||
uint32_t x = 0u;
|
||||
while (x < width) {
|
||||
while (x < x_max_excl) {
|
||||
bool first_column = x == 0u;
|
||||
uint32_t end = x + 672u;
|
||||
if (end > width) {
|
||||
end = width;
|
||||
if (end > x_max_excl) {
|
||||
end = x_max_excl;
|
||||
}
|
||||
|
||||
uint32_t src_len0 = ((end - x) + inv_h0 - 1u) / inv_h0;
|
||||
@@ -974,25 +986,27 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter(
|
||||
}
|
||||
|
||||
// Last row.
|
||||
if (y_max_excl != height) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
dst, width, height - 1u, //
|
||||
src_ptr0, src_ptr1, src_ptr2, //
|
||||
stride0, stride1, stride2, //
|
||||
inv_h0, inv_h1, inv_h2, //
|
||||
inv_v0, inv_v1, inv_v2, //
|
||||
half_width_for_2to1, //
|
||||
h1v2_bias, //
|
||||
scratch_buffer_2k_ptr, //
|
||||
if (middle_y_max_excl != y_max_excl) {
|
||||
wuffs_private_impl__swizzle_ycc__general__triangle_filter_edge_row(
|
||||
dst, x_max_excl, middle_y_max_excl, //
|
||||
src_ptr0, src_ptr1, src_ptr2, //
|
||||
stride0, stride1, stride2, //
|
||||
inv_h0, inv_h1, inv_h2, //
|
||||
inv_v0, inv_v1, inv_v2, //
|
||||
half_width_for_2to1, //
|
||||
h1v2_bias, //
|
||||
scratch_buffer_2k_ptr, //
|
||||
upfunc0, upfunc1, upfunc2, conv3func);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter(
|
||||
wuffs_private_impl__swizzle_ycc__general__box_filter(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t x_min_incl,
|
||||
uint32_t x_max_excl,
|
||||
uint32_t y_min_incl,
|
||||
uint32_t y_max_excl,
|
||||
const uint8_t* src_ptr0,
|
||||
const uint8_t* src_ptr1,
|
||||
const uint8_t* src_ptr2,
|
||||
@@ -1008,51 +1022,54 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter(
|
||||
uint32_t half_width_for_2to1,
|
||||
uint32_t half_height_for_2to1,
|
||||
uint8_t* scratch_buffer_2k_ptr,
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4],
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func conv3func) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc0 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func (*upfuncs)[4][4],
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_func conv3func) {
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc0 =
|
||||
(*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u];
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc1 =
|
||||
(*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u];
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2 =
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc2 =
|
||||
(*upfuncs)[(inv_h2 - 1u) & 3u][(inv_v2 - 1u) & 3u];
|
||||
|
||||
uint32_t y;
|
||||
for (y = 0u; y < height; y++) {
|
||||
const uint8_t* src0_major = src_ptr0 + ((y / inv_v0) * (size_t)stride0);
|
||||
const uint8_t* src1_major = src_ptr1 + ((y / inv_v1) * (size_t)stride1);
|
||||
const uint8_t* src2_major = src_ptr2 + ((y / inv_v2) * (size_t)stride2);
|
||||
for (y = y_min_incl; y < y_max_excl; y++) {
|
||||
const uint8_t* src0_major =
|
||||
src_ptr0 + (((y - y_min_incl) / inv_v0) * (size_t)stride0);
|
||||
const uint8_t* src1_major =
|
||||
src_ptr1 + (((y - y_min_incl) / inv_v1) * (size_t)stride1);
|
||||
const uint8_t* src2_major =
|
||||
src_ptr2 + (((y - y_min_incl) / inv_v2) * (size_t)stride2);
|
||||
|
||||
uint32_t x = 0u;
|
||||
while (x < width) {
|
||||
uint32_t x = x_min_incl;
|
||||
while (x < x_max_excl) {
|
||||
uint32_t end = x + 672u;
|
||||
if (end > width) {
|
||||
end = width;
|
||||
if (end > x_max_excl) {
|
||||
end = x_max_excl;
|
||||
}
|
||||
|
||||
uint32_t src_len0 = ((end - x) + inv_h0 - 1u) / inv_h0;
|
||||
uint32_t src_len1 = ((end - x) + inv_h1 - 1u) / inv_h1;
|
||||
uint32_t src_len2 = ((end - x) + inv_h2 - 1u) / inv_h2;
|
||||
|
||||
const uint8_t* up0 = (*upfunc0)( //
|
||||
scratch_buffer_2k_ptr + (0u * 672u), //
|
||||
src0_major + (x / inv_h0), //
|
||||
src0_major + (x / inv_h0), //
|
||||
src_len0, //
|
||||
const uint8_t* up0 = (*upfunc0)( //
|
||||
scratch_buffer_2k_ptr + (0u * 672u), //
|
||||
src0_major + ((x - x_min_incl) / inv_h0), //
|
||||
src0_major + ((x - x_min_incl) / inv_h0), //
|
||||
src_len0, //
|
||||
0u, false, false);
|
||||
|
||||
const uint8_t* up1 = (*upfunc1)( //
|
||||
scratch_buffer_2k_ptr + (1u * 672u), //
|
||||
src1_major + (x / inv_h1), //
|
||||
src1_major + (x / inv_h1), //
|
||||
src_len1, //
|
||||
const uint8_t* up1 = (*upfunc1)( //
|
||||
scratch_buffer_2k_ptr + (1u * 672u), //
|
||||
src1_major + ((x - x_min_incl) / inv_h1), //
|
||||
src1_major + ((x - x_min_incl) / inv_h1), //
|
||||
src_len1, //
|
||||
0u, false, false);
|
||||
|
||||
const uint8_t* up2 = (*upfunc2)( //
|
||||
scratch_buffer_2k_ptr + (2u * 672u), //
|
||||
src2_major + (x / inv_h2), //
|
||||
src2_major + (x / inv_h2), //
|
||||
src_len2, //
|
||||
const uint8_t* up2 = (*upfunc2)( //
|
||||
scratch_buffer_2k_ptr + (2u * 672u), //
|
||||
src2_major + ((x - x_min_incl) / inv_h2), //
|
||||
src2_major + ((x - x_min_incl) / inv_h2), //
|
||||
src_len2, //
|
||||
0u, false, false);
|
||||
|
||||
(*conv3func)(dst, x, end, y, up0, up1, up2);
|
||||
@@ -1061,13 +1078,107 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter(
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycck__general__box_filter(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x_min_incl,
|
||||
uint32_t x_max_excl,
|
||||
uint32_t y_min_incl,
|
||||
uint32_t y_max_excl,
|
||||
const uint8_t* src_ptr0,
|
||||
const uint8_t* src_ptr1,
|
||||
const uint8_t* src_ptr2,
|
||||
const uint8_t* src_ptr3,
|
||||
uint32_t stride0,
|
||||
uint32_t stride1,
|
||||
uint32_t stride2,
|
||||
uint32_t stride3,
|
||||
uint32_t inv_h0,
|
||||
uint32_t inv_h1,
|
||||
uint32_t inv_h2,
|
||||
uint32_t inv_h3,
|
||||
uint32_t inv_v0,
|
||||
uint32_t inv_v1,
|
||||
uint32_t inv_v2,
|
||||
uint32_t inv_v3,
|
||||
uint32_t half_width_for_2to1,
|
||||
uint32_t half_height_for_2to1,
|
||||
uint8_t* scratch_buffer_2k_ptr,
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func (*upfuncs)[4][4],
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func) {
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc0 =
|
||||
(*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u];
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc1 =
|
||||
(*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u];
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc2 =
|
||||
(*upfuncs)[(inv_h2 - 1u) & 3u][(inv_v2 - 1u) & 3u];
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfunc3 =
|
||||
(*upfuncs)[(inv_h3 - 1u) & 3u][(inv_v3 - 1u) & 3u];
|
||||
|
||||
uint32_t y;
|
||||
for (y = y_min_incl; y < y_max_excl; y++) {
|
||||
const uint8_t* src0_major =
|
||||
src_ptr0 + (((y - y_min_incl) / inv_v0) * (size_t)stride0);
|
||||
const uint8_t* src1_major =
|
||||
src_ptr1 + (((y - y_min_incl) / inv_v1) * (size_t)stride1);
|
||||
const uint8_t* src2_major =
|
||||
src_ptr2 + (((y - y_min_incl) / inv_v2) * (size_t)stride2);
|
||||
const uint8_t* src3_major =
|
||||
src_ptr3 + (((y - y_min_incl) / inv_v3) * (size_t)stride3);
|
||||
|
||||
uint32_t x = x_min_incl;
|
||||
while (x < x_max_excl) {
|
||||
uint32_t end = x + 480u;
|
||||
if (end > x_max_excl) {
|
||||
end = x_max_excl;
|
||||
}
|
||||
|
||||
uint32_t src_len0 = ((end - x) + inv_h0 - 1u) / inv_h0;
|
||||
uint32_t src_len1 = ((end - x) + inv_h1 - 1u) / inv_h1;
|
||||
uint32_t src_len2 = ((end - x) + inv_h2 - 1u) / inv_h2;
|
||||
uint32_t src_len3 = ((end - x) + inv_h3 - 1u) / inv_h3;
|
||||
|
||||
const uint8_t* up0 = (*upfunc0)( //
|
||||
scratch_buffer_2k_ptr + (0u * 480u), //
|
||||
src0_major + ((x - x_min_incl) / inv_h0), //
|
||||
src0_major + ((x - x_min_incl) / inv_h0), //
|
||||
src_len0, //
|
||||
0u, false, false);
|
||||
|
||||
const uint8_t* up1 = (*upfunc1)( //
|
||||
scratch_buffer_2k_ptr + (1u * 480u), //
|
||||
src1_major + ((x - x_min_incl) / inv_h1), //
|
||||
src1_major + ((x - x_min_incl) / inv_h1), //
|
||||
src_len1, //
|
||||
0u, false, false);
|
||||
|
||||
const uint8_t* up2 = (*upfunc2)( //
|
||||
scratch_buffer_2k_ptr + (2u * 480u), //
|
||||
src2_major + ((x - x_min_incl) / inv_h2), //
|
||||
src2_major + ((x - x_min_incl) / inv_h2), //
|
||||
src_len2, //
|
||||
0u, false, false);
|
||||
|
||||
const uint8_t* up3 = (*upfunc3)( //
|
||||
scratch_buffer_2k_ptr + (3u * 480u), //
|
||||
src3_major + ((x - x_min_incl) / inv_h3), //
|
||||
src3_major + ((x - x_min_incl) / inv_h3), //
|
||||
src_len3, //
|
||||
0u, false, false);
|
||||
|
||||
(*conv4func)(dst, x, end, y, up0, up1, up2, up3);
|
||||
x = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__pixel_swizzler__flattened_length is like
|
||||
// wuffs_private_impl__swizzle_flattened_length is like
|
||||
// wuffs_base__table__flattened_length but returns uint64_t (not size_t) and
|
||||
// also accounts for subsampling.
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__flattened_length(uint32_t width,
|
||||
wuffs_private_impl__swizzle_flattened_length(uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t stride,
|
||||
uint32_t inv_h,
|
||||
@@ -1085,8 +1196,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
const wuffs_base__pixel_swizzler* p,
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
wuffs_base__slice_u8 dst_palette,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t x_min_incl,
|
||||
uint32_t x_max_excl,
|
||||
uint32_t y_min_incl,
|
||||
uint32_t y_max_excl,
|
||||
wuffs_base__slice_u8 src0,
|
||||
wuffs_base__slice_u8 src1,
|
||||
wuffs_base__slice_u8 src2,
|
||||
@@ -1116,13 +1229,18 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
wuffs_base__slice_u8 scratch_buffer_2k) {
|
||||
if (!p) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
} else if (!dst || (width > 0xFFFFu) || (height > 0xFFFFu) || //
|
||||
(4u <= ((unsigned int)h0 - 1u)) || //
|
||||
(4u <= ((unsigned int)h1 - 1u)) || //
|
||||
(4u <= ((unsigned int)h2 - 1u)) || //
|
||||
(4u <= ((unsigned int)v0 - 1u)) || //
|
||||
(4u <= ((unsigned int)v1 - 1u)) || //
|
||||
(4u <= ((unsigned int)v2 - 1u)) || //
|
||||
} else if (!dst || //
|
||||
(x_min_incl > x_max_excl) || //
|
||||
(x_max_excl > 0xFFFFu) || //
|
||||
(y_min_incl > y_max_excl) || //
|
||||
(y_max_excl > 0xFFFFu) || //
|
||||
(4u <= ((unsigned int)h0 - 1u)) || //
|
||||
(4u <= ((unsigned int)h1 - 1u)) || //
|
||||
(4u <= ((unsigned int)h2 - 1u)) || //
|
||||
(4u <= ((unsigned int)v0 - 1u)) || //
|
||||
(4u <= ((unsigned int)v1 - 1u)) || //
|
||||
(4u <= ((unsigned int)v2 - 1u)) || //
|
||||
(triangle_filter_for_2to1 && ((x_min_incl | y_min_incl) > 0u)) ||
|
||||
(scratch_buffer_2k.len < 2048u)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
@@ -1133,8 +1251,8 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t max_incl_h = wuffs_base__u32__max_of_4(h0, h1, h2, h3);
|
||||
uint32_t max_incl_v = wuffs_base__u32__max_of_4(v0, v1, v2, v3);
|
||||
uint32_t max_incl_h = wuffs_private_impl__u32__max_of_4(h0, h1, h2, h3);
|
||||
uint32_t max_incl_v = wuffs_private_impl__u32__max_of_4(v0, v1, v2, v3);
|
||||
|
||||
// Calculate the inverse h and v ratios.
|
||||
//
|
||||
@@ -1149,21 +1267,69 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint32_t inv_v2 = max_incl_v / v2;
|
||||
uint32_t inv_v3 = v3 ? (max_incl_v / v3) : 0u;
|
||||
|
||||
uint32_t half_width_for_2to1 = (width + 1u) / 2u;
|
||||
uint32_t half_height_for_2to1 = (height + 1u) / 2u;
|
||||
if (x_min_incl != 0) {
|
||||
if ((x_min_incl % inv_h0) || (x_min_incl % inv_h1) ||
|
||||
(x_min_incl % inv_h2) || (inv_h3 && (x_min_incl % inv_h3))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
if (y_min_incl != 0) {
|
||||
if ((y_min_incl % inv_v0) || (y_min_incl % inv_v1) ||
|
||||
(y_min_incl % inv_v2) || (inv_v3 && (y_min_incl % inv_v3))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
|
||||
width = wuffs_base__u32__min_of_5( //
|
||||
width, //
|
||||
width0 * inv_h0, //
|
||||
width1 * inv_h1, //
|
||||
width2 * inv_h2, //
|
||||
wuffs_base__pixel_config__width(&dst->pixcfg));
|
||||
height = wuffs_base__u32__min_of_5( //
|
||||
height, //
|
||||
height0 * inv_v0, //
|
||||
height1 * inv_v1, //
|
||||
height2 * inv_v2, //
|
||||
wuffs_base__pixel_config__height(&dst->pixcfg));
|
||||
uint32_t half_width_for_2to1 = ((x_max_excl - x_min_incl) + 1u) / 2u;
|
||||
if (inv_h0 == 2) {
|
||||
half_width_for_2to1 = wuffs_base__u32__min(half_width_for_2to1, width0);
|
||||
}
|
||||
if (inv_h1 == 2) {
|
||||
half_width_for_2to1 = wuffs_base__u32__min(half_width_for_2to1, width1);
|
||||
}
|
||||
if (inv_h2 == 2) {
|
||||
half_width_for_2to1 = wuffs_base__u32__min(half_width_for_2to1, width2);
|
||||
}
|
||||
if (inv_h3 == 2) {
|
||||
half_width_for_2to1 = wuffs_base__u32__min(half_width_for_2to1, width3);
|
||||
}
|
||||
|
||||
uint32_t half_height_for_2to1 = ((y_max_excl - y_min_incl) + 1u) / 2u;
|
||||
if (inv_v0 == 2) {
|
||||
half_height_for_2to1 = wuffs_base__u32__min(half_height_for_2to1, height0);
|
||||
}
|
||||
if (inv_v1 == 2) {
|
||||
half_height_for_2to1 = wuffs_base__u32__min(half_height_for_2to1, height1);
|
||||
}
|
||||
if (inv_v2 == 2) {
|
||||
half_height_for_2to1 = wuffs_base__u32__min(half_height_for_2to1, height2);
|
||||
}
|
||||
if (inv_v3 == 2) {
|
||||
half_height_for_2to1 = wuffs_base__u32__min(half_height_for_2to1, height3);
|
||||
}
|
||||
|
||||
x_max_excl = wuffs_base__u32__min( //
|
||||
wuffs_base__pixel_config__width(&dst->pixcfg), //
|
||||
x_min_incl + wuffs_private_impl__u32__min_of_5( //
|
||||
x_max_excl - x_min_incl, //
|
||||
width0 * inv_h0, //
|
||||
width1 * inv_h1, //
|
||||
width2 * inv_h2, //
|
||||
inv_h3 ? (width3 * inv_h3) : 0xFFFFFFFF));
|
||||
y_max_excl = wuffs_base__u32__min( //
|
||||
wuffs_base__pixel_config__height(&dst->pixcfg), //
|
||||
y_min_incl + wuffs_private_impl__u32__min_of_5( //
|
||||
y_max_excl - y_min_incl, //
|
||||
height0 * inv_v0, //
|
||||
height1 * inv_v1, //
|
||||
height2 * inv_v2, //
|
||||
inv_v3 ? (height3 * inv_v3) : 0xFFFFFFFF));
|
||||
|
||||
if ((x_min_incl >= x_max_excl) || (y_min_incl >= y_max_excl)) {
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
uint32_t width = x_max_excl - x_min_incl;
|
||||
uint32_t height = y_max_excl - y_min_incl;
|
||||
|
||||
if (((h0 * inv_h0) != max_incl_h) || //
|
||||
((h1 * inv_h1) != max_incl_h) || //
|
||||
@@ -1171,18 +1337,18 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
((v0 * inv_v0) != max_incl_v) || //
|
||||
((v1 * inv_v1) != max_incl_v) || //
|
||||
((v2 * inv_v2) != max_incl_v) || //
|
||||
(src0.len < wuffs_base__pixel_swizzler__flattened_length(
|
||||
(src0.len < wuffs_private_impl__swizzle_flattened_length(
|
||||
width, height, stride0, inv_h0, inv_v0)) ||
|
||||
(src1.len < wuffs_base__pixel_swizzler__flattened_length(
|
||||
(src1.len < wuffs_private_impl__swizzle_flattened_length(
|
||||
width, height, stride1, inv_h1, inv_v1)) ||
|
||||
(src2.len < wuffs_base__pixel_swizzler__flattened_length(
|
||||
(src2.len < wuffs_private_impl__swizzle_flattened_length(
|
||||
width, height, stride2, inv_h2, inv_v2))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((h3 != 0u) || (v3 != 0u)) {
|
||||
if (((h3 * inv_h3) != max_incl_h) || //
|
||||
((v3 * inv_v3) != max_incl_v) || //
|
||||
(src3.len < wuffs_base__pixel_swizzler__flattened_length(
|
||||
(src3.len < wuffs_private_impl__swizzle_flattened_length(
|
||||
width, height, stride3, inv_h3, inv_v3))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
@@ -1194,10 +1360,52 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_NONPREMUL_4X16LE)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGRA_PREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGB)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
break;
|
||||
#endif
|
||||
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_PREMUL)
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__disabled_by_wuffs_config_dst_pixel_format_enable_allowlist);
|
||||
}
|
||||
#else // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
|
||||
@@ -1218,88 +1426,113 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
#endif // defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
|
||||
|
||||
if ((width <= 0u) || (height <= 0u)) {
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
// ----
|
||||
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func conv3func = NULL;
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_func conv3func = NULL;
|
||||
|
||||
if (is_rgb_or_cmyk) {
|
||||
conv3func = &wuffs_base__pixel_swizzler__swizzle_rgb__convert_3_general;
|
||||
conv3func = &wuffs_private_impl__swizzle_rgb__convert_3_general;
|
||||
} else {
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
conv3func =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2;
|
||||
conv3func = &wuffs_private_impl__swizzle_ycc__convert_3_bgrx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
conv3func = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx;
|
||||
conv3func = &wuffs_private_impl__swizzle_ycc__convert_3_bgrx;
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
conv3func =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2;
|
||||
conv3func = &wuffs_private_impl__swizzle_ycc__convert_3_rgbx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
conv3func = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx;
|
||||
conv3func = &wuffs_private_impl__swizzle_ycc__convert_3_rgbx;
|
||||
break;
|
||||
default:
|
||||
conv3func = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_general;
|
||||
conv3func = &wuffs_private_impl__swizzle_ycc__convert_3_general;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void (*func)(
|
||||
wuffs_base__pixel_buffer * dst, //
|
||||
uint32_t width, //
|
||||
uint32_t height, //
|
||||
const uint8_t* src_ptr0, //
|
||||
const uint8_t* src_ptr1, //
|
||||
const uint8_t* src_ptr2, //
|
||||
uint32_t stride0, //
|
||||
uint32_t stride1, //
|
||||
uint32_t stride2, //
|
||||
uint32_t inv_h0, //
|
||||
uint32_t inv_h1, //
|
||||
uint32_t inv_h2, //
|
||||
uint32_t inv_v0, //
|
||||
uint32_t inv_v1, //
|
||||
uint32_t inv_v2, //
|
||||
uint32_t half_width_for_2to1, //
|
||||
uint32_t half_height_for_2to1, //
|
||||
uint8_t* scratch_buffer_2k_ptr, //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func(*upfuncs)[4][4],
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func conv3func) =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter;
|
||||
void (*func3)(wuffs_base__pixel_buffer * dst, //
|
||||
uint32_t x_min_incl, //
|
||||
uint32_t x_max_excl, //
|
||||
uint32_t y_min_incl, //
|
||||
uint32_t y_max_excl, //
|
||||
const uint8_t* src_ptr0, //
|
||||
const uint8_t* src_ptr1, //
|
||||
const uint8_t* src_ptr2, //
|
||||
uint32_t stride0, //
|
||||
uint32_t stride1, //
|
||||
uint32_t stride2, //
|
||||
uint32_t inv_h0, //
|
||||
uint32_t inv_h1, //
|
||||
uint32_t inv_h2, //
|
||||
uint32_t inv_v0, //
|
||||
uint32_t inv_v1, //
|
||||
uint32_t inv_v2, //
|
||||
uint32_t half_width_for_2to1, //
|
||||
uint32_t half_height_for_2to1, //
|
||||
uint8_t* scratch_buffer_2k_ptr, //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func(*upfuncs)[4][4],
|
||||
wuffs_private_impl__swizzle_ycc__convert_3_func conv3func) =
|
||||
&wuffs_private_impl__swizzle_ycc__general__box_filter;
|
||||
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfuncs[4][4];
|
||||
memcpy(&upfuncs, &wuffs_base__pixel_swizzler__swizzle_ycc__upsample_funcs,
|
||||
void (*func4)(wuffs_base__pixel_buffer * dst, //
|
||||
uint32_t x_min_incl, //
|
||||
uint32_t x_max_excl, //
|
||||
uint32_t y_min_incl, //
|
||||
uint32_t y_max_excl, //
|
||||
const uint8_t* src_ptr0, //
|
||||
const uint8_t* src_ptr1, //
|
||||
const uint8_t* src_ptr2, //
|
||||
const uint8_t* src_ptr3, //
|
||||
uint32_t stride0, //
|
||||
uint32_t stride1, //
|
||||
uint32_t stride2, //
|
||||
uint32_t stride3, //
|
||||
uint32_t inv_h0, //
|
||||
uint32_t inv_h1, //
|
||||
uint32_t inv_h2, //
|
||||
uint32_t inv_h3, //
|
||||
uint32_t inv_v0, //
|
||||
uint32_t inv_v1, //
|
||||
uint32_t inv_v2, //
|
||||
uint32_t inv_v3, //
|
||||
uint32_t half_width_for_2to1, //
|
||||
uint32_t half_height_for_2to1, //
|
||||
uint8_t* scratch_buffer_2k_ptr, //
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func(*upfuncs)[4][4],
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func) =
|
||||
&wuffs_private_impl__swizzle_ycck__general__box_filter;
|
||||
|
||||
wuffs_private_impl__swizzle_ycc__upsample_func upfuncs[4][4];
|
||||
memcpy(&upfuncs, &wuffs_private_impl__swizzle_ycc__upsample_funcs,
|
||||
sizeof upfuncs);
|
||||
|
||||
if (triangle_filter_for_2to1 &&
|
||||
(wuffs_base__pixel_swizzler__has_triangle_upsampler(inv_h0, inv_v0) ||
|
||||
wuffs_base__pixel_swizzler__has_triangle_upsampler(inv_h1, inv_v1) ||
|
||||
wuffs_base__pixel_swizzler__has_triangle_upsampler(inv_h2, inv_v2))) {
|
||||
func = &wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter;
|
||||
(wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h0, inv_v0) ||
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h1, inv_v1) ||
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h2, inv_v2) ||
|
||||
wuffs_private_impl__swizzle_has_triangle_upsampler(inv_h3, inv_v3))) {
|
||||
func3 = &wuffs_private_impl__swizzle_ycc__general__triangle_filter;
|
||||
func4 = &wuffs_private_impl__swizzle_ycck__general__triangle_filter;
|
||||
|
||||
upfuncs[0][1] =
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1v2_triangle;
|
||||
upfuncs[1][0] =
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v1_triangle;
|
||||
upfuncs[1][1] =
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle;
|
||||
upfuncs[0][1] = wuffs_private_impl__swizzle_ycc__upsample_inv_h1v2_triangle;
|
||||
upfuncs[1][0] = wuffs_private_impl__swizzle_ycc__upsample_inv_h2v1_triangle;
|
||||
upfuncs[1][1] = wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle;
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
// Don't use our AVX2 implementation for GCC (but do use it for clang). For
|
||||
// some unknown reason, GCC performs noticably better on the non-SIMD
|
||||
@@ -1315,34 +1548,33 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
#else
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
upfuncs[1][1] =
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2;
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v2_triangle_x86_avx2;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((h3 != 0u) || (v3 != 0u)) {
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_4_func conv4func =
|
||||
is_rgb_or_cmyk
|
||||
? &wuffs_base__pixel_swizzler__swizzle_cmyk__convert_4_general
|
||||
: &wuffs_base__pixel_swizzler__swizzle_ycck__convert_4_general;
|
||||
wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter( //
|
||||
dst, width, height, //
|
||||
src0.ptr, src1.ptr, src2.ptr, src3.ptr, //
|
||||
stride0, stride1, stride2, stride3, //
|
||||
inv_h0, inv_h1, inv_h2, inv_h3, //
|
||||
inv_v0, inv_v1, inv_v2, inv_v3, //
|
||||
half_width_for_2to1, half_height_for_2to1, //
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func =
|
||||
is_rgb_or_cmyk ? &wuffs_private_impl__swizzle_cmyk__convert_4_general
|
||||
: &wuffs_private_impl__swizzle_ycck__convert_4_general;
|
||||
(*func4)( //
|
||||
dst, x_min_incl, x_max_excl, y_min_incl, y_max_excl, //
|
||||
src0.ptr, src1.ptr, src2.ptr, src3.ptr, //
|
||||
stride0, stride1, stride2, stride3, //
|
||||
inv_h0, inv_h1, inv_h2, inv_h3, //
|
||||
inv_v0, inv_v1, inv_v2, inv_v3, //
|
||||
half_width_for_2to1, half_height_for_2to1, //
|
||||
scratch_buffer_2k.ptr, &upfuncs, conv4func);
|
||||
|
||||
} else {
|
||||
(*func)( //
|
||||
dst, width, height, //
|
||||
src0.ptr, src1.ptr, src2.ptr, //
|
||||
stride0, stride1, stride2, //
|
||||
inv_h0, inv_h1, inv_h2, //
|
||||
inv_v0, inv_v1, inv_v2, //
|
||||
half_width_for_2to1, half_height_for_2to1, //
|
||||
(*func3)( //
|
||||
dst, x_min_incl, x_max_excl, y_min_incl, y_max_excl, //
|
||||
src0.ptr, src1.ptr, src2.ptr, //
|
||||
stride0, stride1, stride2, //
|
||||
inv_h0, inv_h1, inv_h2, //
|
||||
inv_v0, inv_v1, inv_v2, //
|
||||
half_width_for_2to1, half_height_for_2to1, //
|
||||
scratch_buffer_2k.ptr, &upfuncs, conv3func);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,42 +11,50 @@
|
||||
// ---------------- Ranges and Rects
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__range_ii_u32__get_min_incl(const wuffs_base__range_ii_u32* r) {
|
||||
wuffs_private_impl__range_ii_u32__get_min_incl(
|
||||
const wuffs_base__range_ii_u32* r) {
|
||||
return r->min_incl;
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__range_ii_u32__get_max_incl(const wuffs_base__range_ii_u32* r) {
|
||||
wuffs_private_impl__range_ii_u32__get_max_incl(
|
||||
const wuffs_base__range_ii_u32* r) {
|
||||
return r->max_incl;
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__range_ie_u32__get_min_incl(const wuffs_base__range_ie_u32* r) {
|
||||
wuffs_private_impl__range_ie_u32__get_min_incl(
|
||||
const wuffs_base__range_ie_u32* r) {
|
||||
return r->min_incl;
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__range_ie_u32__get_max_excl(const wuffs_base__range_ie_u32* r) {
|
||||
wuffs_private_impl__range_ie_u32__get_max_excl(
|
||||
const wuffs_base__range_ie_u32* r) {
|
||||
return r->max_excl;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__range_ii_u64__get_min_incl(const wuffs_base__range_ii_u64* r) {
|
||||
wuffs_private_impl__range_ii_u64__get_min_incl(
|
||||
const wuffs_base__range_ii_u64* r) {
|
||||
return r->min_incl;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__range_ii_u64__get_max_incl(const wuffs_base__range_ii_u64* r) {
|
||||
wuffs_private_impl__range_ii_u64__get_max_incl(
|
||||
const wuffs_base__range_ii_u64* r) {
|
||||
return r->max_incl;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__range_ie_u64__get_min_incl(const wuffs_base__range_ie_u64* r) {
|
||||
wuffs_private_impl__range_ie_u64__get_min_incl(
|
||||
const wuffs_base__range_ie_u64* r) {
|
||||
return r->min_incl;
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__range_ie_u64__get_max_excl(const wuffs_base__range_ie_u64* r) {
|
||||
wuffs_private_impl__range_ie_u64__get_max_excl(
|
||||
const wuffs_base__range_ie_u64* r) {
|
||||
return r->max_excl;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,49 +39,53 @@ wuffs_base__make_token(uint64_t repr) {
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_BASE__TOKEN__LENGTH__MAX_INCL 0xFFFF
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VALUE__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__VALUE_EXTENSION__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT 42
|
||||
#define WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__VALUE_BASE_CATEGORY__SHIFT 38
|
||||
#define WUFFS_BASE__TOKEN__VALUE_BASE_DETAIL__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__CONTINUED__SHIFT 16
|
||||
#define WUFFS_BASE__TOKEN__LENGTH__SHIFT 0
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VALUE_EXTENSION__NUM_BITS 46
|
||||
// clang-format off
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VBC__FILLER 0
|
||||
#define WUFFS_BASE__TOKEN__VBC__STRUCTURE 1
|
||||
#define WUFFS_BASE__TOKEN__VBC__STRING 2
|
||||
#define WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT 3
|
||||
#define WUFFS_BASE__TOKEN__VBC__LITERAL 4
|
||||
#define WUFFS_BASE__TOKEN__VBC__NUMBER 5
|
||||
#define WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED 6
|
||||
#define WUFFS_BASE__TOKEN__LENGTH__MAX_INCL 0xFFFF
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VALUE__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__VALUE_EXTENSION__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT 42
|
||||
#define WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__VALUE_BASE_CATEGORY__SHIFT 38
|
||||
#define WUFFS_BASE__TOKEN__VALUE_BASE_DETAIL__SHIFT 17
|
||||
#define WUFFS_BASE__TOKEN__CONTINUED__SHIFT 16
|
||||
#define WUFFS_BASE__TOKEN__LENGTH__SHIFT 0
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VALUE_EXTENSION__NUM_BITS 46
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VBC__FILLER 0
|
||||
#define WUFFS_BASE__TOKEN__VBC__STRUCTURE 1
|
||||
#define WUFFS_BASE__TOKEN__VBC__STRING 2
|
||||
#define WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT 3
|
||||
#define WUFFS_BASE__TOKEN__VBC__LITERAL 4
|
||||
#define WUFFS_BASE__TOKEN__VBC__NUMBER 5
|
||||
#define WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED 6
|
||||
#define WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED 7
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VBD__FILLER__PUNCTUATION 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__FILLER__PUNCTUATION 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_BLOCK 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_LINE 0x00004
|
||||
#define WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_LINE 0x00004
|
||||
|
||||
// COMMENT_ANY is a bit-wise or of COMMENT_BLOCK AND COMMENT_LINE.
|
||||
#define WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_ANY 0x00006
|
||||
#define WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_ANY 0x00006
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__POP 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__POP 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_NONE 0x00010
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_LIST 0x00020
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_DICT 0x00040
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE 0x01000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST 0x02000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT 0x04000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE 0x01000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST 0x02000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT 0x04000
|
||||
|
||||
// --------
|
||||
|
||||
@@ -101,11 +105,11 @@ wuffs_base__make_token(uint64_t repr) {
|
||||
//
|
||||
// The lack of any particular bit is conservative: it is valid for all-ASCII
|
||||
// strings, in a single- or multi-token chain, to have none of these bits set.
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__DEFINITELY_UTF_8 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__DEFINITELY_UTF_8 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_SHOULD_BE_UTF_8 0x00004
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__DEFINITELY_ASCII 0x00010
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_MUST_BE_ASCII 0x00020
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__DEFINITELY_ASCII 0x00010
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_MUST_BE_ASCII 0x00020
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_SHOULD_BE_ASCII 0x00040
|
||||
|
||||
// CONVERT_D_DST_S_SRC means that multiples of S source bytes (possibly padded)
|
||||
@@ -120,22 +124,22 @@ wuffs_base__make_token(uint64_t repr) {
|
||||
// When src is the empty string, multiple conversion algorithms are applicable
|
||||
// (so these bits are not necessarily mutually exclusive), all producing the
|
||||
// same empty dst string.
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP 0x00100
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY 0x00200
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP 0x00100
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY 0x00200
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_2_SRC_HEXADECIMAL 0x00400
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_4_SRC_BACKSLASH_X 0x00800
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_3_DST_4_SRC_BASE_64_STD 0x01000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_3_DST_4_SRC_BASE_64_URL 0x02000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_4_DST_5_SRC_ASCII_85 0x04000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_4_DST_5_SRC_ASCII_85 0x04000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_5_DST_8_SRC_BASE_32_HEX 0x08000
|
||||
#define WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_5_DST_8_SRC_BASE_32_STD 0x10000
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VBD__LITERAL__UNDEFINED 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__LITERAL__NULL 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__LITERAL__FALSE 0x00004
|
||||
#define WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE 0x00008
|
||||
#define WUFFS_BASE__TOKEN__VBD__LITERAL__NULL 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__LITERAL__FALSE 0x00004
|
||||
#define WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE 0x00008
|
||||
|
||||
// --------
|
||||
|
||||
@@ -148,8 +152,8 @@ wuffs_base__make_token(uint64_t repr) {
|
||||
// For a source string of "+123" or "-0x9A", only the first two are valid.
|
||||
//
|
||||
// For a source string of "123.", only the first one is valid.
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT 0x00001
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED 0x00002
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_UNSIGNED 0x00004
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_INF 0x00010
|
||||
@@ -161,11 +165,15 @@ wuffs_base__make_token(uint64_t repr) {
|
||||
// "300", which are big-endian, little-endian or text. For binary formats, the
|
||||
// token length (after adjusting for FORMAT_IGNORE_ETC) discriminates
|
||||
// e.g. u16 little-endian vs u32 little-endian.
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_BINARY_BIG_ENDIAN 0x00100
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_BINARY_BIG_ENDIAN 0x00100
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_BINARY_LITTLE_ENDIAN 0x00200
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_TEXT 0x00400
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_TEXT 0x00400
|
||||
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_IGNORE_FIRST_BYTE 0x01000
|
||||
#define WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_IGNORE_FIRST_BYTE 0x01000
|
||||
|
||||
// --------
|
||||
|
||||
// clang-format on
|
||||
|
||||
// --------
|
||||
|
||||
@@ -277,6 +285,22 @@ wuffs_base__token::length() const {
|
||||
|
||||
// --------
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
|
||||
static inline wuffs_base__token* //
|
||||
wuffs_base__strip_const_from_token_ptr(const wuffs_base__token* ptr) {
|
||||
return (wuffs_base__token*)ptr;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// --------
|
||||
|
||||
typedef WUFFS_BASE__SLICE(wuffs_base__token) wuffs_base__slice_token;
|
||||
|
||||
static inline wuffs_base__slice_token //
|
||||
@@ -430,7 +454,8 @@ wuffs_base__token_buffer__compact(wuffs_base__token_buffer* buf) {
|
||||
// wuffs_base__token_buffer__compact_retaining moves any written but unread
|
||||
// tokens closer to the start of the buffer. It retains H tokens of history
|
||||
// (the most recently read tokens), where H is min(buf->meta.ri,
|
||||
// history_retain_length). A postcondition is that buf->meta.ri == H.
|
||||
// history_retain_length). It is therefore a no-op if history_retain_length is
|
||||
// UINT64_MAX. A postcondition is that buf->meta.ri == H.
|
||||
//
|
||||
// wuffs_base__token_buffer__compact_retaining(0) is equivalent to
|
||||
// wuffs_base__token_buffer__compact().
|
||||
|
||||
+66
-50
@@ -127,7 +127,7 @@ func (g *gen) writeBuiltinCall(b *buffer, n *a.Expr, sideEffectsOnly bool, depth
|
||||
return nil
|
||||
}
|
||||
case t.IDTokenWriter:
|
||||
return g.writeBuiltinTokenWriter(b, recv, method.Ident(), n.Args(), depth)
|
||||
return g.writeBuiltinTokenWriter(b, recv, method.Ident(), n.Args(), sideEffectsOnly, depth)
|
||||
case t.IDUtility:
|
||||
switch method.Ident() {
|
||||
case t.IDCPUArchIs32Bit:
|
||||
@@ -159,7 +159,7 @@ func (g *gen) recvName(recv *a.Expr) (string, error) {
|
||||
return "", fmt.Errorf("recvName: cannot cgen a %q expression", recv.Str(g.tm))
|
||||
}
|
||||
|
||||
func (g *gen) writeBuiltinIO(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, depth uint32) error {
|
||||
func (g *gen) writeBuiltinIO(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
|
||||
switch method {
|
||||
case t.IDLength:
|
||||
recvName, err := g.recvName(recv)
|
||||
@@ -168,6 +168,40 @@ func (g *gen) writeBuiltinIO(b *buffer, recv *a.Expr, method t.ID, args []*a.Nod
|
||||
}
|
||||
b.printf("((uint64_t)(%s%s - %s%s))", io2Prefix, recvName, iopPrefix, recvName)
|
||||
return nil
|
||||
|
||||
case t.IDPeekUndoByte:
|
||||
recvName, err := g.recvName(recv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("%s%s[-1]", iopPrefix, recvName)
|
||||
return nil
|
||||
|
||||
case t.IDUndoByte:
|
||||
recvName, err := g.recvName(recv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !sideEffectsOnly {
|
||||
// Generate a two part expression using the comma operator: "(etc,
|
||||
// return_empty_struct call)". The final part is a function call
|
||||
// (to a static inline function) instead of a struct literal, to
|
||||
// avoid a "expression result unused" compiler error.
|
||||
b.writes("(")
|
||||
}
|
||||
b.printf("%s%s--", iopPrefix, recvName)
|
||||
if !sideEffectsOnly {
|
||||
b.writes(", wuffs_base__make_empty_struct())")
|
||||
}
|
||||
return nil
|
||||
|
||||
case t.IDCanUndoByte:
|
||||
recvName, err := g.recvName(recv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("(%s%s > %s%s)", iopPrefix, recvName, io1Prefix, recvName)
|
||||
return nil
|
||||
}
|
||||
return errNoSuchBuiltin
|
||||
}
|
||||
@@ -189,31 +223,13 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
b.writes("))))))")
|
||||
return nil
|
||||
|
||||
case t.IDUndoByte:
|
||||
if !sideEffectsOnly {
|
||||
// Generate a two part expression using the comma operator: "(etc,
|
||||
// return_empty_struct call)". The final part is a function call
|
||||
// (to a static inline function) instead of a struct literal, to
|
||||
// avoid a "expression result unused" compiler error.
|
||||
b.writes("(")
|
||||
}
|
||||
b.printf("%s%s--", iopPrefix, recvName)
|
||||
if !sideEffectsOnly {
|
||||
b.writes(", wuffs_base__make_empty_struct())")
|
||||
}
|
||||
return nil
|
||||
|
||||
case t.IDCanUndoByte:
|
||||
b.printf("(%s%s > %s%s)", iopPrefix, recvName, io1Prefix, recvName)
|
||||
return nil
|
||||
|
||||
case t.IDLimitedCopyU32ToSlice:
|
||||
b.printf("wuffs_base__io_reader__limited_copy_u32_to_slice(\n&%s%s, %s%s,",
|
||||
b.printf("wuffs_private_impl__io_reader__limited_copy_u32_to_slice(\n&%s%s, %s%s,",
|
||||
iopPrefix, recvName, io2Prefix, recvName)
|
||||
return g.writeArgs(b, args, depth)
|
||||
|
||||
case t.IDCountSince:
|
||||
b.printf("wuffs_base__io__count_since(")
|
||||
b.printf("wuffs_private_impl__io__count_since(")
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -229,7 +245,7 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
return nil
|
||||
|
||||
case t.IDMatch7:
|
||||
b.printf("wuffs_base__io_reader__match7(%s%s, %s%s, %s, ",
|
||||
b.printf("wuffs_private_impl__io_reader__match7(%s%s, %s%s, %s, ",
|
||||
iopPrefix, recvName, io2Prefix, recvName, recvName)
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
|
||||
return err
|
||||
@@ -251,7 +267,7 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
return nil
|
||||
|
||||
case t.IDSince:
|
||||
b.printf("wuffs_base__io__since(")
|
||||
b.printf("wuffs_private_impl__io__since(")
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -293,7 +309,7 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
}
|
||||
}
|
||||
|
||||
return g.writeBuiltinIO(b, recv, method, args, depth)
|
||||
return g.writeBuiltinIO(b, recv, method, args, sideEffectsOnly, depth)
|
||||
}
|
||||
|
||||
func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
|
||||
@@ -305,9 +321,12 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
switch method {
|
||||
case t.IDLimitedCopyU32FromHistory,
|
||||
t.IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast,
|
||||
t.IDLimitedCopyU32FromHistory8ByteChunksDistance1FastReturnCusp,
|
||||
t.IDLimitedCopyU32FromHistory8ByteChunksFast,
|
||||
t.IDLimitedCopyU32FromHistoryFast:
|
||||
b.printf("wuffs_base__io_writer__%s(\n&%s%s, %s%s, %s%s",
|
||||
t.IDLimitedCopyU32FromHistory8ByteChunksFastReturnCusp,
|
||||
t.IDLimitedCopyU32FromHistoryFast,
|
||||
t.IDLimitedCopyU32FromHistoryFastReturnCusp:
|
||||
b.printf("wuffs_private_impl__io_writer__%s(\n&%s%s, %s%s, %s%s",
|
||||
method.Str(g.tm), iopPrefix, recvName, io0Prefix, recvName, io2Prefix, recvName)
|
||||
for _, o := range args {
|
||||
b.writes(", ")
|
||||
@@ -324,7 +343,7 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
return err
|
||||
}
|
||||
|
||||
b.printf("wuffs_base__io_writer__limited_copy_u32_from_reader(\n&%s%s, %s%s,",
|
||||
b.printf("wuffs_private_impl__io_writer__limited_copy_u32_from_reader(\n&%s%s, %s%s,",
|
||||
iopPrefix, recvName, io2Prefix, recvName)
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
|
||||
return err
|
||||
@@ -333,17 +352,17 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
return nil
|
||||
|
||||
case t.IDCopyFromSlice:
|
||||
b.printf("wuffs_base__io_writer__copy_from_slice(&%s%s, %s%s,",
|
||||
b.printf("wuffs_private_impl__io_writer__copy_from_slice(&%s%s, %s%s,",
|
||||
iopPrefix, recvName, io2Prefix, recvName)
|
||||
return g.writeArgs(b, args, depth)
|
||||
|
||||
case t.IDLimitedCopyU32FromSlice:
|
||||
b.printf("wuffs_base__io_writer__limited_copy_u32_from_slice(\n&%s%s, %s%s,",
|
||||
b.printf("wuffs_private_impl__io_writer__limited_copy_u32_from_slice(\n&%s%s, %s%s,",
|
||||
iopPrefix, recvName, io2Prefix, recvName)
|
||||
return g.writeArgs(b, args, depth)
|
||||
|
||||
case t.IDCountSince:
|
||||
b.printf("wuffs_base__io__count_since(")
|
||||
b.printf("wuffs_private_impl__io__count_since(")
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -364,7 +383,7 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
return nil
|
||||
|
||||
case t.IDSince:
|
||||
b.printf("wuffs_base__io__since(")
|
||||
b.printf("wuffs_private_impl__io__since(")
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -396,10 +415,10 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
}
|
||||
}
|
||||
|
||||
return g.writeBuiltinIO(b, recv, method, args, depth)
|
||||
return g.writeBuiltinIO(b, recv, method, args, sideEffectsOnly, depth)
|
||||
}
|
||||
|
||||
func (g *gen) writeBuiltinTokenWriter(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, depth uint32) error {
|
||||
func (g *gen) writeBuiltinTokenWriter(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
|
||||
switch method {
|
||||
case t.IDWriteSimpleTokenFast, t.IDWriteExtendedTokenFast:
|
||||
recvName, err := g.recvName(recv)
|
||||
@@ -443,7 +462,7 @@ func (g *gen) writeBuiltinTokenWriter(b *buffer, recv *a.Expr, method t.ID, args
|
||||
return nil
|
||||
}
|
||||
|
||||
return g.writeBuiltinIO(b, recv, method, args, depth)
|
||||
return g.writeBuiltinIO(b, recv, method, args, sideEffectsOnly, depth)
|
||||
}
|
||||
|
||||
func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, returnType *a.TypeExpr, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
|
||||
@@ -629,7 +648,7 @@ func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, retur
|
||||
case "make_m128i_single_u32":
|
||||
fName, tName = "_mm_cvtsi32_si128", "int32_t"
|
||||
case "make_m128i_single_u64":
|
||||
fName, tName = "_mm_cvtsi64x_si128", "int64_t"
|
||||
fName, tName = "_mm_cvtsi64_si128", "int64_t"
|
||||
case "make_m128i_slice128", "make_m128i_slice_u16lex8":
|
||||
fName, tName, ptr = "_mm_lddqu_si128", "const __m128i*)(const void*", true
|
||||
case "make_m128i_zeroes":
|
||||
@@ -804,7 +823,7 @@ func (g *gen) writeBuiltinNumType(b *buffer, recv *a.Expr, method t.ID, args []*
|
||||
case t.IDLowBits:
|
||||
// "recv.low_bits(n:etc)" in C is one of:
|
||||
// - "((recv) & constant)"
|
||||
// - "((recv) & WUFFS_BASE__LOW_BITS_MASK__UXX(n))"
|
||||
// - "((recv) & WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__UXX(n))"
|
||||
b.writes("((")
|
||||
if err := g.writeExpr(b, recv, false, depth); err != nil {
|
||||
return err
|
||||
@@ -820,7 +839,7 @@ func (g *gen) writeBuiltinNumType(b *buffer, recv *a.Expr, method t.ID, args []*
|
||||
if sz, err := g.sizeof(recv.MType()); err != nil {
|
||||
return err
|
||||
} else {
|
||||
b.printf("WUFFS_BASE__LOW_BITS_MASK__U%d(", 8*sz)
|
||||
b.printf("WUFFS_PRIVATE_IMPL__LOW_BITS_MASK__U%d(", 8*sz)
|
||||
}
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
|
||||
return err
|
||||
@@ -892,21 +911,21 @@ func (g *gen) writeBuiltinNumType(b *buffer, recv *a.Expr, method t.ID, args []*
|
||||
func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
|
||||
switch method {
|
||||
case t.IDBulkLoadHostEndian:
|
||||
b.writes("wuffs_base__bulk_load_host_endian(")
|
||||
b.writes("wuffs_private_impl__bulk_load_host_endian(")
|
||||
if err := g.writeBuiltinSliceBulkMethodRecv(b, recv, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.writeArgs(b, args, depth)
|
||||
|
||||
case t.IDBulkMemset:
|
||||
b.writes("wuffs_base__bulk_memset(")
|
||||
b.writes("wuffs_private_impl__bulk_memset(")
|
||||
if err := g.writeBuiltinSliceBulkMethodRecv(b, recv, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.writeArgs(b, args, depth)
|
||||
|
||||
case t.IDBulkSaveHostEndian:
|
||||
b.writes("wuffs_base__bulk_save_host_endian(")
|
||||
b.writes("wuffs_private_impl__bulk_save_host_endian(")
|
||||
if err := g.writeBuiltinSliceBulkMethodRecv(b, recv, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -918,7 +937,7 @@ func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a.
|
||||
}
|
||||
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
b.writes("wuffs_base__slice_u8__copy_from_slice(")
|
||||
b.writes("wuffs_private_impl__slice_u8__copy_from_slice(")
|
||||
if err := g.writeExpr(b, recv, false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -943,7 +962,7 @@ func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a.
|
||||
|
||||
case t.IDSuffix:
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
b.writes("wuffs_base__slice_u8__suffix(")
|
||||
b.writes("wuffs_private_impl__slice_u8__suffix(")
|
||||
if err := g.writeExpr(b, recv, false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1141,7 +1160,7 @@ func (g *gen) writeBuiltinTable(b *buffer, recv *a.Expr, method t.ID, args []*a.
|
||||
|
||||
case t.IDRowU32:
|
||||
// TODO: don't assume that the table is a table of base.u8.
|
||||
b.writes("wuffs_base__table_u8__row_u32(")
|
||||
b.writes("wuffs_private_impl__table_u8__row_u32(")
|
||||
if err := g.writeExpr(b, recv, false, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1247,8 +1266,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
}
|
||||
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s.scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ", scratchName)
|
||||
@@ -1285,8 +1303,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
switch method.Ident() {
|
||||
case t.IDWriteU8:
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s.scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ", scratchName)
|
||||
@@ -1338,8 +1355,7 @@ func (g *gen) writeReadUxxAsUyy(b *buffer, n *a.Expr, preName string, xx uint8,
|
||||
}
|
||||
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s.scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("if (WUFFS_BASE__LIKELY(io2_%s - iop_%s >= %d)) {\n", recvName, recvName, xx/8)
|
||||
|
||||
+25
-9
@@ -50,7 +50,7 @@ const (
|
||||
aPrefix = "a_" // Function argument.
|
||||
fPrefix = "f_" // Struct field.
|
||||
iPrefix = "i_" // Iterate variable.
|
||||
oPrefix = "o_" // Temporary io_bind variable.
|
||||
oPrefix = "o_" // Temporary IOManip variable.
|
||||
pPrefix = "p_" // Coroutine suspension point (program counter).
|
||||
sPrefix = "s_" // Coroutine stack (saved local variables).
|
||||
tPrefix = "t_" // Temporary local variable.
|
||||
@@ -67,10 +67,12 @@ const (
|
||||
// The other two prefixes, giving names like io1_etc and io2_etc, are auxiliary
|
||||
// pointers: lower and upper inclusive bounds. As an iop_etc pointer advances,
|
||||
// it cannot advance past io2_etc. In the rarer case that an iop_etc pointer
|
||||
// retreats, undoing a read or write, it cannot retreat past io1_etc.
|
||||
// retreats, undoing a read or write, it cannot retreat past io1_etc. The
|
||||
// io0_etc pointer is used to calculate the history_length and is the base that
|
||||
// marks are relative to.
|
||||
//
|
||||
// The iop_etc pointer can change over the lifetime of a function. The ioN_etc
|
||||
// pointers, for numeric N, cannot.
|
||||
// pointers, for numeric N, cannot (except by IOManip blocks).
|
||||
//
|
||||
// At the start of a function, these pointers are initialized from an
|
||||
// io_buffer's fields (ptr, ri, wi, len). For an io_reader:
|
||||
@@ -235,6 +237,16 @@ func (b *buffer) writeb(x byte) { *b = append(*b, x)
|
||||
func (b *buffer) writes(s string) { *b = append(*b, s...) }
|
||||
func (b *buffer) writex(s []byte) { *b = append(*b, s...) }
|
||||
|
||||
func (b *buffer) undoWrites(s string) bool {
|
||||
nb := len(*b)
|
||||
ns := len(s)
|
||||
if (nb < ns) || (string((*b)[nb-ns:]) != s) {
|
||||
return false
|
||||
}
|
||||
*b = (*b)[:nb-ns]
|
||||
return true
|
||||
}
|
||||
|
||||
func expandBangInsert(b *buffer, s string, m map[string]func(*buffer) error) error {
|
||||
for {
|
||||
remaining := ""
|
||||
@@ -1037,7 +1049,11 @@ func (g *gen) gatherScalarConsts(b *buffer, n *a.Const) error {
|
||||
|
||||
func (g *gen) writeConst(b *buffer, n *a.Const) error {
|
||||
if cv := n.Value().ConstValue(); cv != nil {
|
||||
b.printf("#define %s%s %v\n\n", g.PKGPREFIX, n.QID()[1].Str(g.tm), cv)
|
||||
suffix := ""
|
||||
if cv.Sign() >= 0 {
|
||||
suffix = "u"
|
||||
}
|
||||
b.printf("#define %s%s %v%s\n\n", g.PKGPREFIX, n.QID()[1].Str(g.tm), cv, suffix)
|
||||
} else {
|
||||
b.writes("static const ")
|
||||
if err := g.writeCTypeName(b, n.XType(), "\n"+g.PKGPREFIX, n.QID()[1].Str(g.tm)); err != nil {
|
||||
@@ -1067,6 +1083,9 @@ func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||
b.writes("\n}")
|
||||
} else if cv := n.ConstValue(); cv != nil {
|
||||
b.writes(cv.String())
|
||||
if cv.Sign() >= 0 {
|
||||
b.writeb('u')
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("invalid const value %q", n.Str(g.tm))
|
||||
}
|
||||
@@ -1074,9 +1093,6 @@ func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
||||
// TODO: allow max depth > 1 for recursive coroutines.
|
||||
const maxDepth = 1
|
||||
|
||||
b.writes("// Do not access the private_impl's or private_data's fields directly. There\n")
|
||||
b.writes("// is no API/ABI compatibility or safety guarantee if you do so. Instead, use\n")
|
||||
b.writes("// the wuffs_foo__bar__baz functions.\n")
|
||||
@@ -1128,7 +1144,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
||||
needEmptyLine = false
|
||||
b.writeb('\n')
|
||||
}
|
||||
b.printf("uint32_t %s%s[%d];\n", pPrefix, o.FuncName().Str(g.tm), maxDepth)
|
||||
b.printf("uint32_t %s%s;\n", pPrefix, o.FuncName().Str(g.tm))
|
||||
|
||||
} else if o.Choosy() {
|
||||
if needEmptyLine {
|
||||
@@ -1193,7 +1209,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
||||
b.writes("uint64_t scratch;\n")
|
||||
}
|
||||
if oldInnerLenB1 != len(*b) {
|
||||
b.printf("} %s%s[%d];\n", sPrefix, o.FuncName().Str(g.tm), maxDepth)
|
||||
b.printf("} %s%s;\n", sPrefix, o.FuncName().Str(g.tm))
|
||||
} else {
|
||||
*b = (*b)[:oldInnerLenB0]
|
||||
needEmptyLine = oldNeedEmptyLine
|
||||
|
||||
@@ -66,8 +66,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
|
||||
|
||||
} else if ident == t.IDCoroutineResumed {
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
b.printf("(self->private_impl.%s%s[0] != 0)",
|
||||
b.printf("(self->private_impl.%s%s != 0)",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
} else {
|
||||
b.writes("false")
|
||||
@@ -114,7 +113,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
|
||||
}
|
||||
qid := recvTyp.QID()
|
||||
|
||||
b.printf("wuffs_base__ignore_status("+
|
||||
b.printf("wuffs_private_impl__ignore_status("+
|
||||
"%s%s__initialize(%s", g.packagePrefix(qid), qid[1].Str(g.tm), addr)
|
||||
if err := g.writeExpr(b, recv, false, depth); err != nil {
|
||||
return err
|
||||
@@ -287,7 +286,7 @@ func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
opName, lhsCast, tildeMod := "", false, false
|
||||
opName, lhsCast, overallCast := "", false, n.MType().IsSmallInteger()
|
||||
|
||||
op := n.Operator()
|
||||
switch op {
|
||||
@@ -307,10 +306,10 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
return g.writeExprAs(b, n.LHS().AsExpr(), n.RHS().AsTypeExpr(), depth)
|
||||
|
||||
case t.IDXBinaryTildeModPlus, t.IDXBinaryTildeModMinus, t.IDXBinaryTildeModStar:
|
||||
tildeMod = true
|
||||
overallCast = true
|
||||
|
||||
case t.IDXBinaryTildeModShiftL:
|
||||
tildeMod = true
|
||||
overallCast = true
|
||||
fallthrough
|
||||
|
||||
case t.IDXBinaryShiftL, t.IDXBinaryShiftR:
|
||||
@@ -327,7 +326,7 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
b.writeb('(')
|
||||
if tildeMod {
|
||||
if overallCast {
|
||||
b.writeb('(')
|
||||
if err := g.writeCTypeName(b, n.MType(), "", ""); err != nil {
|
||||
return err
|
||||
@@ -355,7 +354,7 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if tildeMod {
|
||||
if overallCast {
|
||||
b.writeb(')')
|
||||
}
|
||||
b.writeb(')')
|
||||
|
||||
+14
-9
@@ -206,14 +206,14 @@ func (g *gen) writeFuncPrototype(b *buffer, n *a.Func) error {
|
||||
return err
|
||||
}
|
||||
if caMacro != "" {
|
||||
b.printf("#if defined(WUFFS_BASE__CPU_ARCH__%s)\n", caMacro)
|
||||
b.printf("#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__%s)\n", caMacro)
|
||||
}
|
||||
if err := g.writeFuncSignature(b, n, wfsCDecl); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(";\n")
|
||||
if caMacro != "" {
|
||||
b.printf("#endif // defined(WUFFS_BASE__CPU_ARCH__%s)\n", caMacro)
|
||||
b.printf("#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__%s)\n", caMacro)
|
||||
}
|
||||
b.writes("\n")
|
||||
if n.Choosy() {
|
||||
@@ -237,7 +237,7 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error {
|
||||
}
|
||||
b.printf("// -------- func %s.%s\n\n", g.pkgName, n.QQID().Str(g.tm))
|
||||
if caMacro != "" {
|
||||
b.printf("#if defined(WUFFS_BASE__CPU_ARCH__%s)\n", caMacro)
|
||||
b.printf("#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__%s)\n", caMacro)
|
||||
}
|
||||
if caAttribute != "" {
|
||||
b.printf("%s\n", caAttribute)
|
||||
@@ -277,7 +277,7 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error {
|
||||
b.writex(k.bEpilogue)
|
||||
b.writes("}\n")
|
||||
if caMacro != "" {
|
||||
b.printf("#endif // defined(WUFFS_BASE__CPU_ARCH__%s)\n", caMacro)
|
||||
b.printf("#endif // defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__%s)\n", caMacro)
|
||||
}
|
||||
if caName != "" {
|
||||
b.printf("// ‼ WUFFS MULTI-FILE SECTION -%s\n", caName)
|
||||
@@ -343,11 +343,17 @@ func writeOutParamZeroValue(b *buffer, tm *t.Map, typ *a.TypeExpr) error {
|
||||
return nil
|
||||
} else if typ.IsEitherSliceType() {
|
||||
if inner := typ.Inner(); (inner.Decorator() == 0) && (inner.QID() == t.QID{t.IDBase, t.IDU8}) {
|
||||
b.writes("wuffs_base__make_slice_u8(NULL, 0)")
|
||||
b.writes("wuffs_base__empty_slice_u8()")
|
||||
return nil
|
||||
}
|
||||
} else if (typ.Decorator() == 0) && (typ.QID()[0] == t.IDBase) {
|
||||
switch typ.QID()[1] {
|
||||
case t.IDBitvec256:
|
||||
b.writes("wuffs_base__utility__make_bitvec256(0u, 0u, 0u, 0u)")
|
||||
return nil
|
||||
case t.IDOptionalU63:
|
||||
b.writes("wuffs_base__utility__make_optional_u63(false, 0u)")
|
||||
return nil
|
||||
case t.IDRangeIEU32:
|
||||
b.writes("wuffs_base__utility__empty_range_ie_u32()")
|
||||
return nil
|
||||
@@ -467,8 +473,7 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
|
||||
func (g *gen) writeFuncImplBodyResume(b *buffer) error {
|
||||
if g.currFunk.coroSuspPoint > 0 {
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0];\n",
|
||||
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
resumeBuffer := buffer{}
|
||||
@@ -511,13 +516,13 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
// We've reached the end of the function body. Reset the coroutine
|
||||
// suspension point so that the next call to this function starts at
|
||||
// the top.
|
||||
b.printf("self->private_impl.%s%s[0] = 0;\n",
|
||||
b.printf("self->private_impl.%s%s = 0;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
b.writes("goto exit;\n}\n\n") // Close the coroutine switch.
|
||||
|
||||
b.writes("goto suspend;\nsuspend:\n") // The goto avoids the "unused label" warning.
|
||||
|
||||
b.printf("self->private_impl.%s%s[0] = "+
|
||||
b.printf("self->private_impl.%s%s = "+
|
||||
"wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
if g.currFunk.astFunc.Public() {
|
||||
|
||||
@@ -331,11 +331,13 @@ func (h *livenessHelper) doIOManip(r livenesses, n *a.IOManip, depth uint32) err
|
||||
if err := h.doExpr(r, n.IO()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := h.doExpr(r, n.Arg1()); err != nil {
|
||||
return err
|
||||
if arg1 := n.Arg1(); arg1 != nil {
|
||||
if err := h.doExpr(r, arg1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if histPos := n.HistoryPosition(); histPos != nil {
|
||||
if err := h.doExpr(r, n.HistoryPosition()); err != nil {
|
||||
if err := h.doExpr(r, histPos); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
+176
-100
@@ -162,33 +162,44 @@ func (g *gen) writeStatementAssign1(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr
|
||||
if op != t.IDTildeSatPlusEq {
|
||||
uOp = "sub"
|
||||
}
|
||||
b.printf("wuffs_base__u%d__sat_%s_indirect(&", uBits, uOp)
|
||||
b.printf("wuffs_private_impl__u%d__sat_%s_indirect(&", uBits, uOp)
|
||||
opName, closer = ", ", ")"
|
||||
|
||||
case t.IDPlusEq, t.IDMinusEq:
|
||||
if lTyp.IsNumType() {
|
||||
if u := lTyp.QID()[1]; u == t.IDU8 || u == t.IDU16 {
|
||||
disableWconversion = true
|
||||
}
|
||||
}
|
||||
fallthrough
|
||||
|
||||
default:
|
||||
opName = cOpName(op)
|
||||
if opName == "" {
|
||||
return fmt.Errorf("unrecognized operator %q", op.AmbiguousForm().Str(g.tm))
|
||||
}
|
||||
|
||||
if op.IsAssign() && lTyp.IsSmallInteger() {
|
||||
switch op {
|
||||
case t.IDAmpEq, t.IDPipeEq, t.IDHatEq, t.IDEq, t.IDEqQuestion:
|
||||
// No-op.
|
||||
|
||||
default:
|
||||
disableWconversion = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const disableWconversion0 = "" +
|
||||
"#if defined(__GNUC__)\n" +
|
||||
"#pragma GCC diagnostic push\n" +
|
||||
"#pragma GCC diagnostic ignored \"-Wconversion\"\n" +
|
||||
"#endif\n"
|
||||
|
||||
const disableWconversion1 = "" +
|
||||
"#if defined(__GNUC__)\n" +
|
||||
"#pragma GCC diagnostic pop\n" +
|
||||
"#endif\n"
|
||||
|
||||
// "x += 1" triggers -Wconversion, if x is smaller than an int (i.e. a
|
||||
// uint8_t or a uint16_t). This is arguably a clang/gcc bug, but in any
|
||||
// case, we work around it in Wuffs.
|
||||
if disableWconversion {
|
||||
b.writes("#if defined(__GNUC__)\n")
|
||||
b.writes("#pragma GCC diagnostic push\n")
|
||||
b.writes("#pragma GCC diagnostic ignored \"-Wconversion\"\n")
|
||||
b.writes("#endif\n")
|
||||
if disableWconversion && !b.undoWrites(disableWconversion1) {
|
||||
b.writes(disableWconversion0)
|
||||
}
|
||||
|
||||
n := len(*b)
|
||||
@@ -211,9 +222,7 @@ func (g *gen) writeStatementAssign1(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr
|
||||
}
|
||||
|
||||
if disableWconversion {
|
||||
b.writes("#if defined(__GNUC__)\n")
|
||||
b.writes("#pragma GCC diagnostic pop\n")
|
||||
b.writes("#endif\n")
|
||||
b.writes(disableWconversion1)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -243,7 +252,7 @@ func (g *gen) writeStatementChoose(b *buffer, n *a.Choose, depth uint32) error {
|
||||
conclusive = true
|
||||
break
|
||||
}
|
||||
b.printf("#if defined(WUFFS_BASE__CPU_ARCH__%s)\n"+
|
||||
b.printf("#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__%s)\n"+
|
||||
"wuffs_base__cpu_arch__have_%s() ? &%s%s__%s%s :\n"+
|
||||
"#endif\n",
|
||||
caMacro, caName, g.pkgPrefix, recv.Str(g.tm), id.Str(g.tm), suffix)
|
||||
@@ -273,15 +282,18 @@ func cpuArchCNames(asserts []*a.Node) (caMacro string, caName string, caAttribut
|
||||
caMacro, caName, caAttribute = "ARM_NEON", "arm_neon", ""
|
||||
case t.IDX86SSE42:
|
||||
caMacro, caName, caAttribute =
|
||||
"X86_FAMILY", "x86_sse42",
|
||||
"X86_64_V2",
|
||||
"x86_sse42",
|
||||
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"pclmul,popcnt,sse4.2\")"
|
||||
case t.IDX86AVX2:
|
||||
caMacro, caName, caAttribute =
|
||||
"X86_64", "x86_avx2",
|
||||
"X86_64_V3",
|
||||
"x86_avx2",
|
||||
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"pclmul,popcnt,sse4.2,avx2\")"
|
||||
case t.IDX86BMI2:
|
||||
caMacro, caName, caAttribute =
|
||||
"X86_FAMILY", "x86_bmi2",
|
||||
"X86_64_V3",
|
||||
"x86_bmi2",
|
||||
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"bmi2\")"
|
||||
}
|
||||
}
|
||||
@@ -311,66 +323,105 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
|
||||
// instead of block-scoped (smaller scope) if the coro_susp_point
|
||||
// switch can jump past this initialization??
|
||||
b.writes("{\n")
|
||||
{
|
||||
if n.Keyword() == t.IDIOBind {
|
||||
b.printf("wuffs_base__io_buffer* %s%d_%s%s = %s%s;\n",
|
||||
oPrefix, ioBindNum, prefix, name,
|
||||
prefix, name)
|
||||
b.printf("%suint8_t *%s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, iopPrefix, prefix, name,
|
||||
iopPrefix, prefix, name)
|
||||
b.printf("%suint8_t *%s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io0Prefix, prefix, name,
|
||||
io0Prefix, prefix, name)
|
||||
b.printf("%suint8_t *%s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io1Prefix, prefix, name,
|
||||
io1Prefix, prefix, name)
|
||||
b.printf("%suint8_t *%s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io2Prefix, prefix, name,
|
||||
io2Prefix, prefix, name)
|
||||
b.printf("%s%s = wuffs_base__io_%s__set("+
|
||||
"\n&%s%s,\n&%s%s%s,\n&%s%s%s,\n&%s%s%s,\n&%s%s%s,\n",
|
||||
prefix, name, cTyp,
|
||||
uPrefix, name,
|
||||
iopPrefix, prefix, name,
|
||||
io0Prefix, prefix, name,
|
||||
io1Prefix, prefix, name,
|
||||
io2Prefix, prefix, name)
|
||||
if err := g.writeExpr(b, n.Arg1(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(",\n")
|
||||
if err := g.writeExpr(b, n.HistoryPosition(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(");\n")
|
||||
|
||||
} else {
|
||||
if !isWriter {
|
||||
b.printf("const bool %s%d_closed_%s%s = %s%s->meta.closed;\n",
|
||||
oPrefix, ioBindNum, prefix, name, prefix, name)
|
||||
}
|
||||
b.printf("%suint8_t *%s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io2Prefix, prefix, name, io2Prefix, prefix, name)
|
||||
b.printf("wuffs_base__io_%s__limit(&%s%s%s, %s%s%s,\n",
|
||||
cTyp,
|
||||
io2Prefix, prefix, name,
|
||||
iopPrefix, prefix, name)
|
||||
if err := g.writeExpr(b, n.Arg1(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(");\n")
|
||||
b.printf("if (%s%s) {\n", prefix, name)
|
||||
b.printf("size_t n = ((size_t)(%s%s%s - %s%s->data.ptr));\n",
|
||||
io2Prefix, prefix, name, prefix, name)
|
||||
if !isWriter {
|
||||
b.printf("%s%s->meta.closed = %s%s->meta.closed && (%s%s->%s <= n);\n",
|
||||
prefix, name, prefix, name, prefix, name, end)
|
||||
}
|
||||
b.printf("%s%s->%s = n;\n",
|
||||
prefix, name, end)
|
||||
b.printf("}\n")
|
||||
switch n.Keyword() {
|
||||
case t.IDIOBind:
|
||||
b.printf("wuffs_base__io_buffer* %s%d_%s%s = %s%s;\n",
|
||||
oPrefix, ioBindNum, prefix, name,
|
||||
prefix, name)
|
||||
b.printf("%suint8_t* %s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, iopPrefix, prefix, name,
|
||||
iopPrefix, prefix, name)
|
||||
b.printf("%suint8_t* %s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io0Prefix, prefix, name,
|
||||
io0Prefix, prefix, name)
|
||||
b.printf("%suint8_t* %s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io1Prefix, prefix, name,
|
||||
io1Prefix, prefix, name)
|
||||
b.printf("%suint8_t* %s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io2Prefix, prefix, name,
|
||||
io2Prefix, prefix, name)
|
||||
b.printf("%s%s = wuffs_private_impl__io_%s__set("+
|
||||
"\n&%s%s,\n&%s%s%s,\n&%s%s%s,\n&%s%s%s,\n&%s%s%s,\n",
|
||||
prefix, name, cTyp,
|
||||
uPrefix, name,
|
||||
iopPrefix, prefix, name,
|
||||
io0Prefix, prefix, name,
|
||||
io1Prefix, prefix, name,
|
||||
io2Prefix, prefix, name)
|
||||
if err := g.writeExpr(b, n.Arg1(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(",\n")
|
||||
if err := g.writeExpr(b, n.HistoryPosition(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(");\n")
|
||||
|
||||
case t.IDIOForgetHistory:
|
||||
if !isWriter {
|
||||
return fmt.Errorf("unsupported io_forget_history for an io_reader")
|
||||
}
|
||||
b.printf("%suint8_t* %s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io0Prefix, prefix, name,
|
||||
io0Prefix, prefix, name)
|
||||
b.printf("%suint8_t* %s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io1Prefix, prefix, name,
|
||||
io1Prefix, prefix, name)
|
||||
b.printf("%s%s%s = %s%s%s;\n",
|
||||
io0Prefix, prefix, name, iopPrefix, prefix, name)
|
||||
b.printf("%s%s%s = %s%s%s;\n",
|
||||
io1Prefix, prefix, name, iopPrefix, prefix, name)
|
||||
b.printf("wuffs_base__io_buffer %s%d_%s%s;\n",
|
||||
oPrefix, ioBindNum, prefix, name)
|
||||
b.printf("if (%s%s) {\n",
|
||||
prefix, name)
|
||||
if isWriter {
|
||||
b.printf("memcpy(&%s%d_%s%s, %s%s, sizeof(*%s%s));\n",
|
||||
oPrefix, ioBindNum, prefix, name,
|
||||
prefix, name,
|
||||
prefix, name)
|
||||
b.printf("size_t wi%d = %s%s->meta.wi;\n",
|
||||
ioBindNum, prefix, name)
|
||||
b.printf("%s%s->data.ptr += wi%d;\n",
|
||||
prefix, name, ioBindNum)
|
||||
b.printf("%s%s->data.len -= wi%d;\n",
|
||||
prefix, name, ioBindNum)
|
||||
b.printf("%s%s->meta.ri = 0;\n",
|
||||
prefix, name)
|
||||
b.printf("%s%s->meta.wi = 0;\n",
|
||||
prefix, name)
|
||||
b.printf("%s%s->meta.pos = wuffs_base__u64__sat_add(%s%s->meta.pos, wi%d);\n",
|
||||
prefix, name, prefix, name, ioBindNum)
|
||||
} else {
|
||||
// TODO.
|
||||
}
|
||||
b.printf("}\n")
|
||||
|
||||
case t.IDIOLimit:
|
||||
if !isWriter {
|
||||
b.printf("const bool %s%d_closed_%s%s = %s%s->meta.closed;\n",
|
||||
oPrefix, ioBindNum, prefix, name, prefix, name)
|
||||
}
|
||||
b.printf("%suint8_t* %s%d_%s%s%s = %s%s%s;\n",
|
||||
qualifier, oPrefix, ioBindNum, io2Prefix, prefix, name, io2Prefix, prefix, name)
|
||||
b.printf("wuffs_private_impl__io_%s__limit(&%s%s%s, %s%s%s,\n",
|
||||
cTyp,
|
||||
io2Prefix, prefix, name,
|
||||
iopPrefix, prefix, name)
|
||||
if err := g.writeExpr(b, n.Arg1(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(");\n")
|
||||
b.printf("if (%s%s) {\n", prefix, name)
|
||||
b.printf("size_t n = ((size_t)(%s%s%s - %s%s->data.ptr));\n",
|
||||
io2Prefix, prefix, name, prefix, name)
|
||||
if !isWriter {
|
||||
b.printf("%s%s->meta.closed = %s%s->meta.closed && (%s%s->%s <= n);\n",
|
||||
prefix, name, prefix, name, prefix, name, end)
|
||||
}
|
||||
b.printf("%s%s->%s = n;\n",
|
||||
prefix, name, end)
|
||||
b.printf("}\n")
|
||||
}
|
||||
|
||||
for _, o := range n.Body() {
|
||||
@@ -379,34 +430,59 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if n.Keyword() == t.IDIOBind {
|
||||
b.printf("%s%s = %s%d_%s%s;\n",
|
||||
switch n.Keyword() {
|
||||
case t.IDIOBind:
|
||||
b.printf("%s%s = %s%d_%s%s;\n",
|
||||
prefix, name,
|
||||
oPrefix, ioBindNum, prefix, name)
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
iopPrefix, prefix, name,
|
||||
oPrefix, ioBindNum, iopPrefix, prefix, name)
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
io0Prefix, prefix, name,
|
||||
oPrefix, ioBindNum, io0Prefix, prefix, name)
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
io1Prefix, prefix, name,
|
||||
oPrefix, ioBindNum, io1Prefix, prefix, name)
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
io2Prefix, prefix, name,
|
||||
oPrefix, ioBindNum, io2Prefix, prefix, name)
|
||||
|
||||
case t.IDIOForgetHistory:
|
||||
b.printf("if (%s%s) {\n",
|
||||
prefix, name)
|
||||
if isWriter {
|
||||
b.printf("memcpy(%s%s, &%s%d_%s%s, sizeof(*%s%s));\n",
|
||||
prefix, name,
|
||||
oPrefix, ioBindNum, prefix, name)
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
iopPrefix, prefix, name,
|
||||
oPrefix, ioBindNum, iopPrefix, prefix, name)
|
||||
oPrefix, ioBindNum, prefix, name,
|
||||
prefix, name)
|
||||
b.printf("%s%s->meta.wi = ((size_t)(%s%s%s - %s%s->data.ptr));\n",
|
||||
prefix, name, iopPrefix, prefix, name, prefix, name)
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
io0Prefix, prefix, name,
|
||||
oPrefix, ioBindNum, io0Prefix, prefix, name)
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
io1Prefix, prefix, name,
|
||||
oPrefix, ioBindNum, io1Prefix, prefix, name)
|
||||
} else {
|
||||
// TODO.
|
||||
}
|
||||
b.printf("}\n")
|
||||
|
||||
case t.IDIOLimit:
|
||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||
io2Prefix, prefix, name,
|
||||
oPrefix, ioBindNum, io2Prefix, prefix, name)
|
||||
if n.Keyword() == t.IDIOLimit {
|
||||
b.printf("if (%s%s) {\n", prefix, name)
|
||||
b.printf("if (%s%s) {\n", prefix, name)
|
||||
if !isWriter {
|
||||
b.printf("%s%s->meta.closed = %s%d_closed_%s%s;\n",
|
||||
prefix, name, oPrefix, ioBindNum, prefix, name)
|
||||
b.printf("%s%s->%s = ((size_t)(%s%s%s - %s%s->data.ptr));\n",
|
||||
prefix, name, end,
|
||||
io2Prefix, prefix, name,
|
||||
prefix, name)
|
||||
b.printf("}\n")
|
||||
}
|
||||
b.printf("%s%s->%s = ((size_t)(%s%s%s - %s%s->data.ptr));\n",
|
||||
prefix, name, end,
|
||||
io2Prefix, prefix, name,
|
||||
prefix, name)
|
||||
b.printf("}\n")
|
||||
}
|
||||
b.writes("}\n")
|
||||
return nil
|
||||
@@ -609,7 +685,7 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
}
|
||||
|
||||
if couldBeSuspension {
|
||||
b.writes("wuffs_base__status__ensure_not_a_suspension(")
|
||||
b.writes("wuffs_private_impl__status__ensure_not_a_suspension(")
|
||||
}
|
||||
if err := g.writeExpr(b, retExpr, false, depth); err != nil {
|
||||
return err
|
||||
@@ -682,18 +758,18 @@ func (g *gen) writeIterateRound(b *buffer, assigns []*a.Node, body []*a.Node, ro
|
||||
b.printf("%s%s.len = %d;\n", vPrefix, name, length)
|
||||
}
|
||||
name0 := assigns[0].AsAssign().LHS().Ident().Str(g.tm)
|
||||
b.printf("uint8_t* %send%d_%s = ", iPrefix, round, name0)
|
||||
b.printf("const uint8_t* %send%d_%s = wuffs_private_impl__ptr_u8_plus_len(", iPrefix, round, name0)
|
||||
if (length == 1) && (advance == 1) && (unroll == 1) {
|
||||
b.printf("%sslice_%s.ptr + %sslice_%s.len;\n",
|
||||
b.printf("%sslice_%s.ptr, %sslice_%s.len);\n",
|
||||
iPrefix, name0, iPrefix, name0)
|
||||
} else if length == advance {
|
||||
b.printf("%s%s.ptr + (((%sslice_%s.len - (size_t)(%s%s.ptr - %sslice_%s.ptr)) / %d) * %d);\n",
|
||||
b.printf("%s%s.ptr, (((%sslice_%s.len - (size_t)(%s%s.ptr - %sslice_%s.ptr)) / %d) * %d));\n",
|
||||
vPrefix, name0, iPrefix, name0,
|
||||
vPrefix, name0, iPrefix, name0,
|
||||
length*unroll, length*unroll)
|
||||
} else {
|
||||
b.printf("%s%s.ptr + wuffs_base__iterate_total_advance("+
|
||||
"(%sslice_%s.len - (size_t)(%s%s.ptr - %sslice_%s.ptr)), %d, %d);\n",
|
||||
b.printf("%s%s.ptr, wuffs_private_impl__iterate_total_advance("+
|
||||
"(%sslice_%s.len - (size_t)(%s%s.ptr - %sslice_%s.ptr)), %d, %d));\n",
|
||||
vPrefix, name0, iPrefix, name0,
|
||||
vPrefix, name0, iPrefix, name0,
|
||||
length+(advance*(unroll-1)), advance*unroll)
|
||||
|
||||
@@ -280,8 +280,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, f *funk, n *a.Var, suspend bool) er
|
||||
} else {
|
||||
local := fmt.Sprintf("%s%s", vPrefix, n.Name().Str(g.tm))
|
||||
lhs := local
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
rhs := fmt.Sprintf("self->private_data.%s%s[0].%s", sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
|
||||
rhs := fmt.Sprintf("self->private_data.%s%s.%s", sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
|
||||
if suspend {
|
||||
lhs, rhs = rhs, lhs
|
||||
}
|
||||
|
||||
+8
-2
@@ -607,8 +607,9 @@ func NewField(flags Flags, name t.ID, xType *TypeExpr) *Field {
|
||||
}
|
||||
|
||||
// IOManip is "io_bind (io:LHS, data:MHS, history_position:RHS) { List2 }" or
|
||||
// "io_limit (io:LHS, limit:MHS) { List2 }":
|
||||
// - ID0: <IDIOBind|IDIOLimit>
|
||||
// "io_forget_history (io:LHS) { List2 }" or "io_limit (io:LHS, limit:MHS) {
|
||||
// List2 }":
|
||||
// - ID0: <IDIOBind|IDIOForgetHistory|IDIOLimit>
|
||||
// - LHS: <Expr>
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <Expr>
|
||||
@@ -1007,6 +1008,11 @@ func (n *TypeExpr) IsContainerOfSpecificNumType(container t.ID, numType t.ID) bo
|
||||
return (n.id0 == container) && n.Inner().IsNumType() && (n.Inner().id2 == numType)
|
||||
}
|
||||
|
||||
func (n *TypeExpr) IsSmallInteger() bool {
|
||||
return n.id0 == 0 && n.id1 == t.IDBase &&
|
||||
(n.id2 == t.IDU8 || n.id2 == t.IDU16)
|
||||
}
|
||||
|
||||
func (n *TypeExpr) IsUnsignedInteger() bool {
|
||||
return n.id0 == 0 && n.id1 == t.IDBase &&
|
||||
(n.id2 == t.IDU8 || n.id2 == t.IDU16 || n.id2 == t.IDU32 || n.id2 == t.IDU64)
|
||||
|
||||
+69
-12
@@ -51,6 +51,7 @@ var FourCCs = [...][2]string{
|
||||
{"KVPK", "Key-Value Pair (Key)"},
|
||||
{"KVPV", "Key-Value Pair (Value)"},
|
||||
{"LZ4 ", "Lempel–Ziv 4"},
|
||||
{"LZIP", "Lzip"},
|
||||
{"LZMA", "Lempel–Ziv Markov-chain Algorithm"},
|
||||
{"MD ", "Markdown"},
|
||||
{"MTIM", "Modification Time"},
|
||||
@@ -114,8 +115,8 @@ var Consts = [...]struct {
|
||||
{t.IDU32, "0x20000008", "PIXEL_FORMAT__Y"},
|
||||
{t.IDU32, "0x2000000B", "PIXEL_FORMAT__Y_16LE"},
|
||||
{t.IDU32, "0x2010000B", "PIXEL_FORMAT__Y_16BE"},
|
||||
{t.IDU32, "0x21000008", "PIXEL_FORMAT__YA_NONPREMUL"},
|
||||
{t.IDU32, "0x22000008", "PIXEL_FORMAT__YA_PREMUL"},
|
||||
{t.IDU32, "0x21000088", "PIXEL_FORMAT__YA_NONPREMUL"},
|
||||
{t.IDU32, "0x22000088", "PIXEL_FORMAT__YA_PREMUL"},
|
||||
|
||||
{t.IDU32, "0x40020888", "PIXEL_FORMAT__YCBCR"},
|
||||
{t.IDU32, "0x41038888", "PIXEL_FORMAT__YCBCRA_NONPREMUL"},
|
||||
@@ -152,6 +153,7 @@ var Consts = [...]struct {
|
||||
// ----
|
||||
|
||||
{t.IDU32, "1", "QUIRK_IGNORE_CHECKSUM"},
|
||||
{t.IDU32, "2", "QUIRK_QUALITY"},
|
||||
|
||||
// ----
|
||||
|
||||
@@ -245,6 +247,7 @@ var Statuses = [...]string{
|
||||
`"$mispositioned read"`,
|
||||
`"$mispositioned write"`,
|
||||
`"$short read"`,
|
||||
`"$short workbuf"`,
|
||||
`"$short write"`,
|
||||
|
||||
// Errors.
|
||||
@@ -260,9 +263,11 @@ var Statuses = [...]string{
|
||||
`"#bad workbuf length"`,
|
||||
`"#bad wuffs version"`,
|
||||
`"#cannot return a suspension"`,
|
||||
`"#disabled by WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST"`,
|
||||
`"#disabled by previous error"`,
|
||||
`"#initialize falsely claimed already zeroed"`,
|
||||
`"#initialize not called"`,
|
||||
`"#insufficient history"`,
|
||||
`"#interleaved coroutine calls"`,
|
||||
`"#no more information"`,
|
||||
`"#not enough data"`,
|
||||
@@ -284,6 +289,10 @@ var Types = []string{
|
||||
"u32",
|
||||
"u64",
|
||||
|
||||
"bitvec256",
|
||||
|
||||
"optional_u63",
|
||||
|
||||
"empty_struct",
|
||||
"bool",
|
||||
"utility",
|
||||
@@ -362,6 +371,8 @@ var funcsOther = [...]string{
|
||||
"u64.max(no_less_than: u64) u64",
|
||||
"u64.min(no_more_than: u64) u64",
|
||||
|
||||
"bitvec256.get_u64(i: u32[..=3]) u64",
|
||||
|
||||
// ---- utility
|
||||
|
||||
"utility.cpu_arch_is_32_bit() bool",
|
||||
@@ -374,6 +385,8 @@ var funcsOther = [...]string{
|
||||
"utility.empty_rect_ii_u32() rect_ii_u32",
|
||||
"utility.empty_rect_ie_u32() rect_ie_u32",
|
||||
"utility.empty_slice_u8() slice u8",
|
||||
"utility.make_bitvec256(e00: u64, e01: u64, e02: u64, e03: u64) bitvec256",
|
||||
"utility.make_optional_u63(has_value: bool, value: u64[..= 0x7FFF_FFFF_FFFF_FFFF]) optional_u63",
|
||||
"utility.make_pixel_format(repr: u32) pixel_format",
|
||||
"utility.make_range_ii_u32(min_incl: u32, max_incl: u32) range_ii_u32",
|
||||
"utility.make_range_ie_u32(min_incl: u32, max_excl: u32) range_ie_u32",
|
||||
@@ -383,6 +396,7 @@ var funcsOther = [...]string{
|
||||
"min_incl_x: u32, min_incl_y: u32, max_incl_x: u32, max_incl_y: u32) rect_ii_u32",
|
||||
"utility.make_rect_ie_u32(" +
|
||||
"min_incl_x: u32, min_incl_y: u32, max_excl_x: u32, max_excl_y: u32) rect_ie_u32",
|
||||
"utility.sign_extend_convert_u8_u32(a: u8) u32",
|
||||
"utility.sign_extend_convert_u16_u32(a: u16) u32",
|
||||
"utility.sign_extend_rshift_u32(a: u32, n: u32[..= 31]) u32",
|
||||
"utility.sign_extend_rshift_u64(a: u64, n: u32[..= 63]) u64",
|
||||
@@ -424,6 +438,7 @@ var funcsOther = [...]string{
|
||||
// ---- io_reader
|
||||
|
||||
"io_reader.can_undo_byte() bool",
|
||||
"io_reader.peek_undo_byte() u8",
|
||||
"io_reader.undo_byte!()",
|
||||
|
||||
"io_reader.read_u8?() u8",
|
||||
@@ -519,6 +534,10 @@ var funcsOther = [...]string{
|
||||
|
||||
// ---- io_writer
|
||||
|
||||
"io_writer.can_undo_byte() bool",
|
||||
"io_writer.peek_undo_byte() u8",
|
||||
"io_writer.undo_byte!()",
|
||||
|
||||
"io_writer.write_u8?(a: u8)",
|
||||
"io_writer.write_u16be?(a: u16)",
|
||||
"io_writer.write_u16le?(a: u16)",
|
||||
@@ -570,6 +589,7 @@ var funcsOther = [...]string{
|
||||
"io_writer.limited_copy_u32_from_slice!(up_to: u32, s: roslice u8) u32",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - up_to >= 1
|
||||
// - up_to <= this.length()
|
||||
// - distance >= 1
|
||||
// - distance <= this.history_length()
|
||||
@@ -577,6 +597,15 @@ var funcsOther = [...]string{
|
||||
"io_writer.limited_copy_u32_from_history_fast!(up_to: u32, distance: u32) u32",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - up_to >= 1
|
||||
// - up_to <= this.length()
|
||||
// - distance >= 1
|
||||
// - distance <= this.history_length()
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_fast_return_cusp!(up_to: u32, distance: u32) u32[..= 0xFFFF]",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - up_to >= 1
|
||||
// - (up_to + 8) <= this.length()
|
||||
// - distance >= 8
|
||||
// - distance <= this.history_length()
|
||||
@@ -584,12 +613,29 @@ var funcsOther = [...]string{
|
||||
"io_writer.limited_copy_u32_from_history_8_byte_chunks_fast!(up_to: u32, distance: u32) u32",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - up_to >= 1
|
||||
// - (up_to + 8) <= this.length()
|
||||
// - distance >= 8
|
||||
// - distance <= this.history_length()
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_8_byte_chunks_fast_return_cusp!(up_to: u32, distance: u32) u32[..= 0xFFFF]",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - up_to >= 1
|
||||
// - (up_to + 8) <= this.length()
|
||||
// - distance == 1
|
||||
// - distance <= this.history_length()
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_8_byte_chunks_distance_1_fast!(up_to: u32, distance: u32) u32",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - up_to >= 1
|
||||
// - (up_to + 8) <= this.length()
|
||||
// - distance == 1
|
||||
// - distance <= this.history_length()
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp!(up_to: u32, distance: u32) u32[..= 0xFFFF]",
|
||||
|
||||
// ---- token_writer
|
||||
|
||||
"token_writer.write_simple_token_fast!(" +
|
||||
@@ -646,8 +692,10 @@ var funcsOther = [...]string{
|
||||
"pixel_swizzler.swizzle_ycck!(" +
|
||||
"dst: ptr pixel_buffer," +
|
||||
"dst_palette: slice u8," +
|
||||
"width: u32[..= 0xFFFF]," +
|
||||
"height: u32[..= 0xFFFF]," +
|
||||
"x_min_incl: u32[..= 0xFFFF]," +
|
||||
"x_max_excl: u32[..= 0xFFFF]," +
|
||||
"y_min_incl: u32[..= 0xFFFF]," +
|
||||
"y_max_excl: u32[..= 0xFFFF]," +
|
||||
"src0: slice u8," +
|
||||
"src1: slice u8," +
|
||||
"src2: slice u8," +
|
||||
@@ -939,17 +987,19 @@ var funcsOther = [...]string{
|
||||
var Interfaces = []string{
|
||||
"hasher_u32",
|
||||
"hasher_u64",
|
||||
"hasher_bitvec256",
|
||||
"image_decoder",
|
||||
"io_transformer",
|
||||
"token_decoder",
|
||||
}
|
||||
|
||||
var InterfacesMap = map[string]bool{
|
||||
"hasher_u32": true,
|
||||
"hasher_u64": true,
|
||||
"image_decoder": true,
|
||||
"io_transformer": true,
|
||||
"token_decoder": true,
|
||||
"hasher_u32": true,
|
||||
"hasher_u64": true,
|
||||
"hasher_bitvec256": true,
|
||||
"image_decoder": true,
|
||||
"io_transformer": true,
|
||||
"token_decoder": true,
|
||||
}
|
||||
|
||||
var InterfaceFuncs = []string{
|
||||
@@ -969,6 +1019,14 @@ var InterfaceFuncs = []string{
|
||||
"hasher_u64.update!(x: roslice u8)",
|
||||
"hasher_u64.update_u64!(x: roslice u8) u64",
|
||||
|
||||
// ---- hasher_bitvec256
|
||||
|
||||
"hasher_bitvec256.checksum_bitvec256() bitvec256",
|
||||
"hasher_bitvec256.get_quirk(key: u32) u64",
|
||||
"hasher_bitvec256.set_quirk!(key: u32, value: u64) status",
|
||||
"hasher_bitvec256.update!(x: roslice u8)",
|
||||
"hasher_bitvec256.update_bitvec256!(x: roslice u8) bitvec256",
|
||||
|
||||
// ---- image_decoder
|
||||
|
||||
"image_decoder.decode_frame?(" +
|
||||
@@ -978,7 +1036,6 @@ var InterfaceFuncs = []string{
|
||||
"image_decoder.decode_image_config?(dst: nptr image_config, src: io_reader)",
|
||||
"image_decoder.frame_dirty_rect() rect_ie_u32",
|
||||
"image_decoder.get_quirk(key: u32) u64",
|
||||
"image_decoder.history_retain_length() u64",
|
||||
"image_decoder.num_animation_loops() u32",
|
||||
"image_decoder.num_decoded_frame_configs() u64",
|
||||
"image_decoder.num_decoded_frames() u64",
|
||||
@@ -990,8 +1047,9 @@ var InterfaceFuncs = []string{
|
||||
|
||||
// ---- io_transformer
|
||||
|
||||
// TODO: "io_transformer.add_history!(hist: slice u8)"? Should it take a workbuf arg?
|
||||
"io_transformer.dst_history_retain_length() optional_u63",
|
||||
"io_transformer.get_quirk(key: u32) u64",
|
||||
"io_transformer.history_retain_length() u64",
|
||||
"io_transformer.set_quirk!(key: u32, value: u64) status",
|
||||
"io_transformer.transform_io?(dst: io_writer, src: io_reader, workbuf: slice u8)",
|
||||
"io_transformer.workbuf_len() range_ii_u64",
|
||||
@@ -1000,7 +1058,6 @@ var InterfaceFuncs = []string{
|
||||
|
||||
"token_decoder.decode_tokens?(dst: token_writer, src: io_reader, workbuf: slice u8)",
|
||||
"token_decoder.get_quirk(key: u32) u64",
|
||||
"token_decoder.history_retain_length() u64",
|
||||
"token_decoder.set_quirk!(key: u32, value: u64) status",
|
||||
"token_decoder.workbuf_len() range_ii_u64",
|
||||
}
|
||||
|
||||
@@ -84,6 +84,15 @@ func (z *facts) appendFact(fact *a.Expr) {
|
||||
*z = append(*z, fact)
|
||||
}
|
||||
|
||||
func (z *facts) dropAnyFactsMentioning(n *a.Expr) error {
|
||||
return z.update(func(x *a.Expr) (*a.Expr, error) {
|
||||
if x.Mentions(n) {
|
||||
return nil, nil
|
||||
}
|
||||
return x, nil
|
||||
})
|
||||
}
|
||||
|
||||
// update applies f to each fact, replacing the slice element with the result
|
||||
// of the function call. The slice is then compacted to remove all nils.
|
||||
func (z *facts) update(f func(*a.Expr) (*a.Expr, error)) error {
|
||||
|
||||
+73
-33
@@ -207,11 +207,30 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
|
||||
return o, nil
|
||||
}
|
||||
|
||||
var errUpdateReturnsNil = errors.New("update returns nil")
|
||||
|
||||
func updateFactsForSuspension(x *a.Expr) (*a.Expr, error) {
|
||||
if x.Mentions(exprArgs) || x.Mentions(exprThis) {
|
||||
// Drop any facts involving args, this or ptr-typed local variables.
|
||||
if err := x.AsNode().Walk(func(innerNode *a.Node) error {
|
||||
if innerNode.Kind() != a.KExpr {
|
||||
return nil
|
||||
}
|
||||
n := innerNode.AsExpr()
|
||||
if n.MType().HasPointers() {
|
||||
return errUpdateReturnsNil
|
||||
} else if n.Operator() == 0 {
|
||||
switch n.Ident() {
|
||||
case t.IDArgs, t.IDThis:
|
||||
return errUpdateReturnsNil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}); err == errUpdateReturnsNil {
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO: drop any facts involving ptr-typed local variables?
|
||||
|
||||
return x, nil
|
||||
}
|
||||
|
||||
@@ -265,18 +284,21 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
||||
if _, err := q.bcheckExpr(n.IO(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := q.bcheckExpr(n.Arg1(), 0); err != nil {
|
||||
return err
|
||||
if arg1 := n.Arg1(); arg1 != nil {
|
||||
if _, err := q.bcheckExpr(arg1, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if histPos := n.HistoryPosition(); histPos != nil {
|
||||
if _, err := q.bcheckExpr(histPos, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
q.facts.dropAnyFactsMentioning(n.IO())
|
||||
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: invalidate any facts regarding the io_bind expressions.
|
||||
q.facts.dropAnyFactsMentioning(n.IO())
|
||||
|
||||
case a.KIf:
|
||||
if err := q.bcheckIf(n.AsIf()); err != nil {
|
||||
@@ -460,18 +482,18 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
lTyp = lhs.MType()
|
||||
}
|
||||
|
||||
if (rhs.Operator() == a.ExprOperatorCall) && rhs.Effect().Coroutine() && (op != t.IDEqQuestion) {
|
||||
if err := q.facts.update(updateFactsForSuspension); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
nb, err := q.bcheckAssignment1(lhs, lTyp, op, rhs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if (rhs.Operator() == a.ExprOperatorCall) && rhs.Effect().Impure() {
|
||||
if rhs.Effect().Coroutine() && (op != t.IDEqQuestion) {
|
||||
if err := q.facts.update(updateFactsForSuspension); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
recv := rhs.LHS().AsExpr().LHS().AsExpr()
|
||||
if err := q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
||||
if _, ok := oldFacts[x]; !ok {
|
||||
@@ -507,13 +529,7 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
}
|
||||
|
||||
if op == t.IDEq {
|
||||
// Drop any facts involving lhs.
|
||||
if err := q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
||||
if x.Mentions(lhs) {
|
||||
return nil, nil
|
||||
}
|
||||
return x, nil
|
||||
}); err != nil {
|
||||
if err := q.facts.dropAnyFactsMentioning(lhs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1196,22 +1212,25 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
|
||||
}
|
||||
|
||||
} else if recvTyp.IsIOTokenType() {
|
||||
if method == t.IDUndoByte {
|
||||
if err := q.canUndoByte(recv); err != nil {
|
||||
if (method == t.IDUndoByte) || (method == t.IDPeekUndoByte) {
|
||||
if err := q.canUndoByte(recv, method == t.IDPeekUndoByte); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
} else if method == t.IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast {
|
||||
} else if (method == t.IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast) ||
|
||||
(method == t.IDLimitedCopyU32FromHistory8ByteChunksDistance1FastReturnCusp) {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), eight, nil, one); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
} else if method == t.IDLimitedCopyU32FromHistory8ByteChunksFast {
|
||||
} else if (method == t.IDLimitedCopyU32FromHistory8ByteChunksFast) ||
|
||||
(method == t.IDLimitedCopyU32FromHistory8ByteChunksFastReturnCusp) {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), eight, eight, nil); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
} else if method == t.IDLimitedCopyU32FromHistoryFast {
|
||||
} else if (method == t.IDLimitedCopyU32FromHistoryFast) ||
|
||||
(method == t.IDLimitedCopyU32FromHistoryFastReturnCusp) {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), nil, one, nil); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
@@ -1259,7 +1278,7 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
|
||||
}
|
||||
}
|
||||
|
||||
} else if recvTyp.Eq(typeExprSliceU8) {
|
||||
} else if recvTyp.Eq(typeExprSliceU8) || recvTyp.Eq(typeExprRosliceU8) {
|
||||
if method >= t.IDPeekU8 {
|
||||
if m := method - t.IDPeekU8; m < t.ID(len(ioMethodAdvances)) {
|
||||
au := ioMethodAdvances[m]
|
||||
@@ -1318,11 +1337,13 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
|
||||
return bounds{}, errNotASpecialCase
|
||||
}
|
||||
|
||||
func (q *checker) canUndoByte(recv *a.Expr) error {
|
||||
func (q *checker) canUndoByte(recv *a.Expr, justPeeking bool) error {
|
||||
for _, x := range q.facts {
|
||||
if lhs, meth, args, _ := x.IsMethodCall(); (meth != t.IDCanUndoByte) || (len(args) != 0) ||
|
||||
!lhs.Eq(recv) {
|
||||
continue
|
||||
} else if justPeeking {
|
||||
return nil
|
||||
}
|
||||
return q.facts.update(func(o *a.Expr) (*a.Expr, error) {
|
||||
if o.Mentions(recv) {
|
||||
@@ -1336,6 +1357,7 @@ func (q *checker) canUndoByte(recv *a.Expr) error {
|
||||
|
||||
func (q *checker) canLimitedCopyU32FromHistoryFast(recv *a.Expr, args []*a.Node, adj *big.Int, minDistance *big.Int, exactDistance *big.Int) error {
|
||||
// As per cgen's io-private.h, there are three pre-conditions:
|
||||
// - upTo >= one
|
||||
// - (upTo + adj) <= this.length()
|
||||
// - either (distance >= minDistance) or (distance == exactDistance),
|
||||
// depending on which of minDistance and exactDistance is non-nil.
|
||||
@@ -1349,8 +1371,26 @@ func (q *checker) canLimitedCopyU32FromHistoryFast(recv *a.Expr, args []*a.Node,
|
||||
upTo := args[0].AsArg().Value()
|
||||
distance := args[1].AsArg().Value()
|
||||
|
||||
// Check "upTo <= this.length()".
|
||||
// Check "upto >= one".
|
||||
check0:
|
||||
for {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDXBinaryGreaterEq {
|
||||
continue
|
||||
}
|
||||
if lhs := x.LHS().AsExpr(); !lhs.Eq(upTo) {
|
||||
continue
|
||||
}
|
||||
if rcv := x.RHS().AsExpr().ConstValue(); (rcv == nil) || (rcv.Sign() <= 0) {
|
||||
continue
|
||||
}
|
||||
break check0
|
||||
}
|
||||
return fmt.Errorf("check: could not prove %s >= 1", upTo.Str(q.tm))
|
||||
}
|
||||
|
||||
// Check "upTo <= this.length()".
|
||||
check1:
|
||||
for {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDXBinaryLessEq {
|
||||
@@ -1387,7 +1427,7 @@ check0:
|
||||
continue
|
||||
}
|
||||
|
||||
break check0
|
||||
break check1
|
||||
}
|
||||
if adj == nil {
|
||||
return fmt.Errorf("check: could not prove (%s as base.u64) <= %s.length()",
|
||||
@@ -1398,7 +1438,7 @@ check0:
|
||||
}
|
||||
|
||||
// Check "distance >= minDistance".
|
||||
check1a:
|
||||
check2a:
|
||||
for minDistance != nil {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDXBinaryGreaterEq {
|
||||
@@ -1410,13 +1450,13 @@ check1a:
|
||||
if rcv := x.RHS().AsExpr().ConstValue(); (rcv == nil) || (rcv.Cmp(minDistance) < 0) {
|
||||
continue
|
||||
}
|
||||
break check1a
|
||||
break check2a
|
||||
}
|
||||
return fmt.Errorf("check: could not prove %s >= %v", distance.Str(q.tm), minDistance)
|
||||
}
|
||||
|
||||
// Check "distance == exactDistance".
|
||||
check1b:
|
||||
check2b:
|
||||
for exactDistance != nil {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDXBinaryEqEq {
|
||||
@@ -1428,13 +1468,13 @@ check1b:
|
||||
if rcv := x.RHS().AsExpr().ConstValue(); (rcv == nil) || (rcv.Cmp(exactDistance) != 0) {
|
||||
continue
|
||||
}
|
||||
break check1b
|
||||
break check2b
|
||||
}
|
||||
return fmt.Errorf("check: could not prove %s == %v", distance.Str(q.tm), exactDistance)
|
||||
}
|
||||
|
||||
// Check "distance <= this.history_length()".
|
||||
check2:
|
||||
check3:
|
||||
for {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDXBinaryLessEq {
|
||||
@@ -1460,7 +1500,7 @@ check2:
|
||||
continue
|
||||
}
|
||||
|
||||
break check2
|
||||
break check3
|
||||
}
|
||||
return fmt.Errorf("check: could not prove %s <= %s.history_length()",
|
||||
distance.Str(q.tm), recv.Str(q.tm))
|
||||
|
||||
+121
-10
@@ -98,6 +98,9 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
|
||||
builtInInterfaces: map[t.QID][]t.QQID{},
|
||||
builtInInterfaceFuncs: map[t.QQID]*a.Func{},
|
||||
unseenInterfaceImpls: map[t.QQID]*a.Func{},
|
||||
|
||||
chooseAlternatives: map[t.QID][]t.ID{},
|
||||
noRecursiveMarks: map[t.QID]uint8{},
|
||||
}
|
||||
|
||||
for _, funcs := range builtin.Funcs {
|
||||
@@ -166,13 +169,14 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
|
||||
}
|
||||
|
||||
for _, phase := range phases {
|
||||
for _, f := range files {
|
||||
if phase.kind == a.KInvalid {
|
||||
if err := phase.check(c, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
continue
|
||||
if phase.kind == a.KInvalid {
|
||||
if err := phase.check(c, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
for _, n := range f.TopLevelDecls() {
|
||||
if n.Kind() != phase.kind {
|
||||
continue
|
||||
@@ -198,10 +202,12 @@ var phases = [...]struct {
|
||||
{a.KStruct, (*Checker).checkStructDecl},
|
||||
{a.KInvalid, (*Checker).checkStructCycles},
|
||||
{a.KStruct, (*Checker).checkStructFields},
|
||||
{a.KFunc, (*Checker).gatherChooseAlternatives},
|
||||
{a.KFunc, (*Checker).checkFuncSignature},
|
||||
{a.KFunc, (*Checker).checkFuncContract},
|
||||
{a.KFunc, (*Checker).checkFuncImplements},
|
||||
{a.KFunc, (*Checker).checkFuncBody},
|
||||
{a.KFunc, (*Checker).checkNoRecursiveFuncs},
|
||||
{a.KInvalid, (*Checker).checkInterfacesSatisfied},
|
||||
{a.KStruct, (*Checker).checkFieldMethodCollisions},
|
||||
{a.KInvalid, (*Checker).checkAllTypeChecked},
|
||||
@@ -242,6 +248,9 @@ type Checker struct {
|
||||
builtInInterfaceFuncs map[t.QQID]*a.Func
|
||||
unseenInterfaceImpls map[t.QQID]*a.Func
|
||||
|
||||
chooseAlternatives map[t.QID][]t.ID
|
||||
noRecursiveMarks map[t.QID]uint8
|
||||
|
||||
unsortedStructs []*a.Struct
|
||||
}
|
||||
|
||||
@@ -494,7 +503,7 @@ func (c *Checker) checkStructCycles(_ *a.Node) error {
|
||||
|
||||
func (c *Checker) checkStructFields(node *a.Node) error {
|
||||
n := node.AsStruct()
|
||||
if err := c.checkFields(n.Fields(), true, true, true); err != nil {
|
||||
if err := c.checkFields(n.Fields(), true, false, true, true); err != nil {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("%v in struct %s", err, n.QID().Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
@@ -504,7 +513,7 @@ func (c *Checker) checkStructFields(node *a.Node) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Checker) checkFields(fields []*a.Node, banCPUArchTypes bool, banPtrTypes bool, checkDefaultZeroValue bool) error {
|
||||
func (c *Checker) checkFields(fields []*a.Node, banCPUArchTypes bool, banNonBaseTypes bool, banPtrTypes bool, checkDefaultZeroValue bool) error {
|
||||
if len(fields) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -522,10 +531,16 @@ func (c *Checker) checkFields(fields []*a.Node, banCPUArchTypes bool, banPtrType
|
||||
if err := checkTypeExpr(q, f.XType()); err != nil {
|
||||
return fmt.Errorf("%v for field %q", err, f.Name().Str(c.tm))
|
||||
}
|
||||
if banCPUArchTypes && f.XType().Innermost().IsCPUArchType() {
|
||||
|
||||
innermost := f.XType().Innermost()
|
||||
if banCPUArchTypes && innermost.IsCPUArchType() {
|
||||
return fmt.Errorf("check: cpu_arch type %q not allowed for field %q",
|
||||
f.XType().Str(c.tm), f.Name().Str(c.tm))
|
||||
}
|
||||
if banNonBaseTypes && (innermost.QID()[0] != t.IDBase) {
|
||||
return fmt.Errorf("check: non-base type %q not allowed for field %q",
|
||||
f.XType().Str(c.tm), f.Name().Str(c.tm))
|
||||
}
|
||||
if banPtrTypes && f.XType().HasPointers() {
|
||||
return fmt.Errorf("check: pointer-containing type %q not allowed for field %q",
|
||||
f.XType().Str(c.tm), f.Name().Str(c.tm))
|
||||
@@ -556,13 +571,34 @@ func checkTypeExpr(q *checker, n *a.TypeExpr) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Checker) gatherChooseAlternatives(node *a.Node) error {
|
||||
n := node.AsFunc()
|
||||
return node.Walk(func(innerNode *a.Node) error {
|
||||
if innerNode.Kind() == a.KChoose {
|
||||
o := innerNode.AsChoose()
|
||||
receiverType := n.Receiver()[1]
|
||||
oQID := t.QID{receiverType, o.Name()}
|
||||
chooseAlternatives := c.chooseAlternatives[oQID]
|
||||
for _, p := range o.Args() {
|
||||
p := p.AsExpr()
|
||||
pQID := t.QID{receiverType, p.Ident()}
|
||||
if oQID[1] != pQID[1] {
|
||||
chooseAlternatives = append(chooseAlternatives, pQID[1])
|
||||
}
|
||||
}
|
||||
c.chooseAlternatives[oQID] = chooseAlternatives
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Checker) checkFuncSignature(node *a.Node) error {
|
||||
return c.checkFuncSignature1(node, true)
|
||||
}
|
||||
|
||||
func (c *Checker) checkFuncSignature1(node *a.Node, banCPUArchTypes bool) error {
|
||||
n := node.AsFunc()
|
||||
if err := c.checkFields(n.In().Fields(), banCPUArchTypes, false, false); err != nil {
|
||||
if err := c.checkFields(n.In().Fields(), banCPUArchTypes, true, false, false); err != nil {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("%v in in-params for func %s", err, n.QQID().Str(c.tm)),
|
||||
Filename: n.Filename(),
|
||||
@@ -753,6 +789,81 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkNoRecursiveFuncs essentially performs a topological sort (via a
|
||||
// depth-first search), ordering bar and baz functions on whether bar's body
|
||||
// (or asserts) calls the this.baz method.
|
||||
//
|
||||
// https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search
|
||||
func (c *Checker) checkNoRecursiveFuncs(node *a.Node) error {
|
||||
_, err := c.checkNoRecursiveFuncs1(nil, node.AsFunc())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Checker) checkNoRecursiveFuncs1(dst []t.QID, n *a.Func) ([]t.QID, error) {
|
||||
nQID := n.QQID().QIDSuffix()
|
||||
dst = append(dst, nQID)
|
||||
|
||||
const (
|
||||
unmarked = 0
|
||||
temporary = 1
|
||||
permanent = 2
|
||||
)
|
||||
switch c.noRecursiveMarks[nQID] {
|
||||
case temporary:
|
||||
hidden, names := true, make([]string, 0, len(dst))
|
||||
for _, qid := range dst {
|
||||
if hidden {
|
||||
if qid != nQID {
|
||||
continue
|
||||
}
|
||||
hidden = false
|
||||
}
|
||||
names = append(names, qid.Str(c.tm))
|
||||
}
|
||||
return nil, fmt.Errorf("check: recursive call chain: %s", names)
|
||||
case permanent:
|
||||
return dst, nil
|
||||
}
|
||||
c.noRecursiveMarks[nQID] = temporary
|
||||
|
||||
if err := n.AsNode().Walk(func(innerNode *a.Node) error {
|
||||
if innerNode.Kind() != a.KExpr {
|
||||
return nil
|
||||
}
|
||||
o := innerNode.AsExpr()
|
||||
if o.Operator() != t.IDOpenParen {
|
||||
return nil
|
||||
}
|
||||
foo := o.LHS().AsExpr().IsThisDotFoo()
|
||||
if foo == 0 {
|
||||
return nil
|
||||
}
|
||||
qqid := n.QQID()
|
||||
qqid[2] = foo
|
||||
|
||||
for _, altID := range c.chooseAlternatives[qqid.QIDSuffix()] {
|
||||
altQQID := t.QQID{qqid[0], qqid[1], altID}
|
||||
dst1, err1 := c.checkNoRecursiveFuncs1(dst, c.funcs[altQQID])
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
dst = dst1
|
||||
}
|
||||
|
||||
dst1, err1 := c.checkNoRecursiveFuncs1(dst, c.funcs[qqid])
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
dst = dst1
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.noRecursiveMarks[nQID] = permanent
|
||||
return dst[:len(dst)-1], nil
|
||||
}
|
||||
|
||||
func (c *Checker) checkInterfacesSatisfied(node *a.Node) error {
|
||||
if len(c.unseenInterfaceImpls) == 0 {
|
||||
return nil
|
||||
|
||||
@@ -86,7 +86,7 @@ func TestCheck(tt *testing.T) {
|
||||
{
|
||||
// Redundant, but shows the labeled jump syntax.
|
||||
continue.label
|
||||
} endwhile.label
|
||||
}.label
|
||||
}
|
||||
`) + "\n"
|
||||
|
||||
|
||||
+16
-3
@@ -49,8 +49,7 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, ad
|
||||
return q.optimizeIOMethodAdvanceExpr(receiver, advanceExpr, update)
|
||||
}
|
||||
|
||||
// Check if receiver looks like "a[i .. j]" where i and j are constants and
|
||||
// ((j - i) >= advance).
|
||||
// Check if the receiver looks like "a[i .. j]".
|
||||
if _, i, j, ok := receiver.IsSlice(); ok {
|
||||
icv := (*big.Int)(nil)
|
||||
if i == nil {
|
||||
@@ -64,11 +63,25 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, ad
|
||||
jcv = j.ConstValue()
|
||||
}
|
||||
|
||||
if (icv != nil) && (jcv != nil) {
|
||||
switch {
|
||||
case (icv != nil) && (jcv != nil):
|
||||
// OK if i and j are constants and ((j - i) >= advance).
|
||||
n := big.NewInt(0).Sub(jcv, icv)
|
||||
if n.Cmp(advance) >= 0 {
|
||||
retOK = true
|
||||
}
|
||||
|
||||
case (i != nil) && (j != nil) && (j.Operator() == t.IDXBinaryPlus):
|
||||
// OK if j is (i + constant) and (constant >= advance).
|
||||
n := (*big.Int)(nil)
|
||||
if j.LHS().AsExpr().Eq(i) {
|
||||
n = j.RHS().AsExpr().ConstValue()
|
||||
} else if j.RHS().AsExpr().Eq(i) {
|
||||
n = j.LHS().AsExpr().ConstValue()
|
||||
}
|
||||
if n != nil && (n.Cmp(advance) >= 0) {
|
||||
retOK = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ var (
|
||||
typeExprU32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil)
|
||||
typeExprU64 = a.NewTypeExpr(0, t.IDBase, t.IDU64, nil, nil, nil)
|
||||
|
||||
typeExprBitvec256 = a.NewTypeExpr(0, t.IDBase, t.IDBitvec256, nil, nil, nil)
|
||||
|
||||
typeExprOptionalU63 = a.NewTypeExpr(0, t.IDBase, t.IDOptionalU63, nil, nil, nil)
|
||||
|
||||
typeExprEmptyStruct = a.NewTypeExpr(0, t.IDBase, t.IDEmptyStruct, nil, nil, nil)
|
||||
typeExprBool = a.NewTypeExpr(0, t.IDBase, t.IDBool, nil, nil, nil)
|
||||
typeExprUtility = a.NewTypeExpr(0, t.IDBase, t.IDUtility, nil, nil, nil)
|
||||
@@ -111,6 +115,10 @@ var builtInTypeMap = typeMap{
|
||||
t.IDU32: typeExprU32,
|
||||
t.IDU64: typeExprU64,
|
||||
|
||||
t.IDBitvec256: typeExprBitvec256,
|
||||
|
||||
t.IDOptionalU63: typeExprOptionalU63,
|
||||
|
||||
t.IDEmptyStruct: typeExprEmptyStruct,
|
||||
t.IDBool: typeExprBool,
|
||||
t.IDUtility: typeExprUtility,
|
||||
|
||||
+18
-8
@@ -160,16 +160,26 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
n.Keyword().Str(q.tm), n.IO().Str(q.tm), typ.Str(q.tm))
|
||||
}
|
||||
|
||||
arg1Typ := typeExprSliceU8
|
||||
if n.Keyword() == t.IDIOLimit {
|
||||
arg1Typ := (*a.TypeExpr)(nil)
|
||||
switch n.Keyword() {
|
||||
case t.IDIOBind:
|
||||
arg1Typ = typeExprRosliceU8
|
||||
if n.IO().MType().Eq(typeExprIOWriter) {
|
||||
arg1Typ = typeExprSliceU8
|
||||
}
|
||||
case t.IDIOForgetHistory:
|
||||
// No-op.
|
||||
case t.IDIOLimit:
|
||||
arg1Typ = typeExprU64
|
||||
}
|
||||
if err := q.tcheckExpr(n.Arg1(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if typ := n.Arg1().MType(); !typ.EqIgnoringRefinementsLHSReadOnly(arg1Typ) {
|
||||
return fmt.Errorf("check: %s expression %q, of type %q, does not have type %q",
|
||||
n.Keyword().Str(q.tm), n.Arg1().Str(q.tm), typ.Str(q.tm), arg1Typ.Str(q.tm))
|
||||
if arg1Typ != nil {
|
||||
if err := q.tcheckExpr(n.Arg1(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if typ := n.Arg1().MType(); !arg1Typ.EqIgnoringRefinementsLHSReadOnly(typ) {
|
||||
return fmt.Errorf("check: %s expression %q, of type %q, does not have type %q",
|
||||
n.Keyword().Str(q.tm), n.Arg1().Str(q.tm), typ.Str(q.tm), arg1Typ.Str(q.tm))
|
||||
}
|
||||
}
|
||||
|
||||
if n.Keyword() == t.IDIOBind {
|
||||
|
||||
@@ -85,7 +85,10 @@ func checkPackageName(s string) string {
|
||||
// Deny certain package names.
|
||||
switch s {
|
||||
case "base", "base_private", "base_private_header", "base_public", "base_public_header",
|
||||
"config", "implementation", "include_guard", "initialize", "version":
|
||||
"config", "implementation", "include_guard", "initialize", "private", "version":
|
||||
return ""
|
||||
}
|
||||
if strings.HasPrefix(s, "private_") {
|
||||
return ""
|
||||
}
|
||||
return s
|
||||
|
||||
+44
-49
@@ -756,24 +756,6 @@ func (p *parser) parseLabel() (t.ID, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (p *parser) parseEndwhile(label t.ID) bool {
|
||||
if p.peek1() != t.IDEndwhile {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if label != 0 {
|
||||
if p.peek1() != t.IDDot {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() != label {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
x := p.peek1()
|
||||
if x == t.IDVar {
|
||||
@@ -858,7 +840,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
}
|
||||
return a.NewChoose(name, args).AsNode(), nil
|
||||
|
||||
case t.IDIOBind, t.IDIOLimit:
|
||||
case t.IDIOBind, t.IDIOForgetHistory, t.IDIOLimit:
|
||||
return p.parseIOManipNode()
|
||||
|
||||
case t.IDIf:
|
||||
@@ -930,14 +912,21 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
n.SetBody(body)
|
||||
p.loops.Pop()
|
||||
|
||||
if !p.parseEndwhile(label) {
|
||||
dotLabel := ""
|
||||
if label != 0 {
|
||||
dotLabel = "." + label.Str(p.tm)
|
||||
if label != 0 {
|
||||
seenDotLabel := false
|
||||
if p.peek1() == t.IDDot {
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() == label {
|
||||
p.src = p.src[1:]
|
||||
seenDotLabel = true
|
||||
}
|
||||
}
|
||||
if !seenDotLabel {
|
||||
return nil, fmt.Errorf(`parse: expected .%s at %s:%d`,
|
||||
label.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
return nil, fmt.Errorf(`parse: expected endwhile%s at %s:%d`,
|
||||
dotLabel, p.filename, p.line())
|
||||
}
|
||||
|
||||
if !doubleCurly {
|
||||
// No-op.
|
||||
} else if n.HasContinue() {
|
||||
@@ -1080,13 +1069,16 @@ func (p *parser) parseIOManipNode() (*a.Node, error) {
|
||||
}
|
||||
|
||||
arg1Name := t.ID(0)
|
||||
if keyword == t.IDIOBind {
|
||||
switch keyword {
|
||||
case t.IDIOBind:
|
||||
arg1Name = t.IDData
|
||||
if io.Operator() != 0 {
|
||||
return nil, fmt.Errorf(`parse: invalid %s argument %q at %s:%d`,
|
||||
keyword.Str(p.tm), io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
} else {
|
||||
case t.IDIOForgetHistory:
|
||||
// No-op.
|
||||
case t.IDIOLimit:
|
||||
arg1Name = t.IDLimit
|
||||
if (io.Operator() != 0) && (io.IsArgsDotFoo() == 0) {
|
||||
return nil, fmt.Errorf(`parse: invalid %s argument %q at %s:%d`,
|
||||
@@ -1094,31 +1086,34 @@ func (p *parser) parseIOManipNode() (*a.Node, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
arg1 := (*a.Expr)(nil)
|
||||
if arg1Name != 0 {
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != arg1Name {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected %q, got %q at %s:%d`, arg1Name.Str(p.tm), got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if x := p.peek1(); x != arg1Name {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected %q, got %q at %s:%d`, arg1Name.Str(p.tm), got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
arg1, err := p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if arg1.Effect() != 0 {
|
||||
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
arg1, err = p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if arg1.Effect() != 0 {
|
||||
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
}
|
||||
|
||||
histPos := (*a.Expr)(nil)
|
||||
|
||||
+94
-74
@@ -192,6 +192,10 @@ func (x QQID) Str(m *Map) string {
|
||||
return m.ByID(x[2])
|
||||
}
|
||||
|
||||
func (x QQID) QIDSuffix() QID {
|
||||
return QID{x[1], x[2]}
|
||||
}
|
||||
|
||||
// Token combines an ID and the line number it was seen.
|
||||
type Token struct {
|
||||
ID ID
|
||||
@@ -364,32 +368,32 @@ const (
|
||||
minKeyword = 0xB0
|
||||
maxKeyword = 0xCF
|
||||
|
||||
IDAssert = ID(0xB0)
|
||||
IDBreak = ID(0xB1)
|
||||
IDChoose = ID(0xB2)
|
||||
IDChoosy = ID(0xB3)
|
||||
IDConst = ID(0xB4)
|
||||
IDContinue = ID(0xB5)
|
||||
IDElse = ID(0xB6)
|
||||
IDEndwhile = ID(0xB7)
|
||||
IDFunc = ID(0xB8)
|
||||
IDIOBind = ID(0xB9)
|
||||
IDIOLimit = ID(0xBA)
|
||||
IDIf = ID(0xBB)
|
||||
IDImplements = ID(0xBC)
|
||||
IDInv = ID(0xBD)
|
||||
IDIterate = ID(0xBE)
|
||||
IDPost = ID(0xBF)
|
||||
IDPre = ID(0xC0)
|
||||
IDPri = ID(0xC1)
|
||||
IDPub = ID(0xC2)
|
||||
IDReturn = ID(0xC3)
|
||||
IDStruct = ID(0xC4)
|
||||
IDUse = ID(0xC5)
|
||||
IDVar = ID(0xC6)
|
||||
IDVia = ID(0xC7)
|
||||
IDWhile = ID(0xC8)
|
||||
IDYield = ID(0xC9)
|
||||
IDAssert = ID(0xB0)
|
||||
IDBreak = ID(0xB1)
|
||||
IDChoose = ID(0xB2)
|
||||
IDChoosy = ID(0xB3)
|
||||
IDConst = ID(0xB4)
|
||||
IDContinue = ID(0xB5)
|
||||
IDElse = ID(0xB6)
|
||||
IDFunc = ID(0xB7)
|
||||
IDIOBind = ID(0xB8)
|
||||
IDIOForgetHistory = ID(0xB9)
|
||||
IDIOLimit = ID(0xBA)
|
||||
IDIf = ID(0xBB)
|
||||
IDImplements = ID(0xBC)
|
||||
IDInv = ID(0xBD)
|
||||
IDIterate = ID(0xBE)
|
||||
IDPost = ID(0xBF)
|
||||
IDPre = ID(0xC0)
|
||||
IDPri = ID(0xC1)
|
||||
IDPub = ID(0xC2)
|
||||
IDReturn = ID(0xC3)
|
||||
IDStruct = ID(0xC4)
|
||||
IDUse = ID(0xC5)
|
||||
IDVar = ID(0xC6)
|
||||
IDVia = ID(0xC7)
|
||||
IDWhile = ID(0xC8)
|
||||
IDYield = ID(0xC9)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -467,6 +471,11 @@ const (
|
||||
IDU32 = ID(0x116)
|
||||
IDU64 = ID(0x117)
|
||||
|
||||
IDBitvec128 = ID(0x118)
|
||||
IDBitvec256 = ID(0x119)
|
||||
|
||||
IDOptionalU63 = ID(0x11C)
|
||||
|
||||
IDBase = ID(0x120)
|
||||
IDBool = ID(0x121)
|
||||
IDEmptyIOReader = ID(0x122)
|
||||
@@ -512,14 +521,17 @@ const (
|
||||
IDSkipU32 = ID(0x16C)
|
||||
IDSkipU32Fast = ID(0x16D)
|
||||
|
||||
IDCopyFromSlice = ID(0x170)
|
||||
IDLimitedCopyU32FromHistory = ID(0x171)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast = ID(0x172)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast = ID(0x173)
|
||||
IDLimitedCopyU32FromHistoryFast = ID(0x174)
|
||||
IDLimitedCopyU32FromReader = ID(0x175)
|
||||
IDLimitedCopyU32FromSlice = ID(0x176)
|
||||
IDLimitedCopyU32ToSlice = ID(0x177)
|
||||
IDCopyFromSlice = ID(0x170)
|
||||
IDLimitedCopyU32FromHistory = ID(0x171)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast = ID(0x172)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1FastReturnCusp = ID(0x173)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast = ID(0x174)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFastReturnCusp = ID(0x175)
|
||||
IDLimitedCopyU32FromHistoryFast = ID(0x176)
|
||||
IDLimitedCopyU32FromHistoryFastReturnCusp = ID(0x177)
|
||||
IDLimitedCopyU32FromReader = ID(0x178)
|
||||
IDLimitedCopyU32FromSlice = ID(0x179)
|
||||
IDLimitedCopyU32ToSlice = ID(0x17A)
|
||||
|
||||
// -------- 0x180 block.
|
||||
|
||||
@@ -556,9 +568,8 @@ const (
|
||||
|
||||
// --------
|
||||
|
||||
IDPeekU64LEAt = ID(0x1A0)
|
||||
|
||||
IDPeekU8 = ID(0x1A1)
|
||||
IDPeekUndoByte = ID(0x1A0)
|
||||
IDPeekU8 = ID(0x1A1)
|
||||
|
||||
IDPeekU8AsU16 = ID(0x1A5)
|
||||
IDPeekU16BE = ID(0x1A6)
|
||||
@@ -588,9 +599,9 @@ const (
|
||||
IDPeekU64BE = ID(0x1BE)
|
||||
IDPeekU64LE = ID(0x1BF)
|
||||
|
||||
// --------
|
||||
IDPeekU64LEAt = ID(0x1C0)
|
||||
|
||||
// TODO: IDUnwriteU8?
|
||||
// --------
|
||||
|
||||
IDWriteU8 = ID(0x1C1)
|
||||
IDWriteU16BE = ID(0x1C2)
|
||||
@@ -807,32 +818,32 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
|
||||
IDNot: "not",
|
||||
|
||||
IDAssert: "assert",
|
||||
IDBreak: "break",
|
||||
IDChoose: "choose",
|
||||
IDChoosy: "choosy",
|
||||
IDConst: "const",
|
||||
IDContinue: "continue",
|
||||
IDElse: "else",
|
||||
IDEndwhile: "endwhile",
|
||||
IDFunc: "func",
|
||||
IDIOBind: "io_bind",
|
||||
IDIOLimit: "io_limit",
|
||||
IDIf: "if",
|
||||
IDImplements: "implements",
|
||||
IDInv: "inv",
|
||||
IDIterate: "iterate",
|
||||
IDPost: "post",
|
||||
IDPre: "pre",
|
||||
IDPri: "pri",
|
||||
IDPub: "pub",
|
||||
IDReturn: "return",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDVia: "via",
|
||||
IDWhile: "while",
|
||||
IDYield: "yield",
|
||||
IDAssert: "assert",
|
||||
IDBreak: "break",
|
||||
IDChoose: "choose",
|
||||
IDChoosy: "choosy",
|
||||
IDConst: "const",
|
||||
IDContinue: "continue",
|
||||
IDElse: "else",
|
||||
IDFunc: "func",
|
||||
IDIOBind: "io_bind",
|
||||
IDIOForgetHistory: "io_forget_history",
|
||||
IDIOLimit: "io_limit",
|
||||
IDIf: "if",
|
||||
IDImplements: "implements",
|
||||
IDInv: "inv",
|
||||
IDIterate: "iterate",
|
||||
IDPost: "post",
|
||||
IDPre: "pre",
|
||||
IDPri: "pri",
|
||||
IDPub: "pub",
|
||||
IDReturn: "return",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDVia: "via",
|
||||
IDWhile: "while",
|
||||
IDYield: "yield",
|
||||
|
||||
IDArray: "array",
|
||||
IDNptr: "nptr",
|
||||
@@ -910,6 +921,11 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDU32: "u32",
|
||||
IDU64: "u64",
|
||||
|
||||
IDBitvec128: "bitvec128",
|
||||
IDBitvec256: "bitvec256",
|
||||
|
||||
IDOptionalU63: "optional_u63",
|
||||
|
||||
IDBase: "base",
|
||||
IDBool: "bool",
|
||||
IDEmptyIOReader: "empty_io_reader",
|
||||
@@ -957,12 +973,15 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
|
||||
IDCopyFromSlice: "copy_from_slice",
|
||||
IDLimitedCopyU32FromHistory: "limited_copy_u32_from_history",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",
|
||||
IDLimitedCopyU32FromHistoryFast: "limited_copy_u32_from_history_fast",
|
||||
IDLimitedCopyU32FromReader: "limited_copy_u32_from_reader",
|
||||
IDLimitedCopyU32FromSlice: "limited_copy_u32_from_slice",
|
||||
IDLimitedCopyU32ToSlice: "limited_copy_u32_to_slice",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1FastReturnCusp: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFastReturnCusp: "limited_copy_u32_from_history_8_byte_chunks_fast_return_cusp",
|
||||
IDLimitedCopyU32FromHistoryFast: "limited_copy_u32_from_history_fast",
|
||||
IDLimitedCopyU32FromHistoryFastReturnCusp: "limited_copy_u32_from_history_fast_return_cusp",
|
||||
IDLimitedCopyU32FromReader: "limited_copy_u32_from_reader",
|
||||
IDLimitedCopyU32FromSlice: "limited_copy_u32_from_slice",
|
||||
IDLimitedCopyU32ToSlice: "limited_copy_u32_to_slice",
|
||||
|
||||
// -------- 0x180 block.
|
||||
|
||||
@@ -999,9 +1018,8 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
|
||||
// --------
|
||||
|
||||
IDPeekU64LEAt: "peek_u64le_at",
|
||||
|
||||
IDPeekU8: "peek_u8",
|
||||
IDPeekUndoByte: "peek_undo_byte",
|
||||
IDPeekU8: "peek_u8",
|
||||
|
||||
IDPeekU8AsU16: "peek_u8_as_u16",
|
||||
IDPeekU16BE: "peek_u16be",
|
||||
@@ -1031,6 +1049,8 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDPeekU64BE: "peek_u64be",
|
||||
IDPeekU64LE: "peek_u64le",
|
||||
|
||||
IDPeekU64LEAt: "peek_u64le_at",
|
||||
|
||||
// --------
|
||||
|
||||
IDWriteU8: "write_u8",
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
// back-references.
|
||||
//
|
||||
// The main benefit, compared to full LZMA/Xz, is that this implementation is
|
||||
// much simpler and hence easier to study. It is around 800 lines of code.
|
||||
// much simpler and hence easier to study. It is around 800 lines of code,
|
||||
// about a third of which are comments.
|
||||
//
|
||||
// Example compression numbers on a small English text file (at
|
||||
// https://github.com/google/wuffs/blob/main/test/data/romeo.txt):
|
||||
@@ -55,6 +56,9 @@
|
||||
// linux-5.0.1.tar.xz file size above differs from what cdn.kernel.org served.
|
||||
package litonlylzma
|
||||
|
||||
// When editing this file, consider setting "allowTestsToExecOtherPrograms =
|
||||
// true" in the test code.
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"hash/crc32"
|
||||
@@ -655,6 +659,18 @@ func encodeXz(dst []byte, src []byte) (appendedDst []byte, retErr error) {
|
||||
srcChunk, remaining = remaining, nil
|
||||
}
|
||||
|
||||
// Emit 3 or 6 bytes of LZMA2 header. The LZMA2 file format also allows
|
||||
// for chunks to depend on previous chunks. But, as said above, we
|
||||
// produce independent chunks (favoring simplicity over maximizing
|
||||
// compression ratio). We emit one of:
|
||||
//
|
||||
// 00000001 U U - Uncompressed, reset dic, need reset state and set new prop
|
||||
// 111uuuuu U U P P S - LZMA, reset state + set new prop, reset dic
|
||||
//
|
||||
// "U U" or "uuuuu U U" is a 16-bit or 21-bit (unpacked_size - 1), "P
|
||||
// P" is a uint16_t (packed_size - 1) and S holds the LZMA properties.
|
||||
//
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/781863cdf592da3e97420f50de5dac056ad352a5/C/Lzma2Dec.c#L17-L23
|
||||
rawLZMA = encodeRaw(rawLZMA[:0], srcChunk)
|
||||
if (len(srcChunk) + 3) <= (len(rawLZMA) + 6) {
|
||||
dst = append(dst,
|
||||
|
||||
@@ -13,6 +13,7 @@ package litonlylzma
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -65,3 +66,64 @@ func TestRoundTripOneThousand0x00s(tt *testing.T) { testRoundTrip(tt, oneThousan
|
||||
func TestRoundTripOneThousand0xFFs(tt *testing.T) { testRoundTrip(tt, oneThousand0xFFs) }
|
||||
func TestRoundTripPiTxt(tt *testing.T) { testRoundTrip(tt, "pi.txt") }
|
||||
func TestRoundTripRomeoTxt(tt *testing.T) { testRoundTrip(tt, "romeo.txt") }
|
||||
|
||||
func TestUsrBinFoocatCompat(tt *testing.T) {
|
||||
// Set "allowTestsToExecOtherPrograms = true" for more test coverage,
|
||||
// checking compatibility with third-party decompression tools that are
|
||||
// often available (at a well known location) on Linux.
|
||||
const allowTestsToExecOtherPrograms = false
|
||||
if !allowTestsToExecOtherPrograms {
|
||||
tt.Skip("not configured to exec third-party programs")
|
||||
}
|
||||
|
||||
testCases := [...]struct {
|
||||
fileFormat FileFormat
|
||||
command string
|
||||
}{
|
||||
{FileFormatLZMA, "/usr/bin/lzcat"},
|
||||
{FileFormatXz, "/usr/bin/xzcat"},
|
||||
}
|
||||
|
||||
// Not every system has "/usr/bin/{lzcat,xzcat}" commands.
|
||||
for _, tc := range testCases {
|
||||
if _, err := os.Stat(tc.command); err != nil {
|
||||
tt.Skipf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
pi, err := os.ReadFile("../../test/data/pi.txt")
|
||||
if err != nil {
|
||||
tt.Fatalf("ReadFile: %v", err)
|
||||
} else if len(pi) != 100003 {
|
||||
tt.Fatalf("ReadFile: unexpected pi.txt file length")
|
||||
}
|
||||
|
||||
lengths := [...]int{0, 1, 10, 100, 1e3, 1e4, 1e5}
|
||||
|
||||
for _, tc := range testCases {
|
||||
for _, length := range lengths {
|
||||
original := pi[:length]
|
||||
|
||||
compressed, err := tc.fileFormat.Encode(nil, original)
|
||||
if err != nil {
|
||||
tt.Fatalf("%v, length=%d: Encode: %v", tc.fileFormat, length, err)
|
||||
}
|
||||
|
||||
stdout := bytes.Buffer{}
|
||||
stderr := bytes.Buffer{}
|
||||
|
||||
cmd := exec.Command(tc.command)
|
||||
cmd.Stdin = bytes.NewReader(compressed)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
tt.Fatalf("%v, length=%d: Run: %v\nstderr:\n%s", tc.fileFormat, length, err, stderr.Bytes())
|
||||
}
|
||||
|
||||
recovered := stdout.Bytes()
|
||||
if !bytes.Equal(original, recovered) {
|
||||
tt.Fatalf("%v, length=%d: round trip produced different bytes", tc.fileFormat, length)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ compiling it.
|
||||
|
||||
# Latest Stable Version
|
||||
|
||||
**Version 0.2 (December 2019)** is the latest stable version. Stable means that
|
||||
**Version 0.3 (April 2023)** is the latest stable version. Stable means that
|
||||
its API won't change any further, but being a "version 0.x" means that:
|
||||
|
||||
- It will not have long term support.
|
||||
|
||||
+22466
-5904
File diff suppressed because it is too large.
Load diff
+20
-18
@@ -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
|
||||
// 00d5e35865a2f2718f4bb2596adaaa54bd639bbe committed on 2023-04-08.
|
||||
#define WUFFS_VERSION 0x000030003
|
||||
// a138188d5742c0469de983878a430bdbe7e50e77 committed on 2024-04-19.
|
||||
#define WUFFS_VERSION 0x000030004
|
||||
#define WUFFS_VERSION_MAJOR 0
|
||||
#define WUFFS_VERSION_MINOR 3
|
||||
#define WUFFS_VERSION_PATCH 3
|
||||
#define WUFFS_VERSION_PATCH 4
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL ""
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3399
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20230408
|
||||
#define WUFFS_VERSION_STRING "0.3.3+3399.20230408"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3401
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20240419
|
||||
#define WUFFS_VERSION_STRING "0.3.4+3401.20240419"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -41569,20 +41569,22 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
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)) {
|
||||
if (self->private_impl.f_seen_trns || ((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;
|
||||
} else if (self->private_impl.f_color_type > 3) {
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
+22471
-5909
File diff suppressed because it is too large.
Load diff
+34
-4
@@ -19,11 +19,13 @@ package main
|
||||
// Usage: go run checksum.go -algorithm=crc32/ieee < foo.bar
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"flag"
|
||||
"fmt"
|
||||
"hash"
|
||||
"hash/adler32"
|
||||
"hash/crc32"
|
||||
"hash/crc64"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -34,6 +36,7 @@ import (
|
||||
|
||||
var (
|
||||
algorithm = flag.String("algorithm", "adler32", "checksum algorithm")
|
||||
count = flag.Int("count", 300, "number of cases (max 300), needs -pi flag")
|
||||
pi = flag.Bool("pi", false, "checksum the digits of pi instead of stdin")
|
||||
)
|
||||
|
||||
@@ -48,19 +51,32 @@ func main1() error {
|
||||
flag.Parse()
|
||||
|
||||
if *pi {
|
||||
const digits = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170"
|
||||
if len(digits) != 99 {
|
||||
const digits = "3." +
|
||||
"141592653589793238462643383279502884197169399375105820974944592307816406" +
|
||||
"286208998628034825342117067982148086513282306647093844609550582231725359" +
|
||||
"408128481117450284102701938521105559644622948954930381964428810975665933" +
|
||||
"446128475648233786783165271201909145648566923460348610454326648213393607" +
|
||||
"260249141"
|
||||
if len(digits) != 299 {
|
||||
panic("bad len(digits)")
|
||||
} else if (*count < 0) || (len(digits) < (*count - 1)) {
|
||||
return fmt.Errorf("invalid count: %d", *count)
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
newLine := false
|
||||
for i := 0; i < *count; i++ {
|
||||
if err := do(strings.NewReader(digits[:i])); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Print(",")
|
||||
if i&7 == 7 {
|
||||
newLine = i&7 == 7
|
||||
if newLine {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
if !newLine {
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
} else {
|
||||
if err := do(os.Stdin); err != nil {
|
||||
return err
|
||||
@@ -77,6 +93,10 @@ func do(r io.Reader) error {
|
||||
h = adler32.New()
|
||||
case "crc32/ieee":
|
||||
h = crc32.NewIEEE()
|
||||
case "crc64/ecma":
|
||||
h = crc64.New(crc64.MakeTable(crc64.ECMA))
|
||||
case "sha256":
|
||||
h = sha256.New()
|
||||
case "xxhash32":
|
||||
h = xxHash32.New(0)
|
||||
case "xxhash64":
|
||||
@@ -94,6 +114,16 @@ func do(r io.Reader) error {
|
||||
fmt.Printf("0x%08X", h.Sum32())
|
||||
case hash.Hash64:
|
||||
fmt.Printf("0x%016X", h.Sum64())
|
||||
case hash.Hash:
|
||||
b := h.Sum(nil)
|
||||
for i, x := range b {
|
||||
if i == 0 {
|
||||
fmt.Printf("0x")
|
||||
} else if (i & 7) == 0 {
|
||||
fmt.Printf("_")
|
||||
}
|
||||
fmt.Printf("%02X", x)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("algorithm %q is not a Hash32 or Hash64", *algorithm)
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func doWriteDeflate(deflateCompressed []byte, uncompressed []byte, filename stri
|
||||
filename = filename[:len(filename)-3]
|
||||
}
|
||||
filename += ".deflate"
|
||||
if err := os.WriteFile(filename, deflateCompressed, 0666); err != nil {
|
||||
if err := os.WriteFile(filename, deflateCompressed, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("wrote %s\n", filename)
|
||||
@@ -167,7 +167,7 @@ func doWriteZlib(deflateCompressed []byte, uncompressed []byte, filename string)
|
||||
filename = filename[:len(filename)-3]
|
||||
}
|
||||
filename += ".zlib"
|
||||
if err := os.WriteFile(filename, asZlib, 0666); err != nil {
|
||||
if err := os.WriteFile(filename, asZlib, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("wrote %s\n", filename)
|
||||
|
||||
@@ -65,8 +65,11 @@
|
||||
#define WUFFS_CONFIG__MODULE__NETPBM
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__QOI
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__VP8
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__WEBP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
@@ -123,12 +126,18 @@ handle_image_decoder(wuffs_base__io_buffer src,
|
||||
case WUFFS_BASE__FOURCC__PNG:
|
||||
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__QOI:
|
||||
dec = wuffs_qoi__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;
|
||||
case WUFFS_BASE__FOURCC__WEBP:
|
||||
dec = wuffs_webp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
default:
|
||||
return unsupported_file_format;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ to use the wuffs_aux C++ API to decode an image and iterate over its pixels.
|
||||
#define WUFFS_CONFIG__MODULE__NETPBM
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__QOI
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
@@ -44,7 +44,7 @@ func main1() error {
|
||||
// the slicing-by-M algorithm. We use an M of 16.
|
||||
for i := 0; i < 256; i++ {
|
||||
crc := tables[0][i]
|
||||
for j := 1; j < 16; j++ {
|
||||
for j := 1; j < len(tables); j++ {
|
||||
crc = tables[0][crc&0xFF] ^ (crc >> 8)
|
||||
tables[j][i] = crc
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// print-crc32-x86-sse42-code.go prints the std/crc32 x86/SSE4.2 Wuffs code
|
||||
// based on some C code generated by https://github.com/corsix/fast-crc32/
|
||||
//
|
||||
// Usage: go run print-crc32-x86-sse42-code.go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
reXEqLoadu = regexp.MustCompile(`^__m128i x(\d+) = _mm_loadu_si128`)
|
||||
reKEqSetr = regexp.MustCompile(`^k = _mm_setr_epi32\(([^,]+), ([^,]+), ([^,]+), ([^\)]+)\);$`)
|
||||
reYEqClmul = regexp.MustCompile(`^y(\d+) = clmul_lo\(x(\d+), k\), x(\d+) = clmul_hi\(x(\d+), k\);$`)
|
||||
reYEqXorLoadu = regexp.MustCompile(`^y(\d+) = _mm_xor_si128\(y(\d+), _mm_loadu_si128`)
|
||||
reYEqXorYX = regexp.MustCompile(`^y(\d+) = _mm_xor_si128\(y(\d+), x(\d+)\), x(\d+) = _mm_xor_si128\(x(\d+), y(\d+)\);$`)
|
||||
)
|
||||
|
||||
fmt.Println("// BEGIN script/print-crc32-x86-sse42-code.go generated code.")
|
||||
for src := srcSSECRC32V8; src != ""; {
|
||||
i := strings.IndexByte(src, '\n')
|
||||
line := strings.TrimSpace(src[:i])
|
||||
src = src[i+1:]
|
||||
|
||||
if (line == "") || strings.HasPrefix(line, "/*") {
|
||||
continue
|
||||
|
||||
} else if s := reXEqLoadu.FindStringSubmatch(line); len(s) > 0 {
|
||||
n, _ := strconv.Atoi(s[1])
|
||||
fmt.Printf("x%d = util.make_m128i_slice128(a: args.x[0x%02X .. 0x%02X])\n", n, 16*(n), 16*(n+1))
|
||||
|
||||
} else if line == "__m128i k;" {
|
||||
continue
|
||||
|
||||
} else if s := reKEqSetr.FindStringSubmatch(line); len(s) > 0 {
|
||||
fmt.Printf("kk = util.make_m128i_multiple_u32(a00: %s, a01: %s, a02: %s, a03: %s)\n", s[1], s[2], s[3], s[4])
|
||||
|
||||
} else if line == "x0 = _mm_xor_si128(_mm_cvtsi32_si128(crc0), x0);" {
|
||||
fmt.Printf("x0 = x0._mm_xor_si128(b: util.make_m128i_single_u32(a: s))\n")
|
||||
|
||||
} else if line == "buf += 128;" {
|
||||
fmt.Printf("args.x = args.x[128 ..]\n")
|
||||
|
||||
} else if line == "len -= 128;" {
|
||||
continue
|
||||
|
||||
} else if line == "while (len >= 128) {" {
|
||||
fmt.Printf("while args.x.length() >= 128 {\n")
|
||||
|
||||
} else if line == "}" {
|
||||
fmt.Printf("} endwhile\n")
|
||||
|
||||
} else if s := reYEqClmul.FindStringSubmatch(line); len(s) > 0 {
|
||||
fmt.Printf("y%s = x%s._mm_clmulepi64_si128(b: kk, imm8: 0x00)\n", s[1], s[2])
|
||||
fmt.Printf("x%s = x%s._mm_clmulepi64_si128(b: kk, imm8: 0x11)\n", s[3], s[4])
|
||||
|
||||
} else if s := reYEqXorLoadu.FindStringSubmatch(line); len(s) > 0 {
|
||||
n, _ := strconv.Atoi(s[1])
|
||||
fmt.Printf("y%d = y%d._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x%02X .. 0x%02X]))\n", n, n, 16*(n), 16*(n+1))
|
||||
fmt.Printf("x%d = x%d._mm_xor_si128(b: y%d)\n", n, n, n)
|
||||
|
||||
} else if s := reYEqXorYX.FindStringSubmatch(line); len(s) > 0 {
|
||||
fmt.Printf("y%s = y%s._mm_xor_si128(b: x%s)\n", s[1], s[2], s[3])
|
||||
fmt.Printf("x%s = x%s._mm_xor_si128(b: y%s)\n", s[4], s[5], s[6])
|
||||
|
||||
} else if line == "crc0 = crc_u64(0, _mm_extract_epi64(x0, 0));" {
|
||||
fmt.Printf("kk = util.make_m128i_multiple_u32(a00: 0xF701_1641, a01: 0xB4E5_B025, a02: 0xDB71_0641, a03: 1)\n")
|
||||
fmt.Printf("s = util.make_m128i_single_u64(a: x0._mm_extract_epi64(imm8: 0)).\n")
|
||||
fmt.Printf(" _mm_clmulepi64_si128(b: kk, imm8: 0x00).\n")
|
||||
fmt.Printf(" _mm_clmulepi64_si128(b: kk, imm8: 0x10).\n")
|
||||
fmt.Printf(" _mm_extract_epi32(imm8: 2)\n")
|
||||
|
||||
// fmt.Printf("s = util.make_m128i_single_u64(a: (s as base.u64) ^ args.x.peek_u64le()).\n")
|
||||
} else if line == "crc0 = crc_u64(crc0, _mm_extract_epi64(x0, 1));" {
|
||||
fmt.Printf("kk = util.make_m128i_multiple_u32(a00: 0xF701_1641, a01: 0xB4E5_B025, a02: 0xDB71_0641, a03: 1)\n")
|
||||
fmt.Printf("s = util.make_m128i_single_u64(a: x0._mm_extract_epi64(imm8: 1) ^ (s as base.u64)).\n")
|
||||
fmt.Printf(" _mm_clmulepi64_si128(b: kk, imm8: 0x00).\n")
|
||||
fmt.Printf(" _mm_clmulepi64_si128(b: kk, imm8: 0x10).\n")
|
||||
fmt.Printf(" _mm_extract_epi32(imm8: 2)\n")
|
||||
|
||||
} else {
|
||||
fmt.Printf("// Could not process %q.\n", line)
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Println("// END script/print-crc32-x86-sse42-code.go generated code.")
|
||||
}
|
||||
|
||||
// This is the core (inside "if (len >= 128)") of the code produced by
|
||||
// generate.c in https://github.com/corsix/fast-crc32/ when parameterized by
|
||||
// "./generate -i sse -p crc32 -a v8".
|
||||
const srcSSECRC32V8 = `
|
||||
/* First vector chunk. */
|
||||
__m128i x0 = _mm_loadu_si128((const __m128i*)buf), y0;
|
||||
__m128i x1 = _mm_loadu_si128((const __m128i*)(buf + 16)), y1;
|
||||
__m128i x2 = _mm_loadu_si128((const __m128i*)(buf + 32)), y2;
|
||||
__m128i x3 = _mm_loadu_si128((const __m128i*)(buf + 48)), y3;
|
||||
__m128i x4 = _mm_loadu_si128((const __m128i*)(buf + 64)), y4;
|
||||
__m128i x5 = _mm_loadu_si128((const __m128i*)(buf + 80)), y5;
|
||||
__m128i x6 = _mm_loadu_si128((const __m128i*)(buf + 96)), y6;
|
||||
__m128i x7 = _mm_loadu_si128((const __m128i*)(buf + 112)), y7;
|
||||
__m128i k;
|
||||
k = _mm_setr_epi32(0x33fff533, 0, 0x910eeec1, 0);
|
||||
x0 = _mm_xor_si128(_mm_cvtsi32_si128(crc0), x0);
|
||||
buf += 128;
|
||||
len -= 128;
|
||||
/* Main loop. */
|
||||
while (len >= 128) {
|
||||
y0 = clmul_lo(x0, k), x0 = clmul_hi(x0, k);
|
||||
y1 = clmul_lo(x1, k), x1 = clmul_hi(x1, k);
|
||||
y2 = clmul_lo(x2, k), x2 = clmul_hi(x2, k);
|
||||
y3 = clmul_lo(x3, k), x3 = clmul_hi(x3, k);
|
||||
y4 = clmul_lo(x4, k), x4 = clmul_hi(x4, k);
|
||||
y5 = clmul_lo(x5, k), x5 = clmul_hi(x5, k);
|
||||
y6 = clmul_lo(x6, k), x6 = clmul_hi(x6, k);
|
||||
y7 = clmul_lo(x7, k), x7 = clmul_hi(x7, k);
|
||||
y0 = _mm_xor_si128(y0, _mm_loadu_si128((const __m128i*)buf)), x0 = _mm_xor_si128(x0, y0);
|
||||
y1 = _mm_xor_si128(y1, _mm_loadu_si128((const __m128i*)(buf + 16))), x1 = _mm_xor_si128(x1, y1);
|
||||
y2 = _mm_xor_si128(y2, _mm_loadu_si128((const __m128i*)(buf + 32))), x2 = _mm_xor_si128(x2, y2);
|
||||
y3 = _mm_xor_si128(y3, _mm_loadu_si128((const __m128i*)(buf + 48))), x3 = _mm_xor_si128(x3, y3);
|
||||
y4 = _mm_xor_si128(y4, _mm_loadu_si128((const __m128i*)(buf + 64))), x4 = _mm_xor_si128(x4, y4);
|
||||
y5 = _mm_xor_si128(y5, _mm_loadu_si128((const __m128i*)(buf + 80))), x5 = _mm_xor_si128(x5, y5);
|
||||
y6 = _mm_xor_si128(y6, _mm_loadu_si128((const __m128i*)(buf + 96))), x6 = _mm_xor_si128(x6, y6);
|
||||
y7 = _mm_xor_si128(y7, _mm_loadu_si128((const __m128i*)(buf + 112))), x7 = _mm_xor_si128(x7, y7);
|
||||
buf += 128;
|
||||
len -= 128;
|
||||
}
|
||||
/* Reduce x0 ... x7 to just x0. */
|
||||
k = _mm_setr_epi32(0xae689191, 0, 0xccaa009e, 0);
|
||||
y0 = clmul_lo(x0, k), x0 = clmul_hi(x0, k);
|
||||
y2 = clmul_lo(x2, k), x2 = clmul_hi(x2, k);
|
||||
y4 = clmul_lo(x4, k), x4 = clmul_hi(x4, k);
|
||||
y6 = clmul_lo(x6, k), x6 = clmul_hi(x6, k);
|
||||
y0 = _mm_xor_si128(y0, x1), x0 = _mm_xor_si128(x0, y0);
|
||||
y2 = _mm_xor_si128(y2, x3), x2 = _mm_xor_si128(x2, y2);
|
||||
y4 = _mm_xor_si128(y4, x5), x4 = _mm_xor_si128(x4, y4);
|
||||
y6 = _mm_xor_si128(y6, x7), x6 = _mm_xor_si128(x6, y6);
|
||||
k = _mm_setr_epi32(0xf1da05aa, 0, 0x81256527, 0);
|
||||
y0 = clmul_lo(x0, k), x0 = clmul_hi(x0, k);
|
||||
y4 = clmul_lo(x4, k), x4 = clmul_hi(x4, k);
|
||||
y0 = _mm_xor_si128(y0, x2), x0 = _mm_xor_si128(x0, y0);
|
||||
y4 = _mm_xor_si128(y4, x6), x4 = _mm_xor_si128(x4, y4);
|
||||
k = _mm_setr_epi32(0x8f352d95, 0, 0x1d9513d7, 0);
|
||||
y0 = clmul_lo(x0, k), x0 = clmul_hi(x0, k);
|
||||
y0 = _mm_xor_si128(y0, x4), x0 = _mm_xor_si128(x0, y0);
|
||||
/* Reduce 128 bits to 32 bits, and multiply by x^32. */
|
||||
crc0 = crc_u64(0, _mm_extract_epi64(x0, 0));
|
||||
crc0 = crc_u64(crc0, _mm_extract_epi64(x0, 1));
|
||||
`
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
package main
|
||||
|
||||
// This program is obsolete.
|
||||
//
|
||||
// print-crc32-x86-sse42-magic-numbers.go prints the std/crc32
|
||||
// IEEE_X86_SSE42_ETC magic number tables.
|
||||
//
|
||||
@@ -60,7 +62,7 @@ const px = "100000100110000010001110110110111"
|
||||
// P(x)' = 0x1_11011011_01110001_00000110_01000001
|
||||
const pxdash = "111011011011100010000011001000001"
|
||||
|
||||
var spaces = strings.Repeat(" ", 1024)
|
||||
var spaces = strings.Repeat(" ", 9999)
|
||||
|
||||
func debugf(format string, a ...interface{}) {
|
||||
if false { // Change false to true to show the long divisions.
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// print-crc64-magic-numbers.go prints the std/crc64 magic number tables.
|
||||
//
|
||||
// Usage: go run print-crc64-magic-numbers.go
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"hash/crc64"
|
||||
"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")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
flag.Parse()
|
||||
tables := [8]crc64.Table{}
|
||||
tables[0] = *crc64.MakeTable(crc64.ECMA)
|
||||
|
||||
// Use the same slicing-by-M algorithm as for std/crc32, with M = 8.
|
||||
for i := 0; i < 256; i++ {
|
||||
crc := tables[0][i]
|
||||
for j := 1; j < len(tables); j++ {
|
||||
crc = tables[0][crc&0xFF] ^ (crc >> 8)
|
||||
tables[j][i] = crc
|
||||
}
|
||||
}
|
||||
|
||||
for i, t := range tables {
|
||||
if *reverse {
|
||||
reverseTable(&t)
|
||||
}
|
||||
if i != 0 {
|
||||
fmt.Println("],[")
|
||||
}
|
||||
for j, x := range t {
|
||||
fmt.Printf("0x%016X,", x)
|
||||
if j&3 == 3 {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// reverseTable reverses the bits in the keys and values of a crc64.Table
|
||||
// (which is a [256]uint32).
|
||||
func reverseTable(t *crc64.Table) {
|
||||
revT := crc64.Table{}
|
||||
for i, v := range *t {
|
||||
revI := reverse8[i]
|
||||
revV := uint64(0)
|
||||
for j := 0; j < 64; j++ {
|
||||
if (v & (uint64(1) << j)) != 0 {
|
||||
revV |= uint64(1) << (63 - 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,118 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// print-crc64-x86-sse42-magic-numbers.go prints the std/crc64
|
||||
// ECMA_X86_SSE42_ETC magic number tables.
|
||||
//
|
||||
// It is like print-crc32-x86-sse42-magic-numbers.go but for CRC-64/ECMA, not
|
||||
// CRC-32/IEEE.
|
||||
//
|
||||
// Usage: go run print-crc64-x86-sse42-magic-numbers.go
|
||||
//
|
||||
// Output:
|
||||
// Px' = 0x92D8_AF2B_AF0E_1E85
|
||||
// k1' = 0x6AE3_EFBB_9DD4_41F3
|
||||
// k2' = 0x081F_6054_A784_2DF4
|
||||
// k3' = 0xE05D_D497_CA39_3AE4
|
||||
// k4' = 0xDABE_95AF_C787_5F40
|
||||
// μ' = 0x9C3E_466C_1729_63D5
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// px is the P(x) polynomial, a bit-reversal (with explicit high bit) of the
|
||||
// CRC-64/ECMA polynomial sometimes written as 0xC96C_5795_D787_0F42.
|
||||
// P(x) = 0x1_42F0_E1EB_A9EA_3693
|
||||
// P(x) = 0b1_01000010_11110000_11100001_11101011_10101001_11101010_00110110_10010011
|
||||
const px = "10100001011110000111000011110101110101001111010100011011010010011"
|
||||
|
||||
var spaces = strings.Repeat(" ", 9999)
|
||||
|
||||
func debugf(format string, a ...interface{}) {
|
||||
if false { // Change false to true to show the long divisions.
|
||||
fmt.Printf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
func show(name string, value string) {
|
||||
v := uint64(0)
|
||||
if strings.Contains(name, "'") {
|
||||
for i := len(value) - 1; i >= 0; i-- {
|
||||
v = (v << 1) | uint64(value[i]&1)
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < len(value); i++ {
|
||||
v = (v << 1) | uint64(value[i]&1)
|
||||
}
|
||||
}
|
||||
fmt.Printf("%s = 0x%04X_%04X_%04X_%04X\n", name,
|
||||
0xFFFF&(v>>48), 0xFFFF&(v>>32), 0xFFFF&(v>>16), 0xFFFF&(v>>0))
|
||||
}
|
||||
|
||||
func calcKn(name string, power int) {
|
||||
numerator := "1" + strings.Repeat("0", power)
|
||||
b := []byte(numerator)
|
||||
i := 0
|
||||
debugf(" %s\n", numerator)
|
||||
for i+len(px) < len(numerator) {
|
||||
for j := 0; j < len(px); j++ {
|
||||
b[i+j] ^= 1 & px[j]
|
||||
}
|
||||
debugf(" %s%s\n", spaces[:i], px)
|
||||
for ; (i < len(b)) && (b[i] == '0'); i++ {
|
||||
b[i] = ' '
|
||||
}
|
||||
debugf(" %s\n", b)
|
||||
}
|
||||
show(name, string(b[len(b)-len(px):]))
|
||||
}
|
||||
|
||||
func calcMu(name string) {
|
||||
numerator := "1" + strings.Repeat("0", 128)
|
||||
mu := make([]byte, 129)
|
||||
b := []byte(numerator)
|
||||
i := 0
|
||||
debugf(" %s\n", numerator)
|
||||
for i+len(px) < len(numerator) {
|
||||
for j := 0; j < len(px); j++ {
|
||||
b[i+j] ^= 1 & px[j]
|
||||
}
|
||||
debugf(" %s%s\n", spaces[:i], px)
|
||||
b[i] = ':'
|
||||
mu[i] = '1'
|
||||
i++
|
||||
for ; (i < len(b)) && (b[i] == '0'); i++ {
|
||||
b[i] = ' '
|
||||
mu[i] = '0'
|
||||
}
|
||||
debugf(" %s\n", b)
|
||||
}
|
||||
show(name, string(mu[:65]))
|
||||
}
|
||||
|
||||
func main() {
|
||||
calcKn("fold1a'", 128+64)
|
||||
calcKn("fold1b'", 128)
|
||||
calcKn("fold2a'", 256+64)
|
||||
calcKn("fold2b'", 256)
|
||||
calcKn("fold4a'", 512+64)
|
||||
calcKn("fold4b'", 512)
|
||||
calcKn("fold8a'", 1024+64)
|
||||
calcKn("fold8b'", 1024)
|
||||
calcMu("μ' ")
|
||||
show("Px'", px)
|
||||
}
|
||||
@@ -53,8 +53,11 @@ print-image-metadata prints images' metadata.
|
||||
#define WUFFS_CONFIG__MODULE__NETPBM
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__QOI
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__VP8
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__WEBP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
@@ -385,12 +388,18 @@ redirect:
|
||||
case WUFFS_BASE__FOURCC__PNG:
|
||||
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__QOI:
|
||||
dec = wuffs_qoi__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;
|
||||
case WUFFS_BASE__FOURCC__WEBP:
|
||||
dec = wuffs_webp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
default:
|
||||
return "main: unsupported file format";
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@
|
||||
//
|
||||
// Pass -a (--all-tokens) to print all tokens, including whitespace.
|
||||
//
|
||||
// Pass -i=cbor (--input-format=cbor) to parse CBOR instead of JSON.
|
||||
//
|
||||
// Pass -q (--quirks) to enable all of a pre-defined set of various parser
|
||||
// quirks. For example, allowing JSON comments or JSON "inf" numbers.
|
||||
//
|
||||
// If the input or output is larger than the program's buffers (64 MiB and
|
||||
// 131072 tokens by default), there may be multiple valid tokenizations of any
|
||||
// given input. For example, if a source string "abcde" straddles an I/O
|
||||
@@ -418,7 +423,7 @@ compute_exit_code(const char* status_msg) {
|
||||
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);
|
||||
n = strlen(status_msg);
|
||||
}
|
||||
fprintf(stderr, "%s\n", status_msg);
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2023 The Wuffs Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
# option. This file may not be copied, modified, or distributed
|
||||
# except according to those terms.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
# ----------------
|
||||
|
||||
# This script prints the CRC-32 checksum of the decompressed data of every file
|
||||
# given as a command line argument: if a file then itself, if a directory then
|
||||
# the files under it. It skips any non-compressed file found (non-compressed
|
||||
# meaning not decodable by Wuffs' standard library).
|
||||
#
|
||||
# It is not perfect. It can have false positives and false negatives.
|
||||
# Nonetheless, running it regularly (compiled against the in-development
|
||||
# release/c/wuffs-unsupported-snapshot.c) can help detect regressions.
|
||||
|
||||
if [ ! -e wuffs-root-directory.txt ]; then
|
||||
echo "$0 should be run from the Wuffs root directory."
|
||||
exit 1
|
||||
elif [ ! -e gen/bin/example-mzcat ]; then
|
||||
echo "Run \"./build-example.sh example/mzcat\" first."
|
||||
exit 1
|
||||
elif [ ! -e gen/bin/example-crc32 ]; then
|
||||
echo "Run \"./build-example.sh example/crc32\" first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sources=$@
|
||||
if [ $# -eq 0 ]; then
|
||||
sources=test/data
|
||||
fi
|
||||
|
||||
# ----
|
||||
|
||||
handle() {
|
||||
local c=$(gen/bin/example-mzcat --output-crc32-digest <$1 2>/dev/null)
|
||||
if [ "$c" != "BAD 00000000" ]; then
|
||||
echo $c $1
|
||||
fi
|
||||
}
|
||||
|
||||
# ----
|
||||
|
||||
echo "# Generated by script/print-mzcat-checksums.sh"
|
||||
for f in $sources; do
|
||||
if [ -f $f ]; then
|
||||
handle $f
|
||||
elif [ -d $f ]; then
|
||||
for g in `find $f -type f | LANG=C sort`; do
|
||||
handle $g
|
||||
done
|
||||
else
|
||||
echo "Could not open $f"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -47,8 +47,8 @@ fi
|
||||
# ----
|
||||
|
||||
handle() {
|
||||
local c=$(gen/bin/example-convert-to-nia <$1 2>/dev/null | gen/bin/example-crc32)
|
||||
if [ "$c" != "00000000" ]; then
|
||||
local c=$(gen/bin/example-convert-to-nia --output-crc32-digest <$1 2>/dev/null)
|
||||
if [ "$c" != "BAD 00000000" ]; then
|
||||
echo $c $1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ compute_exit_code(const char* status_msg) {
|
||||
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);
|
||||
n = strlen(status_msg);
|
||||
}
|
||||
fprintf(stderr, "%s\n", status_msg);
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
|
||||
@@ -96,7 +96,7 @@ func main1() error {
|
||||
data := ([]byte)(nil)
|
||||
data = append(data, src[:pos]...)
|
||||
data = append(data, "\xFF\xD9"...) // Append an EOI marker.
|
||||
if err := os.WriteFile(outName, data, 0666); err != nil {
|
||||
if err := os.WriteFile(outName, data, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Wrote %s (cut at 0x%08X = %6d bytes).\n", outName, pos, pos)
|
||||
|
||||
@@ -71,7 +71,7 @@ pri func hasher.up!(x: roslice base.u8),
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ pri func hasher.up_arm_neon!(x: roslice base.u8),
|
||||
s1 ~mod+= args.x[0] as base.u32
|
||||
s2 ~mod+= s1
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
|
||||
@@ -186,6 +186,6 @@ pri func hasher.up_arm_neon!(x: roslice base.u8),
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
}
|
||||
@@ -172,6 +172,6 @@ pri func hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
}
|
||||
+53
-54
@@ -15,8 +15,7 @@ pub status "#unsupported BMP file"
|
||||
|
||||
pri status "@internal note: short read"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pri const COMPRESSION_NONE : base.u32 = 0
|
||||
pri const COMPRESSION_RLE8 : base.u32 = 1
|
||||
@@ -96,7 +95,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -104,6 +103,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
var width : base.u32
|
||||
var height : base.u32
|
||||
var planes : base.u32
|
||||
var n : base.u32
|
||||
var dst_pixfmt : base.u32
|
||||
var byte_width : base.u32
|
||||
|
||||
@@ -276,7 +276,8 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
}
|
||||
} else if this.bitmap_info_len >= 40 {
|
||||
// Skip the rest of the BITMAPINFOHEADER.
|
||||
args.src.skip_u32?(n: this.bitmap_info_len - 40)
|
||||
n = this.bitmap_info_len - 40
|
||||
args.src.skip_u32?(n: n)
|
||||
} else {
|
||||
return "#unsupported BMP file"
|
||||
}
|
||||
@@ -384,6 +385,11 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
(this.channel_num_bits[2] > 8) or
|
||||
(this.channel_num_bits[3] > 8) {
|
||||
dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
} else if ((this.src_pixfmt == base.PIXEL_FORMAT__INDEXED__BGRA_BINARY) or
|
||||
(this.src_pixfmt == base.PIXEL_FORMAT__BGR) or
|
||||
(this.src_pixfmt == base.PIXEL_FORMAT__BGRX)) or
|
||||
((this.src_pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE) and (this.channel_masks[3] == 0)) {
|
||||
dst_pixfmt = base.PIXEL_FORMAT__BGRX
|
||||
}
|
||||
|
||||
args.dst.set!(
|
||||
@@ -407,7 +413,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -453,7 +459,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -506,7 +512,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
args.src.skip_u32?(n: this.pending_pad)
|
||||
this.pending_pad = 0
|
||||
@@ -547,7 +553,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
}
|
||||
this.pending_pad -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while.inner true {
|
||||
if this.dst_x == this.width {
|
||||
@@ -587,7 +593,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
}
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
@@ -595,7 +601,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
@@ -606,8 +612,8 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -668,11 +674,10 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
dst = this.util.empty_slice_u8()
|
||||
}
|
||||
|
||||
while.goto_suspend true {{
|
||||
while.inner true {
|
||||
if rle_state == RLE_STATE_NEUTRAL {
|
||||
if args.src.length() < 1 {
|
||||
break.goto_suspend
|
||||
break.inner
|
||||
}
|
||||
code = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -686,7 +691,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
|
||||
} else if rle_state == RLE_STATE_RUN {
|
||||
if args.src.length() < 1 {
|
||||
break.goto_suspend
|
||||
break.inner
|
||||
}
|
||||
code = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -696,7 +701,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
assert p0 < 255 via "a < b: a < c; c <= b"(c: this.rle_length)
|
||||
this.scratch[p0] = code
|
||||
p0 += 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
indexes[0] = (code >> 4) as base.u8
|
||||
indexes[1] = code & 0x0F
|
||||
@@ -706,7 +711,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
this.scratch[p0 + 0] = indexes[0]
|
||||
this.scratch[p0 + 1] = indexes[1]
|
||||
p0 += 2
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
@@ -718,7 +723,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
|
||||
} else if rle_state == RLE_STATE_ESCAPE {
|
||||
if args.src.length() < 1 {
|
||||
break.goto_suspend
|
||||
break.inner
|
||||
}
|
||||
code = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -770,7 +775,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
this.scratch[p0 + 0x03] = (0x0F & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 255) + 0x04
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
p0 = p0.min(no_more_than: this.rle_length)
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
@@ -781,11 +786,11 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
}
|
||||
|
||||
if this.rle_length > 0 {
|
||||
break.goto_suspend
|
||||
break.inner
|
||||
}
|
||||
if this.rle_padded {
|
||||
if args.src.length() < 1 {
|
||||
break.goto_suspend
|
||||
break.inner
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.rle_padded = false
|
||||
@@ -795,7 +800,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
|
||||
} else if rle_state == RLE_STATE_DELTA_X {
|
||||
if args.src.length() < 1 {
|
||||
break.goto_suspend
|
||||
break.inner
|
||||
}
|
||||
this.rle_delta_x = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -804,7 +809,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
|
||||
} // else (rle_state == RLE_STATE_DELTA_Y).
|
||||
if args.src.length() < 1 {
|
||||
break.goto_suspend
|
||||
break.inner
|
||||
}
|
||||
code = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -845,18 +850,16 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
dst_palette: dst_palette,
|
||||
num_pixels: 0xFFFF_FFFF_FFFF_FFFF)
|
||||
code -= 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
rle_state = RLE_STATE_NEUTRAL
|
||||
continue.middle
|
||||
|
||||
} endwhile.inner
|
||||
}} endwhile.goto_suspend
|
||||
}.inner
|
||||
this.rle_state = rle_state
|
||||
return "@internal note: short read"
|
||||
} endwhile.middle
|
||||
} endwhile.outer
|
||||
}.middle
|
||||
}.outer
|
||||
|
||||
while this.dst_y < this.height {
|
||||
row = tab.row_u32(y: this.dst_y)
|
||||
@@ -868,7 +871,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
|
||||
dst_palette: dst_palette,
|
||||
num_pixels: 0xFFFF_FFFF_FFFF_FFFF)
|
||||
this.dst_y ~mod+= this.dst_y_inc
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -912,7 +915,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
||||
}
|
||||
this.pending_pad -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while.inner true {
|
||||
if this.dst_x == this.width {
|
||||
@@ -966,17 +969,17 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
||||
{
|
||||
c |= c ~mod<< num_bits
|
||||
num_bits *= 2
|
||||
} endwhile
|
||||
}
|
||||
c >>= num_bits - 16
|
||||
this.scratch[(8 * p0) + (2 * channel) + 0] = (0xFF & (c >> 0)) as base.u8
|
||||
this.scratch[(8 * p0) + (2 * channel) + 1] = (0xFF & (c >> 8)) as base.u8
|
||||
}
|
||||
|
||||
channel += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
p0 += 1
|
||||
} endwhile
|
||||
}
|
||||
// -------- END convert to PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE.
|
||||
|
||||
dst = tab.row_u32(y: this.dst_y)
|
||||
@@ -996,8 +999,8 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -1060,12 +1063,12 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
args.src.skip_u32_fast!(actual: 256, worst_case: 256)
|
||||
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 64))
|
||||
chunk_count -= 64
|
||||
} endwhile
|
||||
}
|
||||
while (chunk_count >= 8) and (args.src.length() >= 32) {
|
||||
args.src.skip_u32_fast!(actual: 32, worst_case: 32)
|
||||
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 8))
|
||||
chunk_count -= 8
|
||||
} endwhile
|
||||
}
|
||||
while chunk_count > 0 {
|
||||
if args.src.length() < 4 {
|
||||
return "@internal note: short read"
|
||||
@@ -1073,7 +1076,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 1))
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
continue.loop
|
||||
}
|
||||
dst = dst[i ..]
|
||||
@@ -1121,7 +1124,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
this.scratch[p0 + 0x1F] = (0x01 & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 511) + 0x20
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else if this.bits_per_pixel == 2 {
|
||||
// Calculate the remaining number of 32-bit chunks. At 2 bits per
|
||||
@@ -1149,7 +1152,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
this.scratch[p0 + 0x0F] = (0x03 & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 511) + 0x10
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
// Calculate the remaining number of 32-bit chunks. At 4 bits per
|
||||
@@ -1169,7 +1172,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
this.scratch[p0 + 0x07] = (0x0F & (chunk_bits >> 0x00)) as base.u8
|
||||
p0 = (p0 & 511) + 0x08
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
p0 = p0.min(no_more_than: this.width ~sat- this.dst_x)
|
||||
@@ -1181,7 +1184,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile.loop
|
||||
}.loop
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -1237,7 +1240,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
@@ -1257,10 +1260,6 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
this.io_redirect_fourcc = 1
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -1279,7 +1278,7 @@ pri func decoder.read_palette?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.src_palette[(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
while (i < 256) and (this.padding >= 4) {
|
||||
this.padding -= 4
|
||||
@@ -1290,7 +1289,7 @@ pri func decoder.read_palette?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.src_palette[(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
while i < 256 {
|
||||
@@ -1299,7 +1298,7 @@ pri func decoder.read_palette?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = 0x00
|
||||
this.src_palette[(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.process_masks?() {
|
||||
@@ -1316,7 +1315,7 @@ pri func decoder.process_masks?() {
|
||||
{
|
||||
n ~mod+= 1
|
||||
mask >>= 1
|
||||
} endwhile
|
||||
}
|
||||
this.channel_shifts[i] = (n & 31) as base.u8
|
||||
|
||||
n = 0
|
||||
@@ -1325,7 +1324,7 @@ pri func decoder.process_masks?() {
|
||||
{
|
||||
n ~mod+= 1
|
||||
mask >>= 1
|
||||
} endwhile
|
||||
}
|
||||
if (mask <> 0) or (n > 32) {
|
||||
return "#bad header"
|
||||
}
|
||||
@@ -1335,5 +1334,5 @@ pri func decoder.process_masks?() {
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ pub status "#unsupported block randomization"
|
||||
|
||||
pri status "#internal error: inconsistent Huffman decoder state"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pri const CLAMP_TO_5 : roarray[8] base.u8[..= 5] = [0, 1, 2, 3, 4, 5, 5, 5]
|
||||
|
||||
@@ -107,6 +107,9 @@ pub struct decoder? implements base.io_transformer(
|
||||
)
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if (args.key == base.QUIRK_IGNORE_CHECKSUM) and this.ignore_checksum {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -118,8 +121,8 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.util.make_optional_u63(has_value: true, value: 0)
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
@@ -137,34 +140,34 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var c : base.u8
|
||||
var c8 : 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 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x42 {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x5A {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x5A {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x68 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x68 {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if (c < '1') or ('9' < c) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 < '1') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.max_incl_block_size = ((c - '0') as base.u32) * 100000
|
||||
this.max_incl_block_size = ((c8 - '0') as base.u32) * 100000
|
||||
|
||||
while true {
|
||||
// Read the 48-bit tag.
|
||||
@@ -172,8 +175,8 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
i = 0
|
||||
while i < 48 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -182,7 +185,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if tag == 0x1772_4538_5090 {
|
||||
break
|
||||
@@ -206,7 +209,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
this.decode_huffman_slow?(src: args.src)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.invert_bwt!()
|
||||
|
||||
@@ -225,7 +228,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
break
|
||||
}
|
||||
this.flush_slow?(dst: args.dst)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.block_checksum_have ^= 0xFFFF_FFFF
|
||||
if (not this.ignore_checksum) and (this.block_checksum_have <> this.block_checksum_want) {
|
||||
@@ -234,15 +237,15 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
this.final_checksum_have = this.block_checksum_have ^ (
|
||||
(this.final_checksum_have >> 31) |
|
||||
(this.final_checksum_have ~mod<< 1))
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the 32-bit final checksum.
|
||||
final_checksum_want = 0
|
||||
i = 0
|
||||
while i < 32 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -251,14 +254,14 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (not this.ignore_checksum) and (this.final_checksum_have <> final_checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
var selector : base.u32
|
||||
@@ -271,8 +274,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
i = 0
|
||||
while i < 32 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -281,12 +284,12 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the "block randomized" bit.
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -301,8 +304,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
i = 0
|
||||
while i < 24 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -311,21 +314,21 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Reset the presence bitmap.
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.presence[i] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the 16-bit high-level presence bitmap.
|
||||
i = 0
|
||||
while i < 256 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -335,7 +338,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 16
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the 16-bit low-level presence bitmaps.
|
||||
this.scratch = 0
|
||||
@@ -347,8 +350,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
}
|
||||
while true {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -360,8 +363,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
if (i & 15) == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
if (this.scratch < 1) or (256 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
@@ -372,8 +375,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
i = 0
|
||||
while i < 3 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -382,7 +385,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (this.scratch < 2) or (6 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
@@ -393,8 +396,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
i = 0
|
||||
while i < 15 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -403,7 +406,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (this.scratch < 1) or (18001 < this.scratch) {
|
||||
return "#bad block header"
|
||||
}
|
||||
@@ -415,7 +418,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
assert i < 6 via "a < b: a < c; c <= b"(c: this.num_huffman_codes)
|
||||
this.mtft[i] = i as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read each section's Huffman code selector, applying the MTFT.
|
||||
i = 0
|
||||
@@ -428,8 +431,8 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
inv i < 18001,
|
||||
{
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -444,7 +447,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
if selector >= this.num_huffman_codes {
|
||||
return "#bad block header"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Move to front.
|
||||
if selector == 0 {
|
||||
@@ -459,7 +462,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the Huffman codes.
|
||||
i = 0
|
||||
@@ -472,7 +475,7 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
}
|
||||
this.build_huffman_table!(which: i)
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Initialize the MTFT state.
|
||||
i = 0
|
||||
@@ -483,18 +486,18 @@ pri func decoder.prepare_block?(src: base.io_reader) {
|
||||
j ~mod+= 1
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Initialize the letter counts.
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.letter_counts[i] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var i : base.u32
|
||||
var code_length : base.u32
|
||||
|
||||
@@ -504,8 +507,8 @@ pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
i = 0
|
||||
while i < 5 {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -514,7 +517,7 @@ pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Read the code lengths.
|
||||
i = 0
|
||||
@@ -528,8 +531,8 @@ pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -542,8 +545,8 @@ pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
this.n_bits -= 1
|
||||
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -554,12 +557,12 @@ pri func decoder.read_code_lengths?(src: base.io_reader) {
|
||||
}
|
||||
this.bits ~mod<<= 1
|
||||
this.n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.code_lengths_bitmask |= (1 as base.u32) << (code_length & 31)
|
||||
this.bwt[i] = code_length
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// build_huffman_tree builds a canonical Huffman tree given the symbols' code
|
||||
@@ -666,7 +669,7 @@ pri func decoder.build_huffman_tree!(which: base.u32[..= 5]) base.status {
|
||||
this.huffman_trees[args.which][num_branch_nodes][1] = 0
|
||||
num_branch_nodes += 1
|
||||
stack_height += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
node_index = stack_values[stack_height - 1]
|
||||
if symbol_index < 2 {
|
||||
@@ -691,13 +694,13 @@ pri func decoder.build_huffman_tree!(which: base.u32[..= 5]) base.status {
|
||||
break
|
||||
}
|
||||
stack_height -= 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
symbol_index += 1
|
||||
} endwhile
|
||||
}
|
||||
code_length += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if stack_height <> 0 {
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
@@ -721,10 +724,10 @@ pri func decoder.build_huffman_table!(which: base.u32[..= 5]) {
|
||||
child = this.huffman_trees[args.which][child][bits >> 31]
|
||||
bits ~mod<<= 1
|
||||
n_bits += 1
|
||||
} endwhile
|
||||
}
|
||||
this.huffman_tables[args.which][i] = (child | (n_bits << 12)) as base.u16
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// invert_bwt performs "two passes over the data, and one pass over the
|
||||
@@ -745,7 +748,7 @@ pri func decoder.invert_bwt!() {
|
||||
sum ~mod+= this.letter_counts[i]
|
||||
this.letter_counts[i] = old_sum
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Second data pass, but per the README.md file, calculate the U column
|
||||
// instead of the BWT technical report's T column.
|
||||
@@ -756,7 +759,7 @@ pri func decoder.invert_bwt!() {
|
||||
this.bwt[this.letter_counts[letter] & 1_048575] |= i << 12
|
||||
this.letter_counts[letter] ~mod+= 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// The table below was created by script/print-crc32-magic-numbers.go with the
|
||||
|
||||
@@ -56,12 +56,12 @@ pri func decoder.flush_fast!(dst: base.io_writer) {
|
||||
args.dst.write_u8_fast!(a: flush_prev)
|
||||
}
|
||||
flush_repeat_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
flush_repeat_count = 0
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.flush_pointer = flush_pointer
|
||||
this.flush_repeat_count = flush_repeat_count
|
||||
|
||||
@@ -54,12 +54,12 @@ pri func decoder.flush_slow?(dst: base.io_writer) {
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8?(a: flush_prev)
|
||||
flush_repeat_count -= 1
|
||||
} endwhile
|
||||
}
|
||||
flush_repeat_count = 0
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.flush_pointer = flush_pointer
|
||||
this.flush_repeat_count = flush_repeat_count
|
||||
|
||||
@@ -62,7 +62,7 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
n_bits -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if child < 0x300 { // mNN symbol.
|
||||
// Move to front.
|
||||
@@ -108,8 +108,8 @@ pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
|
||||
assert i < 900000 via "a < b: a < c; c <= b"(c: j)
|
||||
this.bwt[i] = mtft0
|
||||
i += 1
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
}
|
||||
}.outer
|
||||
|
||||
this.bits = bits
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_huffman_slow?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var node_index : base.u32[..= 256]
|
||||
|
||||
var child : base.u16
|
||||
@@ -36,8 +36,8 @@ pri func decoder.decode_huffman_slow?(src: base.io_reader) {
|
||||
node_index = 0
|
||||
while true {
|
||||
if this.n_bits <= 0 {
|
||||
c = args.src.read_u8?()
|
||||
this.bits = (c as base.u32) << 24
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32) << 24
|
||||
this.n_bits = 8
|
||||
assert this.n_bits > 0
|
||||
}
|
||||
@@ -94,8 +94,8 @@ pri func decoder.decode_huffman_slow?(src: base.io_reader) {
|
||||
assert i < 900000 via "a < b: a < c; c <= b"(c: j)
|
||||
this.bwt[i] = mtft0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
}
|
||||
}.outer
|
||||
}
|
||||
+16
-24
@@ -16,10 +16,6 @@ pri status "#internal error: inconsistent token length"
|
||||
|
||||
// --------
|
||||
|
||||
// DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE is the largest
|
||||
// history_retain_length (for compact_retaining) that a decoder will request.
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
// DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE is the largest workbuf length that a
|
||||
// decoder will request.
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
@@ -121,10 +117,6 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.empty_range_ii_u64()
|
||||
}
|
||||
@@ -141,7 +133,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
var vminor : base.u32[..= 0x1FF_FFFF]
|
||||
var vminor_alt : base.u32[..= 0x1FF_FFFF]
|
||||
var continued : base.u32[..= 1]
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var c_major : base.u8[..= 0x07]
|
||||
var c_minor : base.u8[..= 0x1F]
|
||||
var tagged : base.bool
|
||||
@@ -168,10 +160,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
yield? base."$short read"
|
||||
continue.outer
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
c8 = args.src.peek_u8()
|
||||
|
||||
if (indefinite_string_major_type <> 0) and (indefinite_string_major_type <> (c >> 5)) {
|
||||
if c <> 0xFF {
|
||||
if (indefinite_string_major_type <> 0) and (indefinite_string_major_type <> (c8 >> 5)) {
|
||||
if c8 <> 0xFF {
|
||||
return "#bad input"
|
||||
}
|
||||
vminor = (base.TOKEN__VBC__STRING << 21) |
|
||||
@@ -192,8 +184,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
c_major = (c >> 5) as base.u8
|
||||
c_minor = c & 0x1F
|
||||
c_major = (c8 >> 5) as base.u8
|
||||
c_minor = c8 & 0x1F
|
||||
if c_minor < 0x18 {
|
||||
string_length = c_minor as base.u64
|
||||
} else {
|
||||
@@ -238,7 +230,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
return "#internal error: inconsistent I/O"
|
||||
}} endwhile.goto_have_string_length
|
||||
}}.goto_have_string_length
|
||||
}
|
||||
|
||||
if c_major == 0 {
|
||||
@@ -370,7 +362,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
} endwhile
|
||||
}
|
||||
// -------- END Major type 2: a byte string.
|
||||
|
||||
} else if c_major == 3 {
|
||||
@@ -455,7 +447,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
} endwhile
|
||||
}
|
||||
// -------- END Major type 3: a text string.
|
||||
|
||||
} else if c_major == 4 {
|
||||
@@ -467,7 +459,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
while (token_length > 0) and (args.src.can_undo_byte()) {
|
||||
args.src.undo_byte!()
|
||||
token_length -= 1
|
||||
} endwhile
|
||||
}
|
||||
return "#unsupported recursion depth"
|
||||
}
|
||||
|
||||
@@ -534,7 +526,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
while (token_length > 0) and (args.src.can_undo_byte()) {
|
||||
args.src.undo_byte!()
|
||||
token_length -= 1
|
||||
} endwhile
|
||||
}
|
||||
return "#unsupported recursion depth"
|
||||
}
|
||||
|
||||
@@ -721,14 +713,14 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
// -------- END Major type 7: miscellaneous.
|
||||
}
|
||||
break.goto_fail
|
||||
}} endwhile.goto_fail
|
||||
}}.goto_fail
|
||||
|
||||
if args.src.can_undo_byte() {
|
||||
args.src.undo_byte!()
|
||||
return "#bad input"
|
||||
}
|
||||
return "#internal error: inconsistent I/O"
|
||||
}} endwhile.goto_parsed_a_leaf_value
|
||||
}}.goto_parsed_a_leaf_value
|
||||
|
||||
// We've just parsed a leaf (non-container) value, or the (explicit or
|
||||
// implicit) close of a container (array or object).
|
||||
@@ -761,7 +753,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
{
|
||||
yield? base."$short write"
|
||||
continue
|
||||
} endwhile
|
||||
}
|
||||
depth -= 1
|
||||
|
||||
// Fill in FROM_ETC.
|
||||
@@ -795,11 +787,11 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
value_minor: vminor_alt,
|
||||
continued: 0,
|
||||
length: 0)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// We've parsed the top-level value and we're therefore done overall.
|
||||
break.outer
|
||||
} endwhile.outer
|
||||
}.outer
|
||||
|
||||
this.end_of_data = true
|
||||
}
|
||||
@@ -28,7 +28,6 @@ pub func ieee_hasher.update!(x: roslice base.u8) {
|
||||
if this.state == 0 {
|
||||
choose up = [
|
||||
up_arm_crc32,
|
||||
up_x86_avx2,
|
||||
up_x86_sse42]
|
||||
}
|
||||
this.up!(x: args.x)
|
||||
|
||||
@@ -22,7 +22,7 @@ pri func ieee_hasher.up_arm_crc32!(x: roslice base.u8),
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = s.crc32b(b: args.x[0])
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
iterate (p = args.x)(length: 8, advance: 8, unroll: 16) {
|
||||
s = s.crc32d(b: p.peek_u64le())
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
// Copyright 2021 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// See "SIMD Implementations" in README.md for a link to Gopal et al. "Fast CRC
|
||||
// Computation for Generic Polynomials Using PCLMULQDQ Instruction".
|
||||
|
||||
// up_x86_avx2 is exactly the same as up_x86_sse42 except for the "choose
|
||||
// cpu_arch >= x86_avx2". With AVX, PCLMULQDQ has a three-operand form, not
|
||||
// just a two-operand form: https://www.felixcloutier.com/x86/pclmulqdq
|
||||
pri func ieee_hasher.up_x86_avx2!(x: roslice base.u8),
|
||||
choose cpu_arch >= x86_avx2,
|
||||
{
|
||||
var s : base.u32
|
||||
var p : roslice base.u8
|
||||
|
||||
var util : base.x86_sse42_utility
|
||||
var k : base.x86_m128i
|
||||
var x0 : base.x86_m128i
|
||||
var x1 : base.x86_m128i
|
||||
var x2 : base.x86_m128i
|
||||
var x3 : base.x86_m128i
|
||||
var y0 : base.x86_m128i
|
||||
var y1 : base.x86_m128i
|
||||
var y2 : base.x86_m128i
|
||||
var y3 : base.x86_m128i
|
||||
|
||||
var tail_index : base.u64
|
||||
|
||||
s = 0xFFFF_FFFF ^ this.state
|
||||
|
||||
// Align to a 16-byte boundary.
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
|
||||
// For short inputs, just do a simple loop.
|
||||
if args.x.length() < 64 {
|
||||
iterate (p = args.x)(length: 1, advance: 1, unroll: 1) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
return nothing
|
||||
}
|
||||
|
||||
// Load 128×4 = 512 bits from the first 64-byte chunk.
|
||||
x0 = util.make_m128i_slice128(a: args.x[0x00 .. 0x10])
|
||||
x1 = util.make_m128i_slice128(a: args.x[0x10 .. 0x20])
|
||||
x2 = util.make_m128i_slice128(a: args.x[0x20 .. 0x30])
|
||||
x3 = util.make_m128i_slice128(a: args.x[0x30 .. 0x40])
|
||||
|
||||
// Combine with the initial state.
|
||||
x0 = x0._mm_xor_si128(b: util.make_m128i_single_u32(a: s))
|
||||
|
||||
// Process the remaining 64-byte chunks.
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K1K2[.. 16])
|
||||
iterate (p = args.x[64 ..])(length: 64, advance: 64, unroll: 1) {
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y2 = x2._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y3 = x3._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x2 = x2._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x3 = x3._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
|
||||
x0 = x0._mm_xor_si128(b: y0)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x00 .. 0x10]))
|
||||
x1 = x1._mm_xor_si128(b: y1)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x10 .. 0x20]))
|
||||
x2 = x2._mm_xor_si128(b: y2)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x20 .. 0x30]))
|
||||
x3 = x3._mm_xor_si128(b: y3)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x30 .. 0x40]))
|
||||
}
|
||||
|
||||
// Reduce 128×4 = 512 bits to 128 bits.
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K3K4[.. 16])
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x2)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x3)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
|
||||
// Reduce 128 bits to 64 bits.
|
||||
x1 = x0._mm_clmulepi64_si128(b: k, imm8: 0x10)
|
||||
x2 = util.make_m128i_multiple_u32(
|
||||
a00: 0xFFFF_FFFF,
|
||||
a01: 0x0000_0000,
|
||||
a02: 0xFFFF_FFFF,
|
||||
a03: 0x0000_0000)
|
||||
x0 = x0._mm_srli_si128(imm8: 8)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K5ZZ[.. 16])
|
||||
x1 = x0._mm_srli_si128(imm8: 4)
|
||||
x0 = x0._mm_and_si128(b: x2)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
|
||||
// Reduce 64 bits to 32 bits (Barrett Reduction) and extract.
|
||||
//
|
||||
// Barrett Reduction is Algorithm 1 (page 14) of Gopal et al., after
|
||||
// adjusting for bit-reflection as per Figure 12 (page 21).
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_PXMU[.. 16])
|
||||
x1 = x0._mm_and_si128(b: x2)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x10)
|
||||
x1 = x1._mm_and_si128(b: x2)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
s = x0._mm_extract_epi32(imm8: 1)
|
||||
|
||||
// Handle the tail of args.x that wasn't a complete 64-byte chunk.
|
||||
tail_index = args.x.length() & 0xFFFF_FFFF_FFFF_FFC0 // And-not 64.
|
||||
if tail_index < args.x.length() {
|
||||
iterate (p = args.x[tail_index ..])(length: 1, advance: 1, unroll: 1) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
}
|
||||
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
}
|
||||
+110
-117
@@ -8,29 +8,29 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// See "SIMD Implementations" in README.md for a link to Gopal et al. "Fast CRC
|
||||
// Computation for Generic Polynomials Using PCLMULQDQ Instruction".
|
||||
|
||||
pri func ieee_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
choose cpu_arch >= x86_sse42,
|
||||
{
|
||||
var s : base.u32
|
||||
var p : roslice base.u8
|
||||
|
||||
var util : base.x86_sse42_utility
|
||||
var k : base.x86_m128i
|
||||
var kk : base.x86_m128i
|
||||
var x0 : base.x86_m128i
|
||||
var x1 : base.x86_m128i
|
||||
var x2 : base.x86_m128i
|
||||
var x3 : base.x86_m128i
|
||||
var x4 : base.x86_m128i
|
||||
var x5 : base.x86_m128i
|
||||
var x6 : base.x86_m128i
|
||||
var x7 : base.x86_m128i
|
||||
var y0 : base.x86_m128i
|
||||
var y1 : base.x86_m128i
|
||||
var y2 : base.x86_m128i
|
||||
var y3 : base.x86_m128i
|
||||
|
||||
var tail_index : base.u64
|
||||
var y4 : base.x86_m128i
|
||||
var y5 : base.x86_m128i
|
||||
var y6 : base.x86_m128i
|
||||
var y7 : base.x86_m128i
|
||||
|
||||
s = 0xFFFF_FFFF ^ this.state
|
||||
|
||||
@@ -38,120 +38,113 @@ pri func ieee_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
|
||||
// For short inputs, just do a simple loop.
|
||||
if args.x.length() < 64 {
|
||||
iterate (p = args.x)(length: 1, advance: 1, unroll: 1) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
return nothing
|
||||
}
|
||||
|
||||
// Load 128×4 = 512 bits from the first 64-byte chunk.
|
||||
x0 = util.make_m128i_slice128(a: args.x[0x00 .. 0x10])
|
||||
x1 = util.make_m128i_slice128(a: args.x[0x10 .. 0x20])
|
||||
x2 = util.make_m128i_slice128(a: args.x[0x20 .. 0x30])
|
||||
x3 = util.make_m128i_slice128(a: args.x[0x30 .. 0x40])
|
||||
|
||||
// Combine with the initial state.
|
||||
x0 = x0._mm_xor_si128(b: util.make_m128i_single_u32(a: s))
|
||||
|
||||
// Process the remaining 64-byte chunks.
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K1K2[.. 16])
|
||||
iterate (p = args.x[64 ..])(length: 64, advance: 64, unroll: 1) {
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y2 = x2._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y3 = x3._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x2 = x2._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x3 = x3._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
|
||||
x0 = x0._mm_xor_si128(b: y0)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x00 .. 0x10]))
|
||||
x1 = x1._mm_xor_si128(b: y1)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x10 .. 0x20]))
|
||||
x2 = x2._mm_xor_si128(b: y2)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x20 .. 0x30]))
|
||||
x3 = x3._mm_xor_si128(b: y3)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x30 .. 0x40]))
|
||||
if args.x.length() >= 128 {
|
||||
// BEGIN script/print-crc32-x86-sse42-code.go generated code.
|
||||
x0 = util.make_m128i_slice128(a: args.x[0x00 .. 0x10])
|
||||
x1 = util.make_m128i_slice128(a: args.x[0x10 .. 0x20])
|
||||
x2 = util.make_m128i_slice128(a: args.x[0x20 .. 0x30])
|
||||
x3 = util.make_m128i_slice128(a: args.x[0x30 .. 0x40])
|
||||
x4 = util.make_m128i_slice128(a: args.x[0x40 .. 0x50])
|
||||
x5 = util.make_m128i_slice128(a: args.x[0x50 .. 0x60])
|
||||
x6 = util.make_m128i_slice128(a: args.x[0x60 .. 0x70])
|
||||
x7 = util.make_m128i_slice128(a: args.x[0x70 .. 0x80])
|
||||
kk = util.make_m128i_multiple_u32(a00: 0x33FF_F533, a01: 0, a02: 0x910E_EEC1, a03: 0)
|
||||
x0 = x0._mm_xor_si128(b: util.make_m128i_single_u32(a: s))
|
||||
args.x = args.x[128 ..]
|
||||
while args.x.length() >= 128 {
|
||||
y0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y1 = x1._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x1 = x1._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y2 = x2._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x2 = x2._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y3 = x3._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x3 = x3._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y4 = x4._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x4 = x4._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y5 = x5._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x5 = x5._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y6 = x6._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x6 = x6._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y7 = x7._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x7 = x7._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y0 = y0._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x00 .. 0x10]))
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y1 = y1._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x10 .. 0x20]))
|
||||
x1 = x1._mm_xor_si128(b: y1)
|
||||
y2 = y2._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x20 .. 0x30]))
|
||||
x2 = x2._mm_xor_si128(b: y2)
|
||||
y3 = y3._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x30 .. 0x40]))
|
||||
x3 = x3._mm_xor_si128(b: y3)
|
||||
y4 = y4._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x40 .. 0x50]))
|
||||
x4 = x4._mm_xor_si128(b: y4)
|
||||
y5 = y5._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x50 .. 0x60]))
|
||||
x5 = x5._mm_xor_si128(b: y5)
|
||||
y6 = y6._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x60 .. 0x70]))
|
||||
x6 = x6._mm_xor_si128(b: y6)
|
||||
y7 = y7._mm_xor_si128(b: util.make_m128i_slice128(a: args.x[0x70 .. 0x80]))
|
||||
x7 = x7._mm_xor_si128(b: y7)
|
||||
args.x = args.x[128 ..]
|
||||
}
|
||||
kk = util.make_m128i_multiple_u32(a00: 0xAE68_9191, a01: 0, a02: 0xCCAA_009E, a03: 0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y2 = x2._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x2 = x2._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y4 = x4._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x4 = x4._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y6 = x6._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x6 = x6._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y0 = y0._mm_xor_si128(b: x1)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y2 = y2._mm_xor_si128(b: x3)
|
||||
x2 = x2._mm_xor_si128(b: y2)
|
||||
y4 = y4._mm_xor_si128(b: x5)
|
||||
x4 = x4._mm_xor_si128(b: y4)
|
||||
y6 = y6._mm_xor_si128(b: x7)
|
||||
x6 = x6._mm_xor_si128(b: y6)
|
||||
kk = util.make_m128i_multiple_u32(a00: 0xF1DA_05AA, a01: 0, a02: 0x8125_6527, a03: 0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y4 = x4._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x4 = x4._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y0 = y0._mm_xor_si128(b: x2)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y4 = y4._mm_xor_si128(b: x6)
|
||||
x4 = x4._mm_xor_si128(b: y4)
|
||||
kk = util.make_m128i_multiple_u32(a00: 0x8F35_2D95, a01: 0, a02: 0x1D95_13D7, a03: 0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: kk, imm8: 0x11)
|
||||
y0 = y0._mm_xor_si128(b: x4)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
kk = util.make_m128i_multiple_u32(a00: 0xF701_1641, a01: 0xB4E5_B025, a02: 0xDB71_0641, a03: 1)
|
||||
s = util.make_m128i_single_u64(a: x0._mm_extract_epi64(imm8: 0)).
|
||||
_mm_clmulepi64_si128(b: kk, imm8: 0x00).
|
||||
_mm_clmulepi64_si128(b: kk, imm8: 0x10).
|
||||
_mm_extract_epi32(imm8: 2)
|
||||
kk = util.make_m128i_multiple_u32(a00: 0xF701_1641, a01: 0xB4E5_B025, a02: 0xDB71_0641, a03: 1)
|
||||
s = util.make_m128i_single_u64(a: x0._mm_extract_epi64(imm8: 1) ^ (s as base.u64)).
|
||||
_mm_clmulepi64_si128(b: kk, imm8: 0x00).
|
||||
_mm_clmulepi64_si128(b: kk, imm8: 0x10).
|
||||
_mm_extract_epi32(imm8: 2)
|
||||
// END script/print-crc32-x86-sse42-code.go generated code.
|
||||
}
|
||||
|
||||
// Reduce 128×4 = 512 bits to 128 bits.
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K3K4[.. 16])
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x2)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x3)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
while args.x.length() >= 8 {
|
||||
kk = util.make_m128i_multiple_u32(a00: 0xF701_1641, a01: 0xB4E5_B025, a02: 0xDB71_0641, a03: 1)
|
||||
s = util.make_m128i_single_u64(a: args.x.peek_u64le() ^ (s as base.u64)).
|
||||
_mm_clmulepi64_si128(b: kk, imm8: 0x00).
|
||||
_mm_clmulepi64_si128(b: kk, imm8: 0x10).
|
||||
_mm_extract_epi32(imm8: 2)
|
||||
args.x = args.x[8 ..]
|
||||
}
|
||||
|
||||
// Reduce 128 bits to 64 bits.
|
||||
x1 = x0._mm_clmulepi64_si128(b: k, imm8: 0x10)
|
||||
x2 = util.make_m128i_multiple_u32(
|
||||
a00: 0xFFFF_FFFF,
|
||||
a01: 0x0000_0000,
|
||||
a02: 0xFFFF_FFFF,
|
||||
a03: 0x0000_0000)
|
||||
x0 = x0._mm_srli_si128(imm8: 8)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K5ZZ[.. 16])
|
||||
x1 = x0._mm_srli_si128(imm8: 4)
|
||||
x0 = x0._mm_and_si128(b: x2)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
|
||||
// Reduce 64 bits to 32 bits (Barrett Reduction) and extract.
|
||||
//
|
||||
// Barrett Reduction is Algorithm 1 (page 14) of Gopal et al., after
|
||||
// adjusting for bit-reflection as per Figure 12 (page 21).
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_PXMU[.. 16])
|
||||
x1 = x0._mm_and_si128(b: x2)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x10)
|
||||
x1 = x1._mm_and_si128(b: x2)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
s = x0._mm_extract_epi32(imm8: 1)
|
||||
|
||||
// Handle the tail of args.x that wasn't a complete 64-byte chunk.
|
||||
tail_index = args.x.length() & 0xFFFF_FFFF_FFFF_FFC0 // And-not 64.
|
||||
if tail_index < args.x.length() {
|
||||
iterate (p = args.x[tail_index ..])(length: 1, advance: 1, unroll: 1) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
while args.x.length() > 0 {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
}
|
||||
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
}
|
||||
|
||||
// These constants come from page 22 of Gopal et al. They are also reproduced
|
||||
// by script/print-crc32-x86-sse42-magic-numbers.go which is runnable online at
|
||||
// https://play.golang.org/p/wH1q6GfhKOE
|
||||
//
|
||||
// The k6' constant from the Gopal paper is unused.
|
||||
|
||||
pri const IEEE_X86_SSE42_K1K2 : roarray[16] base.u8 = [
|
||||
0xD4, 0x2B, 0x44, 0x54, 0x01, 0x00, 0x00, 0x00, // k1' = 0x1_5444_2BD4
|
||||
0x96, 0x15, 0xE4, 0xC6, 0x01, 0x00, 0x00, 0x00, // k2' = 0x1_C6E4_1596
|
||||
]
|
||||
|
||||
pri const IEEE_X86_SSE42_K3K4 : roarray[16] base.u8 = [
|
||||
0xD0, 0x97, 0x19, 0x75, 0x01, 0x00, 0x00, 0x00, // k3' = 0x1_7519_97D0
|
||||
0x9E, 0x00, 0xAA, 0xCC, 0x00, 0x00, 0x00, 0x00, // k4' = 0x0_CCAA_009E
|
||||
]
|
||||
|
||||
pri const IEEE_X86_SSE42_K5ZZ : roarray[16] base.u8 = [
|
||||
0x24, 0x61, 0xCD, 0x63, 0x01, 0x00, 0x00, 0x00, // k5' = 0x1_63CD_6124
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Unused
|
||||
]
|
||||
|
||||
pri const IEEE_X86_SSE42_PXMU : roarray[16] base.u8 = [
|
||||
0x41, 0x06, 0x71, 0xDB, 0x01, 0x00, 0x00, 0x00, // Px' = 0x1_DB71_0641
|
||||
0x41, 0x16, 0x01, 0xF7, 0x01, 0x00, 0x00, 0x00, // μ' = 0x1_F701_1641
|
||||
]
|
||||
@@ -0,0 +1,595 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pub struct ecma_hasher? implements base.hasher_u64(
|
||||
state : base.u64,
|
||||
)
|
||||
|
||||
pub func ecma_hasher.get_quirk(key: base.u32) base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func ecma_hasher.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func ecma_hasher.update!(x: roslice base.u8) {
|
||||
if this.state == 0 {
|
||||
choose up = [
|
||||
up_x86_sse42]
|
||||
}
|
||||
this.up!(x: args.x)
|
||||
}
|
||||
|
||||
pub func ecma_hasher.update_u64!(x: roslice base.u8) base.u64 {
|
||||
this.update!(x: args.x)
|
||||
return this.checksum_u64()
|
||||
}
|
||||
|
||||
pri func ecma_hasher.up!(x: roslice base.u8),
|
||||
choosy,
|
||||
{
|
||||
var s : base.u64
|
||||
var p : roslice base.u8
|
||||
|
||||
s = 0xFFFF_FFFF_FFFF_FFFF ^ this.state
|
||||
|
||||
// Use the same slicing-by-M algorithm as for std/crc32, with M = 8.
|
||||
iterate (p = args.x)(length: 8, advance: 8, unroll: 1) {
|
||||
s ^= ((p[0x00] as base.u64) << 0) |
|
||||
((p[0x01] as base.u64) << 8) |
|
||||
((p[0x02] as base.u64) << 16) |
|
||||
((p[0x03] as base.u64) << 24) |
|
||||
((p[0x04] as base.u64) << 32) |
|
||||
((p[0x05] as base.u64) << 40) |
|
||||
((p[0x06] as base.u64) << 48) |
|
||||
((p[0x07] as base.u64) << 56)
|
||||
s = ECMA_TABLE[0x00][0xFF & (s >> 56)] ^
|
||||
ECMA_TABLE[0x01][0xFF & (s >> 48)] ^
|
||||
ECMA_TABLE[0x02][0xFF & (s >> 40)] ^
|
||||
ECMA_TABLE[0x03][0xFF & (s >> 32)] ^
|
||||
ECMA_TABLE[0x04][0xFF & (s >> 24)] ^
|
||||
ECMA_TABLE[0x05][0xFF & (s >> 16)] ^
|
||||
ECMA_TABLE[0x06][0xFF & (s >> 8)] ^
|
||||
ECMA_TABLE[0x07][0xFF & (s >> 0)]
|
||||
} else (length: 1, advance: 1, unroll: 1) {
|
||||
s = ECMA_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
|
||||
this.state = 0xFFFF_FFFF_FFFF_FFFF ^ s
|
||||
}
|
||||
|
||||
pub func ecma_hasher.checksum_u64() base.u64 {
|
||||
return this.state
|
||||
}
|
||||
|
||||
// The table below was created by script/print-crc64-magic-numbers.go.
|
||||
|
||||
pri const ECMA_TABLE : roarray[8] roarray[256] base.u64 = [[
|
||||
0x0000_0000_0000_0000, 0xB32E_4CBE_03A7_5F6F, 0xF484_3657_A840_A05B, 0x47AA_7AE9_ABE7_FF34,
|
||||
0x7BD0_C384_FF8F_5E33, 0xC8FE_8F3A_FC28_015C, 0x8F54_F5D3_57CF_FE68, 0x3C7A_B96D_5468_A107,
|
||||
0xF7A1_8709_FF1E_BC66, 0x448F_CBB7_FCB9_E309, 0x0325_B15E_575E_1C3D, 0xB00B_FDE0_54F9_4352,
|
||||
0x8C71_448D_0091_E255, 0x3F5F_0833_0336_BD3A, 0x78F5_72DA_A8D1_420E, 0xCBDB_3E64_AB76_1D61,
|
||||
0x7D9B_A138_5133_6649, 0xCEB5_ED86_5294_3926, 0x891F_976F_F973_C612, 0x3A31_DBD1_FAD4_997D,
|
||||
0x064B_62BC_AEBC_387A, 0xB565_2E02_AD1B_6715, 0xF2CF_54EB_06FC_9821, 0x41E1_1855_055B_C74E,
|
||||
0x8A3A_2631_AE2D_DA2F, 0x3914_6A8F_AD8A_8540, 0x7EBE_1066_066D_7A74, 0xCD90_5CD8_05CA_251B,
|
||||
0xF1EA_E5B5_51A2_841C, 0x42C4_A90B_5205_DB73, 0x056E_D3E2_F9E2_2447, 0xB640_9F5C_FA45_7B28,
|
||||
0xFB37_4270_A266_CC92, 0x4819_0ECE_A1C1_93FD, 0x0FB3_7427_0A26_6CC9, 0xBC9D_3899_0981_33A6,
|
||||
0x80E7_81F4_5DE9_92A1, 0x33C9_CD4A_5E4E_CDCE, 0x7463_B7A3_F5A9_32FA, 0xC74D_FB1D_F60E_6D95,
|
||||
0x0C96_C579_5D78_70F4, 0xBFB8_89C7_5EDF_2F9B, 0xF812_F32E_F538_D0AF, 0x4B3C_BF90_F69F_8FC0,
|
||||
0x7746_06FD_A2F7_2EC7, 0xC468_4A43_A150_71A8, 0x83C2_30AA_0AB7_8E9C, 0x30EC_7C14_0910_D1F3,
|
||||
0x86AC_E348_F355_AADB, 0x3582_AFF6_F0F2_F5B4, 0x7228_D51F_5B15_0A80, 0xC106_99A1_58B2_55EF,
|
||||
0xFD7C_20CC_0CDA_F4E8, 0x4E52_6C72_0F7D_AB87, 0x09F8_169B_A49A_54B3, 0xBAD6_5A25_A73D_0BDC,
|
||||
0x710D_6441_0C4B_16BD, 0xC223_28FF_0FEC_49D2, 0x8589_5216_A40B_B6E6, 0x36A7_1EA8_A7AC_E989,
|
||||
0x0ADD_A7C5_F3C4_488E, 0xB9F3_EB7B_F063_17E1, 0xFE59_9192_5B84_E8D5, 0x4D77_DD2C_5823_B7BA,
|
||||
0x64B6_2BCA_EBC3_87A1, 0xD798_6774_E864_D8CE, 0x9032_1D9D_4383_27FA, 0x231C_5123_4024_7895,
|
||||
0x1F66_E84E_144C_D992, 0xAC48_A4F0_17EB_86FD, 0xEBE2_DE19_BC0C_79C9, 0x58CC_92A7_BFAB_26A6,
|
||||
0x9317_ACC3_14DD_3BC7, 0x2039_E07D_177A_64A8, 0x6793_9A94_BC9D_9B9C, 0xD4BD_D62A_BF3A_C4F3,
|
||||
0xE8C7_6F47_EB52_65F4, 0x5BE9_23F9_E8F5_3A9B, 0x1C43_5910_4312_C5AF, 0xAF6D_15AE_40B5_9AC0,
|
||||
0x192D_8AF2_BAF0_E1E8, 0xAA03_C64C_B957_BE87, 0xEDA9_BCA5_12B0_41B3, 0x5E87_F01B_1117_1EDC,
|
||||
0x62FD_4976_457F_BFDB, 0xD1D3_05C8_46D8_E0B4, 0x9679_7F21_ED3F_1F80, 0x2557_339F_EE98_40EF,
|
||||
0xEE8C_0DFB_45EE_5D8E, 0x5DA2_4145_4649_02E1, 0x1A08_3BAC_EDAE_FDD5, 0xA926_7712_EE09_A2BA,
|
||||
0x955C_CE7F_BA61_03BD, 0x2672_82C1_B9C6_5CD2, 0x61D8_F828_1221_A3E6, 0xD2F6_B496_1186_FC89,
|
||||
0x9F81_69BA_49A5_4B33, 0x2CAF_2504_4A02_145C, 0x6B05_5FED_E1E5_EB68, 0xD82B_1353_E242_B407,
|
||||
0xE451_AA3E_B62A_1500, 0x577F_E680_B58D_4A6F, 0x10D5_9C69_1E6A_B55B, 0xA3FB_D0D7_1DCD_EA34,
|
||||
0x6820_EEB3_B6BB_F755, 0xDB0E_A20D_B51C_A83A, 0x9CA4_D8E4_1EFB_570E, 0x2F8A_945A_1D5C_0861,
|
||||
0x13F0_2D37_4934_A966, 0xA0DE_6189_4A93_F609, 0xE774_1B60_E174_093D, 0x545A_57DE_E2D3_5652,
|
||||
0xE21A_C882_1896_2D7A, 0x5134_843C_1B31_7215, 0x169E_FED5_B0D6_8D21, 0xA5B0_B26B_B371_D24E,
|
||||
0x99CA_0B06_E719_7349, 0x2AE4_47B8_E4BE_2C26, 0x6D4E_3D51_4F59_D312, 0xDE60_71EF_4CFE_8C7D,
|
||||
0x15BB_4F8B_E788_911C, 0xA695_0335_E42F_CE73, 0xE13F_79DC_4FC8_3147, 0x5211_3562_4C6F_6E28,
|
||||
0x6E6B_8C0F_1807_CF2F, 0xDD45_C0B1_1BA0_9040, 0x9AEF_BA58_B047_6F74, 0x29C1_F6E6_B3E0_301B,
|
||||
0xC96C_5795_D787_0F42, 0x7A42_1B2B_D420_502D, 0x3DE8_61C2_7FC7_AF19, 0x8EC6_2D7C_7C60_F076,
|
||||
0xB2BC_9411_2808_5171, 0x0192_D8AF_2BAF_0E1E, 0x4638_A246_8048_F12A, 0xF516_EEF8_83EF_AE45,
|
||||
0x3ECD_D09C_2899_B324, 0x8DE3_9C22_2B3E_EC4B, 0xCA49_E6CB_80D9_137F, 0x7967_AA75_837E_4C10,
|
||||
0x451D_1318_D716_ED17, 0xF633_5FA6_D4B1_B278, 0xB199_254F_7F56_4D4C, 0x02B7_69F1_7CF1_1223,
|
||||
0xB4F7_F6AD_86B4_690B, 0x07D9_BA13_8513_3664, 0x4073_C0FA_2EF4_C950, 0xF35D_8C44_2D53_963F,
|
||||
0xCF27_3529_793B_3738, 0x7C09_7997_7A9C_6857, 0x3BA3_037E_D17B_9763, 0x888D_4FC0_D2DC_C80C,
|
||||
0x4356_71A4_79AA_D56D, 0xF078_3D1A_7A0D_8A02, 0xB7D2_47F3_D1EA_7536, 0x04FC_0B4D_D24D_2A59,
|
||||
0x3886_B220_8625_8B5E, 0x8BA8_FE9E_8582_D431, 0xCC02_8477_2E65_2B05, 0x7F2C_C8C9_2DC2_746A,
|
||||
0x325B_15E5_75E1_C3D0, 0x8175_595B_7646_9CBF, 0xC6DF_23B2_DDA1_638B, 0x75F1_6F0C_DE06_3CE4,
|
||||
0x498B_D661_8A6E_9DE3, 0xFAA5_9ADF_89C9_C28C, 0xBD0F_E036_222E_3DB8, 0x0E21_AC88_2189_62D7,
|
||||
0xC5FA_92EC_8AFF_7FB6, 0x76D4_DE52_8958_20D9, 0x317E_A4BB_22BF_DFED, 0x8250_E805_2118_8082,
|
||||
0xBE2A_5168_7570_2185, 0x0D04_1DD6_76D7_7EEA, 0x4AAE_673F_DD30_81DE, 0xF980_2B81_DE97_DEB1,
|
||||
0x4FC0_B4DD_24D2_A599, 0xFCEE_F863_2775_FAF6, 0xBB44_828A_8C92_05C2, 0x086A_CE34_8F35_5AAD,
|
||||
0x3410_7759_DB5D_FBAA, 0x873E_3BE7_D8FA_A4C5, 0xC094_410E_731D_5BF1, 0x73BA_0DB0_70BA_049E,
|
||||
0xB861_33D4_DBCC_19FF, 0x0B4F_7F6A_D86B_4690, 0x4CE5_0583_738C_B9A4, 0xFFCB_493D_702B_E6CB,
|
||||
0xC3B1_F050_2443_47CC, 0x709F_BCEE_27E4_18A3, 0x3735_C607_8C03_E797, 0x841B_8AB9_8FA4_B8F8,
|
||||
0xADDA_7C5F_3C44_88E3, 0x1EF4_30E1_3FE3_D78C, 0x595E_4A08_9404_28B8, 0xEA70_06B6_97A3_77D7,
|
||||
0xD60A_BFDB_C3CB_D6D0, 0x6524_F365_C06C_89BF, 0x228E_898C_6B8B_768B, 0x91A0_C532_682C_29E4,
|
||||
0x5A7B_FB56_C35A_3485, 0xE955_B7E8_C0FD_6BEA, 0xAEFF_CD01_6B1A_94DE, 0x1DD1_81BF_68BD_CBB1,
|
||||
0x21AB_38D2_3CD5_6AB6, 0x9285_746C_3F72_35D9, 0xD52F_0E85_9495_CAED, 0x6601_423B_9732_9582,
|
||||
0xD041_DD67_6D77_EEAA, 0x636F_91D9_6ED0_B1C5, 0x24C5_EB30_C537_4EF1, 0x97EB_A78E_C690_119E,
|
||||
0xAB91_1EE3_92F8_B099, 0x18BF_525D_915F_EFF6, 0x5F15_28B4_3AB8_10C2, 0xEC3B_640A_391F_4FAD,
|
||||
0x27E0_5A6E_9269_52CC, 0x94CE_16D0_91CE_0DA3, 0xD364_6C39_3A29_F297, 0x604A_2087_398E_ADF8,
|
||||
0x5C30_99EA_6DE6_0CFF, 0xEF1E_D554_6E41_5390, 0xA8B4_AFBD_C5A6_ACA4, 0x1B9A_E303_C601_F3CB,
|
||||
0x56ED_3E2F_9E22_4471, 0xE5C3_7291_9D85_1B1E, 0xA269_0878_3662_E42A, 0x1147_44C6_35C5_BB45,
|
||||
0x2D3D_FDAB_61AD_1A42, 0x9E13_B115_620A_452D, 0xD9B9_CBFC_C9ED_BA19, 0x6A97_8742_CA4A_E576,
|
||||
0xA14C_B926_613C_F817, 0x1262_F598_629B_A778, 0x55C8_8F71_C97C_584C, 0xE6E6_C3CF_CADB_0723,
|
||||
0xDA9C_7AA2_9EB3_A624, 0x69B2_361C_9D14_F94B, 0x2E18_4CF5_36F3_067F, 0x9D36_004B_3554_5910,
|
||||
0x2B76_9F17_CF11_2238, 0x9858_D3A9_CCB6_7D57, 0xDFF2_A940_6751_8263, 0x6CDC_E5FE_64F6_DD0C,
|
||||
0x50A6_5C93_309E_7C0B, 0xE388_102D_3339_2364, 0xA422_6AC4_98DE_DC50, 0x170C_267A_9B79_833F,
|
||||
0xDCD7_181E_300F_9E5E, 0x6FF9_54A0_33A8_C131, 0x2853_2E49_984F_3E05, 0x9B7D_62F7_9BE8_616A,
|
||||
0xA707_DB9A_CF80_C06D, 0x1429_9724_CC27_9F02, 0x5383_EDCD_67C0_6036, 0xE0AD_A173_6467_3F59,
|
||||
],[
|
||||
0x0000_0000_0000_0000, 0x54E9_7992_5CD0_F10D, 0xA9D2_F324_B9A1_E21A, 0xFD3B_8AB6_E571_1317,
|
||||
0xC17D_4962_DC4D_DAB1, 0x9594_30F0_809D_2BBC, 0x68AF_BA46_65EC_38AB, 0x3C46_C3D4_393C_C9A6,
|
||||
0x1022_3DEE_1795_ABE7, 0x44CB_447C_4B45_5AEA, 0xB9F0_CECA_AE34_49FD, 0xED19_B758_F2E4_B8F0,
|
||||
0xD15F_748C_CBD8_7156, 0x85B6_0D1E_9708_805B, 0x788D_87A8_7279_934C, 0x2C64_FE3A_2EA9_6241,
|
||||
0x2044_7BDC_2F2B_57CE, 0x74AD_024E_73FB_A6C3, 0x8996_88F8_968A_B5D4, 0xDD7F_F16A_CA5A_44D9,
|
||||
0xE139_32BE_F366_8D7F, 0xB5D0_4B2C_AFB6_7C72, 0x48EB_C19A_4AC7_6F65, 0x1C02_B808_1617_9E68,
|
||||
0x3066_4632_38BE_FC29, 0x648F_3FA0_646E_0D24, 0x99B4_B516_811F_1E33, 0xCD5D_CC84_DDCF_EF3E,
|
||||
0xF11B_0F50_E4F3_2698, 0xA5F2_76C2_B823_D795, 0x58C9_FC74_5D52_C482, 0x0C20_85E6_0182_358F,
|
||||
0x4088_F7B8_5E56_AF9C, 0x1461_8E2A_0286_5E91, 0xE95A_049C_E7F7_4D86, 0xBDB3_7D0E_BB27_BC8B,
|
||||
0x81F5_BEDA_821B_752D, 0xD51C_C748_DECB_8420, 0x2827_4DFE_3BBA_9737, 0x7CCE_346C_676A_663A,
|
||||
0x50AA_CA56_49C3_047B, 0x0443_B3C4_1513_F576, 0xF978_3972_F062_E661, 0xAD91_40E0_ACB2_176C,
|
||||
0x91D7_8334_958E_DECA, 0xC53E_FAA6_C95E_2FC7, 0x3805_7010_2C2F_3CD0, 0x6CEC_0982_70FF_CDDD,
|
||||
0x60CC_8C64_717D_F852, 0x3425_F5F6_2DAD_095F, 0xC91E_7F40_C8DC_1A48, 0x9DF7_06D2_940C_EB45,
|
||||
0xA1B1_C506_AD30_22E3, 0xF558_BC94_F1E0_D3EE, 0x0863_3622_1491_C0F9, 0x5C8A_4FB0_4841_31F4,
|
||||
0x70EE_B18A_66E8_53B5, 0x2407_C818_3A38_A2B8, 0xD93C_42AE_DF49_B1AF, 0x8DD5_3B3C_8399_40A2,
|
||||
0xB193_F8E8_BAA5_8904, 0xE57A_817A_E675_7809, 0x1841_0BCC_0304_6B1E, 0x4CA8_725E_5FD4_9A13,
|
||||
0x8111_EF70_BCAD_5F38, 0xD5F8_96E2_E07D_AE35, 0x28C3_1C54_050C_BD22, 0x7C2A_65C6_59DC_4C2F,
|
||||
0x406C_A612_60E0_8589, 0x1485_DF80_3C30_7484, 0xE9BE_5536_D941_6793, 0xBD57_2CA4_8591_969E,
|
||||
0x9133_D29E_AB38_F4DF, 0xC5DA_AB0C_F7E8_05D2, 0x38E1_21BA_1299_16C5, 0x6C08_5828_4E49_E7C8,
|
||||
0x504E_9BFC_7775_2E6E, 0x04A7_E26E_2BA5_DF63, 0xF99C_68D8_CED4_CC74, 0xAD75_114A_9204_3D79,
|
||||
0xA155_94AC_9386_08F6, 0xF5BC_ED3E_CF56_F9FB, 0x0887_6788_2A27_EAEC, 0x5C6E_1E1A_76F7_1BE1,
|
||||
0x6028_DDCE_4FCB_D247, 0x34C1_A45C_131B_234A, 0xC9FA_2EEA_F66A_305D, 0x9D13_5778_AABA_C150,
|
||||
0xB177_A942_8413_A311, 0xE59E_D0D0_D8C3_521C, 0x18A5_5A66_3DB2_410B, 0x4C4C_23F4_6162_B006,
|
||||
0x700A_E020_585E_79A0, 0x24E3_99B2_048E_88AD, 0xD9D8_1304_E1FF_9BBA, 0x8D31_6A96_BD2F_6AB7,
|
||||
0xC199_18C8_E2FB_F0A4, 0x9570_615A_BE2B_01A9, 0x684B_EBEC_5B5A_12BE, 0x3CA2_927E_078A_E3B3,
|
||||
0x00E4_51AA_3EB6_2A15, 0x540D_2838_6266_DB18, 0xA936_A28E_8717_C80F, 0xFDDF_DB1C_DBC7_3902,
|
||||
0xD1BB_2526_F56E_5B43, 0x8552_5CB4_A9BE_AA4E, 0x7869_D602_4CCF_B959, 0x2C80_AF90_101F_4854,
|
||||
0x10C6_6C44_2923_81F2, 0x442F_15D6_75F3_70FF, 0xB914_9F60_9082_63E8, 0xEDFD_E6F2_CC52_92E5,
|
||||
0xE1DD_6314_CDD0_A76A, 0xB534_1A86_9100_5667, 0x480F_9030_7471_4570, 0x1CE6_E9A2_28A1_B47D,
|
||||
0x20A0_2A76_119D_7DDB, 0x7449_53E4_4D4D_8CD6, 0x8972_D952_A83C_9FC1, 0xDD9B_A0C0_F4EC_6ECC,
|
||||
0xF1FF_5EFA_DA45_0C8D, 0xA516_2768_8695_FD80, 0x582D_ADDE_63E4_EE97, 0x0CC4_D44C_3F34_1F9A,
|
||||
0x3082_1798_0608_D63C, 0x646B_6E0A_5AD8_2731, 0x9950_E4BC_BFA9_3426, 0xCDB9_9D2E_E379_C52B,
|
||||
0x90FB_71CA_D654_A0F5, 0xC412_0858_8A84_51F8, 0x3929_82EE_6FF5_42EF, 0x6DC0_FB7C_3325_B3E2,
|
||||
0x5186_38A8_0A19_7A44, 0x056F_413A_56C9_8B49, 0xF854_CB8C_B3B8_985E, 0xACBD_B21E_EF68_6953,
|
||||
0x80D9_4C24_C1C1_0B12, 0xD430_35B6_9D11_FA1F, 0x290B_BF00_7860_E908, 0x7DE2_C692_24B0_1805,
|
||||
0x41A4_0546_1D8C_D1A3, 0x154D_7CD4_415C_20AE, 0xE876_F662_A42D_33B9, 0xBC9F_8FF0_F8FD_C2B4,
|
||||
0xB0BF_0A16_F97F_F73B, 0xE456_7384_A5AF_0636, 0x196D_F932_40DE_1521, 0x4D84_80A0_1C0E_E42C,
|
||||
0x71C2_4374_2532_2D8A, 0x252B_3AE6_79E2_DC87, 0xD810_B050_9C93_CF90, 0x8CF9_C9C2_C043_3E9D,
|
||||
0xA09D_37F8_EEEA_5CDC, 0xF474_4E6A_B23A_ADD1, 0x094F_C4DC_574B_BEC6, 0x5DA6_BD4E_0B9B_4FCB,
|
||||
0x61E0_7E9A_32A7_866D, 0x3509_0708_6E77_7760, 0xC832_8DBE_8B06_6477, 0x9CDB_F42C_D7D6_957A,
|
||||
0xD073_8672_8802_0F69, 0x849A_FFE0_D4D2_FE64, 0x79A1_7556_31A3_ED73, 0x2D48_0CC4_6D73_1C7E,
|
||||
0x110E_CF10_544F_D5D8, 0x45E7_B682_089F_24D5, 0xB8DC_3C34_EDEE_37C2, 0xEC35_45A6_B13E_C6CF,
|
||||
0xC051_BB9C_9F97_A48E, 0x94B8_C20E_C347_5583, 0x6983_48B8_2636_4694, 0x3D6A_312A_7AE6_B799,
|
||||
0x012C_F2FE_43DA_7E3F, 0x55C5_8B6C_1F0A_8F32, 0xA8FE_01DA_FA7B_9C25, 0xFC17_7848_A6AB_6D28,
|
||||
0xF037_FDAE_A729_58A7, 0xA4DE_843C_FBF9_A9AA, 0x59E5_0E8A_1E88_BABD, 0x0D0C_7718_4258_4BB0,
|
||||
0x314A_B4CC_7B64_8216, 0x65A3_CD5E_27B4_731B, 0x9898_47E8_C2C5_600C, 0xCC71_3E7A_9E15_9101,
|
||||
0xE015_C040_B0BC_F340, 0xB4FC_B9D2_EC6C_024D, 0x49C7_3364_091D_115A, 0x1D2E_4AF6_55CD_E057,
|
||||
0x2168_8922_6CF1_29F1, 0x7581_F0B0_3021_D8FC, 0x88BA_7A06_D550_CBEB, 0xDC53_0394_8980_3AE6,
|
||||
0x11EA_9EBA_6AF9_FFCD, 0x4503_E728_3629_0EC0, 0xB838_6D9E_D358_1DD7, 0xECD1_140C_8F88_ECDA,
|
||||
0xD097_D7D8_B6B4_257C, 0x847E_AE4A_EA64_D471, 0x7945_24FC_0F15_C766, 0x2DAC_5D6E_53C5_366B,
|
||||
0x01C8_A354_7D6C_542A, 0x5521_DAC6_21BC_A527, 0xA81A_5070_C4CD_B630, 0xFCF3_29E2_981D_473D,
|
||||
0xC0B5_EA36_A121_8E9B, 0x945C_93A4_FDF1_7F96, 0x6967_1912_1880_6C81, 0x3D8E_6080_4450_9D8C,
|
||||
0x31AE_E566_45D2_A803, 0x6547_9CF4_1902_590E, 0x987C_1642_FC73_4A19, 0xCC95_6FD0_A0A3_BB14,
|
||||
0xF0D3_AC04_999F_72B2, 0xA43A_D596_C54F_83BF, 0x5901_5F20_203E_90A8, 0x0DE8_26B2_7CEE_61A5,
|
||||
0x218C_D888_5247_03E4, 0x7565_A11A_0E97_F2E9, 0x885E_2BAC_EBE6_E1FE, 0xDCB7_523E_B736_10F3,
|
||||
0xE0F1_91EA_8E0A_D955, 0xB418_E878_D2DA_2858, 0x4923_62CE_37AB_3B4F, 0x1DCA_1B5C_6B7B_CA42,
|
||||
0x5162_6902_34AF_5051, 0x058B_1090_687F_A15C, 0xF8B0_9A26_8D0E_B24B, 0xAC59_E3B4_D1DE_4346,
|
||||
0x901F_2060_E8E2_8AE0, 0xC4F6_59F2_B432_7BED, 0x39CD_D344_5143_68FA, 0x6D24_AAD6_0D93_99F7,
|
||||
0x4140_54EC_233A_FBB6, 0x15A9_2D7E_7FEA_0ABB, 0xE892_A7C8_9A9B_19AC, 0xBC7B_DE5A_C64B_E8A1,
|
||||
0x803D_1D8E_FF77_2107, 0xD4D4_641C_A3A7_D00A, 0x29EF_EEAA_46D6_C31D, 0x7D06_9738_1A06_3210,
|
||||
0x7126_12DE_1B84_079F, 0x25CF_6B4C_4754_F692, 0xD8F4_E1FA_A225_E585, 0x8C1D_9868_FEF5_1488,
|
||||
0xB05B_5BBC_C7C9_DD2E, 0xE4B2_222E_9B19_2C23, 0x1989_A898_7E68_3F34, 0x4D60_D10A_22B8_CE39,
|
||||
0x6104_2F30_0C11_AC78, 0x35ED_56A2_50C1_5D75, 0xC8D6_DC14_B5B0_4E62, 0x9C3F_A586_E960_BF6F,
|
||||
0xA079_6652_D05C_76C9, 0xF490_1FC0_8C8C_87C4, 0x09AB_9576_69FD_94D3, 0x5D42_ECE4_352D_65DE,
|
||||
],[
|
||||
0x0000_0000_0000_0000, 0x3F0B_E14A_916A_6DCB, 0x7E17_C295_22D4_DB96, 0x411C_23DF_B3BE_B65D,
|
||||
0xFC2F_852A_45A9_B72C, 0xC324_6460_D4C3_DAE7, 0x8238_47BF_677D_6CBA, 0xBD33_A6F5_F617_0171,
|
||||
0x6A87_A57F_245D_70DD, 0x558C_4435_B537_1D16, 0x1490_67EA_0689_AB4B, 0x2B9B_86A0_97E3_C680,
|
||||
0x96A8_2055_61F4_C7F1, 0xA9A3_C11F_F09E_AA3A, 0xE8BF_E2C0_4320_1C67, 0xD7B4_038A_D24A_71AC,
|
||||
0xD50F_4AFE_48BA_E1BA, 0xEA04_ABB4_D9D0_8C71, 0xAB18_886B_6A6E_3A2C, 0x9413_6921_FB04_57E7,
|
||||
0x2920_CFD4_0D13_5696, 0x162B_2E9E_9C79_3B5D, 0x5737_0D41_2FC7_8D00, 0x683C_EC0B_BEAD_E0CB,
|
||||
0xBF88_EF81_6CE7_9167, 0x8083_0ECB_FD8D_FCAC, 0xC19F_2D14_4E33_4AF1, 0xFE94_CC5E_DF59_273A,
|
||||
0x43A7_6AAB_294E_264B, 0x7CAC_8BE1_B824_4B80, 0x3DB0_A83E_0B9A_FDDD, 0x02BB_4974_9AF0_9016,
|
||||
0x38C6_3AD7_3E7B_DDF1, 0x07CD_DB9D_AF11_B03A, 0x46D1_F842_1CAF_0667, 0x79DA_1908_8DC5_6BAC,
|
||||
0xC4E9_BFFD_7BD2_6ADD, 0xFBE2_5EB7_EAB8_0716, 0xBAFE_7D68_5906_B14B, 0x85F5_9C22_C86C_DC80,
|
||||
0x5241_9FA8_1A26_AD2C, 0x6D4A_7EE2_8B4C_C0E7, 0x2C56_5D3D_38F2_76BA, 0x135D_BC77_A998_1B71,
|
||||
0xAE6E_1A82_5F8F_1A00, 0x9165_FBC8_CEE5_77CB, 0xD079_D817_7D5B_C196, 0xEF72_395D_EC31_AC5D,
|
||||
0xEDC9_7029_76C1_3C4B, 0xD2C2_9163_E7AB_5180, 0x93DE_B2BC_5415_E7DD, 0xACD5_53F6_C57F_8A16,
|
||||
0x11E6_F503_3368_8B67, 0x2EED_1449_A202_E6AC, 0x6FF1_3796_11BC_50F1, 0x50FA_D6DC_80D6_3D3A,
|
||||
0x874E_D556_529C_4C96, 0xB845_341C_C3F6_215D, 0xF959_17C3_7048_9700, 0xC652_F689_E122_FACB,
|
||||
0x7B61_507C_1735_FBBA, 0x446A_B136_865F_9671, 0x0576_92E9_35E1_202C, 0x3A7D_73A3_A48B_4DE7,
|
||||
0x718C_75AE_7CF7_BBE2, 0x4E87_94E4_ED9D_D629, 0x0F9B_B73B_5E23_6074, 0x3090_5671_CF49_0DBF,
|
||||
0x8DA3_F084_395E_0CCE, 0xB2A8_11CE_A834_6105, 0xF3B4_3211_1B8A_D758, 0xCCBF_D35B_8AE0_BA93,
|
||||
0x1B0B_D0D1_58AA_CB3F, 0x2400_319B_C9C0_A6F4, 0x651C_1244_7A7E_10A9, 0x5A17_F30E_EB14_7D62,
|
||||
0xE724_55FB_1D03_7C13, 0xD82F_B4B1_8C69_11D8, 0x9933_976E_3FD7_A785, 0xA638_7624_AEBD_CA4E,
|
||||
0xA483_3F50_344D_5A58, 0x9B88_DE1A_A527_3793, 0xDA94_FDC5_1699_81CE, 0xE59F_1C8F_87F3_EC05,
|
||||
0x58AC_BA7A_71E4_ED74, 0x67A7_5B30_E08E_80BF, 0x26BB_78EF_5330_36E2, 0x19B0_99A5_C25A_5B29,
|
||||
0xCE04_9A2F_1010_2A85, 0xF10F_7B65_817A_474E, 0xB013_58BA_32C4_F113, 0x8F18_B9F0_A3AE_9CD8,
|
||||
0x322B_1F05_55B9_9DA9, 0x0D20_FE4F_C4D3_F062, 0x4C3C_DD90_776D_463F, 0x7337_3CDA_E607_2BF4,
|
||||
0x494A_4F79_428C_6613, 0x7641_AE33_D3E6_0BD8, 0x375D_8DEC_6058_BD85, 0x0856_6CA6_F132_D04E,
|
||||
0xB565_CA53_0725_D13F, 0x8A6E_2B19_964F_BCF4, 0xCB72_08C6_25F1_0AA9, 0xF479_E98C_B49B_6762,
|
||||
0x23CD_EA06_66D1_16CE, 0x1CC6_0B4C_F7BB_7B05, 0x5DDA_2893_4405_CD58, 0x62D1_C9D9_D56F_A093,
|
||||
0xDFE2_6F2C_2378_A1E2, 0xE0E9_8E66_B212_CC29, 0xA1F5_ADB9_01AC_7A74, 0x9EFE_4CF3_90C6_17BF,
|
||||
0x9C45_0587_0A36_87A9, 0xA34E_E4CD_9B5C_EA62, 0xE252_C712_28E2_5C3F, 0xDD59_2658_B988_31F4,
|
||||
0x606A_80AD_4F9F_3085, 0x5F61_61E7_DEF5_5D4E, 0x1E7D_4238_6D4B_EB13, 0x2176_A372_FC21_86D8,
|
||||
0xF6C2_A0F8_2E6B_F774, 0xC9C9_41B2_BF01_9ABF, 0x88D5_626D_0CBF_2CE2, 0xB7DE_8327_9DD5_4129,
|
||||
0x0AED_25D2_6BC2_4058, 0x35E6_C498_FAA8_2D93, 0x74FA_E747_4916_9BCE, 0x4BF1_060D_D87C_F605,
|
||||
0xE318_EB5C_F9EF_77C4, 0xDC13_0A16_6885_1A0F, 0x9D0F_29C9_DB3B_AC52, 0xA204_C883_4A51_C199,
|
||||
0x1F37_6E76_BC46_C0E8, 0x203C_8F3C_2D2C_AD23, 0x6120_ACE3_9E92_1B7E, 0x5E2B_4DA9_0FF8_76B5,
|
||||
0x899F_4E23_DDB2_0719, 0xB694_AF69_4CD8_6AD2, 0xF788_8CB6_FF66_DC8F, 0xC883_6DFC_6E0C_B144,
|
||||
0x75B0_CB09_981B_B035, 0x4ABB_2A43_0971_DDFE, 0x0BA7_099C_BACF_6BA3, 0x34AC_E8D6_2BA5_0668,
|
||||
0x3617_A1A2_B155_967E, 0x091C_40E8_203F_FBB5, 0x4800_6337_9381_4DE8, 0x770B_827D_02EB_2023,
|
||||
0xCA38_2488_F4FC_2152, 0xF533_C5C2_6596_4C99, 0xB42F_E61D_D628_FAC4, 0x8B24_0757_4742_970F,
|
||||
0x5C90_04DD_9508_E6A3, 0x639B_E597_0462_8B68, 0x2287_C648_B7DC_3D35, 0x1D8C_2702_26B6_50FE,
|
||||
0xA0BF_81F7_D0A1_518F, 0x9FB4_60BD_41CB_3C44, 0xDEA8_4362_F275_8A19, 0xE1A3_A228_631F_E7D2,
|
||||
0xDBDE_D18B_C794_AA35, 0xE4D5_30C1_56FE_C7FE, 0xA5C9_131E_E540_71A3, 0x9AC2_F254_742A_1C68,
|
||||
0x27F1_54A1_823D_1D19, 0x18FA_B5EB_1357_70D2, 0x59E6_9634_A0E9_C68F, 0x66ED_777E_3183_AB44,
|
||||
0xB159_74F4_E3C9_DAE8, 0x8E52_95BE_72A3_B723, 0xCF4E_B661_C11D_017E, 0xF045_572B_5077_6CB5,
|
||||
0x4D76_F1DE_A660_6DC4, 0x727D_1094_370A_000F, 0x3361_334B_84B4_B652, 0x0C6A_D201_15DE_DB99,
|
||||
0x0ED1_9B75_8F2E_4B8F, 0x31DA_7A3F_1E44_2644, 0x70C6_59E0_ADFA_9019, 0x4FCD_B8AA_3C90_FDD2,
|
||||
0xF2FE_1E5F_CA87_FCA3, 0xCDF5_FF15_5BED_9168, 0x8CE9_DCCA_E853_2735, 0xB3E2_3D80_7939_4AFE,
|
||||
0x6456_3E0A_AB73_3B52, 0x5B5D_DF40_3A19_5699, 0x1A41_FC9F_89A7_E0C4, 0x254A_1DD5_18CD_8D0F,
|
||||
0x9879_BB20_EEDA_8C7E, 0xA772_5A6A_7FB0_E1B5, 0xE66E_79B5_CC0E_57E8, 0xD965_98FF_5D64_3A23,
|
||||
0x9294_9EF2_8518_CC26, 0xAD9F_7FB8_1472_A1ED, 0xEC83_5C67_A7CC_17B0, 0xD388_BD2D_36A6_7A7B,
|
||||
0x6EBB_1BD8_C0B1_7B0A, 0x51B0_FA92_51DB_16C1, 0x10AC_D94D_E265_A09C, 0x2FA7_3807_730F_CD57,
|
||||
0xF813_3B8D_A145_BCFB, 0xC718_DAC7_302F_D130, 0x8604_F918_8391_676D, 0xB90F_1852_12FB_0AA6,
|
||||
0x043C_BEA7_E4EC_0BD7, 0x3B37_5FED_7586_661C, 0x7A2B_7C32_C638_D041, 0x4520_9D78_5752_BD8A,
|
||||
0x479B_D40C_CDA2_2D9C, 0x7890_3546_5CC8_4057, 0x398C_1699_EF76_F60A, 0x0687_F7D3_7E1C_9BC1,
|
||||
0xBBB4_5126_880B_9AB0, 0x84BF_B06C_1961_F77B, 0xC5A3_93B3_AADF_4126, 0xFAA8_72F9_3BB5_2CED,
|
||||
0x2D1C_7173_E9FF_5D41, 0x1217_9039_7895_308A, 0x530B_B3E6_CB2B_86D7, 0x6C00_52AC_5A41_EB1C,
|
||||
0xD133_F459_AC56_EA6D, 0xEE38_1513_3D3C_87A6, 0xAF24_36CC_8E82_31FB, 0x902F_D786_1FE8_5C30,
|
||||
0xAA52_A425_BB63_11D7, 0x9559_456F_2A09_7C1C, 0xD445_66B0_99B7_CA41, 0xEB4E_87FA_08DD_A78A,
|
||||
0x567D_210F_FECA_A6FB, 0x6976_C045_6FA0_CB30, 0x286A_E39A_DC1E_7D6D, 0x1761_02D0_4D74_10A6,
|
||||
0xC0D5_015A_9F3E_610A, 0xFFDE_E010_0E54_0CC1, 0xBEC2_C3CF_BDEA_BA9C, 0x81C9_2285_2C80_D757,
|
||||
0x3CFA_8470_DA97_D626, 0x03F1_653A_4BFD_BBED, 0x42ED_46E5_F843_0DB0, 0x7DE6_A7AF_6929_607B,
|
||||
0x7F5D_EEDB_F3D9_F06D, 0x4056_0F91_62B3_9DA6, 0x014A_2C4E_D10D_2BFB, 0x3E41_CD04_4067_4630,
|
||||
0x8372_6BF1_B670_4741, 0xBC79_8ABB_271A_2A8A, 0xFD65_A964_94A4_9CD7, 0xC26E_482E_05CE_F11C,
|
||||
0x15DA_4BA4_D784_80B0, 0x2AD1_AAEE_46EE_ED7B, 0x6BCD_8931_F550_5B26, 0x54C6_687B_643A_36ED,
|
||||
0xE9F5_CE8E_922D_379C, 0xD6FE_2FC4_0347_5A57, 0x97E2_0C1B_B0F9_EC0A, 0xA8E9_ED51_2193_81C1,
|
||||
],[
|
||||
0x0000_0000_0000_0000, 0x1DEE_8A5E_222C_A1DC, 0x3BDD_14BC_4459_43B8, 0x2633_9EE2_6675_E264,
|
||||
0x77BA_2978_88B2_8770, 0x6A54_A326_AA9E_26AC, 0x4C67_3DC4_CCEB_C4C8, 0x5189_B79A_EEC7_6514,
|
||||
0xEF74_52F1_1165_0EE0, 0xF29A_D8AF_3349_AF3C, 0xD4A9_464D_553C_4D58, 0xC947_CC13_7710_EC84,
|
||||
0x98CE_7B89_99D7_8990, 0x8520_F1D7_BBFB_284C, 0xA313_6F35_DD8E_CA28, 0xBEFD_E56B_FFA2_6BF4,
|
||||
0x4C30_0AC9_8DC4_0345, 0x51DE_8097_AFE8_A299, 0x77ED_1E75_C99D_40FD, 0x6A03_942B_EBB1_E121,
|
||||
0x3B8A_23B1_0576_8435, 0x2664_A9EF_275A_25E9, 0x0057_370D_412F_C78D, 0x1DB9_BD53_6303_6651,
|
||||
0xA344_5838_9CA1_0DA5, 0xBEAA_D266_BE8D_AC79, 0x9899_4C84_D8F8_4E1D, 0x8577_C6DA_FAD4_EFC1,
|
||||
0xD4FE_7140_1413_8AD5, 0xC910_FB1E_363F_2B09, 0xEF23_65FC_504A_C96D, 0xF2CD_EFA2_7266_68B1,
|
||||
0x9860_1593_1B88_068A, 0x858E_9FCD_39A4_A756, 0xA3BD_012F_5FD1_4532, 0xBE53_8B71_7DFD_E4EE,
|
||||
0xEFDA_3CEB_933A_81FA, 0xF234_B6B5_B116_2026, 0xD407_2857_D763_C242, 0xC9E9_A209_F54F_639E,
|
||||
0x7714_4762_0AED_086A, 0x6AFA_CD3C_28C1_A9B6, 0x4CC9_53DE_4EB4_4BD2, 0x5127_D980_6C98_EA0E,
|
||||
0x00AE_6E1A_825F_8F1A, 0x1D40_E444_A073_2EC6, 0x3B73_7AA6_C606_CCA2, 0x269D_F0F8_E42A_6D7E,
|
||||
0xD450_1F5A_964C_05CF, 0xC9BE_9504_B460_A413, 0xEF8D_0BE6_D215_4677, 0xF263_81B8_F039_E7AB,
|
||||
0xA3EA_3622_1EFE_82BF, 0xBE04_BC7C_3CD2_2363, 0x9837_229E_5AA7_C107, 0x85D9_A8C0_788B_60DB,
|
||||
0x3B24_4DAB_8729_0B2F, 0x26CA_C7F5_A505_AAF3, 0x00F9_5917_C370_4897, 0x1D17_D349_E15C_E94B,
|
||||
0x4C9E_64D3_0F9B_8C5F, 0x5170_EE8D_2DB7_2D83, 0x7743_706F_4BC2_CFE7, 0x6AAD_FA31_69EE_6E3B,
|
||||
0xA218_840D_981E_1391, 0xBFF6_0E53_BA32_B24D, 0x99C5_90B1_DC47_5029, 0x842B_1AEF_FE6B_F1F5,
|
||||
0xD5A2_AD75_10AC_94E1, 0xC84C_272B_3280_353D, 0xEE7F_B9C9_54F5_D759, 0xF391_3397_76D9_7685,
|
||||
0x4D6C_D6FC_897B_1D71, 0x5082_5CA2_AB57_BCAD, 0x76B1_C240_CD22_5EC9, 0x6B5F_481E_EF0E_FF15,
|
||||
0x3AD6_FF84_01C9_9A01, 0x2738_75DA_23E5_3BDD, 0x010B_EB38_4590_D9B9, 0x1CE5_6166_67BC_7865,
|
||||
0xEE28_8EC4_15DA_10D4, 0xF3C6_049A_37F6_B108, 0xD5F5_9A78_5183_536C, 0xC81B_1026_73AF_F2B0,
|
||||
0x9992_A7BC_9D68_97A4, 0x847C_2DE2_BF44_3678, 0xA24F_B300_D931_D41C, 0xBFA1_395E_FB1D_75C0,
|
||||
0x015C_DC35_04BF_1E34, 0x1CB2_566B_2693_BFE8, 0x3A81_C889_40E6_5D8C, 0x276F_42D7_62CA_FC50,
|
||||
0x76E6_F54D_8C0D_9944, 0x6B08_7F13_AE21_3898, 0x4D3B_E1F1_C854_DAFC, 0x50D5_6BAF_EA78_7B20,
|
||||
0x3A78_919E_8396_151B, 0x2796_1BC0_A1BA_B4C7, 0x01A5_8522_C7CF_56A3, 0x1C4B_0F7C_E5E3_F77F,
|
||||
0x4DC2_B8E6_0B24_926B, 0x502C_32B8_2908_33B7, 0x761F_AC5A_4F7D_D1D3, 0x6BF1_2604_6D51_700F,
|
||||
0xD50C_C36F_92F3_1BFB, 0xC8E2_4931_B0DF_BA27, 0xEED1_D7D3_D6AA_5843, 0xF33F_5D8D_F486_F99F,
|
||||
0xA2B6_EA17_1A41_9C8B, 0xBF58_6049_386D_3D57, 0x996B_FEAB_5E18_DF33, 0x8485_74F5_7C34_7EEF,
|
||||
0x7648_9B57_0E52_165E, 0x6BA6_1109_2C7E_B782, 0x4D95_8FEB_4A0B_55E6, 0x507B_05B5_6827_F43A,
|
||||
0x01F2_B22F_86E0_912E, 0x1C1C_3871_A4CC_30F2, 0x3A2F_A693_C2B9_D296, 0x27C1_2CCD_E095_734A,
|
||||
0x993C_C9A6_1F37_18BE, 0x84D2_43F8_3D1B_B962, 0xA2E1_DD1A_5B6E_5B06, 0xBF0F_5744_7942_FADA,
|
||||
0xEE86_E0DE_9785_9FCE, 0xF368_6A80_B5A9_3E12, 0xD55B_F462_D3DC_DC76, 0xC8B5_7E3C_F1F0_7DAA,
|
||||
0xD6E9_A730_9F32_39A7, 0xCB07_2D6E_BD1E_987B, 0xED34_B38C_DB6B_7A1F, 0xF0DA_39D2_F947_DBC3,
|
||||
0xA153_8E48_1780_BED7, 0xBCBD_0416_35AC_1F0B, 0x9A8E_9AF4_53D9_FD6F, 0x8760_10AA_71F5_5CB3,
|
||||
0x399D_F5C1_8E57_3747, 0x2473_7F9F_AC7B_969B, 0x0240_E17D_CA0E_74FF, 0x1FAE_6B23_E822_D523,
|
||||
0x4E27_DCB9_06E5_B037, 0x53C9_56E7_24C9_11EB, 0x75FA_C805_42BC_F38F, 0x6814_425B_6090_5253,
|
||||
0x9AD9_ADF9_12F6_3AE2, 0x8737_27A7_30DA_9B3E, 0xA104_B945_56AF_795A, 0xBCEA_331B_7483_D886,
|
||||
0xED63_8481_9A44_BD92, 0xF08D_0EDF_B868_1C4E, 0xD6BE_903D_DE1D_FE2A, 0xCB50_1A63_FC31_5FF6,
|
||||
0x75AD_FF08_0393_3402, 0x6843_7556_21BF_95DE, 0x4E70_EBB4_47CA_77BA, 0x539E_61EA_65E6_D666,
|
||||
0x0217_D670_8B21_B372, 0x1FF9_5C2E_A90D_12AE, 0x39CA_C2CC_CF78_F0CA, 0x2424_4892_ED54_5116,
|
||||
0x4E89_B2A3_84BA_3F2D, 0x5367_38FD_A696_9EF1, 0x7554_A61F_C0E3_7C95, 0x68BA_2C41_E2CF_DD49,
|
||||
0x3933_9BDB_0C08_B85D, 0x24DD_1185_2E24_1981, 0x02EE_8F67_4851_FBE5, 0x1F00_0539_6A7D_5A39,
|
||||
0xA1FD_E052_95DF_31CD, 0xBC13_6A0C_B7F3_9011, 0x9A20_F4EE_D186_7275, 0x87CE_7EB0_F3AA_D3A9,
|
||||
0xD647_C92A_1D6D_B6BD, 0xCBA9_4374_3F41_1761, 0xED9A_DD96_5934_F505, 0xF074_57C8_7B18_54D9,
|
||||
0x02B9_B86A_097E_3C68, 0x1F57_3234_2B52_9DB4, 0x3964_ACD6_4D27_7FD0, 0x248A_2688_6F0B_DE0C,
|
||||
0x7503_9112_81CC_BB18, 0x68ED_1B4C_A3E0_1AC4, 0x4EDE_85AE_C595_F8A0, 0x5330_0FF0_E7B9_597C,
|
||||
0xEDCD_EA9B_181B_3288, 0xF023_60C5_3A37_9354, 0xD610_FE27_5C42_7130, 0xCBFE_7479_7E6E_D0EC,
|
||||
0x9A77_C3E3_90A9_B5F8, 0x8799_49BD_B285_1424, 0xA1AA_D75F_D4F0_F640, 0xBC44_5D01_F6DC_579C,
|
||||
0x74F1_233D_072C_2A36, 0x691F_A963_2500_8BEA, 0x4F2C_3781_4375_698E, 0x52C2_BDDF_6159_C852,
|
||||
0x034B_0A45_8F9E_AD46, 0x1EA5_801B_ADB2_0C9A, 0x3896_1EF9_CBC7_EEFE, 0x2578_94A7_E9EB_4F22,
|
||||
0x9B85_71CC_1649_24D6, 0x866B_FB92_3465_850A, 0xA058_6570_5210_676E, 0xBDB6_EF2E_703C_C6B2,
|
||||
0xEC3F_58B4_9EFB_A3A6, 0xF1D1_D2EA_BCD7_027A, 0xD7E2_4C08_DAA2_E01E, 0xCA0C_C656_F88E_41C2,
|
||||
0x38C1_29F4_8AE8_2973, 0x252F_A3AA_A8C4_88AF, 0x031C_3D48_CEB1_6ACB, 0x1EF2_B716_EC9D_CB17,
|
||||
0x4F7B_008C_025A_AE03, 0x5295_8AD2_2076_0FDF, 0x74A6_1430_4603_EDBB, 0x6948_9E6E_642F_4C67,
|
||||
0xD7B5_7B05_9B8D_2793, 0xCA5B_F15B_B9A1_864F, 0xEC68_6FB9_DFD4_642B, 0xF186_E5E7_FDF8_C5F7,
|
||||
0xA00F_527D_133F_A0E3, 0xBDE1_D823_3113_013F, 0x9BD2_46C1_5766_E35B, 0x863C_CC9F_754A_4287,
|
||||
0xEC91_36AE_1CA4_2CBC, 0xF17F_BCF0_3E88_8D60, 0xD74C_2212_58FD_6F04, 0xCAA2_A84C_7AD1_CED8,
|
||||
0x9B2B_1FD6_9416_ABCC, 0x86C5_9588_B63A_0A10, 0xA0F6_0B6A_D04F_E874, 0xBD18_8134_F263_49A8,
|
||||
0x03E5_645F_0DC1_225C, 0x1E0B_EE01_2FED_8380, 0x3838_70E3_4998_61E4, 0x25D6_FABD_6BB4_C038,
|
||||
0x745F_4D27_8573_A52C, 0x69B1_C779_A75F_04F0, 0x4F82_599B_C12A_E694, 0x526C_D3C5_E306_4748,
|
||||
0xA0A1_3C67_9160_2FF9, 0xBD4F_B639_B34C_8E25, 0x9B7C_28DB_D539_6C41, 0x8692_A285_F715_CD9D,
|
||||
0xD71B_151F_19D2_A889, 0xCAF5_9F41_3BFE_0955, 0xECC6_01A3_5D8B_EB31, 0xF128_8BFD_7FA7_4AED,
|
||||
0x4FD5_6E96_8005_2119, 0x523B_E4C8_A229_80C5, 0x7408_7A2A_C45C_62A1, 0x69E6_F074_E670_C37D,
|
||||
0x386F_47EE_08B7_A669, 0x2581_CDB0_2A9B_07B5, 0x03B2_5352_4CEE_E5D1, 0x1E5C_D90C_6EC2_440D,
|
||||
],[
|
||||
0x0000_0000_0000_0000, 0x5C2D_7760_33C4_205E, 0xB85A_EEC0_6788_40BC, 0xE477_99A0_544C_60E2,
|
||||
0xE26D_72AB_601E_9FFD, 0xBE40_05CB_53DA_BFA3, 0x5A37_9C6B_0796_DF41, 0x061A_EB0B_3452_FF1F,
|
||||
0x5602_4A7D_6F33_217F, 0x0A2F_3D1D_5CF7_0121, 0xEE58_A4BD_08BB_61C3, 0xB275_D3DD_3B7F_419D,
|
||||
0xB46F_38D6_0F2D_BE82, 0xE842_4FB6_3CE9_9EDC, 0x0C35_D616_68A5_FE3E, 0x5018_A176_5B61_DE60,
|
||||
0xAC04_94FA_DE66_42FE, 0xF029_E39A_EDA2_62A0, 0x145E_7A3A_B9EE_0242, 0x4873_0D5A_8A2A_221C,
|
||||
0x4E69_E651_BE78_DD03, 0x1244_9131_8DBC_FD5D, 0xF633_0891_D9F0_9DBF, 0xAA1E_7FF1_EA34_BDE1,
|
||||
0xFA06_DE87_B155_6381, 0xA62B_A9E7_8291_43DF, 0x425C_3047_D6DD_233D, 0x1E71_4727_E519_0363,
|
||||
0x186B_AC2C_D14B_FC7C, 0x4446_DB4C_E28F_DC22, 0xA031_42EC_B6C3_BCC0, 0xFC1C_358C_8507_9C9E,
|
||||
0xCAD1_86DE_13C2_9B79, 0x96FC_F1BE_2006_BB27, 0x728B_681E_744A_DBC5, 0x2EA6_1F7E_478E_FB9B,
|
||||
0x28BC_F475_73DC_0484, 0x7491_8315_4018_24DA, 0x90E6_1AB5_1454_4438, 0xCCCB_6DD5_2790_6466,
|
||||
0x9CD3_CCA3_7CF1_BA06, 0xC0FE_BBC3_4F35_9A58, 0x2489_2263_1B79_FABA, 0x78A4_5503_28BD_DAE4,
|
||||
0x7EBE_BE08_1CEF_25FB, 0x2293_C968_2F2B_05A5, 0xC6E4_50C8_7B67_6547, 0x9AC9_27A8_48A3_4519,
|
||||
0x66D5_1224_CDA4_D987, 0x3AF8_6544_FE60_F9D9, 0xDE8F_FCE4_AA2C_993B, 0x82A2_8B84_99E8_B965,
|
||||
0x84B8_608F_ADBA_467A, 0xD895_17EF_9E7E_6624, 0x3CE2_8E4F_CA32_06C6, 0x60CF_F92F_F9F6_2698,
|
||||
0x30D7_5859_A297_F8F8, 0x6CFA_2F39_9153_D8A6, 0x888D_B699_C51F_B844, 0xD4A0_C1F9_F6DB_981A,
|
||||
0xD2BA_2AF2_C289_6705, 0x8E97_5D92_F14D_475B, 0x6AE0_C432_A501_27B9, 0x36CD_B352_96C5_07E7,
|
||||
0x077B_A297_888B_2877, 0x5B56_D5F7_BB4F_0829, 0xBF21_4C57_EF03_68CB, 0xE30C_3B37_DCC7_4895,
|
||||
0xE516_D03C_E895_B78A, 0xB93B_A75C_DB51_97D4, 0x5D4C_3EFC_8F1D_F736, 0x0161_499C_BCD9_D768,
|
||||
0x5179_E8EA_E7B8_0908, 0x0D54_9F8A_D47C_2956, 0xE923_062A_8030_49B4, 0xB50E_714A_B3F4_69EA,
|
||||
0xB314_9A41_87A6_96F5, 0xEF39_ED21_B462_B6AB, 0x0B4E_7481_E02E_D649, 0x5763_03E1_D3EA_F617,
|
||||
0xAB7F_366D_56ED_6A89, 0xF752_410D_6529_4AD7, 0x1325_D8AD_3165_2A35, 0x4F08_AFCD_02A1_0A6B,
|
||||
0x4912_44C6_36F3_F574, 0x153F_33A6_0537_D52A, 0xF148_AA06_517B_B5C8, 0xAD65_DD66_62BF_9596,
|
||||
0xFD7D_7C10_39DE_4BF6, 0xA150_0B70_0A1A_6BA8, 0x4527_92D0_5E56_0B4A, 0x190A_E5B0_6D92_2B14,
|
||||
0x1F10_0EBB_59C0_D40B, 0x433D_79DB_6A04_F455, 0xA74A_E07B_3E48_94B7, 0xFB67_971B_0D8C_B4E9,
|
||||
0xCDAA_2449_9B49_B30E, 0x9187_5329_A88D_9350, 0x75F0_CA89_FCC1_F3B2, 0x29DD_BDE9_CF05_D3EC,
|
||||
0x2FC7_56E2_FB57_2CF3, 0x73EA_2182_C893_0CAD, 0x979D_B822_9CDF_6C4F, 0xCBB0_CF42_AF1B_4C11,
|
||||
0x9BA8_6E34_F47A_9271, 0xC785_1954_C7BE_B22F, 0x23F2_80F4_93F2_D2CD, 0x7FDF_F794_A036_F293,
|
||||
0x79C5_1C9F_9464_0D8C, 0x25E8_6BFF_A7A0_2DD2, 0xC19F_F25F_F3EC_4D30, 0x9DB2_853F_C028_6D6E,
|
||||
0x61AE_B0B3_452F_F1F0, 0x3D83_C7D3_76EB_D1AE, 0xD9F4_5E73_22A7_B14C, 0x85D9_2913_1163_9112,
|
||||
0x83C3_C218_2531_6E0D, 0xDFEE_B578_16F5_4E53, 0x3B99_2CD8_42B9_2EB1, 0x67B4_5BB8_717D_0EEF,
|
||||
0x37AC_FACE_2A1C_D08F, 0x6B81_8DAE_19D8_F0D1, 0x8FF6_140E_4D94_9033, 0xD3DB_636E_7E50_B06D,
|
||||
0xD5C1_8865_4A02_4F72, 0x89EC_FF05_79C6_6F2C, 0x6D9B_66A5_2D8A_0FCE, 0x31B6_11C5_1E4E_2F90,
|
||||
0x0EF7_452F_1116_50EE, 0x52DA_324F_22D2_70B0, 0xB6AD_ABEF_769E_1052, 0xEA80_DC8F_455A_300C,
|
||||
0xEC9A_3784_7108_CF13, 0xB0B7_40E4_42CC_EF4D, 0x54C0_D944_1680_8FAF, 0x08ED_AE24_2544_AFF1,
|
||||
0x58F5_0F52_7E25_7191, 0x04D8_7832_4DE1_51CF, 0xE0AF_E192_19AD_312D, 0xBC82_96F2_2A69_1173,
|
||||
0xBA98_7DF9_1E3B_EE6C, 0xE6B5_0A99_2DFF_CE32, 0x02C2_9339_79B3_AED0, 0x5EEF_E459_4A77_8E8E,
|
||||
0xA2F3_D1D5_CF70_1210, 0xFEDE_A6B5_FCB4_324E, 0x1AA9_3F15_A8F8_52AC, 0x4684_4875_9B3C_72F2,
|
||||
0x409E_A37E_AF6E_8DED, 0x1CB3_D41E_9CAA_ADB3, 0xF8C4_4DBE_C8E6_CD51, 0xA4E9_3ADE_FB22_ED0F,
|
||||
0xF4F1_9BA8_A043_336F, 0xA8DC_ECC8_9387_1331, 0x4CAB_7568_C7CB_73D3, 0x1086_0208_F40F_538D,
|
||||
0x169C_E903_C05D_AC92, 0x4AB1_9E63_F399_8CCC, 0xAEC6_07C3_A7D5_EC2E, 0xF2EB_70A3_9411_CC70,
|
||||
0xC426_C3F1_02D4_CB97, 0x980B_B491_3110_EBC9, 0x7C7C_2D31_655C_8B2B, 0x2051_5A51_5698_AB75,
|
||||
0x264B_B15A_62CA_546A, 0x7A66_C63A_510E_7434, 0x9E11_5F9A_0542_14D6, 0xC23C_28FA_3686_3488,
|
||||
0x9224_898C_6DE7_EAE8, 0xCE09_FEEC_5E23_CAB6, 0x2A7E_674C_0A6F_AA54, 0x7653_102C_39AB_8A0A,
|
||||
0x7049_FB27_0DF9_7515, 0x2C64_8C47_3E3D_554B, 0xC813_15E7_6A71_35A9, 0x943E_6287_59B5_15F7,
|
||||
0x6822_570B_DCB2_8969, 0x340F_206B_EF76_A937, 0xD078_B9CB_BB3A_C9D5, 0x8C55_CEAB_88FE_E98B,
|
||||
0x8A4F_25A0_BCAC_1694, 0xD662_52C0_8F68_36CA, 0x3215_CB60_DB24_5628, 0x6E38_BC00_E8E0_7676,
|
||||
0x3E20_1D76_B381_A816, 0x620D_6A16_8045_8848, 0x867A_F3B6_D409_E8AA, 0xDA57_84D6_E7CD_C8F4,
|
||||
0xDC4D_6FDD_D39F_37EB, 0x8060_18BD_E05B_17B5, 0x6417_811D_B417_7757, 0x383A_F67D_87D3_5709,
|
||||
0x098C_E7B8_999D_7899, 0x55A1_90D8_AA59_58C7, 0xB1D6_0978_FE15_3825, 0xEDFB_7E18_CDD1_187B,
|
||||
0xEBE1_9513_F983_E764, 0xB7CC_E273_CA47_C73A, 0x53BB_7BD3_9E0B_A7D8, 0x0F96_0CB3_ADCF_8786,
|
||||
0x5F8E_ADC5_F6AE_59E6, 0x03A3_DAA5_C56A_79B8, 0xE7D4_4305_9126_195A, 0xBBF9_3465_A2E2_3904,
|
||||
0xBDE3_DF6E_96B0_C61B, 0xE1CE_A80E_A574_E645, 0x05B9_31AE_F138_86A7, 0x5994_46CE_C2FC_A6F9,
|
||||
0xA588_7342_47FB_3A67, 0xF9A5_0422_743F_1A39, 0x1DD2_9D82_2073_7ADB, 0x41FF_EAE2_13B7_5A85,
|
||||
0x47E5_01E9_27E5_A59A, 0x1BC8_7689_1421_85C4, 0xFFBF_EF29_406D_E526, 0xA392_9849_73A9_C578,
|
||||
0xF38A_393F_28C8_1B18, 0xAFA7_4E5F_1B0C_3B46, 0x4BD0_D7FF_4F40_5BA4, 0x17FD_A09F_7C84_7BFA,
|
||||
0x11E7_4B94_48D6_84E5, 0x4DCA_3CF4_7B12_A4BB, 0xA9BD_A554_2F5E_C459, 0xF590_D234_1C9A_E407,
|
||||
0xC35D_6166_8A5F_E3E0, 0x9F70_1606_B99B_C3BE, 0x7B07_8FA6_EDD7_A35C, 0x272A_F8C6_DE13_8302,
|
||||
0x2130_13CD_EA41_7C1D, 0x7D1D_64AD_D985_5C43, 0x996A_FD0D_8DC9_3CA1, 0xC547_8A6D_BE0D_1CFF,
|
||||
0x955F_2B1B_E56C_C29F, 0xC972_5C7B_D6A8_E2C1, 0x2D05_C5DB_82E4_8223, 0x7128_B2BB_B120_A27D,
|
||||
0x7732_59B0_8572_5D62, 0x2B1F_2ED0_B6B6_7D3C, 0xCF68_B770_E2FA_1DDE, 0x9345_C010_D13E_3D80,
|
||||
0x6F59_F59C_5439_A11E, 0x3374_82FC_67FD_8140, 0xD703_1B5C_33B1_E1A2, 0x8B2E_6C3C_0075_C1FC,
|
||||
0x8D34_8737_3427_3EE3, 0xD119_F057_07E3_1EBD, 0x356E_69F7_53AF_7E5F, 0x6943_1E97_606B_5E01,
|
||||
0x395B_BFE1_3B0A_8061, 0x6576_C881_08CE_A03F, 0x8101_5121_5C82_C0DD, 0xDD2C_2641_6F46_E083,
|
||||
0xDB36_CD4A_5B14_1F9C, 0x871B_BA2A_68D0_3FC2, 0x636C_238A_3C9C_5F20, 0x3F41_54EA_0F58_7F7E,
|
||||
],[
|
||||
0x0000_0000_0000_0000, 0x6184_D55F_7212_67C6, 0xC309_AABE_E424_CF8C, 0xA28D_7FE1_9636_A84A,
|
||||
0x14CB_FA56_6747_819D, 0x754F_2F09_1555_E65B, 0xD7C2_50E8_8363_4E11, 0xB646_85B7_F171_29D7,
|
||||
0x2997_F4AC_CE8F_033A, 0x4813_21F3_BC9D_64FC, 0xEA9E_5E12_2AAB_CCB6, 0x8B1A_8B4D_58B9_AB70,
|
||||
0x3D5C_0EFA_A9C8_82A7, 0x5CD8_DBA5_DBDA_E561, 0xFE55_A444_4DEC_4D2B, 0x9FD1_711B_3FFE_2AED,
|
||||
0x532F_E959_9D1E_0674, 0x32AB_3C06_EF0C_61B2, 0x9026_43E7_793A_C9F8, 0xF1A2_96B8_0B28_AE3E,
|
||||
0x47E4_130F_FA59_87E9, 0x2660_C650_884B_E02F, 0x84ED_B9B1_1E7D_4865, 0xE569_6CEE_6C6F_2FA3,
|
||||
0x7AB8_1DF5_5391_054E, 0x1B3C_C8AA_2183_6288, 0xB9B1_B74B_B7B5_CAC2, 0xD835_6214_C5A7_AD04,
|
||||
0x6E73_E7A3_34D6_84D3, 0x0FF7_32FC_46C4_E315, 0xAD7A_4D1D_D0F2_4B5F, 0xCCFE_9842_A2E0_2C99,
|
||||
0xA65F_D2B3_3A3C_0CE8, 0xC7DB_07EC_482E_6B2E, 0x6556_780D_DE18_C364, 0x04D2_AD52_AC0A_A4A2,
|
||||
0xB294_28E5_5D7B_8D75, 0xD310_FDBA_2F69_EAB3, 0x719D_825B_B95F_42F9, 0x1019_5704_CB4D_253F,
|
||||
0x8FC8_261F_F4B3_0FD2, 0xEE4C_F340_86A1_6814, 0x4CC1_8CA1_1097_C05E, 0x2D45_59FE_6285_A798,
|
||||
0x9B03_DC49_93F4_8E4F, 0xFA87_0916_E1E6_E989, 0x580A_76F7_77D0_41C3, 0x398E_A3A8_05C2_2605,
|
||||
0xF570_3BEA_A722_0A9C, 0x94F4_EEB5_D530_6D5A, 0x3679_9154_4306_C510, 0x57FD_440B_3114_A2D6,
|
||||
0xE1BB_C1BC_C065_8B01, 0x803F_14E3_B277_ECC7, 0x22B2_6B02_2441_448D, 0x4336_BE5D_5653_234B,
|
||||
0xDCE7_CF46_69AD_09A6, 0xBD63_1A19_1BBF_6E60, 0x1FEE_65F8_8D89_C62A, 0x7E6A_B0A7_FF9B_A1EC,
|
||||
0xC82C_3510_0EEA_883B, 0xA9A8_E04F_7CF8_EFFD, 0x0B25_9FAE_EACE_47B7, 0x6AA1_4AF1_98DC_2071,
|
||||
0xDE67_0A4D_DB76_0755, 0xBFE3_DF12_A964_6093, 0x1D6E_A0F3_3F52_C8D9, 0x7CEA_75AC_4D40_AF1F,
|
||||
0xCAAC_F01B_BC31_86C8, 0xAB28_2544_CE23_E10E, 0x09A5_5AA5_5815_4944, 0x6821_8FFA_2A07_2E82,
|
||||
0xF7F0_FEE1_15F9_046F, 0x9674_2BBE_67EB_63A9, 0x34F9_545F_F1DD_CBE3, 0x557D_8100_83CF_AC25,
|
||||
0xE33B_04B7_72BE_85F2, 0x82BF_D1E8_00AC_E234, 0x2032_AE09_969A_4A7E, 0x41B6_7B56_E488_2DB8,
|
||||
0x8D48_E314_4668_0121, 0xECCC_364B_347A_66E7, 0x4E41_49AA_A24C_CEAD, 0x2FC5_9CF5_D05E_A96B,
|
||||
0x9983_1942_212F_80BC, 0xF807_CC1D_533D_E77A, 0x5A8A_B3FC_C50B_4F30, 0x3B0E_66A3_B719_28F6,
|
||||
0xA4DF_17B8_88E7_021B, 0xC55B_C2E7_FAF5_65DD, 0x67D6_BD06_6CC3_CD97, 0x0652_6859_1ED1_AA51,
|
||||
0xB014_EDEE_EFA0_8386, 0xD190_38B1_9DB2_E440, 0x731D_4750_0B84_4C0A, 0x1299_920F_7996_2BCC,
|
||||
0x7838_D8FE_E14A_0BBD, 0x19BC_0DA1_9358_6C7B, 0xBB31_7240_056E_C431, 0xDAB5_A71F_777C_A3F7,
|
||||
0x6CF3_22A8_860D_8A20, 0x0D77_F7F7_F41F_EDE6, 0xAFFA_8816_6229_45AC, 0xCE7E_5D49_103B_226A,
|
||||
0x51AF_2C52_2FC5_0887, 0x302B_F90D_5DD7_6F41, 0x92A6_86EC_CBE1_C70B, 0xF322_53B3_B9F3_A0CD,
|
||||
0x4564_D604_4882_891A, 0x24E0_035B_3A90_EEDC, 0x866D_7CBA_ACA6_4696, 0xE7E9_A9E5_DEB4_2150,
|
||||
0x2B17_31A7_7C54_0DC9, 0x4A93_E4F8_0E46_6A0F, 0xE81E_9B19_9870_C245, 0x899A_4E46_EA62_A583,
|
||||
0x3FDC_CBF1_1B13_8C54, 0x5E58_1EAE_6901_EB92, 0xFCD5_614F_FF37_43D8, 0x9D51_B410_8D25_241E,
|
||||
0x0280_C50B_B2DB_0EF3, 0x6304_1054_C0C9_6935, 0xC189_6FB5_56FF_C17F, 0xA00D_BAEA_24ED_A6B9,
|
||||
0x164B_3F5D_D59C_8F6E, 0x77CF_EA02_A78E_E8A8, 0xD542_95E3_31B8_40E2, 0xB4C6_40BC_43AA_2724,
|
||||
0x2E16_BBB0_19E2_102F, 0x4F92_6EEF_6BF0_77E9, 0xED1F_110E_FDC6_DFA3, 0x8C9B_C451_8FD4_B865,
|
||||
0x3ADD_41E6_7EA5_91B2, 0x5B59_94B9_0CB7_F674, 0xF9D4_EB58_9A81_5E3E, 0x9850_3E07_E893_39F8,
|
||||
0x0781_4F1C_D76D_1315, 0x6605_9A43_A57F_74D3, 0xC488_E5A2_3349_DC99, 0xA50C_30FD_415B_BB5F,
|
||||
0x134A_B54A_B02A_9288, 0x72CE_6015_C238_F54E, 0xD043_1FF4_540E_5D04, 0xB1C7_CAAB_261C_3AC2,
|
||||
0x7D39_52E9_84FC_165B, 0x1CBD_87B6_F6EE_719D, 0xBE30_F857_60D8_D9D7, 0xDFB4_2D08_12CA_BE11,
|
||||
0x69F2_A8BF_E3BB_97C6, 0x0876_7DE0_91A9_F000, 0xAAFB_0201_079F_584A, 0xCB7F_D75E_758D_3F8C,
|
||||
0x54AE_A645_4A73_1561, 0x352A_731A_3861_72A7, 0x97A7_0CFB_AE57_DAED, 0xF623_D9A4_DC45_BD2B,
|
||||
0x4065_5C13_2D34_94FC, 0x21E1_894C_5F26_F33A, 0x836C_F6AD_C910_5B70, 0xE2E8_23F2_BB02_3CB6,
|
||||
0x8849_6903_23DE_1CC7, 0xE9CD_BC5C_51CC_7B01, 0x4B40_C3BD_C7FA_D34B, 0x2AC4_16E2_B5E8_B48D,
|
||||
0x9C82_9355_4499_9D5A, 0xFD06_460A_368B_FA9C, 0x5F8B_39EB_A0BD_52D6, 0x3E0F_ECB4_D2AF_3510,
|
||||
0xA1DE_9DAF_ED51_1FFD, 0xC05A_48F0_9F43_783B, 0x62D7_3711_0975_D071, 0x0353_E24E_7B67_B7B7,
|
||||
0xB515_67F9_8A16_9E60, 0xD491_B2A6_F804_F9A6, 0x761C_CD47_6E32_51EC, 0x1798_1818_1C20_362A,
|
||||
0xDB66_805A_BEC0_1AB3, 0xBAE2_5505_CCD2_7D75, 0x186F_2AE4_5AE4_D53F, 0x79EB_FFBB_28F6_B2F9,
|
||||
0xCFAD_7A0C_D987_9B2E, 0xAE29_AF53_AB95_FCE8, 0x0CA4_D0B2_3DA3_54A2, 0x6D20_05ED_4FB1_3364,
|
||||
0xF2F1_74F6_704F_1989, 0x9375_A1A9_025D_7E4F, 0x31F8_DE48_946B_D605, 0x507C_0B17_E679_B1C3,
|
||||
0xE63A_8EA0_1708_9814, 0x87BE_5BFF_651A_FFD2, 0x2533_241E_F32C_5798, 0x44B7_F141_813E_305E,
|
||||
0xF071_B1FD_C294_177A, 0x91F5_64A2_B086_70BC, 0x3378_1B43_26B0_D8F6, 0x52FC_CE1C_54A2_BF30,
|
||||
0xE4BA_4BAB_A5D3_96E7, 0x853E_9EF4_D7C1_F121, 0x27B3_E115_41F7_596B, 0x4637_344A_33E5_3EAD,
|
||||
0xD9E6_4551_0C1B_1440, 0xB862_900E_7E09_7386, 0x1AEF_EFEF_E83F_DBCC, 0x7B6B_3AB0_9A2D_BC0A,
|
||||
0xCD2D_BF07_6B5C_95DD, 0xACA9_6A58_194E_F21B, 0x0E24_15B9_8F78_5A51, 0x6FA0_C0E6_FD6A_3D97,
|
||||
0xA35E_58A4_5F8A_110E, 0xC2DA_8DFB_2D98_76C8, 0x6057_F21A_BBAE_DE82, 0x01D3_2745_C9BC_B944,
|
||||
0xB795_A2F2_38CD_9093, 0xD611_77AD_4ADF_F755, 0x749C_084C_DCE9_5F1F, 0x1518_DD13_AEFB_38D9,
|
||||
0x8AC9_AC08_9105_1234, 0xEB4D_7957_E317_75F2, 0x49C0_06B6_7521_DDB8, 0x2844_D3E9_0733_BA7E,
|
||||
0x9E02_565E_F642_93A9, 0xFF86_8301_8450_F46F, 0x5D0B_FCE0_1266_5C25, 0x3C8F_29BF_6074_3BE3,
|
||||
0x562E_634E_F8A8_1B92, 0x37AA_B611_8ABA_7C54, 0x9527_C9F0_1C8C_D41E, 0xF4A3_1CAF_6E9E_B3D8,
|
||||
0x42E5_9918_9FEF_9A0F, 0x2361_4C47_EDFD_FDC9, 0x81EC_33A6_7BCB_5583, 0xE068_E6F9_09D9_3245,
|
||||
0x7FB9_97E2_3627_18A8, 0x1E3D_42BD_4435_7F6E, 0xBCB0_3D5C_D203_D724, 0xDD34_E803_A011_B0E2,
|
||||
0x6B72_6DB4_5160_9935, 0x0AF6_B8EB_2372_FEF3, 0xA87B_C70A_B544_56B9, 0xC9FF_1255_C756_317F,
|
||||
0x0501_8A17_65B6_1DE6, 0x6485_5F48_17A4_7A20, 0xC608_20A9_8192_D26A, 0xA78C_F5F6_F380_B5AC,
|
||||
0x11CA_7041_02F1_9C7B, 0x704E_A51E_70E3_FBBD, 0xD2C3_DAFF_E6D5_53F7, 0xB347_0FA0_94C7_3431,
|
||||
0x2C96_7EBB_AB39_1EDC, 0x4D12_ABE4_D92B_791A, 0xEF9F_D405_4F1D_D150, 0x8E1B_015A_3D0F_B696,
|
||||
0x385D_84ED_CC7E_9F41, 0x59D9_51B2_BE6C_F887, 0xFB54_2E53_285A_50CD, 0x9AD0_FB0C_5A48_370B,
|
||||
],[
|
||||
0x0000_0000_0000_0000, 0x22EF_0D59_34F9_64EC, 0x45DE_1AB2_69F2_C9D8, 0x6731_17EB_5D0B_AD34,
|
||||
0x8BBC_3564_D3E5_93B0, 0xA953_383D_E71C_F75C, 0xCE62_2FD6_BA17_5A68, 0xEC8D_228F_8EEE_3E84,
|
||||
0x85A0_C5E2_08C5_39E5, 0xA74F_C8BB_3C3C_5D09, 0xC07E_DF50_6137_F03D, 0xE291_D209_55CE_94D1,
|
||||
0x0E1C_F086_DB20_AA55, 0x2CF3_FDDF_EFD9_CEB9, 0x4BC2_EA34_B2D2_638D, 0x692D_E76D_862B_0761,
|
||||
0x9999_24EF_BE84_6D4F, 0xBB76_29B6_8A7D_09A3, 0xDC47_3E5D_D776_A497, 0xFEA8_3304_E38F_C07B,
|
||||
0x1225_118B_6D61_FEFF, 0x30CA_1CD2_5998_9A13, 0x57FB_0B39_0493_3727, 0x7514_0660_306A_53CB,
|
||||
0x1C39_E10D_B641_54AA, 0x3ED6_EC54_82B8_3046, 0x59E7_FBBF_DFB3_9D72, 0x7B08_F6E6_EB4A_F99E,
|
||||
0x9785_D469_65A4_C71A, 0xB56A_D930_515D_A3F6, 0xD25B_CEDB_0C56_0EC2, 0xF0B4_C382_38AF_6A2E,
|
||||
0xA1EA_E6F4_D206_C41B, 0x8305_EBAD_E6FF_A0F7, 0xE434_FC46_BBF4_0DC3, 0xC6DB_F11F_8F0D_692F,
|
||||
0x2A56_D390_01E3_57AB, 0x08B9_DEC9_351A_3347, 0x6F88_C922_6811_9E73, 0x4D67_C47B_5CE8_FA9F,
|
||||
0x244A_2316_DAC3_FDFE, 0x06A5_2E4F_EE3A_9912, 0x6194_39A4_B331_3426, 0x437B_34FD_87C8_50CA,
|
||||
0xAFF6_1672_0926_6E4E, 0x8D19_1B2B_3DDF_0AA2, 0xEA28_0CC0_60D4_A796, 0xC8C7_0199_542D_C37A,
|
||||
0x3873_C21B_6C82_A954, 0x1A9C_CF42_587B_CDB8, 0x7DAD_D8A9_0570_608C, 0x5F42_D5F0_3189_0460,
|
||||
0xB3CF_F77F_BF67_3AE4, 0x9120_FA26_8B9E_5E08, 0xF611_EDCD_D695_F33C, 0xD4FE_E094_E26C_97D0,
|
||||
0xBDD3_07F9_6447_90B1, 0x9F3C_0AA0_50BE_F45D, 0xF80D_1D4B_0DB5_5969, 0xDAE2_1012_394C_3D85,
|
||||
0x366F_329D_B7A2_0301, 0x1480_3FC4_835B_67ED, 0x73B1_282F_DE50_CAD9, 0x515E_2576_EAA9_AE35,
|
||||
0xD10D_62C2_0B03_96B3, 0xF3E2_6F9B_3FFA_F25F, 0x94D3_7870_62F1_5F6B, 0xB63C_7529_5608_3B87,
|
||||
0x5AB1_57A6_D8E6_0503, 0x785E_5AFF_EC1F_61EF, 0x1F6F_4D14_B114_CCDB, 0x3D80_404D_85ED_A837,
|
||||
0x54AD_A720_03C6_AF56, 0x7642_AA79_373F_CBBA, 0x1173_BD92_6A34_668E, 0x339C_B0CB_5ECD_0262,
|
||||
0xDF11_9244_D023_3CE6, 0xFDFE_9F1D_E4DA_580A, 0x9ACF_88F6_B9D1_F53E, 0xB820_85AF_8D28_91D2,
|
||||
0x4894_462D_B587_FBFC, 0x6A7B_4B74_817E_9F10, 0x0D4A_5C9F_DC75_3224, 0x2FA5_51C6_E88C_56C8,
|
||||
0xC328_7349_6662_684C, 0xE1C7_7E10_529B_0CA0, 0x86F6_69FB_0F90_A194, 0xA419_64A2_3B69_C578,
|
||||
0xCD34_83CF_BD42_C219, 0xEFDB_8E96_89BB_A6F5, 0x88EA_997D_D4B0_0BC1, 0xAA05_9424_E049_6F2D,
|
||||
0x4688_B6AB_6EA7_51A9, 0x6467_BBF2_5A5E_3545, 0x0356_AC19_0755_9871, 0x21B9_A140_33AC_FC9D,
|
||||
0x70E7_8436_D905_52A8, 0x5208_896F_EDFC_3644, 0x3539_9E84_B0F7_9B70, 0x17D6_93DD_840E_FF9C,
|
||||
0xFB5B_B152_0AE0_C118, 0xD9B4_BC0B_3E19_A5F4, 0xBE85_ABE0_6312_08C0, 0x9C6A_A6B9_57EB_6C2C,
|
||||
0xF547_41D4_D1C0_6B4D, 0xD7A8_4C8D_E539_0FA1, 0xB099_5B66_B832_A295, 0x9276_563F_8CCB_C679,
|
||||
0x7EFB_74B0_0225_F8FD, 0x5C14_79E9_36DC_9C11, 0x3B25_6E02_6BD7_3125, 0x19CA_635B_5F2E_55C9,
|
||||
0xE97E_A0D9_6781_3FE7, 0xCB91_AD80_5378_5B0B, 0xACA0_BA6B_0E73_F63F, 0x8E4F_B732_3A8A_92D3,
|
||||
0x62C2_95BD_B464_AC57, 0x402D_98E4_809D_C8BB, 0x271C_8F0F_DD96_658F, 0x05F3_8256_E96F_0163,
|
||||
0x6CDE_653B_6F44_0602, 0x4E31_6862_5BBD_62EE, 0x2900_7F89_06B6_CFDA, 0x0BEF_72D0_324F_AB36,
|
||||
0xE762_505F_BCA1_95B2, 0xC58D_5D06_8858_F15E, 0xA2BC_4AED_D553_5C6A, 0x8053_47B4_E1AA_3886,
|
||||
0x30C2_6AAF_B909_33E3, 0x122D_67F6_8DF0_570F, 0x751C_701D_D0FB_FA3B, 0x57F3_7D44_E402_9ED7,
|
||||
0xBB7E_5FCB_6AEC_A053, 0x9991_5292_5E15_C4BF, 0xFEA0_4579_031E_698B, 0xDC4F_4820_37E7_0D67,
|
||||
0xB562_AF4D_B1CC_0A06, 0x978D_A214_8535_6EEA, 0xF0BC_B5FF_D83E_C3DE, 0xD253_B8A6_ECC7_A732,
|
||||
0x3EDE_9A29_6229_99B6, 0x1C31_9770_56D0_FD5A, 0x7B00_809B_0BDB_506E, 0x59EF_8DC2_3F22_3482,
|
||||
0xA95B_4E40_078D_5EAC, 0x8BB4_4319_3374_3A40, 0xEC85_54F2_6E7F_9774, 0xCE6A_59AB_5A86_F398,
|
||||
0x22E7_7B24_D468_CD1C, 0x0008_767D_E091_A9F0, 0x6739_6196_BD9A_04C4, 0x45D6_6CCF_8963_6028,
|
||||
0x2CFB_8BA2_0F48_6749, 0x0E14_86FB_3BB1_03A5, 0x6925_9110_66BA_AE91, 0x4BCA_9C49_5243_CA7D,
|
||||
0xA747_BEC6_DCAD_F4F9, 0x85A8_B39F_E854_9015, 0xE299_A474_B55F_3D21, 0xC076_A92D_81A6_59CD,
|
||||
0x9128_8C5B_6B0F_F7F8, 0xB3C7_8102_5FF6_9314, 0xD4F6_96E9_02FD_3E20, 0xF619_9BB0_3604_5ACC,
|
||||
0x1A94_B93F_B8EA_6448, 0x387B_B466_8C13_00A4, 0x5F4A_A38D_D118_AD90, 0x7DA5_AED4_E5E1_C97C,
|
||||
0x1488_49B9_63CA_CE1D, 0x3667_44E0_5733_AAF1, 0x5156_530B_0A38_07C5, 0x73B9_5E52_3EC1_6329,
|
||||
0x9F34_7CDD_B02F_5DAD, 0xBDDB_7184_84D6_3941, 0xDAEA_666F_D9DD_9475, 0xF805_6B36_ED24_F099,
|
||||
0x08B1_A8B4_D58B_9AB7, 0x2A5E_A5ED_E172_FE5B, 0x4D6F_B206_BC79_536F, 0x6F80_BF5F_8880_3783,
|
||||
0x830D_9DD0_066E_0907, 0xA1E2_9089_3297_6DEB, 0xC6D3_8762_6F9C_C0DF, 0xE43C_8A3B_5B65_A433,
|
||||
0x8D11_6D56_DD4E_A352, 0xAFFE_600F_E9B7_C7BE, 0xC8CF_77E4_B4BC_6A8A, 0xEA20_7ABD_8045_0E66,
|
||||
0x06AD_5832_0EAB_30E2, 0x2442_556B_3A52_540E, 0x4373_4280_6759_F93A, 0x619C_4FD9_53A0_9DD6,
|
||||
0xE1CF_086D_B20A_A550, 0xC320_0534_86F3_C1BC, 0xA411_12DF_DBF8_6C88, 0x86FE_1F86_EF01_0864,
|
||||
0x6A73_3D09_61EF_36E0, 0x489C_3050_5516_520C, 0x2FAD_27BB_081D_FF38, 0x0D42_2AE2_3CE4_9BD4,
|
||||
0x646F_CD8F_BACF_9CB5, 0x4680_C0D6_8E36_F859, 0x21B1_D73D_D33D_556D, 0x035E_DA64_E7C4_3181,
|
||||
0xEFD3_F8EB_692A_0F05, 0xCD3C_F5B2_5DD3_6BE9, 0xAA0D_E259_00D8_C6DD, 0x88E2_EF00_3421_A231,
|
||||
0x7856_2C82_0C8E_C81F, 0x5AB9_21DB_3877_ACF3, 0x3D88_3630_657C_01C7, 0x1F67_3B69_5185_652B,
|
||||
0xF3EA_19E6_DF6B_5BAF, 0xD105_14BF_EB92_3F43, 0xB634_0354_B699_9277, 0x94DB_0E0D_8260_F69B,
|
||||
0xFDF6_E960_044B_F1FA, 0xDF19_E439_30B2_9516, 0xB828_F3D2_6DB9_3822, 0x9AC7_FE8B_5940_5CCE,
|
||||
0x764A_DC04_D7AE_624A, 0x54A5_D15D_E357_06A6, 0x3394_C6B6_BE5C_AB92, 0x117B_CBEF_8AA5_CF7E,
|
||||
0x4025_EE99_600C_614B, 0x62CA_E3C0_54F5_05A7, 0x05FB_F42B_09FE_A893, 0x2714_F972_3D07_CC7F,
|
||||
0xCB99_DBFD_B3E9_F2FB, 0xE976_D6A4_8710_9617, 0x8E47_C14F_DA1B_3B23, 0xACA8_CC16_EEE2_5FCF,
|
||||
0xC585_2B7B_68C9_58AE, 0xE76A_2622_5C30_3C42, 0x805B_31C9_013B_9176, 0xA2B4_3C90_35C2_F59A,
|
||||
0x4E39_1E1F_BB2C_CB1E, 0x6CD6_1346_8FD5_AFF2, 0x0BE7_04AD_D2DE_02C6, 0x2908_09F4_E627_662A,
|
||||
0xD9BC_CA76_DE88_0C04, 0xFB53_C72F_EA71_68E8, 0x9C62_D0C4_B77A_C5DC, 0xBE8D_DD9D_8383_A130,
|
||||
0x5200_FF12_0D6D_9FB4, 0x70EF_F24B_3994_FB58, 0x17DE_E5A0_649F_566C, 0x3531_E8F9_5066_3280,
|
||||
0x5C1C_0F94_D64D_35E1, 0x7EF3_02CD_E2B4_510D, 0x19C2_1526_BFBF_FC39, 0x3B2D_187F_8B46_98D5,
|
||||
0xD7A0_3AF0_05A8_A651, 0xF54F_37A9_3151_C2BD, 0x927E_2042_6C5A_6F89, 0xB091_2D1B_58A3_0B65,
|
||||
],[
|
||||
0x0000_0000_0000_0000, 0xDABE_95AF_C787_5F40, 0x27A5_8474_2000_A005, 0xFD1B_11DB_E787_FF45,
|
||||
0x4F4B_08E8_4001_400A, 0x95F5_9D47_8786_1F4A, 0x68EE_8C9C_6001_E00F, 0xB250_1933_A786_BF4F,
|
||||
0x9E96_11D0_8002_8014, 0x4428_847F_4785_DF54, 0xB933_95A4_A002_2011, 0x638D_000B_6785_7F51,
|
||||
0xD1DD_1938_C003_C01E, 0x0B63_8C97_0784_9F5E, 0xF678_9D4C_E003_601B, 0x2CC6_08E3_2784_3F5B,
|
||||
0xAFF4_8C8A_AF0B_1EAD, 0x754A_1925_688C_41ED, 0x8851_08FE_8F0B_BEA8, 0x52EF_9D51_488C_E1E8,
|
||||
0xE0BF_8462_EF0A_5EA7, 0x3A01_11CD_288D_01E7, 0xC71A_0016_CF0A_FEA2, 0x1DA4_95B9_088D_A1E2,
|
||||
0x3162_9D5A_2F09_9EB9, 0xEBDC_08F5_E88E_C1F9, 0x16C7_192E_0F09_3EBC, 0xCC79_8C81_C88E_61FC,
|
||||
0x7E29_95B2_6F08_DEB3, 0xA497_001D_A88F_81F3, 0x598C_11C6_4F08_7EB6, 0x8332_8469_888F_21F6,
|
||||
0xCD31_B63E_F118_23DF, 0x178F_2391_369F_7C9F, 0xEA94_324A_D118_83DA, 0x302A_A7E5_169F_DC9A,
|
||||
0x827A_BED6_B119_63D5, 0x58C4_2B79_769E_3C95, 0xA5DF_3AA2_9119_C3D0, 0x7F61_AF0D_569E_9C90,
|
||||
0x53A7_A7EE_711A_A3CB, 0x8919_3241_B69D_FC8B, 0x7402_239A_511A_03CE, 0xAEBC_B635_969D_5C8E,
|
||||
0x1CEC_AF06_311B_E3C1, 0xC652_3AA9_F69C_BC81, 0x3B49_2B72_111B_43C4, 0xE1F7_BEDD_D69C_1C84,
|
||||
0x62C5_3AB4_5E13_3D72, 0xB87B_AF1B_9994_6232, 0x4560_BEC0_7E13_9D77, 0x9FDE_2B6F_B994_C237,
|
||||
0x2D8E_325C_1E12_7D78, 0xF730_A7F3_D995_2238, 0x0A2B_B628_3E12_DD7D, 0xD095_2387_F995_823D,
|
||||
0xFC53_2B64_DE11_BD66, 0x26ED_BECB_1996_E226, 0xDBF6_AF10_FE11_1D63, 0x0148_3ABF_3996_4223,
|
||||
0xB318_238C_9E10_FD6C, 0x69A6_B623_5997_A22C, 0x94BD_A7F8_BE10_5D69, 0x4E03_3257_7997_0229,
|
||||
0x08BB_C356_4D3E_593B, 0xD205_56F9_8AB9_067B, 0x2F1E_4722_6D3E_F93E, 0xF5A0_D28D_AAB9_A67E,
|
||||
0x47F0_CBBE_0D3F_1931, 0x9D4E_5E11_CAB8_4671, 0x6055_4FCA_2D3F_B934, 0xBAEB_DA65_EAB8_E674,
|
||||
0x962D_D286_CD3C_D92F, 0x4C93_4729_0ABB_866F, 0xB188_56F2_ED3C_792A, 0x6B36_C35D_2ABB_266A,
|
||||
0xD966_DA6E_8D3D_9925, 0x03D8_4FC1_4ABA_C665, 0xFEC3_5E1A_AD3D_3920, 0x247D_CBB5_6ABA_6660,
|
||||
0xA74F_4FDC_E235_4796, 0x7DF1_DA73_25B2_18D6, 0x80EA_CBA8_C235_E793, 0x5A54_5E07_05B2_B8D3,
|
||||
0xE804_4734_A234_079C, 0x32BA_D29B_65B3_58DC, 0xCFA1_C340_8234_A799, 0x151F_56EF_45B3_F8D9,
|
||||
0x39D9_5E0C_6237_C782, 0xE367_CBA3_A5B0_98C2, 0x1E7C_DA78_4237_6787, 0xC4C2_4FD7_85B0_38C7,
|
||||
0x7692_56E4_2236_8788, 0xAC2C_C34B_E5B1_D8C8, 0x5137_D290_0236_278D, 0x8B89_473F_C5B1_78CD,
|
||||
0xC58A_7568_BC26_7AE4, 0x1F34_E0C7_7BA1_25A4, 0xE22F_F11C_9C26_DAE1, 0x3891_64B3_5BA1_85A1,
|
||||
0x8AC1_7D80_FC27_3AEE, 0x507F_E82F_3BA0_65AE, 0xAD64_F9F4_DC27_9AEB, 0x77DA_6C5B_1BA0_C5AB,
|
||||
0x5B1C_64B8_3C24_FAF0, 0x81A2_F117_FBA3_A5B0, 0x7CB9_E0CC_1C24_5AF5, 0xA607_7563_DBA3_05B5,
|
||||
0x1457_6C50_7C25_BAFA, 0xCEE9_F9FF_BBA2_E5BA, 0x33F2_E824_5C25_1AFF, 0xE94C_7D8B_9BA2_45BF,
|
||||
0x6A7E_F9E2_132D_6449, 0xB0C0_6C4D_D4AA_3B09, 0x4DDB_7D96_332D_C44C, 0x9765_E839_F4AA_9B0C,
|
||||
0x2535_F10A_532C_2443, 0xFF8B_64A5_94AB_7B03, 0x0290_757E_732C_8446, 0xD82E_E0D1_B4AB_DB06,
|
||||
0xF4E8_E832_932F_E45D, 0x2E56_7D9D_54A8_BB1D, 0xD34D_6C46_B32F_4458, 0x09F3_F9E9_74A8_1B18,
|
||||
0xBBA3_E0DA_D32E_A457, 0x611D_7575_14A9_FB17, 0x9C06_64AE_F32E_0452, 0x46B8_F101_34A9_5B12,
|
||||
0x1177_86AC_9A7C_B276, 0xCBC9_1303_5DFB_ED36, 0x36D2_02D8_BA7C_1273, 0xEC6C_9777_7DFB_4D33,
|
||||
0x5E3C_8E44_DA7D_F27C, 0x8482_1BEB_1DFA_AD3C, 0x7999_0A30_FA7D_5279, 0xA327_9F9F_3DFA_0D39,
|
||||
0x8FE1_977C_1A7E_3262, 0x555F_02D3_DDF9_6D22, 0xA844_1308_3A7E_9267, 0x72FA_86A7_FDF9_CD27,
|
||||
0xC0AA_9F94_5A7F_7268, 0x1A14_0A3B_9DF8_2D28, 0xE70F_1BE0_7A7F_D26D, 0x3DB1_8E4F_BDF8_8D2D,
|
||||
0xBE83_0A26_3577_ACDB, 0x643D_9F89_F2F0_F39B, 0x9926_8E52_1577_0CDE, 0x4398_1BFD_D2F0_539E,
|
||||
0xF1C8_02CE_7576_ECD1, 0x2B76_9761_B2F1_B391, 0xD66D_86BA_5576_4CD4, 0x0CD3_1315_92F1_1394,
|
||||
0x2015_1BF6_B575_2CCF, 0xFAAB_8E59_72F2_738F, 0x07B0_9F82_9575_8CCA, 0xDD0E_0A2D_52F2_D38A,
|
||||
0x6F5E_131E_F574_6CC5, 0xB5E0_86B1_32F3_3385, 0x48FB_976A_D574_CCC0, 0x9245_02C5_12F3_9380,
|
||||
0xDC46_3092_6B64_91A9, 0x06F8_A53D_ACE3_CEE9, 0xFBE3_B4E6_4B64_31AC, 0x215D_2149_8CE3_6EEC,
|
||||
0x930D_387A_2B65_D1A3, 0x49B3_ADD5_ECE2_8EE3, 0xB4A8_BC0E_0B65_71A6, 0x6E16_29A1_CCE2_2EE6,
|
||||
0x42D0_2142_EB66_11BD, 0x986E_B4ED_2CE1_4EFD, 0x6575_A536_CB66_B1B8, 0xBFCB_3099_0CE1_EEF8,
|
||||
0x0D9B_29AA_AB67_51B7, 0xD725_BC05_6CE0_0EF7, 0x2A3E_ADDE_8B67_F1B2, 0xF080_3871_4CE0_AEF2,
|
||||
0x73B2_BC18_C46F_8F04, 0xA90C_29B7_03E8_D044, 0x5417_386C_E46F_2F01, 0x8EA9_ADC3_23E8_7041,
|
||||
0x3CF9_B4F0_846E_CF0E, 0xE647_215F_43E9_904E, 0x1B5C_3084_A46E_6F0B, 0xC1E2_A52B_63E9_304B,
|
||||
0xED24_ADC8_446D_0F10, 0x379A_3867_83EA_5050, 0xCA81_29BC_646D_AF15, 0x103F_BC13_A3EA_F055,
|
||||
0xA26F_A520_046C_4F1A, 0x78D1_308F_C3EB_105A, 0x85CA_2154_246C_EF1F, 0x5F74_B4FB_E3EB_B05F,
|
||||
0x19CC_45FA_D742_EB4D, 0xC372_D055_10C5_B40D, 0x3E69_C18E_F742_4B48, 0xE4D7_5421_30C5_1408,
|
||||
0x5687_4D12_9743_AB47, 0x8C39_D8BD_50C4_F407, 0x7122_C966_B743_0B42, 0xAB9C_5CC9_70C4_5402,
|
||||
0x875A_542A_5740_6B59, 0x5DE4_C185_90C7_3419, 0xA0FF_D05E_7740_CB5C, 0x7A41_45F1_B0C7_941C,
|
||||
0xC811_5CC2_1741_2B53, 0x12AF_C96D_D0C6_7413, 0xEFB4_D8B6_3741_8B56, 0x350A_4D19_F0C6_D416,
|
||||
0xB638_C970_7849_F5E0, 0x6C86_5CDF_BFCE_AAA0, 0x919D_4D04_5849_55E5, 0x4B23_D8AB_9FCE_0AA5,
|
||||
0xF973_C198_3848_B5EA, 0x23CD_5437_FFCF_EAAA, 0xDED6_45EC_1848_15EF, 0x0468_D043_DFCF_4AAF,
|
||||
0x28AE_D8A0_F84B_75F4, 0xF210_4D0F_3FCC_2AB4, 0x0F0B_5CD4_D84B_D5F1, 0xD5B5_C97B_1FCC_8AB1,
|
||||
0x67E5_D048_B84A_35FE, 0xBD5B_45E7_7FCD_6ABE, 0x4040_543C_984A_95FB, 0x9AFE_C193_5FCD_CABB,
|
||||
0xD4FD_F3C4_265A_C892, 0x0E43_666B_E1DD_97D2, 0xF358_77B0_065A_6897, 0x29E6_E21F_C1DD_37D7,
|
||||
0x9BB6_FB2C_665B_8898, 0x4108_6E83_A1DC_D7D8, 0xBC13_7F58_465B_289D, 0x66AD_EAF7_81DC_77DD,
|
||||
0x4A6B_E214_A658_4886, 0x90D5_77BB_61DF_17C6, 0x6DCE_6660_8658_E883, 0xB770_F3CF_41DF_B7C3,
|
||||
0x0520_EAFC_E659_088C, 0xDF9E_7F53_21DE_57CC, 0x2285_6E88_C659_A889, 0xF83B_FB27_01DE_F7C9,
|
||||
0x7B09_7F4E_8951_D63F, 0xA1B7_EAE1_4ED6_897F, 0x5CAC_FB3A_A951_763A, 0x8612_6E95_6ED6_297A,
|
||||
0x3442_77A6_C950_9635, 0xEEFC_E209_0ED7_C975, 0x13E7_F3D2_E950_3630, 0xC959_667D_2ED7_6970,
|
||||
0xE59F_6E9E_0953_562B, 0x3F21_FB31_CED4_096B, 0xC23A_EAEA_2953_F62E, 0x1884_7F45_EED4_A96E,
|
||||
0xAAD4_6676_4952_1621, 0x706A_F3D9_8ED5_4961, 0x8D71_E202_6952_B624, 0x57CF_77AD_AED5_E964,
|
||||
]]
|
||||
@@ -0,0 +1,251 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// Like std/crc32's x86 SIMD implementation, this is based on Gopal et al.
|
||||
// "Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction".
|
||||
// and further optimized a la
|
||||
// https://github.com/JoernEngel/joernblog/blob/778f0007b9a580e477608691f1aa86369f0efdd2/crc64.c
|
||||
|
||||
pri func ecma_hasher.up_x86_sse42!(x: roslice base.u8),
|
||||
choose cpu_arch >= x86_sse42,
|
||||
{
|
||||
var s : base.u64
|
||||
var p : roslice base.u8
|
||||
|
||||
var buf : array[48] base.u8
|
||||
|
||||
var util : base.x86_sse42_utility
|
||||
var xa : base.x86_m128i
|
||||
var xb : base.x86_m128i
|
||||
var xc : base.x86_m128i
|
||||
var xd : base.x86_m128i
|
||||
var xe : base.x86_m128i
|
||||
var xf : base.x86_m128i
|
||||
var xg : base.x86_m128i
|
||||
var xh : base.x86_m128i
|
||||
var mu1 : base.x86_m128i
|
||||
var mu2 : base.x86_m128i
|
||||
var mu4 : base.x86_m128i
|
||||
var mu8 : base.x86_m128i
|
||||
var mupx : base.x86_m128i
|
||||
|
||||
s = 0xFFFF_FFFF_FFFF_FFFF ^ this.state
|
||||
|
||||
// Align to a 16-byte boundary.
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = ECMA_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
}
|
||||
|
||||
while.chain2 true {{
|
||||
while.chain4 true {{
|
||||
if args.x.length() >= 0x80 {
|
||||
// No-op.
|
||||
|
||||
} else if args.x.length() >= 0x40 {
|
||||
// Set up 4 accumulators.
|
||||
xa = util.make_m128i_slice128(a: args.x[0x00 .. 0x10])._mm_xor_si128(b:
|
||||
util.make_m128i_single_u64(a: s))
|
||||
xb = util.make_m128i_slice128(a: args.x[0x10 .. 0x20])
|
||||
xc = util.make_m128i_slice128(a: args.x[0x20 .. 0x30])
|
||||
xd = util.make_m128i_slice128(a: args.x[0x30 .. 0x40])
|
||||
args.x = args.x[0x40 ..]
|
||||
break.chain4
|
||||
|
||||
} else if args.x.length() >= 0x20 {
|
||||
// Set up 2 accumulators.
|
||||
xa = util.make_m128i_slice128(a: args.x[0x00 .. 0x10])._mm_xor_si128(b:
|
||||
util.make_m128i_single_u64(a: s))
|
||||
xb = util.make_m128i_slice128(a: args.x[0x10 .. 0x20])
|
||||
args.x = args.x[0x20 ..]
|
||||
break.chain2
|
||||
|
||||
} else {
|
||||
// For short inputs, just do a simple loop.
|
||||
iterate (p = args.x)(length: 1, advance: 1, unroll: 1) {
|
||||
s = ECMA_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
this.state = 0xFFFF_FFFF_FFFF_FFFF ^ s
|
||||
return nothing
|
||||
}
|
||||
|
||||
// Set up 8 accumulators.
|
||||
xa = util.make_m128i_slice128(a: args.x[0x00 .. 0x10])._mm_xor_si128(b:
|
||||
util.make_m128i_single_u64(a: s))
|
||||
xb = util.make_m128i_slice128(a: args.x[0x10 .. 0x20])
|
||||
xc = util.make_m128i_slice128(a: args.x[0x20 .. 0x30])
|
||||
xd = util.make_m128i_slice128(a: args.x[0x30 .. 0x40])
|
||||
xe = util.make_m128i_slice128(a: args.x[0x40 .. 0x50])
|
||||
xf = util.make_m128i_slice128(a: args.x[0x50 .. 0x60])
|
||||
xg = util.make_m128i_slice128(a: args.x[0x60 .. 0x70])
|
||||
xh = util.make_m128i_slice128(a: args.x[0x70 .. 0x80])
|
||||
args.x = args.x[0x80 ..]
|
||||
|
||||
// Main loop.
|
||||
mu8 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD8[.. 16])
|
||||
while args.x.length() >= 0x80 {
|
||||
xa = xa._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x00 .. 0x10]))
|
||||
xb = xb._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xb._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x10 .. 0x20]))
|
||||
xc = xc._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xc._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x20 .. 0x30]))
|
||||
xd = xd._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xd._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x30 .. 0x40]))
|
||||
xe = xe._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xe._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x40 .. 0x50]))
|
||||
xf = xf._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xf._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x50 .. 0x60]))
|
||||
xg = xg._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xg._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x60 .. 0x70]))
|
||||
xh = xh._mm_clmulepi64_si128(b: mu8, imm8: 0x00)._mm_xor_si128(b:
|
||||
xh._mm_clmulepi64_si128(b: mu8, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x70 .. 0x80]))
|
||||
args.x = args.x[0x80 ..]
|
||||
}
|
||||
|
||||
// Reduce 8 chains down to 4.
|
||||
mu4 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD4[.. 16])
|
||||
xa = xa._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
xe)
|
||||
xb = xb._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xb._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
xf)
|
||||
xc = xc._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xc._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
xg)
|
||||
xd = xd._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xd._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
xh)
|
||||
if args.x.length() > 0x40 {
|
||||
xa = xa._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x00 .. 0x10]))
|
||||
xb = xb._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xb._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x10 .. 0x20]))
|
||||
xc = xc._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xc._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x20 .. 0x30]))
|
||||
xd = xd._mm_clmulepi64_si128(b: mu4, imm8: 0x00)._mm_xor_si128(b:
|
||||
xd._mm_clmulepi64_si128(b: mu4, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x30 .. 0x40]))
|
||||
args.x = args.x[0x40 ..]
|
||||
}
|
||||
|
||||
break.chain4
|
||||
}}.chain4
|
||||
// Reduce 4 chains down to 2.
|
||||
mu2 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD2[.. 16])
|
||||
xa = xa._mm_clmulepi64_si128(b: mu2, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu2, imm8: 0x11))._mm_xor_si128(b:
|
||||
xc)
|
||||
xb = xb._mm_clmulepi64_si128(b: mu2, imm8: 0x00)._mm_xor_si128(b:
|
||||
xb._mm_clmulepi64_si128(b: mu2, imm8: 0x11))._mm_xor_si128(b:
|
||||
xd)
|
||||
if args.x.length() > 0x20 {
|
||||
xa = xa._mm_clmulepi64_si128(b: mu2, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu2, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x00 .. 0x10]))
|
||||
xb = xb._mm_clmulepi64_si128(b: mu2, imm8: 0x00)._mm_xor_si128(b:
|
||||
xb._mm_clmulepi64_si128(b: mu2, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x10 .. 0x20]))
|
||||
args.x = args.x[0x20 ..]
|
||||
}
|
||||
|
||||
break.chain2
|
||||
}}.chain2
|
||||
// Reduce 2 chains down to 1.
|
||||
mu1 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD1[.. 16])
|
||||
xa = xa._mm_clmulepi64_si128(b: mu1, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu1, imm8: 0x11))._mm_xor_si128(b:
|
||||
xb)
|
||||
if args.x.length() > 24 {
|
||||
xa = xa._mm_clmulepi64_si128(b: mu1, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu1, imm8: 0x11))._mm_xor_si128(b:
|
||||
util.make_m128i_slice128(a: args.x[0x00 .. 0x10]))
|
||||
args.x = args.x[0x10 ..]
|
||||
if args.x.length() > 24 {
|
||||
return nothing // Unreachable.
|
||||
}
|
||||
}
|
||||
assert args.x.length() <= 24
|
||||
|
||||
// Copy our accumulator xa and the remaining data to buf, a 48-byte buffer.
|
||||
// The buffer includes the implicitly appended 8 bytes for the CRC.
|
||||
//
|
||||
// | 0-padding | xa | args.x | 0-padding |
|
||||
// | 0-24 bytes | 16 bytes | 0-24 bytes| 8 bytes |
|
||||
//
|
||||
assert (24 - args.x.length()) <= ((24 - args.x.length()) + 16) via "a <= (a + b): 0 <= b"()
|
||||
xa.store_slice128!(a: buf[24 - args.x.length() .. (24 - args.x.length()) + 16])
|
||||
buf[(24 - args.x.length()) + 16 ..].copy_from_slice!(s: args.x)
|
||||
|
||||
// Reduce the 48-byte buffer down to a 16-byte (128-bit) accumulator.
|
||||
mu2 = util.make_m128i_slice128(a: ECMA_X86_SSE42_FOLD2[.. 16])
|
||||
xa = util.make_m128i_slice128(a: buf[0x00 .. 0x10])
|
||||
xb = util.make_m128i_slice128(a: buf[0x10 .. 0x20])
|
||||
xc = util.make_m128i_slice128(a: buf[0x20 .. 0x30])
|
||||
xd = xa._mm_clmulepi64_si128(b: mu2, imm8: 0x00)._mm_xor_si128(b:
|
||||
xa._mm_clmulepi64_si128(b: mu2, imm8: 0x11))
|
||||
xe = xb._mm_clmulepi64_si128(b: mu1, imm8: 0x00)._mm_xor_si128(b:
|
||||
xb._mm_clmulepi64_si128(b: mu1, imm8: 0x11))
|
||||
xa = xd._mm_xor_si128(b: xe._mm_xor_si128(b: xc))
|
||||
|
||||
// Reduce 128-bit to 64-bit via Barrett reduction.
|
||||
mupx = util.make_m128i_slice128(a: ECMA_X86_SSE42_MUPX[.. 16])
|
||||
xb = xa._mm_clmulepi64_si128(b: mupx, imm8: 0x00)
|
||||
xc = xb._mm_clmulepi64_si128(b: mupx, imm8: 0x10)
|
||||
s = xc._mm_xor_si128(b: xb._mm_slli_si128(imm8: 8)).
|
||||
_mm_xor_si128(b: xa)._mm_extract_epi64(imm8: 1)
|
||||
|
||||
this.state = 0xFFFF_FFFF_FFFF_FFFF ^ s
|
||||
}
|
||||
|
||||
// These constants are reproduced by
|
||||
// script/print-crc64-x86-sse42-magic-numbers.go
|
||||
//
|
||||
// The rkN names match the numbers at
|
||||
// https://github.com/intel/isa-l/blob/7b30857e20b84e5afab1a28291189b9dc571110d/crc/crc64_ecma_refl_by16_10.asm#L33-L56
|
||||
|
||||
pri const ECMA_X86_SSE42_FOLD1 : roarray[16] base.u8 = [
|
||||
0xE4, 0x3A, 0x39, 0xCA, 0x97, 0xD4, 0x5D, 0xE0, // fold1a' = 0xE05D_D497_CA39_3AE4 = rk2
|
||||
0x40, 0x5F, 0x87, 0xC7, 0xAF, 0x95, 0xBE, 0xDA, // fold1b' = 0xDABE_95AF_C787_5F40 = rk1
|
||||
]
|
||||
|
||||
pri const ECMA_X86_SSE42_FOLD2 : roarray[16] base.u8 = [
|
||||
0x44, 0xFA, 0x9E, 0x8A, 0x00, 0x5B, 0x09, 0x60, // fold2a' = 0x6009_5B00_8A9E_FA44 = rk20
|
||||
0x51, 0xAF, 0xE1, 0x0F, 0xA3, 0x53, 0xE6, 0x3B, // fold2b' = 0x3BE6_53A3_0FE1_AF51 = rk19
|
||||
]
|
||||
|
||||
pri const ECMA_X86_SSE42_FOLD4 : roarray[16] base.u8 = [
|
||||
0xF3, 0x41, 0xD4, 0x9D, 0xBB, 0xEF, 0xE3, 0x6A, // fold4a' = 0x6AE3_EFBB_9DD4_41F3 = rk16
|
||||
0xF4, 0x2D, 0x84, 0xA7, 0x54, 0x60, 0x1F, 0x08, // fold4b' = 0x081F_6054_A784_2DF4 = rk15
|
||||
]
|
||||
|
||||
pri const ECMA_X86_SSE42_FOLD8 : roarray[16] base.u8 = [
|
||||
0x00, 0x10, 0xCC, 0x4F, 0x1D, 0xD7, 0x57, 0x87, // fold8a' = 0x8757_D71D_4FCC_1000 = rk4
|
||||
0x40, 0xE7, 0x3D, 0xF7, 0x2A, 0x6B, 0xD8, 0xD7, // fold8b' = 0xD7D8_6B2A_F73D_E740 = rk3
|
||||
]
|
||||
|
||||
pri const ECMA_X86_SSE42_MUPX : roarray[16] base.u8 = [
|
||||
0xD5, 0x63, 0x29, 0x17, 0x6C, 0x46, 0x3E, 0x9C, // μ' = 0x9C3E_466C_1729_63D5 = rk7
|
||||
0x85, 0x1E, 0x0E, 0xAF, 0x2B, 0xAF, 0xD8, 0x92, // Px' = 0x92D8_AF2B_AF0E_1E85 = rk8
|
||||
]
|
||||
@@ -28,7 +28,7 @@ pri status "#internal error: inconsistent I/O"
|
||||
pri status "#internal error: inconsistent distance"
|
||||
pri status "#internal error: inconsistent n_bits"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
// TODO: replace the placeholder 1 value with either 0 or (32768 + 512),
|
||||
// depending on whether we'll move decoder.history into the workbuf.
|
||||
@@ -205,8 +205,8 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.util.make_optional_u63(has_value: true, value: 0)
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
@@ -224,7 +224,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -245,7 +245,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
// can change the veracity of any args.dst assertions?
|
||||
this.add_history!(hist: args.dst.since(mark: mark))
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
@@ -261,7 +261,7 @@ pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
this.bits |= b0 << (this.n_bits & 3)
|
||||
this.n_bits = (this.n_bits & 3) + 8
|
||||
} endwhile
|
||||
}
|
||||
final = this.bits & 0x01
|
||||
type = (this.bits >> 1) & 0x03
|
||||
this.bits >>= 3
|
||||
@@ -304,8 +304,8 @@ pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
if this.end_of_block {
|
||||
continue.outer
|
||||
}
|
||||
} endwhile
|
||||
} endwhile.outer
|
||||
}
|
||||
}.outer
|
||||
}
|
||||
|
||||
// decode_uncompressed decodes an uncompresed block as per the RFC section
|
||||
@@ -339,7 +339,7 @@ pri func decoder.decode_uncompressed?(dst: base.io_writer, src: base.io_reader)
|
||||
} else {
|
||||
yield? base."$short read"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6.
|
||||
@@ -350,23 +350,23 @@ pri func decoder.init_fixed_huffman!() base.status {
|
||||
while i < 144 {
|
||||
this.code_lengths[i] = 8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 256 {
|
||||
this.code_lengths[i] = 9
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 280 {
|
||||
this.code_lengths[i] = 7
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 288 {
|
||||
this.code_lengths[i] = 8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 320 {
|
||||
this.code_lengths[i] = 5
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
status = this.init_huff!(which: 0, n_codes0: 0, n_codes1: 288, base_symbol: 257)
|
||||
if status.is_error() {
|
||||
@@ -407,7 +407,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
bits |= b0 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
n_lit = bits.low_bits(n: 5) + 257
|
||||
if n_lit > 286 {
|
||||
return "#bad literal/length code count"
|
||||
@@ -432,17 +432,17 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b1 = args.src.read_u8_as_u32?()
|
||||
bits |= b1 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
assert i < 19 via "a < b: a < c; c <= b"(c: n_clen)
|
||||
this.code_lengths[CODE_ORDER[i]] = (bits & 0x07) as base.u8
|
||||
bits >>= 3
|
||||
n_bits -= 3
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 19 {
|
||||
this.code_lengths[CODE_ORDER[i]] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
status = this.init_huff!(which: 0, n_codes0: 0, n_codes1: 19, base_symbol: 0xFFF)
|
||||
if status.is_error() {
|
||||
return status
|
||||
@@ -469,7 +469,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b2 = args.src.read_u8_as_u32?()
|
||||
bits |= b2 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
// For H-CL, there should be no redirections and all symbols should be
|
||||
// literals.
|
||||
if (table_entry >> 24) <> 0x80 {
|
||||
@@ -518,7 +518,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
b3 = args.src.read_u8_as_u32?()
|
||||
bits |= b3 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
rep_count += bits.low_bits(n: n_extra_bits)
|
||||
bits >>= n_extra_bits
|
||||
n_bits -= n_extra_bits
|
||||
@@ -532,8 +532,8 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
this.code_lengths[i] = rep_symbol
|
||||
i += 1
|
||||
rep_count -= 1
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
if i <> (n_lit + n_dist) {
|
||||
return "#bad Huffman code length count"
|
||||
@@ -626,7 +626,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
counts[this.code_lengths[i] & 15] += 1
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 {
|
||||
return "#no Huffman codes"
|
||||
}
|
||||
@@ -645,7 +645,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
remaining -= counts[i] as base.u32
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if remaining <> 0 {
|
||||
// As a special case, allow a degenerate H-D Huffman table, with only
|
||||
// one 1-bit code.
|
||||
@@ -661,7 +661,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
return ok
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
@@ -690,7 +690,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
// bounds checking can handle it.
|
||||
n_symbols = n_symbols + count
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if n_symbols > 288 {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
@@ -730,7 +730,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
offsets[this.code_lengths[i] & 15] += 1
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate min_cl and max_cl.
|
||||
//
|
||||
@@ -748,7 +748,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
return "#bad Huffman minimum code length"
|
||||
}
|
||||
min_cl += 1
|
||||
} endwhile
|
||||
}
|
||||
max_cl = 15
|
||||
while true,
|
||||
inv n_symbols <= 288,
|
||||
@@ -760,7 +760,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
return "#no Huffman codes"
|
||||
}
|
||||
max_cl -= 1
|
||||
} endwhile
|
||||
}
|
||||
if max_cl <= 9 {
|
||||
this.n_huffs_bits[args.which] = max_cl
|
||||
} else {
|
||||
@@ -848,7 +848,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
remaining <<= 1
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
if (j <= 9) or (15 < j) {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
@@ -909,7 +909,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
}
|
||||
assert (top + ((high_bits | reversed_key) & 511)) < 1024 via "a < b: a < c; c <= b"(c: HUFFS_TABLE_SIZE)
|
||||
this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
if i >= n_symbols {
|
||||
@@ -920,6 +920,6 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
if code >= (1 << 15) {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
@@ -146,6 +146,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
}
|
||||
assert length >= 1
|
||||
|
||||
// Decode a dcode symbol from H-D.
|
||||
table_entry = this.huffs[1][bits & dmask]
|
||||
@@ -190,6 +191,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre args.dst.length() >= 266,
|
||||
pre length >= 1,
|
||||
{
|
||||
// We can therefore prove:
|
||||
assert (length as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
@@ -227,6 +229,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
}
|
||||
assert length >= 1
|
||||
|
||||
if (((dist_minus_1 + 1) as base.u64) > args.dst.history_length()) or
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
@@ -237,6 +240,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert (dist_minus_1 + 1) >= 1
|
||||
assert ((dist_minus_1 + 1) as base.u64) <= args.dst.history_length()
|
||||
assert length >= 1
|
||||
assert (length as base.u64) <= args.dst.length()
|
||||
assert ((length + 8) as base.u64) <= args.dst.length()
|
||||
|
||||
@@ -262,8 +266,8 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.loop
|
||||
}
|
||||
}.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
@@ -287,7 +291,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bits = (bits & (((1 as base.u64) << n_bits) - 1)) as base.u32
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -201,6 +201,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
} else {
|
||||
assert args.src.length() >= 6
|
||||
}
|
||||
assert length >= 1
|
||||
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
@@ -295,6 +296,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre args.dst.length() >= 266,
|
||||
pre length >= 1,
|
||||
{
|
||||
// We can therefore prove:
|
||||
assert (length as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
@@ -332,6 +334,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
}
|
||||
assert length >= 1
|
||||
|
||||
if (((dist_minus_1 + 1) as base.u64) > args.dst.history_length()) or
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
@@ -342,6 +345,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert (dist_minus_1 + 1) >= 1
|
||||
assert ((dist_minus_1 + 1) as base.u64) <= args.dst.history_length()
|
||||
assert length >= 1
|
||||
assert (length as base.u64) <= args.dst.length()
|
||||
assert ((length + 8) as base.u64) <= args.dst.length()
|
||||
|
||||
@@ -362,8 +366,8 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.loop
|
||||
}
|
||||
}.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
@@ -384,7 +388,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bits = bits & (((1 as base.u32) << n_bits) - 1)
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -145,6 +145,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
}
|
||||
assert length >= 1
|
||||
|
||||
// Decode a dcode symbol from H-D.
|
||||
table_entry = this.huffs[1][bits & dmask]
|
||||
@@ -189,6 +190,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre args.dst.length() >= 266,
|
||||
pre length >= 1,
|
||||
{
|
||||
// We can therefore prove:
|
||||
assert (length as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
@@ -226,6 +228,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
}
|
||||
assert length >= 1
|
||||
|
||||
if (((dist_minus_1 + 1) as base.u64) > args.dst.history_length()) or
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
@@ -236,6 +239,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert (dist_minus_1 + 1) >= 1
|
||||
assert ((dist_minus_1 + 1) as base.u64) <= args.dst.history_length()
|
||||
assert length >= 1
|
||||
assert (length as base.u64) <= args.dst.length()
|
||||
assert ((length + 8) as base.u64) <= args.dst.length()
|
||||
|
||||
@@ -261,8 +265,8 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.loop
|
||||
}
|
||||
}.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
@@ -286,7 +290,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.bits = (bits & (((1 as base.u64) << n_bits) - 1)) as base.u32
|
||||
this.n_bits = n_bits
|
||||
|
||||
@@ -58,7 +58,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
bits |= b0 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (table_entry >> 31) <> 0 {
|
||||
// Literal.
|
||||
@@ -86,7 +86,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b1 = args.src.read_u8_as_u32?()
|
||||
bits |= b1 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (table_entry >> 31) <> 0 {
|
||||
// Literal.
|
||||
@@ -126,7 +126,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b2 = args.src.read_u8_as_u32?()
|
||||
bits |= b2 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
// The "+ 253" is the same as "- 3", after the "& 0xFF", but the
|
||||
// plus form won't require an underflow check.
|
||||
length = ((length + 253 + bits.low_bits(n: table_entry_n_bits)) & 0xFF) + 3
|
||||
@@ -147,7 +147,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b3 = args.src.read_u8_as_u32?()
|
||||
bits |= b3 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
// Check for a redirect.
|
||||
if (table_entry >> 28) == 1 {
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
@@ -164,7 +164,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b4 = args.src.read_u8_as_u32?()
|
||||
bits |= b4 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// For H-D, all symbols should be base_number + extra_bits.
|
||||
@@ -191,7 +191,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
b5 = args.src.read_u8_as_u32?()
|
||||
bits |= b5 << n_bits
|
||||
n_bits += 8
|
||||
} endwhile
|
||||
}
|
||||
dist_minus_1 = (dist_minus_1 + bits.low_bits(n: table_entry_n_bits)) & 0x7FFF
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
@@ -243,8 +243,8 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
}
|
||||
length -= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile.inner
|
||||
} endwhile.loop
|
||||
}.inner
|
||||
}.loop
|
||||
|
||||
// TODO: "assert n_bits < 8"? What about (bits >> n_bits)?
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ pub status "#truncated input"
|
||||
|
||||
pri status "#internal error: inconsistent I/O"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
// See the spec appendix E "Interlaced Images" on page 29. The first element
|
||||
// represents either that the frame was non-interlaced, or that all interlace
|
||||
|
||||
+39
-48
@@ -141,7 +141,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -205,7 +205,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
@@ -249,7 +249,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
}
|
||||
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
|
||||
chunk_length = args.src.peek_u8_as_u64()
|
||||
if chunk_length <= 0 {
|
||||
@@ -278,7 +278,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
}
|
||||
|
||||
yield? base."$even more information"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if args.minfo <> nullptr {
|
||||
args.minfo.set!(
|
||||
@@ -333,10 +333,6 @@ pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
max_excl_y: this.dirty_max_excl_y.min(no_more_than: this.height))
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -367,7 +363,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -415,7 +411,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
post args.src.length() > 0,
|
||||
{
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
flags = args.src.peek_u8()
|
||||
if (flags & 0x80) <> 0 {
|
||||
background_color = this.black_color_u32_argb_premul
|
||||
@@ -481,7 +477,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: honor args.opts.
|
||||
@@ -552,22 +548,17 @@ pri func decoder.decode_up_to_id_part1?(src: base.io_reader) {
|
||||
this.call_sequence = 0x60
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// decode_header reads either "GIF87a" or "GIF89a".
|
||||
//
|
||||
// See the spec section 17 "Header" on page 7.
|
||||
pri func decoder.decode_header?(src: base.io_reader) {
|
||||
var c : array[6] base.u8
|
||||
var i : base.u32
|
||||
var c48 : base.u64
|
||||
|
||||
while i < 6 {
|
||||
c[i] = args.src.read_u8?()
|
||||
i += 1
|
||||
} endwhile
|
||||
if (c[0] <> 'G') or (c[1] <> 'I') or (c[2] <> 'F') or (c[3] <> '8') or
|
||||
((c[4] <> '7') and (c[4] <> '9')) or (c[5] <> 'a') {
|
||||
c48 = args.src.read_u48le_as_u64?()
|
||||
if (c48 <> 'GIF87a'le) and (c48 <> 'GIF89a'le) {
|
||||
return "#bad header"
|
||||
}
|
||||
}
|
||||
@@ -606,7 +597,7 @@ pri func decoder.decode_lsd?(src: base.io_reader) {
|
||||
this.palettes[0][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.palettes[0][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.quirks[QUIRK_HONOR_BACKGROUND_COLOR - QUIRKS_BASE] {
|
||||
if (background_color_index <> 0) and
|
||||
@@ -635,7 +626,7 @@ pri func decoder.decode_lsd?(src: base.io_reader) {
|
||||
this.palettes[0][(4 * i) + 2] = 0x00
|
||||
this.palettes[0][(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// decode_extension reads an extension. The Extension Introducer byte has
|
||||
@@ -671,12 +662,12 @@ pri func decoder.skip_blocks?(src: base.io_reader) {
|
||||
return ok
|
||||
}
|
||||
args.src.skip_u32?(n: block_size as base.u32)
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// decode_ae reads an Application Extension.
|
||||
pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var block_size : base.u8
|
||||
var is_animexts : base.bool
|
||||
var is_netscape : base.bool
|
||||
@@ -709,13 +700,13 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
is_xmp = true
|
||||
block_size = 0 // Re-purpose the block_size variable as a counter.
|
||||
while block_size < 11 {
|
||||
c = args.src.read_u8?()
|
||||
is_animexts = is_animexts and (c == ANIMEXTS1DOT0[block_size])
|
||||
is_netscape = is_netscape and (c == NETSCAPE2DOT0[block_size])
|
||||
is_iccp = is_iccp and (c == ICCRGBG1012[block_size])
|
||||
is_xmp = is_xmp and (c == XMPDATAXMP[block_size])
|
||||
c8 = args.src.read_u8?()
|
||||
is_animexts = is_animexts and (c8 == ANIMEXTS1DOT0[block_size])
|
||||
is_netscape = is_netscape and (c8 == NETSCAPE2DOT0[block_size])
|
||||
is_iccp = is_iccp and (c8 == ICCRGBG1012[block_size])
|
||||
is_xmp = is_xmp and (c8 == XMPDATAXMP[block_size])
|
||||
block_size += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if is_animexts or is_netscape {
|
||||
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
|
||||
@@ -725,8 +716,8 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
args.src.skip_u32?(n: block_size as base.u32)
|
||||
break.goto_done
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x01 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x01 {
|
||||
args.src.skip_u32?(n: 2)
|
||||
break.goto_done
|
||||
}
|
||||
@@ -764,19 +755,19 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
this.skip_blocks?(src: args.src)
|
||||
}
|
||||
|
||||
// decode_gc reads a Graphic Control.
|
||||
pri func decoder.decode_gc?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var flags : base.u8
|
||||
var gc_duration_centiseconds : base.u16
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if c <> 4 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 4 {
|
||||
return "#bad graphic control"
|
||||
}
|
||||
|
||||
@@ -803,8 +794,8 @@ pri func decoder.decode_gc?(src: base.io_reader) {
|
||||
this.gc_duration = (gc_duration_centiseconds as base.u64) * 7_056000
|
||||
this.gc_transparent_index = args.src.read_u8?()
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0 {
|
||||
return "#bad graphic control"
|
||||
}
|
||||
}
|
||||
@@ -875,7 +866,7 @@ pri func decoder.decode_id_part1?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
this.palettes[1][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.palettes[1][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
// Set the remaining palette entries to opaque black.
|
||||
while i < 256 {
|
||||
this.palettes[1][(4 * i) + 0] = 0x00
|
||||
@@ -883,7 +874,7 @@ pri func decoder.decode_id_part1?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
this.palettes[1][(4 * i) + 2] = 0x00
|
||||
this.palettes[1][(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
} else if this.quirks[QUIRK_REJECT_EMPTY_PALETTE - QUIRKS_BASE] and (not this.has_global_palette) {
|
||||
return "#bad palette"
|
||||
} else if this.gc_has_transparent_index {
|
||||
@@ -962,7 +953,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
while args.src.length() == 0 {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.compressed_ri == this.compressed_wi {
|
||||
this.compressed_ri = 0
|
||||
@@ -987,7 +978,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
block_size = args.src.peek_u8_as_u64()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while.inner true {
|
||||
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
|
||||
@@ -1041,8 +1032,8 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return "#bad LZW code"
|
||||
}
|
||||
return "#internal error: inconsistent I/O"
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
|
||||
this.compressed_ri = 0
|
||||
this.compressed_wi = 0
|
||||
@@ -1147,7 +1138,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
replicate_dst = tab.row_u32(y: replicate_y0)
|
||||
replicate_dst.copy_from_slice!(s: replicate_src)
|
||||
replicate_y0 += 1
|
||||
} endwhile
|
||||
}
|
||||
this.dirty_max_excl_y = this.dirty_max_excl_y.max(no_less_than: replicate_y1)
|
||||
}
|
||||
|
||||
@@ -1155,7 +1146,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
while (this.interlace > 0) and (this.dst_y >= this.frame_rect_y1) {
|
||||
this.interlace -= 1
|
||||
this.dst_y = this.frame_rect_y0 ~sat+ INTERLACE_START[this.interlace]
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1181,7 +1172,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
while (this.interlace > 0) and (this.dst_y >= this.frame_rect_y1) {
|
||||
this.interlace -= 1
|
||||
this.dst_y = this.frame_rect_y0 ~sat+ INTERLACE_START[this.interlace]
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1189,6 +1180,6 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice b
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
@@ -41,7 +41,7 @@ pri func decoder.lzw_init!() {
|
||||
this.lzw_lm1s[i] = 0
|
||||
this.lzw_suffixes[i][0] = i as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
@@ -194,7 +194,7 @@ pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
// in practice, but is necessary for the overflow checker.
|
||||
o = (o ~mod- 8) & 8191
|
||||
c = this.lzw_prefixes[c] as base.u32
|
||||
} endwhile
|
||||
}
|
||||
first_byte = this.lzw_suffixes[c][0]
|
||||
|
||||
if code == save_code {
|
||||
@@ -235,7 +235,7 @@ pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
this.lzw_read_from_return_value = 1
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Rewind args.src, if we're not in "$short read" and we've read too many
|
||||
// bits.
|
||||
@@ -248,7 +248,7 @@ pri func decoder.lzw_read_from!(src: base.io_reader) {
|
||||
this.lzw_read_from_return_value = 5
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.lzw_save_code = save_code
|
||||
|
||||
+23
-23
@@ -17,7 +17,7 @@ pub status "#bad encoding flags"
|
||||
pub status "#bad header"
|
||||
pub status "#truncated input"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
// TODO: reference deflate.DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE.
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
|
||||
@@ -46,8 +46,8 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.util.make_optional_u63(has_value: true, value: 0)
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
@@ -65,31 +65,31 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var flags : base.u8
|
||||
var xlen : base.u16
|
||||
var mark : base.u64
|
||||
var checksum_got : base.u32
|
||||
var decoded_length_got : base.u32
|
||||
var checksum_have : base.u32
|
||||
var decoded_length_have : base.u32
|
||||
var status : base.status
|
||||
var checksum_want : base.u32
|
||||
var decoded_length_want : base.u32
|
||||
|
||||
// Read the header.
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x1F {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x1F {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x8B {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x8B {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x08 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x08 {
|
||||
return "#bad compression method"
|
||||
}
|
||||
flags = args.src.read_u8?()
|
||||
@@ -109,21 +109,21 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
// filename length to NAME_MAX, which is 255.
|
||||
if (flags & 0x08) <> 0 {
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Handle FCOMMENT.
|
||||
if (flags & 0x10) <> 0 {
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Handle FHCRC.
|
||||
@@ -141,18 +141,18 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
mark = args.dst.mark()
|
||||
status =? this.flate.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if not this.ignore_checksum {
|
||||
checksum_got = this.checksum.update_u32!(x: args.dst.since(mark: mark))
|
||||
decoded_length_got ~mod+= (args.dst.count_since(mark: mark) & 0xFFFF_FFFF) as base.u32
|
||||
checksum_have = this.checksum.update_u32!(x: args.dst.since(mark: mark))
|
||||
decoded_length_have ~mod+= (args.dst.count_since(mark: mark) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
checksum_want = args.src.read_u32le?()
|
||||
decoded_length_want = args.src.read_u32le?()
|
||||
if (not this.ignore_checksum) and
|
||||
((checksum_got <> checksum_want) or (decoded_length_got <> decoded_length_want)) {
|
||||
((checksum_have <> checksum_want) or (decoded_length_have <> decoded_length_want)) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
@@ -628,7 +628,7 @@ pri func decoder.decode_idct_x86_avx2!(dst_buffer: slice base.u8, dst_stride: ba
|
||||
// intermediatedh = i16x16 [in.d0 .. in.d3 in.d4 .. in.d7 in.h0 .. in.h4 in.h5 .. in.h7]
|
||||
|
||||
break.goto_do_second_pass
|
||||
}} endwhile.goto_do_second_pass
|
||||
}}.goto_do_second_pass
|
||||
|
||||
// ----
|
||||
|
||||
|
||||
+337
-201
@@ -15,8 +15,10 @@ pub status "#bad SOF marker"
|
||||
pub status "#bad SOS marker"
|
||||
pub status "#bad header"
|
||||
pub status "#bad marker"
|
||||
pub status "#bad scan count"
|
||||
pub status "#missing Huffman table"
|
||||
pub status "#missing Quantization table"
|
||||
pub status "#rejected progressive JPEG"
|
||||
pub status "#truncated input"
|
||||
pub status "#unsupported arithmetic coding"
|
||||
pub status "#unsupported color model"
|
||||
@@ -32,8 +34,7 @@ pub status "#unsupported scan count"
|
||||
|
||||
pri status "#internal error: inconsistent decoder state"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0xC_00C0_0300
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0xC_00C0_0300
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0xFFFF],
|
||||
@@ -279,6 +280,16 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
bitstream_is_closed : base.bool,
|
||||
|
||||
expect_multiple_scans : base.bool,
|
||||
|
||||
use_lower_quality : base.bool,
|
||||
reject_progressive_jpegs : base.bool,
|
||||
|
||||
swizzle_immediately : base.bool,
|
||||
swizzle_immediately_status : base.status,
|
||||
swizzle_immediately_b_offsets : array[10] base.u32[..= 576],
|
||||
swizzle_immediately_c_offsets : array[5] base.u32,
|
||||
|
||||
// bitstream_padding is the number (per restart) of implicit zeroes
|
||||
// remaining at the end of the bitstream. Its initial 12345 value is
|
||||
// arbitrary.
|
||||
@@ -312,6 +323,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
// Decoding progressive JPEGs can use all of it.
|
||||
mcu_blocks : array[10] array[64] base.u16,
|
||||
|
||||
swizzle_immediately_buffer : array[640] base.u8,
|
||||
|
||||
swizzle_ycck_scratch_buffer_2k : array[2048] base.u8,
|
||||
|
||||
// The dht_temp_etc fields are decode_dht temporary values.
|
||||
@@ -327,10 +340,26 @@ pub struct decoder? implements base.image_decoder(
|
||||
)
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if args.key == base.QUIRK_QUALITY {
|
||||
if this.use_lower_quality {
|
||||
return 0xFFFF_FFFF_FFFF_FFFF
|
||||
}
|
||||
} else if args.key == QUIRK_REJECT_PROGRESSIVE_JPEGS {
|
||||
if this.reject_progressive_jpegs {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
if args.key == base.QUIRK_QUALITY {
|
||||
this.use_lower_quality = args.value >= 0x8000_0000_0000_0000
|
||||
return ok
|
||||
} else if args.key == QUIRK_REJECT_PROGRESSIVE_JPEGS {
|
||||
this.reject_progressive_jpegs = args.value <> 0
|
||||
return ok
|
||||
}
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
@@ -343,11 +372,11 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var marker : base.u8
|
||||
var pixfmt : base.u32
|
||||
|
||||
@@ -355,12 +384,12 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0xFF {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0xFF {
|
||||
return "#bad header"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0xD8 { // SOI (Start Of Image).
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0xD8 { // SOI (Start Of Image).
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
@@ -368,22 +397,22 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
while true {
|
||||
// Read the marker (a two-byte 0xFF 0x?? sequence).
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c == 0xFF {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0xFF {
|
||||
break
|
||||
}
|
||||
// Getting here is invalid according to the JPEG spec, but libjpeg
|
||||
// treats this as a warning (JWRN_EXTRANEOUS_DATA), not an error.
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0xFF {
|
||||
marker = c
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0xFF {
|
||||
marker = c8
|
||||
break
|
||||
}
|
||||
// Section B.1.1.2: "Any marker may optionally be preceded by any
|
||||
// number of [0xFF] fill bytes".
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if marker == 0x00 {
|
||||
// Ignore byte stuffing.
|
||||
@@ -408,7 +437,9 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
|
||||
} else if marker < 0xD0 { // SOFn (Start of Frame) and friends.
|
||||
if marker <= 0xC2 {
|
||||
if this.sof_marker <> 0 {
|
||||
if (marker == 0xC2) and this.reject_progressive_jpegs {
|
||||
return "#rejected progressive JPEG"
|
||||
} else if this.sof_marker <> 0 {
|
||||
return "#bad SOF marker"
|
||||
}
|
||||
this.sof_marker = marker
|
||||
@@ -473,7 +504,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
|
||||
args.src.skip_u32?(n: this.payload_length)
|
||||
this.payload_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
choose decode_idct = [
|
||||
// TODO: decode_idct_arm_neon,
|
||||
@@ -501,20 +532,20 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
}
|
||||
|
||||
pri func decoder.decode_dqt?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var q : base.u8[..= 3]
|
||||
var i : base.u32
|
||||
var c8 : base.u8
|
||||
var q : base.u8[..= 3]
|
||||
var i : base.u32
|
||||
|
||||
while this.payload_length > 0 {
|
||||
this.payload_length -= 1
|
||||
c = args.src.read_u8?()
|
||||
if (c & 0x0F) > 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 & 0x0F) > 3 {
|
||||
return "#bad DQT marker"
|
||||
}
|
||||
q = c & 0x0F
|
||||
if (c >> 4) == 1 {
|
||||
q = c8 & 0x0F
|
||||
if (c8 >> 4) == 1 {
|
||||
return "#unsupported precision"
|
||||
} else if ((c >> 4) > 1) or (this.payload_length < 64) {
|
||||
} else if ((c8 >> 4) > 1) or (this.payload_length < 64) {
|
||||
return "#bad DQT marker"
|
||||
}
|
||||
this.payload_length -= 64
|
||||
@@ -523,7 +554,7 @@ pri func decoder.decode_dqt?(src: base.io_reader) {
|
||||
while i < 64 {
|
||||
i += 1
|
||||
this.quant_tables[q][UNZIG[i]] = args.src.read_u8_as_u16?()
|
||||
} endwhile
|
||||
}
|
||||
this.seen_dqt[q] = true
|
||||
|
||||
if this.sof_marker == 0 {
|
||||
@@ -531,10 +562,10 @@ pri func decoder.decode_dqt?(src: base.io_reader) {
|
||||
while i < 64 {
|
||||
this.saved_quant_tables[q][i] = this.quant_tables[q][i]
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
this.saved_seen_dqt[q] = true
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_dri?(src: base.io_reader) {
|
||||
@@ -597,14 +628,14 @@ pri func decoder.decode_appn?(src: base.io_reader, marker: base.u8) {
|
||||
}
|
||||
}
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
args.src.skip_u32?(n: this.payload_length)
|
||||
this.payload_length = 0
|
||||
}
|
||||
|
||||
pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var comp_h : base.u8
|
||||
var comp_v : base.u8
|
||||
var i : base.u32
|
||||
@@ -628,12 +659,12 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
return "#bad SOF marker"
|
||||
}
|
||||
this.payload_length -= 6
|
||||
c = args.src.read_u8?()
|
||||
if c == 8 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 8 {
|
||||
// No-op.
|
||||
} else if c == 12 {
|
||||
} else if c8 == 12 {
|
||||
return "#unsupported precision (12 bits)"
|
||||
} else if c == 16 {
|
||||
} else if c8 == 16 {
|
||||
return "#unsupported precision (16 bits)"
|
||||
} else {
|
||||
return "#unsupported precision"
|
||||
@@ -646,13 +677,13 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
if this.width == 0 {
|
||||
return base."#unsupported image dimension"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if (c == 0) or (c > 4) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == 0) or (c8 > 4) {
|
||||
return "#bad SOF marker"
|
||||
} else if c == 2 {
|
||||
} else if c8 == 2 {
|
||||
return "#unsupported color model"
|
||||
}
|
||||
this.num_components = c as base.u32
|
||||
this.num_components = c8 as base.u32
|
||||
if this.payload_length <> (3 * this.num_components) {
|
||||
return "#bad SOF marker"
|
||||
}
|
||||
@@ -662,9 +693,9 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
while i < this.num_components {
|
||||
assert i < 4 via "a < b: a < c; c <= b"(c: this.num_components)
|
||||
this.components_c[i] = args.src.read_u8?()
|
||||
c = args.src.read_u8?()
|
||||
comp_h = c >> 4
|
||||
comp_v = c & 0x0F
|
||||
c8 = args.src.read_u8?()
|
||||
comp_h = c8 >> 4
|
||||
comp_v = c8 & 0x0F
|
||||
if (comp_h == 0) or (comp_h > 4) or (comp_v == 0) or (comp_v > 4) {
|
||||
return "#bad SOF marker"
|
||||
}
|
||||
@@ -676,11 +707,11 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
if this.max_incl_components_v < this.components_v[i] {
|
||||
this.max_incl_components_v = this.components_v[i]
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if c >= 4 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 >= 4 {
|
||||
return "#bad SOF marker"
|
||||
}
|
||||
this.components_tq[i] = c
|
||||
this.components_tq[i] = c8
|
||||
|
||||
// Section B.2.2: "the value of C_i shall be different from the values
|
||||
// of C_1 through C_(i-1)".
|
||||
@@ -693,10 +724,10 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
return "#bad SOF marker"
|
||||
}
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.num_components == 1 {
|
||||
// The first (and only) component's H and V factors are effectively
|
||||
@@ -722,7 +753,7 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
has_v24 = has_v24 or (this.components_v[i] == 2) or (this.components_v[i] == 4)
|
||||
has_v3 = has_v3 or (this.components_v[i] == 3)
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (has_h24 and has_h3) or (has_v24 and has_v3) {
|
||||
return "#unsupported fractional sampling"
|
||||
}
|
||||
@@ -787,9 +818,9 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
{
|
||||
this.block_smoothing_lowest_scan_al[i][j] = 16
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.components_workbuf_offsets[0] = 0
|
||||
@@ -830,7 +861,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -879,15 +910,29 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
ddf_status = "#truncated input"
|
||||
}
|
||||
|
||||
if ddf_status.is_error() or (scan_count < this.scan_count) {
|
||||
if (not this.swizzle_immediately) and
|
||||
(ddf_status.is_error() or (scan_count < this.scan_count)) {
|
||||
if this.sof_marker >= 0xC2 {
|
||||
this.apply_progressive_idct!(workbuf: args.workbuf)
|
||||
}
|
||||
|
||||
if this.num_components == 1 {
|
||||
swizzle_status = this.swizzle_gray!(dst: args.dst, workbuf: args.workbuf)
|
||||
swizzle_status = this.swizzle_gray!(
|
||||
dst: args.dst,
|
||||
workbuf: args.workbuf,
|
||||
x0: 0,
|
||||
x1: 0xFFFF_FFFF,
|
||||
y0: 0,
|
||||
y1: 0xFFFF_FFFF,
|
||||
stride: this.components_workbuf_widths[0] as base.u64)
|
||||
} else {
|
||||
swizzle_status = this.swizzle_colorful!(dst: args.dst, workbuf: args.workbuf)
|
||||
swizzle_status = this.swizzle_colorful!(
|
||||
dst: args.dst,
|
||||
workbuf: args.workbuf,
|
||||
x0: 0,
|
||||
x1: 0xFFFF_FFFF,
|
||||
y0: 0,
|
||||
y1: 0xFFFF_FFFF)
|
||||
}
|
||||
if ddf_status.is_error() {
|
||||
return ddf_status
|
||||
@@ -897,13 +942,13 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
}
|
||||
|
||||
yield? ddf_status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var pixfmt : base.u32
|
||||
var status : base.status
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var marker : base.u8
|
||||
|
||||
if this.call_sequence == 0x40 {
|
||||
@@ -930,9 +975,14 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
|
||||
// For progressive JPEGs, zero-initialize the saved pre-IDCT blocks. For
|
||||
// sequential JPEGs, this is a no-op, other than checking that args.workbuf
|
||||
// is long enough.
|
||||
// is long enough and setting this.swizzle_immediately.
|
||||
this.swizzle_immediately = false
|
||||
if this.components_workbuf_offsets[8] > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
if this.sof_marker >= 0xC2 {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
this.swizzle_immediately = this.use_lower_quality
|
||||
this.swizzle_immediately_status = ok
|
||||
} else if this.components_workbuf_offsets[4] < this.components_workbuf_offsets[8] {
|
||||
args.workbuf[this.components_workbuf_offsets[4] .. this.components_workbuf_offsets[8]].bulk_memset!(byte_value: 0)
|
||||
}
|
||||
@@ -949,22 +999,22 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
while true {
|
||||
// Read the marker (a two-byte 0xFF 0x?? sequence).
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c == 0xFF {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0xFF {
|
||||
break
|
||||
}
|
||||
// Getting here is invalid according to the JPEG spec, but libjpeg
|
||||
// treats this as a warning (JWRN_EXTRANEOUS_DATA), not an error.
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0xFF {
|
||||
marker = c
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0xFF {
|
||||
marker = c8
|
||||
break
|
||||
}
|
||||
// Section B.1.1.2: "Any marker may optionally be preceded by any
|
||||
// number of [0xFF] fill bytes".
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if marker == 0x00 {
|
||||
// Ignore byte stuffing.
|
||||
@@ -1007,7 +1057,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
break
|
||||
|
||||
} else if marker == 0xDA { // SOS (Start Of Scan).
|
||||
this.decode_sos?(src: args.src, workbuf: args.workbuf)
|
||||
this.decode_sos?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
continue
|
||||
|
||||
} else if marker == 0xDB { // DQT (Define Quantization Table).
|
||||
@@ -1039,13 +1089,13 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
|
||||
args.src.skip_u32?(n: this.payload_length)
|
||||
this.payload_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var tc : base.u8[..= 1]
|
||||
var th : base.u8[..= 3]
|
||||
var tc4_th : base.u8[..= 7]
|
||||
@@ -1062,12 +1112,12 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
return "#bad DHT marker"
|
||||
}
|
||||
this.payload_length -= 17
|
||||
c = args.src.read_u8?()
|
||||
if ((c >> 4) > 1) or ((c & 0x0F) > 3) {
|
||||
c8 = args.src.read_u8?()
|
||||
if ((c8 >> 4) > 1) or ((c8 & 0x0F) > 3) {
|
||||
return "#bad DHT marker"
|
||||
}
|
||||
tc = c >> 4
|
||||
th = c & 0x0F
|
||||
tc = c8 >> 4
|
||||
th = c8 & 0x0F
|
||||
tc4_th = ((tc * 4) | th) as base.u8
|
||||
|
||||
// SOF0 (which is 0xC0) means a baseline JPEG. The baseline (th <= 1)
|
||||
@@ -1081,14 +1131,14 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
while i < 16 {
|
||||
this.dht_temp_counts[i] = args.src.read_u8?()
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
working_total_count = 0
|
||||
i = 0
|
||||
while i < 16 {
|
||||
working_total_count =
|
||||
(working_total_count + (this.dht_temp_counts[i] as base.u32)) & 0xFFFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if (working_total_count <= 0) or (256 < working_total_count) {
|
||||
return "#bad DHT marker"
|
||||
}
|
||||
@@ -1104,11 +1154,11 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c: total_count)
|
||||
this.huff_tables_symbols[tc4_th][i] = args.src.read_u8?()
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 256 {
|
||||
this.huff_tables_symbols[tc4_th][i] = 0
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// For tc == 0 (DC, not AC tables), the symbols must not exceed 15 (for
|
||||
// lossy JPEG) or 16 (for lossless JPEG). We only support lossy.
|
||||
@@ -1120,7 +1170,7 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
return "#bad DHT marker"
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
failed = this.calculate_huff_tables!(tc4_th: tc4_th, total_count: total_count)
|
||||
@@ -1129,7 +1179,7 @@ pri func decoder.decode_dht?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
this.seen_dht[tc4_th] = true
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: base.u32[..= 256]) base.bool {
|
||||
@@ -1156,12 +1206,12 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
{
|
||||
k = 0
|
||||
bit_length_minus_one = (bit_length_minus_one + 1) & 15
|
||||
} endwhile
|
||||
}
|
||||
assert k < 255 via "a < b: a < c; c <= b"(c: this.dht_temp_counts[bit_length_minus_one])
|
||||
k += 1
|
||||
this.dht_temp_bit_lengths[i] = (bit_length_minus_one + 1) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate dht_temp_bit_strings.
|
||||
bit_length = 0
|
||||
@@ -1177,7 +1227,7 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
}
|
||||
bit_length += 1
|
||||
bit_string ~mod<<= 1
|
||||
} endwhile
|
||||
}
|
||||
this.dht_temp_bit_strings[i] = (bit_string & 0xFFFF) as base.u16
|
||||
bit_string ~mod+= 1
|
||||
|
||||
@@ -1189,7 +1239,7 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate huff_tables_slow[args.tc4_th].
|
||||
k = 0
|
||||
@@ -1209,14 +1259,14 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
if bit_length_minus_one == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Calculate huff_tables_fast[args.tc4_th].
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.huff_tables_fast[args.tc4_th][i] = 0xFFFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
j = 0
|
||||
bit_length_minus_one = 0
|
||||
while bit_length_minus_one < 8 {
|
||||
@@ -1237,26 +1287,28 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
|
||||
this.huff_tables_fast[args.tc4_th][prefix] = fast
|
||||
prefix ~mod+= 1
|
||||
reps -= 1
|
||||
} endwhile
|
||||
}
|
||||
k += 1
|
||||
j ~mod+= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
bit_length_minus_one += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
pri func decoder.decode_sos?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var my : base.u32
|
||||
var mx : base.u32
|
||||
|
||||
var decode_mcu_result : base.u32
|
||||
var bitstream_length : base.u32
|
||||
|
||||
if this.scan_count >= 64 {
|
||||
if this.scan_count >= 32 {
|
||||
return "#unsupported scan count"
|
||||
} else if (this.scan_count > 0) and (not this.expect_multiple_scans) {
|
||||
return "#bad scan count"
|
||||
}
|
||||
|
||||
this.prepare_scan?(src: args.src)
|
||||
@@ -1295,11 +1347,15 @@ pri func decoder.decode_sos?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
inv my < 0x2000,
|
||||
inv mx < 0x2000,
|
||||
{
|
||||
decode_mcu_result = this.decode_mcu!(workbuf: args.workbuf, mx: mx, my: my)
|
||||
decode_mcu_result = this.decode_mcu!(dst: args.dst, workbuf: args.workbuf, mx: mx, my: my)
|
||||
if decode_mcu_result == 0 {
|
||||
break.decode_mcu
|
||||
} else if decode_mcu_result <> 1 {
|
||||
} else if decode_mcu_result == 1 {
|
||||
// No-op.
|
||||
} else if decode_mcu_result == 2 {
|
||||
return "#internal error: inconsistent decoder state"
|
||||
} else {
|
||||
return this.swizzle_immediately_status
|
||||
}
|
||||
|
||||
while.fill_bitstream true,
|
||||
@@ -1322,8 +1378,8 @@ pri func decoder.decode_sos?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
break.fill_bitstream
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile.fill_bitstream
|
||||
} endwhile.decode_mcu
|
||||
}.fill_bitstream
|
||||
}.decode_mcu
|
||||
|
||||
if this.sof_marker >= 0xC2 {
|
||||
this.save_mcu_blocks!(mx: mx, my: my, workbuf: args.workbuf)
|
||||
@@ -1351,15 +1407,15 @@ pri func decoder.decode_sos?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
}
|
||||
|
||||
mx += 1
|
||||
} endwhile
|
||||
}
|
||||
my += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.scan_count ~sat+= 1
|
||||
}
|
||||
|
||||
pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
var j_max_incl : base.u32[..= 9]
|
||||
@@ -1368,11 +1424,11 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
if (this.payload_length < 6) or (this.payload_length > 12) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if (c < 1) or (c > 4) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 < 1) or (c8 > 4) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
this.scan_num_components = c as base.u32
|
||||
this.scan_num_components = c8 as base.u32
|
||||
if (this.scan_num_components > this.num_components) or
|
||||
(this.payload_length <> (4 + (2 * this.scan_num_components))) {
|
||||
return "#bad SOS marker"
|
||||
@@ -1382,7 +1438,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
i = 0
|
||||
while i < this.scan_num_components {
|
||||
assert i < 4 via "a < b: a < c; c <= b"(c: this.scan_num_components)
|
||||
c = args.src.read_u8?()
|
||||
c8 = args.src.read_u8?()
|
||||
|
||||
j = 0
|
||||
while true,
|
||||
@@ -1392,7 +1448,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
assert j < 4 via "a < b: a < c; c <= b"(c: this.num_components)
|
||||
if c == this.components_c[j] {
|
||||
if c8 == this.components_c[j] {
|
||||
if not this.seen_dqt[this.components_tq[j]] {
|
||||
return "#missing Quantization table"
|
||||
}
|
||||
@@ -1400,7 +1456,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
break
|
||||
}
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Section B.2.3: "the value of C_sj shall be different from the values
|
||||
// of C_s1 to C_sj–1".
|
||||
@@ -1413,14 +1469,14 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if ((c >> 4) > 3) or ((c & 0x0F) > 3) {
|
||||
c8 = args.src.read_u8?()
|
||||
if ((c8 >> 4) > 3) or ((c8 & 0x0F) > 3) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
this.scan_comps_td[i] = c >> 4
|
||||
this.scan_comps_ta[i] = c & 0x0F
|
||||
this.scan_comps_td[i] = c8 >> 4
|
||||
this.scan_comps_ta[i] = c8 & 0x0F
|
||||
// SOF0 (which is 0xC0) means a baseline JPEG. The baseline (tx <= 1)
|
||||
// restriction is specified in table B.5.
|
||||
if this.sof_marker == 0xC0 {
|
||||
@@ -1430,7 +1486,13 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.scan_count == 0 {
|
||||
this.expect_multiple_scans =
|
||||
(this.sof_marker >= 0xC2) or
|
||||
(this.scan_num_components < this.num_components)
|
||||
}
|
||||
|
||||
if this.sof_marker < 0xC2 {
|
||||
// At this point, for sequential (not progressive) JPEGs, we should
|
||||
@@ -1443,24 +1505,24 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
this.scan_al = 0
|
||||
|
||||
} else {
|
||||
c = args.src.read_u8?()
|
||||
if c > 63 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 > 63 {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
this.scan_ss = c
|
||||
this.scan_ss = c8
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if (c > 63) or (c < this.scan_ss) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 > 63) or (c8 < this.scan_ss) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
this.scan_se = c
|
||||
this.scan_se = c8
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if ((c >> 4) > 14) or ((c & 0x0F) > 13) {
|
||||
c8 = args.src.read_u8?()
|
||||
if ((c8 >> 4) > 14) or ((c8 & 0x0F) > 13) {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
this.scan_ah = c >> 4
|
||||
this.scan_al = c & 0x0F
|
||||
this.scan_ah = c8 >> 4
|
||||
this.scan_al = c8 & 0x0F
|
||||
if this.scan_ah > 0 {
|
||||
if (this.scan_ah - 1) <> this.scan_al {
|
||||
return "#bad SOS marker"
|
||||
@@ -1507,10 +1569,10 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
assert j <= 9 via "a <= b: a <= c; c <= b"(c: j_max_incl)
|
||||
this.block_smoothing_lowest_scan_al[this.scan_comps_cselector[i]][j] = this.scan_al
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.scan_num_components == 1 {
|
||||
this.calculate_single_component_scan_fields!()
|
||||
@@ -1576,6 +1638,7 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
var b : base.u32
|
||||
var bx_offset : base.u32
|
||||
var by_offset : base.u32
|
||||
var sibo : base.u32
|
||||
var ssel : base.u8[..= 3]
|
||||
var csel : base.u8[..= 3]
|
||||
|
||||
@@ -1590,6 +1653,7 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
v = this.components_v[this.scan_comps_cselector[i]] as base.u32
|
||||
hv = ((this.components_h[this.scan_comps_cselector[i]] as base.u32) *
|
||||
(this.components_v[this.scan_comps_cselector[i]] as base.u32))
|
||||
this.swizzle_immediately_c_offsets[i] = 64 ~mod* total_hv
|
||||
total_hv ~mod+= hv
|
||||
|
||||
while hv > 0,
|
||||
@@ -1608,14 +1672,15 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
}
|
||||
}
|
||||
hv -= 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
if total_hv > 10 {
|
||||
return true
|
||||
}
|
||||
this.mcu_num_blocks = total_hv
|
||||
this.swizzle_immediately_c_offsets[this.scan_num_components] = 64 ~mod* total_hv
|
||||
|
||||
b = 0
|
||||
while b < this.mcu_num_blocks {
|
||||
@@ -1629,8 +1694,12 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
this.mcu_blocks_my_mul[b] = 8 * (this.components_v[csel] as base.u32) * this.components_workbuf_widths[csel]
|
||||
this.mcu_blocks_dc_hselector[b] = 0 | this.scan_comps_td[ssel]
|
||||
this.mcu_blocks_ac_hselector[b] = 4 | this.scan_comps_ta[ssel]
|
||||
sibo = this.swizzle_immediately_c_offsets[csel] ~mod+ (
|
||||
(8 * (this.scan_comps_bx_offset[b] as base.u32)) +
|
||||
(64 * (this.scan_comps_by_offset[b] as base.u32) * (this.components_h[csel] as base.u32)))
|
||||
this.swizzle_immediately_b_offsets[b] = sibo.min(no_more_than: 576)
|
||||
b += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.scan_width_in_mcus = this.width_in_mcus
|
||||
this.scan_height_in_mcus = this.height_in_mcus
|
||||
@@ -1639,7 +1708,7 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
|
||||
pri func decoder.fill_bitstream!(src: base.io_reader) {
|
||||
var wi : base.u32[..= 0x800]
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var new_wi : base.u32[..= 0x800]
|
||||
|
||||
// Compact unread bytes to the start of the buffer.
|
||||
@@ -1658,9 +1727,9 @@ pri func decoder.fill_bitstream!(src: base.io_reader) {
|
||||
|
||||
wi = this.bitstream_wi
|
||||
while (wi < 0x800) and (args.src.length() > 0) {
|
||||
c = args.src.peek_u8()
|
||||
if c < 0xFF {
|
||||
this.bitstream_buffer[wi] = c
|
||||
c8 = args.src.peek_u8()
|
||||
if c8 < 0xFF {
|
||||
this.bitstream_buffer[wi] = c8
|
||||
wi += 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
continue
|
||||
@@ -1676,7 +1745,7 @@ pri func decoder.fill_bitstream!(src: base.io_reader) {
|
||||
wi += 1
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// If we hit a "\xFF\x??" marker then pad the bitstream. In this method
|
||||
// invocation, insert up to 264 bytes of implicit zeroes. Repeated calls to
|
||||
@@ -1739,7 +1808,7 @@ pri func decoder.load_mcu_blocks!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2
|
||||
this.mcu_blocks[b .. (b + 1)].bulk_load_host_endian!(src: args.workbuf[offset ..])
|
||||
}
|
||||
b += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.save_mcu_blocks!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2000], workbuf: slice base.u8) {
|
||||
@@ -1769,11 +1838,11 @@ pri func decoder.save_mcu_blocks!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2
|
||||
this.mcu_blocks[b .. (b + 1)].bulk_save_host_endian!(dst: args.workbuf[offset ..])
|
||||
}
|
||||
b += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.skip_past_the_next_restart_marker?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
|
||||
while true {
|
||||
if args.src.length() < 2 {
|
||||
@@ -1784,24 +1853,24 @@ pri func decoder.skip_past_the_next_restart_marker?(src: base.io_reader) {
|
||||
continue
|
||||
}
|
||||
|
||||
c = (args.src.peek_u16le() >> 8) as base.u8
|
||||
if c < 0xC0 {
|
||||
c8 = (args.src.peek_u16le() >> 8) as base.u8
|
||||
if c8 < 0xC0 {
|
||||
// Either a reserved marker or "\xFF\x00" byte stuffing. Consume it
|
||||
// and continue.
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
continue
|
||||
} else if (c < 0xD0) or (0xD7 < c) {
|
||||
} else if (c8 < 0xD0) or (0xD7 < c8) {
|
||||
// Not an RSTn (Restart) marker. Leave it and break.
|
||||
break
|
||||
}
|
||||
|
||||
c &= 7
|
||||
if (this.next_restart_marker == ((c + 1) & 7)) or
|
||||
(this.next_restart_marker == ((c + 2) & 7)) {
|
||||
c8 &= 7
|
||||
if (this.next_restart_marker == ((c8 + 1) & 7)) or
|
||||
(this.next_restart_marker == ((c8 + 2) & 7)) {
|
||||
// A leading RSTn marker. Leave it and break.
|
||||
break
|
||||
} else if (this.next_restart_marker == ((c + 7) & 7)) or
|
||||
(this.next_restart_marker == ((c + 6) & 7)) {
|
||||
} else if (this.next_restart_marker == ((c8 + 7) & 7)) or
|
||||
(this.next_restart_marker == ((c8 + 6) & 7)) {
|
||||
// A lagging RSTn marker. Consume it and continue.
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
continue
|
||||
@@ -1811,7 +1880,7 @@ pri func decoder.skip_past_the_next_restart_marker?(src: base.io_reader) {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.next_restart_marker = (this.next_restart_marker ~mod+ 1) & 7
|
||||
}
|
||||
@@ -1847,7 +1916,7 @@ pri func decoder.apply_progressive_idct!(workbuf: slice base.u8) {
|
||||
block_smoothing_applicable = false
|
||||
}
|
||||
csel += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
csel = 0
|
||||
while csel < this.num_components {
|
||||
@@ -1907,25 +1976,26 @@ pri func decoder.apply_progressive_idct!(workbuf: slice base.u8) {
|
||||
}
|
||||
|
||||
mx += 1
|
||||
} endwhile
|
||||
}
|
||||
my += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
csel += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.mcu_blocks[.. 1].bulk_load_host_endian!(src: stashed_mcu_blocks_0[..])
|
||||
}
|
||||
|
||||
pri func decoder.swizzle_gray!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) base.status {
|
||||
pri func decoder.swizzle_gray!(dst: ptr base.pixel_buffer, workbuf: slice base.u8, x0: base.u32, x1: base.u32, y0: base.u32, y1: base.u32, stride: base.u64) base.status {
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||
var dst_length : base.u64
|
||||
var x0 : base.u64
|
||||
var x1 : base.u64
|
||||
var tab : table base.u8
|
||||
var dst : slice base.u8
|
||||
var y : base.u32
|
||||
var stride : base.u64[..= 0x4_0000]
|
||||
var y1 : base.u32[..= 0xFFFF]
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
@@ -1935,79 +2005,143 @@ pri func decoder.swizzle_gray!(dst: ptr base.pixel_buffer, workbuf: slice base.u
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||
dst_length = (dst_bytes_per_pixel * this.width) as base.u64
|
||||
x0 = (dst_bytes_per_pixel * args.x0.min(no_more_than: this.width)) as base.u64
|
||||
x1 = (dst_bytes_per_pixel * args.x1.min(no_more_than: this.width)) as base.u64
|
||||
|
||||
tab = args.dst.plane(p: 0)
|
||||
y = 0
|
||||
while y < this.height {
|
||||
assert y < 0xFFFF via "a < b: a < c; c <= b"(c: this.height)
|
||||
y = args.y0
|
||||
y1 = args.y1.min(no_more_than: this.height)
|
||||
while y < y1 {
|
||||
assert y < 0xFFFF via "a < b: a < c; c <= b"(c: y1)
|
||||
dst = tab.row_u32(y: y)
|
||||
if dst_length < dst.length() {
|
||||
dst = dst[.. dst_length]
|
||||
if x1 < dst.length() {
|
||||
dst = dst[.. x1]
|
||||
}
|
||||
if x0 < dst.length() {
|
||||
dst = dst[x0 ..]
|
||||
} else {
|
||||
dst = this.util.empty_slice_u8()
|
||||
}
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
|
||||
src: args.workbuf)
|
||||
stride = this.components_workbuf_widths[0] as base.u64
|
||||
if stride <= args.workbuf.length() {
|
||||
args.workbuf = args.workbuf[stride ..]
|
||||
|
||||
if args.stride <= args.workbuf.length() {
|
||||
args.workbuf = args.workbuf[args.stride ..]
|
||||
} else {
|
||||
args.workbuf = this.util.empty_slice_u8()
|
||||
}
|
||||
|
||||
y += 1
|
||||
} endwhile
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
pri func decoder.swizzle_colorful!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) base.status {
|
||||
var src0 : slice base.u8
|
||||
var src1 : slice base.u8
|
||||
var src2 : slice base.u8
|
||||
var src3 : slice base.u8
|
||||
var status : base.status
|
||||
pri func decoder.swizzle_colorful!(dst: ptr base.pixel_buffer, workbuf: slice base.u8, x0: base.u32, x1: base.u32, y0: base.u32, y1: base.u32) base.status {
|
||||
var i : base.u64
|
||||
var j : base.u64
|
||||
var src0 : slice base.u8
|
||||
var src1 : slice base.u8
|
||||
var src2 : slice base.u8
|
||||
var src3 : slice base.u8
|
||||
var width0 : base.u32[..= 0x1_0008]
|
||||
var width1 : base.u32[..= 0x1_0008]
|
||||
var width2 : base.u32[..= 0x1_0008]
|
||||
var width3 : base.u32[..= 0x1_0008]
|
||||
var height0 : base.u32[..= 0x1_0008]
|
||||
var height1 : base.u32[..= 0x1_0008]
|
||||
var height2 : base.u32[..= 0x1_0008]
|
||||
var height3 : base.u32[..= 0x1_0008]
|
||||
var status : base.status
|
||||
|
||||
if (this.components_workbuf_offsets[0] <= this.components_workbuf_offsets[1]) and
|
||||
(this.components_workbuf_offsets[1] <= args.workbuf.length()) {
|
||||
src0 = args.workbuf[this.components_workbuf_offsets[0] .. this.components_workbuf_offsets[1]]
|
||||
}
|
||||
if this.swizzle_immediately {
|
||||
i = this.swizzle_immediately_c_offsets[0] as base.u64
|
||||
j = this.swizzle_immediately_c_offsets[1] as base.u64
|
||||
if (i <= j) and (j <= 640) {
|
||||
src0 = this.swizzle_immediately_buffer[i .. j]
|
||||
width0 = 8 * (this.components_h[0] as base.u32)
|
||||
height0 = 8 * (this.components_v[0] as base.u32)
|
||||
}
|
||||
|
||||
if (this.components_workbuf_offsets[1] <= this.components_workbuf_offsets[2]) and
|
||||
(this.components_workbuf_offsets[2] <= args.workbuf.length()) {
|
||||
src1 = args.workbuf[this.components_workbuf_offsets[1] .. this.components_workbuf_offsets[2]]
|
||||
}
|
||||
i = this.swizzle_immediately_c_offsets[1] as base.u64
|
||||
j = this.swizzle_immediately_c_offsets[2] as base.u64
|
||||
if (i <= j) and (j <= 640) {
|
||||
src1 = this.swizzle_immediately_buffer[i .. j]
|
||||
width1 = 8 * (this.components_h[1] as base.u32)
|
||||
height1 = 8 * (this.components_v[1] as base.u32)
|
||||
}
|
||||
|
||||
if (this.components_workbuf_offsets[2] <= this.components_workbuf_offsets[3]) and
|
||||
(this.components_workbuf_offsets[3] <= args.workbuf.length()) {
|
||||
src2 = args.workbuf[this.components_workbuf_offsets[2] .. this.components_workbuf_offsets[3]]
|
||||
}
|
||||
i = this.swizzle_immediately_c_offsets[2] as base.u64
|
||||
j = this.swizzle_immediately_c_offsets[3] as base.u64
|
||||
if (i <= j) and (j <= 640) {
|
||||
src2 = this.swizzle_immediately_buffer[i .. j]
|
||||
width2 = 8 * (this.components_h[2] as base.u32)
|
||||
height2 = 8 * (this.components_v[2] as base.u32)
|
||||
}
|
||||
|
||||
if (this.components_workbuf_offsets[3] <= this.components_workbuf_offsets[4]) and
|
||||
(this.components_workbuf_offsets[4] <= args.workbuf.length()) {
|
||||
src3 = args.workbuf[this.components_workbuf_offsets[3] .. this.components_workbuf_offsets[4]]
|
||||
i = this.swizzle_immediately_c_offsets[3] as base.u64
|
||||
j = this.swizzle_immediately_c_offsets[4] as base.u64
|
||||
if (i <= j) and (j <= 640) {
|
||||
src3 = this.swizzle_immediately_buffer[i .. j]
|
||||
width3 = 8 * (this.components_h[3] as base.u32)
|
||||
height3 = 8 * (this.components_v[3] as base.u32)
|
||||
}
|
||||
|
||||
} else {
|
||||
if (this.components_workbuf_offsets[0] <= this.components_workbuf_offsets[1]) and
|
||||
(this.components_workbuf_offsets[1] <= args.workbuf.length()) {
|
||||
src0 = args.workbuf[this.components_workbuf_offsets[0] .. this.components_workbuf_offsets[1]]
|
||||
width0 = this.components_workbuf_widths[0]
|
||||
height0 = this.components_workbuf_heights[0]
|
||||
}
|
||||
|
||||
if (this.components_workbuf_offsets[1] <= this.components_workbuf_offsets[2]) and
|
||||
(this.components_workbuf_offsets[2] <= args.workbuf.length()) {
|
||||
src1 = args.workbuf[this.components_workbuf_offsets[1] .. this.components_workbuf_offsets[2]]
|
||||
width1 = this.components_workbuf_widths[1]
|
||||
height1 = this.components_workbuf_heights[1]
|
||||
}
|
||||
|
||||
if (this.components_workbuf_offsets[2] <= this.components_workbuf_offsets[3]) and
|
||||
(this.components_workbuf_offsets[3] <= args.workbuf.length()) {
|
||||
src2 = args.workbuf[this.components_workbuf_offsets[2] .. this.components_workbuf_offsets[3]]
|
||||
width2 = this.components_workbuf_widths[2]
|
||||
height2 = this.components_workbuf_heights[2]
|
||||
}
|
||||
|
||||
if (this.components_workbuf_offsets[3] <= this.components_workbuf_offsets[4]) and
|
||||
(this.components_workbuf_offsets[4] <= args.workbuf.length()) {
|
||||
src3 = args.workbuf[this.components_workbuf_offsets[3] .. this.components_workbuf_offsets[4]]
|
||||
width3 = this.components_workbuf_widths[3]
|
||||
height3 = this.components_workbuf_heights[3]
|
||||
}
|
||||
}
|
||||
|
||||
status = this.swizzler.swizzle_ycck!(
|
||||
dst: args.dst,
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
x_min_incl: args.x0 & 0xFFFF,
|
||||
x_max_excl: args.x1.min(no_more_than: this.width),
|
||||
y_min_incl: args.y0 & 0xFFFF,
|
||||
y_max_excl: args.y1.min(no_more_than: this.height),
|
||||
src0: src0,
|
||||
src1: src1,
|
||||
src2: src2,
|
||||
src3: src3,
|
||||
width0: this.components_workbuf_widths[0],
|
||||
width1: this.components_workbuf_widths[1],
|
||||
width2: this.components_workbuf_widths[2],
|
||||
width3: this.components_workbuf_widths[3],
|
||||
height0: this.components_workbuf_heights[0],
|
||||
height1: this.components_workbuf_heights[1],
|
||||
height2: this.components_workbuf_heights[2],
|
||||
height3: this.components_workbuf_heights[3],
|
||||
stride0: this.components_workbuf_widths[0],
|
||||
stride1: this.components_workbuf_widths[1],
|
||||
stride2: this.components_workbuf_widths[2],
|
||||
stride3: this.components_workbuf_widths[3],
|
||||
width0: width0,
|
||||
width1: width1,
|
||||
width2: width2,
|
||||
width3: width3,
|
||||
height0: height0,
|
||||
height1: height1,
|
||||
height2: height2,
|
||||
height3: height3,
|
||||
stride0: width0,
|
||||
stride1: width1,
|
||||
stride2: width2,
|
||||
stride3: width3,
|
||||
h0: this.components_h[0],
|
||||
h1: this.components_h[1],
|
||||
h2: this.components_h[2],
|
||||
@@ -2017,7 +2151,7 @@ pri func decoder.swizzle_colorful!(dst: ptr base.pixel_buffer, workbuf: slice ba
|
||||
v2: this.components_v[2],
|
||||
v3: this.components_v[3],
|
||||
is_rgb_or_cmyk: this.is_rgb_or_cmyk,
|
||||
triangle_filter_for_2to1: true,
|
||||
triangle_filter_for_2to1: not this.use_lower_quality,
|
||||
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
|
||||
return status
|
||||
}
|
||||
@@ -2061,6 +2195,7 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
|
||||
this.call_sequence = 0x28
|
||||
this.bitstream_is_closed = false
|
||||
this.expect_multiple_scans = false
|
||||
this.frame_config_io_position = args.io_position
|
||||
this.scan_count = 0
|
||||
this.restart_interval = this.saved_restart_interval
|
||||
@@ -2074,9 +2209,9 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
{
|
||||
this.quant_tables[i][j] = this.saved_quant_tables[i][j]
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 4 {
|
||||
@@ -2086,15 +2221,15 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
{
|
||||
this.block_smoothing_lowest_scan_al[i][j] = 16
|
||||
j += 1
|
||||
} endwhile
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 8 {
|
||||
this.seen_dht[i] = false
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -2107,11 +2242,12 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
if this.use_lower_quality and (this.sof_marker < 0xC2) {
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: 0,
|
||||
max_incl: this.components_workbuf_offsets[8])
|
||||
}
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: this.components_workbuf_offsets[8],
|
||||
max_incl: this.components_workbuf_offsets[8])
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----
|
||||
// --------
|
||||
|
||||
// Consider the 8×8 = 64 coefficients (1 DC, 63 AC) in a block. The low
|
||||
// frequency ones are in the top-left corner and their offsets into the
|
||||
@@ -92,9 +92,9 @@ pri func decoder.load_mcu_blocks_for_single_component_smooth!(mx: base.u32[..= 0
|
||||
}
|
||||
|
||||
dx += 1
|
||||
} endwhile
|
||||
}
|
||||
dy += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
q = this.components_tq[args.csel]
|
||||
q_00 = this.quant_tables[q][0x00] as base.u32
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32,
|
||||
pri func decoder.decode_mcu!(dst: ptr base.pixel_buffer, workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32,
|
||||
choosy,
|
||||
{
|
||||
var ret : base.u32
|
||||
@@ -115,7 +115,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
dc_extend = EXTEND[dc_symbol]
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Process the dc_value in the next dc_symbol (up to 15) bits.
|
||||
@@ -134,7 +134,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
|
||||
this.mcu_zig_index = 1
|
||||
break.dc_component
|
||||
} endwhile.dc_component
|
||||
}.dc_component
|
||||
|
||||
// Ensure that we have enough bits for this iteration of the
|
||||
// while.block loop body. Worst case, there are 64 components and
|
||||
@@ -234,7 +234,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
ac_symbol = 0
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Split the 8-bit ac_symbol into two 4-bit halves, per section
|
||||
@@ -256,7 +256,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
} else if ac_rrrr < 15 {
|
||||
break.ac_components
|
||||
}
|
||||
} endwhile.ac_components
|
||||
}.ac_components
|
||||
|
||||
assert this.mcu_current_block < 10
|
||||
mcb = this.mcu_current_block
|
||||
@@ -266,23 +266,68 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
}
|
||||
|
||||
// Apply IDCT.
|
||||
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[mcb]]
|
||||
stride = this.components_workbuf_widths[csel] as base.u64
|
||||
offset = this.mcu_blocks_offset[mcb] +
|
||||
((this.mcu_blocks_mx_mul[mcb] as base.u64) * (args.mx as base.u64)) +
|
||||
((this.mcu_blocks_my_mul[mcb] as base.u64) * (args.my as base.u64))
|
||||
if offset <= args.workbuf.length() {
|
||||
|
||||
if not this.swizzle_immediately {
|
||||
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[mcb]]
|
||||
stride = this.components_workbuf_widths[csel] as base.u64
|
||||
offset = this.mcu_blocks_offset[mcb] +
|
||||
((this.mcu_blocks_mx_mul[mcb] as base.u64) * (args.mx as base.u64)) +
|
||||
((this.mcu_blocks_my_mul[mcb] as base.u64) * (args.my as base.u64))
|
||||
if offset <= args.workbuf.length() {
|
||||
this.decode_idct!(
|
||||
dst_buffer: args.workbuf[offset ..],
|
||||
dst_stride: stride,
|
||||
q: this.components_tq[csel] as base.u32)
|
||||
|
||||
}
|
||||
|
||||
} else if this.num_components == 1 {
|
||||
this.decode_idct!(
|
||||
dst_buffer: args.workbuf[offset ..],
|
||||
dst_buffer: this.swizzle_immediately_buffer[.. 64],
|
||||
dst_stride: 8,
|
||||
q: this.components_tq[csel] as base.u32)
|
||||
this.swizzle_immediately_status = this.swizzle_gray!(
|
||||
dst: args.dst,
|
||||
workbuf: this.swizzle_immediately_buffer[.. 64],
|
||||
x0: (args.mx + 0) * 8,
|
||||
x1: (args.mx + 1) * 8,
|
||||
y0: (args.my + 0) * 8,
|
||||
y1: (args.my + 1) * 8,
|
||||
stride: 8)
|
||||
if not this.swizzle_immediately_status.is_ok() {
|
||||
ret = 3 // Swizzling failure.
|
||||
break.goto_done
|
||||
}
|
||||
break.block
|
||||
|
||||
} else {
|
||||
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[mcb]]
|
||||
stride = 8 * (this.components_h[csel] as base.u64)
|
||||
this.decode_idct!(
|
||||
dst_buffer: this.swizzle_immediately_buffer[this.swizzle_immediately_b_offsets[mcb] ..],
|
||||
dst_stride: stride,
|
||||
q: this.components_tq[csel] as base.u32)
|
||||
|
||||
if this.mcu_current_block < this.mcu_num_blocks {
|
||||
continue.block
|
||||
}
|
||||
this.swizzle_immediately_status = this.swizzle_colorful!(
|
||||
dst: args.dst,
|
||||
workbuf: this.util.empty_slice_u8(),
|
||||
x0: (args.mx + 0) * 8 * (this.max_incl_components_h as base.u32),
|
||||
x1: (args.mx + 1) * 8 * (this.max_incl_components_h as base.u32),
|
||||
y0: (args.my + 0) * 8 * (this.max_incl_components_v as base.u32),
|
||||
y1: (args.my + 1) * 8 * (this.max_incl_components_v as base.u32))
|
||||
if not this.swizzle_immediately_status.is_ok() {
|
||||
ret = 3 // Swizzling failure.
|
||||
break.goto_done
|
||||
}
|
||||
break.block
|
||||
}
|
||||
} endwhile.block
|
||||
}.block
|
||||
this.mcu_current_block = 0
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
pri func decoder.decode_mcu_progressive_ac_high_bits!(dst: ptr base.pixel_buffer, workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
var ret : base.u32
|
||||
|
||||
var bits : base.u64
|
||||
@@ -147,7 +147,7 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
ac_symbol = 0
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Split the 8-bit ac_symbol into two 4-bit halves, per section
|
||||
@@ -176,13 +176,13 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
}
|
||||
break.ac_components
|
||||
}
|
||||
} endwhile.ac_components
|
||||
}.ac_components
|
||||
|
||||
break.block
|
||||
} endwhile.block
|
||||
}.block
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
pri func decoder.decode_mcu_progressive_ac_low_bit!(dst: ptr base.pixel_buffer, workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
var ret : base.u32
|
||||
|
||||
var bits : base.u64
|
||||
@@ -105,7 +105,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
ac_symbol = 0
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Split the 8-bit ac_symbol into two 4-bit halves, per section
|
||||
@@ -169,7 +169,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
}
|
||||
assert this.mcu_zig_index < 63 via "a < b: a < c; c <= b"(c: (this.scan_se as base.u32))
|
||||
this.mcu_zig_index += 1
|
||||
} endwhile.refine_non_zeroes
|
||||
}.refine_non_zeroes
|
||||
|
||||
if ac_value <> 0 {
|
||||
this.mcu_blocks[0][UNZIG[1 + this.mcu_zig_index]] = ac_value
|
||||
@@ -180,10 +180,10 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
}
|
||||
assert this.mcu_zig_index < 63 via "a < b: a < c; c <= b"(c: (this.scan_se as base.u32))
|
||||
this.mcu_zig_index += 1
|
||||
} endwhile.ac_components
|
||||
}.ac_components
|
||||
|
||||
break.block
|
||||
}} endwhile.goto_do_eob
|
||||
}}.goto_do_eob
|
||||
|
||||
if this.eob_run <= 0 {
|
||||
ret = 2 // Internal error.
|
||||
@@ -222,15 +222,15 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
}
|
||||
assert this.mcu_zig_index < 63 via "a < b: a < c; c <= b"(c: (this.scan_se as base.u32))
|
||||
this.mcu_zig_index += 1
|
||||
} endwhile.refine_eob_non_zeroes
|
||||
}.refine_eob_non_zeroes
|
||||
|
||||
this.eob_run -= 1
|
||||
|
||||
break.block
|
||||
} endwhile.block
|
||||
}.block
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
pri func decoder.decode_mcu_progressive_dc_high_bits!(dst: ptr base.pixel_buffer, workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
var ret : base.u32
|
||||
|
||||
var bits : base.u64
|
||||
@@ -95,7 +95,7 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
|
||||
dc_extend = EXTEND[dc_symbol]
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Process the dc_value in the next dc_symbol (up to 15) bits.
|
||||
@@ -113,15 +113,15 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
|
||||
this.mcu_previous_dc_values[csel] ~mod<< this.scan_al
|
||||
|
||||
break.dc_component
|
||||
} endwhile.dc_component
|
||||
}.dc_component
|
||||
|
||||
assert this.mcu_current_block < 10
|
||||
this.mcu_current_block += 1
|
||||
} endwhile.block
|
||||
}.block
|
||||
this.mcu_current_block = 0
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_mcu_progressive_dc_low_bit!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
pri func decoder.decode_mcu_progressive_dc_low_bit!(dst: ptr base.pixel_buffer, workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
|
||||
var ret : base.u32
|
||||
|
||||
var bits : base.u64
|
||||
@@ -63,15 +63,15 @@ pri func decoder.decode_mcu_progressive_dc_low_bit!(workbuf: slice base.u8, mx:
|
||||
n_bits ~mod-= 1
|
||||
|
||||
break.dc_component
|
||||
} endwhile.dc_component
|
||||
}.dc_component
|
||||
|
||||
assert this.mcu_current_block < 10
|
||||
this.mcu_current_block += 1
|
||||
} endwhile.block
|
||||
}.block
|
||||
this.mcu_current_block = 0
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
pos = (r.position() & 0xFFFF_FFFF) as base.u32
|
||||
if pos > this.bitstream_wi {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// Quirks are discussed in (/doc/note/quirks.md).
|
||||
//
|
||||
// The base38 encoding of "jpeg" is 0x122FF6. Left shifting by 10 gives
|
||||
// 0x48BF_D800.
|
||||
pri const QUIRKS_BASE : base.u32 = 0x48BF_D800
|
||||
|
||||
// --------
|
||||
|
||||
// When this quirk value is non-zero, the decoder will not support progressive
|
||||
// JPEG images. When combined with setting base.QUIRK_QUALITY to "lower
|
||||
// quality", this means that decoding will never require any temporary "work
|
||||
// buffer" memory: decoder.workbuf_len will always return a range (a min and
|
||||
// max pair) whose minimum value is zero.
|
||||
//
|
||||
// The maximum value can still be positive, as using more memory might lead to
|
||||
// faster decoding, but a zero minimum means that it's valid for the caller to
|
||||
// not allocate any memory for a work buffer.
|
||||
//
|
||||
// When opted into lower quality decoding, the workbuf_len minimum will be zero
|
||||
// and positive for sequential and progressive JPEGs respectively, regardless
|
||||
// of this QUIRK_REJECT_PROGRESSIVE_JPEGS key's value. But setting this quirk
|
||||
// explicitly will produce a "#rejected progressive JPEG" error when
|
||||
// encountering a progressive JPEG. This results in more readable calling code,
|
||||
// instead of commenting about "positive work buffer minimum length implies a
|
||||
// progressive JPEG".
|
||||
pub const QUIRK_REJECT_PROGRESSIVE_JPEGS : base.u32 = 0x48BF_D800 | 0x00
|
||||
|
||||
// --------
|
||||
|
||||
// The base.QUIRK_QUALITY key is defined in the base package, not this package.
|
||||
// Still, here's some documentation on how this package responds to that (key,
|
||||
// value) quirk pair.
|
||||
//
|
||||
// If decoder.set_quirk is passed a base.QUIRK_QUALITY as the key argument
|
||||
// then, when re-interpreting the u64 value argument as a signed i64 number, a
|
||||
// negative number opts the decoder in to a slightly worse quality but leaner
|
||||
// (less memory required) chroma upsampling algorithm.
|
||||
//
|
||||
// Negative (in i64 space) means >= 0x8000_0000_0000_0000 (in u64 space).
|
||||
// base.QUIRK_QUALITY__VALUE__LOWER_QUALITY is one such value.
|
||||
//
|
||||
// Specifically, a negative quirk value uses a box filter. A non-negative quirk
|
||||
// value (including the default value, zero) uses the same triangle filter that
|
||||
// libjpeg-turbo also uses by default, which requires chroma upsampling on the
|
||||
// edges of a MCU (Minimum Coded Unit) to remember adjacent MCU's values.
|
||||
//
|
||||
// Leaner means that for common (sequential) JPEG images, the range returned by
|
||||
// decoder.workbuf_len will have a minimum value of zero, meaning that no work
|
||||
// buffer memory needs to be allocated. Decoding rarer (progressive) JPEGs will
|
||||
// still always require a positive amount of work buffer memory, for reasons
|
||||
// unrelated to chroma upsampling. The exact amount required depends on factors
|
||||
// like the JPEG image's width, height, component count and subsampling ratios.
|
||||
//
|
||||
// Regardless of the quirk value, as always, the workbuf_len method returns a
|
||||
// range, whose min and max can be different. The caller is able to choose
|
||||
// between providing the minimal amount of work buffer memory (for slightly
|
||||
// slower decoding) or the maximal amount (for slightly faster decoding).
|
||||
//
|
||||
// Callers that never wish to allocate work buffer memory can simply reject
|
||||
// progressive JPEGs (where "workbuf_len().min_incl > 0" despite setting the
|
||||
// base.QUIRK_QUALITY key to a negative quirk value) as unsupported. See also
|
||||
// QUIRK_REJECT_PROGRESSIVE_JPEGS.
|
||||
//
|
||||
// For some pictures comparing box and triangle filter decodings, see
|
||||
// https://nigeltao.github.io/blog/2024/jpeg-chroma-upsampling.html
|
||||
@@ -21,10 +21,6 @@ pri status "#internal error: inconsistent I/O"
|
||||
|
||||
// --------
|
||||
|
||||
// DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE is the largest
|
||||
// history_retain_length (for compact_retaining) that a decoder will request.
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
// DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE is the largest workbuf length that a
|
||||
// decoder will request.
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
+137
-141
@@ -82,10 +82,6 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.empty_range_ii_u64()
|
||||
}
|
||||
@@ -107,8 +103,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
var stack_byte : base.u32[..= (1024 / 32) - 1]
|
||||
var stack_bit : base.u32[..= 31]
|
||||
var match : base.u32[..= 2]
|
||||
var c4 : base.u32
|
||||
var c : base.u8
|
||||
var c32 : base.u32
|
||||
var c8 : base.u8
|
||||
var backslash : base.u8
|
||||
var char : base.u8
|
||||
var class : base.u8[..= 0x0F]
|
||||
@@ -164,7 +160,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
|
||||
// Consume whitespace.
|
||||
whitespace_length = 0
|
||||
c = 0
|
||||
c8 = 0
|
||||
class = 0
|
||||
while.ws true,
|
||||
inv args.dst.length() > 0,
|
||||
@@ -186,8 +182,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
class = LUT_CLASSES[c]
|
||||
c8 = args.src.peek_u8()
|
||||
class = LUT_CLASSES[c8]
|
||||
if class <> CLASS_WHITESPACE {
|
||||
break.ws
|
||||
}
|
||||
@@ -203,7 +199,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.outer
|
||||
}
|
||||
whitespace_length += 1
|
||||
} endwhile.ws
|
||||
}.ws
|
||||
|
||||
// Emit whitespace.
|
||||
if whitespace_length > 0 {
|
||||
@@ -279,11 +275,11 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
inv args.dst.length() > 0,
|
||||
inv args.src.length() > 0,
|
||||
{
|
||||
c4 = args.src.peek_u32le()
|
||||
if 0x00 <> (LUT_CHARS[0xFF & (c4 >> 0)] |
|
||||
LUT_CHARS[0xFF & (c4 >> 8)] |
|
||||
LUT_CHARS[0xFF & (c4 >> 16)] |
|
||||
LUT_CHARS[0xFF & (c4 >> 24)]) {
|
||||
c32 = args.src.peek_u32le()
|
||||
if 0x00 <> (LUT_CHARS[0xFF & (c32 >> 0)] |
|
||||
LUT_CHARS[0xFF & (c32 >> 8)] |
|
||||
LUT_CHARS[0xFF & (c32 >> 16)] |
|
||||
LUT_CHARS[0xFF & (c32 >> 24)]) {
|
||||
break
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
@@ -300,10 +296,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.string_loop_outer
|
||||
}
|
||||
string_length += 4
|
||||
} endwhile
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
char = LUT_CHARS[c]
|
||||
c8 = args.src.peek_u8()
|
||||
char = LUT_CHARS[c8]
|
||||
|
||||
if char == 0x00 { // Non-special ASCII.
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -360,8 +356,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
yield? base."$short read"
|
||||
continue.string_loop_outer
|
||||
}
|
||||
c = (args.src.peek_u16le() >> 8) as base.u8
|
||||
backslash = LUT_BACKSLASHES[c]
|
||||
c8 = (args.src.peek_u16le() >> 8) as base.u8
|
||||
backslash = LUT_BACKSLASHES[c8]
|
||||
if (backslash & 0x80) <> 0 {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_simple_token_fast!(
|
||||
@@ -384,7 +380,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
} else if c == 'u' {
|
||||
} else if c8 == 'u' {
|
||||
// -------- BEGIN backslash-u.
|
||||
if args.src.length() < 6 {
|
||||
if args.src.is_closed() {
|
||||
@@ -398,18 +394,18 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
uni4_value = 0
|
||||
uni4_ok = 0x80
|
||||
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 0
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 12
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 8
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 4
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 0
|
||||
|
||||
if uni4_ok == 0 {
|
||||
// It wasn't 4 hexadecimal digits. No-op (and
|
||||
@@ -468,18 +464,18 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
uni4_ok = 0x80
|
||||
uni4_string >>= 16
|
||||
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 0
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 12
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 8
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 4
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c8
|
||||
uni4_value |= ((c8 & 0x0F) as base.u32) << 0
|
||||
}
|
||||
|
||||
if (uni4_ok <> 0) and
|
||||
@@ -514,7 +510,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
// -------- END backslash-u.
|
||||
|
||||
} else if (c == 'U') and
|
||||
} else if (c8 == 'U') and
|
||||
this.quirks[QUIRK_ALLOW_BACKSLASH_CAPITAL_U - QUIRKS_BASE] {
|
||||
// -------- BEGIN backslash-capital-u.
|
||||
if args.src.length() < 10 {
|
||||
@@ -528,30 +524,30 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
uni8_value = 0
|
||||
uni8_ok = 0x80
|
||||
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 0)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 28
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 8)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 24
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 16)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 20
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 24)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 16
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 32)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 40)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 48)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 56)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 0
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 0)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 28
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 8)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 24
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 16)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 20
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 24)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 16
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 32)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 12
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 40)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 8
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 48)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 4
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 56)]
|
||||
uni8_ok &= c8
|
||||
uni8_value |= ((c8 & 0x0F) as base.u32) << 0
|
||||
|
||||
if uni8_ok == 0 {
|
||||
// It wasn't 8 hexadecimal digits. No-op (and
|
||||
@@ -580,7 +576,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
// -------- END backslash-capital-u.
|
||||
|
||||
} else if (c == 'x') and
|
||||
} else if (c8 == 'x') and
|
||||
this.quirks[QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS - QUIRKS_BASE] {
|
||||
// -------- BEGIN backslash-x
|
||||
if args.src.length() < 4 {
|
||||
@@ -594,12 +590,12 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
backslash_x_string = args.src.peek_u32le()
|
||||
backslash_x_ok = 0x80
|
||||
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 16)]
|
||||
backslash_x_ok &= c
|
||||
backslash_x_value = ((c & 0x0F) << 4) as base.u8
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 24)]
|
||||
backslash_x_ok &= c
|
||||
backslash_x_value = (backslash_x_value | (c & 0x0F)) as base.u8
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 16)]
|
||||
backslash_x_ok &= c8
|
||||
backslash_x_value = ((c8 & 0x0F) << 4) as base.u8
|
||||
c8 = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 24)]
|
||||
backslash_x_ok &= c8
|
||||
backslash_x_value = (backslash_x_value | (c8 & 0x0F)) as base.u8
|
||||
|
||||
if (backslash_x_ok == 0) or
|
||||
((backslash_x_string & 0xFFFF) <> 0x785C) {
|
||||
@@ -830,8 +826,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.string_loop_outer
|
||||
}
|
||||
return "#bad UTF-8"
|
||||
} endwhile.string_loop_inner
|
||||
} endwhile.string_loop_outer
|
||||
}.string_loop_inner
|
||||
}.string_loop_outer
|
||||
|
||||
// Emit the trailing '"'.
|
||||
while true {
|
||||
@@ -857,7 +853,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continued: 0,
|
||||
length: 1)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// As above, expect must have contained EXPECT_STRING. If it didn't
|
||||
// also contain EXPECT_NUMBER (excluding EXPECT_COMMENT) then we
|
||||
@@ -940,7 +936,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if number_status == 1 {
|
||||
if this.quirks[QUIRK_ALLOW_INF_NAN_NUMBERS - QUIRKS_BASE] {
|
||||
@@ -956,9 +952,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse numbers.
|
||||
|
||||
@@ -1189,7 +1185,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
|
||||
return "#bad input"
|
||||
}} endwhile.goto_parsed_a_leaf_value
|
||||
}}.goto_parsed_a_leaf_value
|
||||
|
||||
// We've just parsed a leaf (non-container) value: literal (null,
|
||||
// false, true), number or string.
|
||||
@@ -1197,7 +1193,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
break.outer
|
||||
}
|
||||
expect = expect_after_value
|
||||
} endwhile.outer
|
||||
}.outer
|
||||
|
||||
if this.quirks[QUIRK_ALLOW_TRAILING_FILLER - QUIRKS_BASE] or
|
||||
this.quirks[QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF - QUIRKS_BASE] {
|
||||
@@ -1208,7 +1204,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
|
||||
pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var n : base.u32[..= 0x3FF]
|
||||
var floating_point : base.u32[..= 0x80]
|
||||
|
||||
@@ -1222,10 +1218,10 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
}
|
||||
break.goto_done
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
c8 = args.src.peek_u8()
|
||||
|
||||
// Scan the optional minus sign.
|
||||
if c <> '-' {
|
||||
if c8 <> '-' {
|
||||
assert args.src.length() > 0
|
||||
assert n <= 1
|
||||
} else {
|
||||
@@ -1240,14 +1236,14 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
n |= 0x100 // A '-' without digits is invalid.
|
||||
break.goto_done
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
c8 = args.src.peek_u8()
|
||||
|
||||
assert args.src.length() > 0
|
||||
assert n <= 1
|
||||
}
|
||||
|
||||
// Scan the opening digits.
|
||||
if c == '0' {
|
||||
if c8 == '0' {
|
||||
n += 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
assert n <= 99
|
||||
@@ -1266,10 +1262,10 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
}
|
||||
break.goto_done
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
c8 = args.src.peek_u8()
|
||||
|
||||
// Scan the optional fraction.
|
||||
if c <> '.' {
|
||||
if c8 <> '.' {
|
||||
assert args.src.length() > 0
|
||||
assert n <= 99
|
||||
} else {
|
||||
@@ -1293,14 +1289,14 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
}
|
||||
break.goto_done
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
c8 = args.src.peek_u8()
|
||||
|
||||
assert args.src.length() > 0
|
||||
assert n <= 99
|
||||
}
|
||||
|
||||
// Scan the optional 'E' or 'e'.
|
||||
if (c <> 'E') and (c <> 'e') {
|
||||
if (c8 <> 'E') and (c8 <> 'e') {
|
||||
break.goto_done
|
||||
}
|
||||
if n >= 99 {
|
||||
@@ -1320,10 +1316,10 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
n |= 0x100 // An 'E' or 'e' without digits is invalid.
|
||||
break.goto_done
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
c8 = args.src.peek_u8()
|
||||
|
||||
// Scan the optional '+' or '-'.
|
||||
if (c <> '+') and (c <> '-') {
|
||||
if (c8 <> '+') and (c8 <> '-') {
|
||||
assert n <= 99
|
||||
} else {
|
||||
if n >= 99 {
|
||||
@@ -1339,14 +1335,14 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
n = this.decode_digits!(src: args.src, n: n)
|
||||
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
return n | floating_point
|
||||
}
|
||||
|
||||
pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u32[..= 0x3FF] {
|
||||
var c : base.u8
|
||||
var n : base.u32[..= 0x3FF]
|
||||
var c8 : base.u8
|
||||
var n : base.u32[..= 0x3FF]
|
||||
|
||||
n = args.n
|
||||
while true {
|
||||
@@ -1356,8 +1352,8 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u
|
||||
}
|
||||
break
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
if 0x00 == LUT_DECIMAL_DIGITS[c] {
|
||||
c8 = args.src.peek_u8()
|
||||
if 0x00 == LUT_DECIMAL_DIGITS[c8] {
|
||||
break
|
||||
}
|
||||
// Cap DECODER_NUMBER_LENGTH_MAX_INCL at an arbitrary value, 99. The
|
||||
@@ -1375,7 +1371,7 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u
|
||||
}
|
||||
n += 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} endwhile
|
||||
}
|
||||
if n == args.n {
|
||||
n |= 0x100
|
||||
}
|
||||
@@ -1383,8 +1379,8 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u
|
||||
}
|
||||
|
||||
pri func decoder.decode_leading?(dst: base.token_writer, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var u : base.u32
|
||||
var c8 : base.u8
|
||||
var u : base.u32
|
||||
|
||||
this.allow_leading_ars =
|
||||
this.quirks[QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR - QUIRKS_BASE]
|
||||
@@ -1403,14 +1399,14 @@ pri func decoder.decode_leading?(dst: base.token_writer, src: base.io_reader) {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
if (c == 0x1E) and this.allow_leading_ars {
|
||||
c8 = args.src.peek_u8()
|
||||
if (c8 == 0x1E) and this.allow_leading_ars {
|
||||
this.allow_leading_ars = false
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0, value_minor: 0, continued: 0, length: 1)
|
||||
continue
|
||||
} else if (c == 0xEF) and this.allow_leading_ubom {
|
||||
} else if (c8 == 0xEF) and this.allow_leading_ubom {
|
||||
if args.src.length() < 3 {
|
||||
if args.src.is_closed() {
|
||||
break
|
||||
@@ -1428,12 +1424,12 @@ pri func decoder.decode_leading?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c2 : base.u16
|
||||
var c8 : base.u8
|
||||
var c16 : base.u16
|
||||
var length : base.u32[..= 0xFFFD]
|
||||
|
||||
this.comment_type = 0
|
||||
@@ -1450,10 +1446,10 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
return ok
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
c2 = args.src.peek_u16le()
|
||||
}
|
||||
c16 = args.src.peek_u16le()
|
||||
|
||||
if (c2 == '/*'le) and this.quirks[QUIRK_ALLOW_COMMENT_BLOCK - QUIRKS_BASE] {
|
||||
if (c16 == '/*'le) and this.quirks[QUIRK_ALLOW_COMMENT_BLOCK - QUIRKS_BASE] {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
length = 2
|
||||
|
||||
@@ -1477,13 +1473,13 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
|
||||
c2 = args.src.peek_u16le()
|
||||
if c2 == '*/'le {
|
||||
c16 = args.src.peek_u16le()
|
||||
if c16 == '*/'le {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
@@ -1507,14 +1503,14 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_block
|
||||
}
|
||||
length += 1
|
||||
} endwhile.comment_block
|
||||
}.comment_block
|
||||
|
||||
} else if (c2 == '//'le) and this.quirks[QUIRK_ALLOW_COMMENT_LINE - QUIRKS_BASE] {
|
||||
} else if (c16 == '//'le) and this.quirks[QUIRK_ALLOW_COMMENT_LINE - QUIRKS_BASE] {
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
length = 2
|
||||
|
||||
@@ -1544,13 +1540,13 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if c == '\n' {
|
||||
c8 = args.src.peek_u8()
|
||||
if c8 == '\n' {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
@@ -1573,17 +1569,17 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
post args.dst.length() > 0,
|
||||
{
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
length = 0
|
||||
continue.comment_line
|
||||
}
|
||||
length += 1
|
||||
} endwhile.comment_line
|
||||
}.comment_line
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
var c4 : base.u32
|
||||
var c32 : base.u32
|
||||
var neg : base.u32[..= 1]
|
||||
|
||||
while true {
|
||||
@@ -1601,8 +1597,8 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
|
||||
// Bitwise or'ing with 0x20 converts upper case ASCII to lower case.
|
||||
|
||||
c4 = args.src.peek_u24le_as_u32()
|
||||
if (c4 | 0x20_2020) == 'inf'le {
|
||||
c32 = args.src.peek_u24le_as_u32()
|
||||
if (c32 | 0x20_2020) == 'inf'le {
|
||||
if args.src.length() > 7 {
|
||||
if (args.src.peek_u64le() | 0x2020_2020_2020_2020) == 'infinity'le {
|
||||
args.dst.write_simple_token_fast!(
|
||||
@@ -1627,7 +1623,7 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
args.src.skip_u32_fast!(actual: 3, worst_case: 3)
|
||||
return ok
|
||||
|
||||
} else if (c4 | 0x20_2020) == 'nan'le {
|
||||
} else if (c32 | 0x20_2020) == 'nan'le {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__NUMBER << 21) |
|
||||
@@ -1636,9 +1632,9 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
length: 3)
|
||||
args.src.skip_u32_fast!(actual: 3, worst_case: 3)
|
||||
return ok
|
||||
} else if (c4 & 0xFF) == '+' {
|
||||
} else if (c32 & 0xFF) == '+' {
|
||||
neg = 0
|
||||
} else if (c4 & 0xFF) == '-' {
|
||||
} else if (c32 & 0xFF) == '-' {
|
||||
neg = 1
|
||||
} else {
|
||||
return "#bad input"
|
||||
@@ -1652,8 +1648,8 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue
|
||||
}
|
||||
|
||||
c4 = args.src.peek_u32le() >> 8
|
||||
if (c4 | 0x20_2020) == 'inf'le {
|
||||
c32 = args.src.peek_u32le() >> 8
|
||||
if (c32 | 0x20_2020) == 'inf'le {
|
||||
if args.src.length() > 8 {
|
||||
if (args.src.peek_u64le_at(offset: 1) | 0x2020_2020_2020_2020) == 'infinity'le {
|
||||
args.dst.write_simple_token_fast!(
|
||||
@@ -1678,7 +1674,7 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
return ok
|
||||
|
||||
} else if (c4 | 0x20_2020) == 'nan'le {
|
||||
} else if (c32 | 0x20_2020) == 'nan'le {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__NUMBER << 21) |
|
||||
@@ -1690,11 +1686,11 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
return "#bad input"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
var whitespace_length : base.u32[..= 0xFFFE]
|
||||
|
||||
if this.quirks[QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF - QUIRKS_BASE] {
|
||||
@@ -1725,8 +1721,8 @@ pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue.outer
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if LUT_CLASSES[c] <> CLASS_WHITESPACE {
|
||||
c8 = args.src.peek_u8()
|
||||
if LUT_CLASSES[c8] <> CLASS_WHITESPACE {
|
||||
if whitespace_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0, value_minor: 0, continued: 0, length: whitespace_length)
|
||||
@@ -1742,15 +1738,15 @@ pri func decoder.decode_trailer?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if (whitespace_length >= 0xFFFE) or (c == this.trailer_stop) {
|
||||
if (whitespace_length >= 0xFFFE) or (c8 == this.trailer_stop) {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0, value_minor: 0, continued: 0, length: whitespace_length + 1)
|
||||
if c == this.trailer_stop {
|
||||
if c8 == this.trailer_stop {
|
||||
return ok
|
||||
}
|
||||
continue.outer
|
||||
}
|
||||
whitespace_length += 1
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
}.inner
|
||||
}.outer
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// The Lzip file format specification is at
|
||||
// https://www.nongnu.org/lzip/manual/lzip_manual.html#File-format
|
||||
|
||||
use "std/crc32"
|
||||
use "std/lzma"
|
||||
|
||||
pub status "#bad checksum"
|
||||
pub status "#bad footer"
|
||||
pub status "#bad header"
|
||||
pub status "#truncated input"
|
||||
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0xFFFF_FFFF + 273
|
||||
|
||||
pub struct decoder? implements base.io_transformer(
|
||||
ignore_checksum : base.bool,
|
||||
|
||||
dsize_have : base.u64,
|
||||
ssize_have : base.u64,
|
||||
|
||||
util : base.utility,
|
||||
) + (
|
||||
crc32 : crc32.ieee_hasher,
|
||||
lzma : lzma.decoder,
|
||||
)
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if (args.key == base.QUIRK_IGNORE_CHECKSUM) and this.ignore_checksum {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
if args.key == base.QUIRK_IGNORE_CHECKSUM {
|
||||
this.ignore_checksum = args.value > 0
|
||||
return ok
|
||||
}
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.lzma.dst_history_retain_length()
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.lzma.workbuf_len()
|
||||
}
|
||||
|
||||
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var c8 : base.u8
|
||||
var c32 : base.u32
|
||||
var c64 : base.u64
|
||||
var dmark : base.u64
|
||||
var smark : base.u64
|
||||
var status : base.status
|
||||
var checksum_want : base.u32
|
||||
var checksum_have : base.u32
|
||||
var size_want : base.u64
|
||||
|
||||
while.outer true {
|
||||
// Read the magic number and version number.
|
||||
//
|
||||
// Some of the test/3pdata/xzsuite/good*v0*.lz files have a 0x00
|
||||
// version number (instead of 0x01). We reject those, just like
|
||||
// /usr/bin/lzip does and as per the Lzip spec.
|
||||
c64 = args.src.read_u40le_as_u64?()
|
||||
if c64 <> 'LZIP\x01'le {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
// Read the dictionary size.
|
||||
c8 = args.src.read_u8?()
|
||||
status = this.lzma.set_quirk!(
|
||||
key: lzma.QUIRK_FORMAT_EXTENSION,
|
||||
value: 0x01 | ((c8 as base.u64) << 8))
|
||||
if not status.is_ok() {
|
||||
if status == base."#bad argument" {
|
||||
return "#bad header"
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
// Decode LZMA.
|
||||
//
|
||||
// Re lzma.QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE, as exercised by
|
||||
// test/3pdata/xzsuite/lzip-testsuite/fox6_mark.lz, the LZMA spec says
|
||||
// that the decoder must check that the byte is zero, but the Lzip spec
|
||||
// says that the byte "must be ignored by the range decoder".
|
||||
this.ssize_have = 0
|
||||
this.dsize_have = 0
|
||||
this.lzma.set_quirk!(key: lzma.QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE, value: 1)
|
||||
while true {
|
||||
dmark = args.dst.mark()
|
||||
smark = args.src.mark()
|
||||
status =? this.lzma.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
this.ssize_have ~mod+= args.src.count_since(mark: smark)
|
||||
this.dsize_have ~mod+= args.dst.count_since(mark: dmark)
|
||||
|
||||
if not this.ignore_checksum {
|
||||
this.crc32.update!(x: args.dst.since(mark: dmark))
|
||||
}
|
||||
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
// Check the checksum.
|
||||
checksum_want = args.src.read_u32le?()
|
||||
if not this.ignore_checksum {
|
||||
checksum_have = this.crc32.checksum_u32()
|
||||
if checksum_have <> checksum_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
|
||||
// Check the uncompressed size.
|
||||
size_want = args.src.read_u64le?()
|
||||
if this.dsize_have <> size_want {
|
||||
return "#bad footer"
|
||||
}
|
||||
|
||||
// Check the compressed size, which includes 6 bytes of header and 20
|
||||
// bytes of footer. Per the spec, it's also capped at 2 PiB.
|
||||
size_want = args.src.read_u64le?()
|
||||
if (size_want < 26) or (0x8_0000_0000_0000 < size_want) {
|
||||
return "#bad footer"
|
||||
} else if this.ssize_have <> (size_want - 26) {
|
||||
return "#bad footer"
|
||||
}
|
||||
|
||||
// Reset state and continue the outer loop, if not at EOF and it looks
|
||||
// like there's another LZIP-encoded chunk.
|
||||
while args.src.length() < 4,
|
||||
post args.src.length() >= 4,
|
||||
{
|
||||
if args.src.is_closed() {
|
||||
break.outer
|
||||
}
|
||||
yield? base."$short read"
|
||||
}
|
||||
c32 = args.src.peek_u32le()
|
||||
if c32 <> 'LZIP'le {
|
||||
break.outer
|
||||
}
|
||||
this.crc32.reset!()
|
||||
this.lzma.reset!()
|
||||
}.outer
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
# LZMA
|
||||
|
||||
Lempel–Ziv–Markov chain algorithm (LZMA) is a general purpose compression
|
||||
format, using range coding and Lempel-Ziv style length-distance
|
||||
back-references. Various descriptions of the file format are at:
|
||||
|
||||
- [LZMA-SDK reference implementation](https://raw.githubusercontent.com/jljusten/LZMA-SDK/781863cdf592da3e97420f50de5dac056ad352a5/CPP/7zip/Bundles/LzmaSpec/LzmaSpec.cpp)
|
||||
- [LZMA-SDK specification](https://raw.githubusercontent.com/jljusten/LZMA-SDK/781863cdf592da3e97420f50de5dac056ad352a5/DOC/lzma-specification.txt)
|
||||
- [Lzip Manual - Stream Format](https://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format)
|
||||
- [Wikipedia (LZMA)](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov_chain_algorithm)
|
||||
|
||||
|
||||
## Byms and Packets
|
||||
|
||||
The compressed stream is a stream of "byms" (binary symbols, either 0 or 1;
|
||||
yeah, it's an awkward term, but less ambiguous than using "bits" for both
|
||||
compressed and uncompressed things). Byms are conceptually very similar to bits
|
||||
(binary digits, ubiquitous in computing, a 0.5 KiB file holds 512 bytes, which
|
||||
is 4096 bits), but are encoded using an adaptive binary range-coder so that N
|
||||
byms usually compresses to fewer than N bits.
|
||||
|
||||
The stream is divided into packets, each packet describing either a single
|
||||
byte, or an LZ77 sequence with its length and distance implicitly or explicitly
|
||||
encoded. Each part of each packet is modeled with independent contexts, so the
|
||||
probability predictions for each bym are correlated with the values of that bym
|
||||
(and related byms from the same field) in previous packets of the same type.
|
||||
|
||||
There are 7 types of packets:
|
||||
|
||||
Symbols Meaning
|
||||
0 ,literal LITERAL byte (8_byms)
|
||||
1,0 ,len ,dist MATCH
|
||||
1,1,0,0 SHORTREP len = 1, dist = Most Recently Used
|
||||
1,1,0,1 ,len LONGREP[0] dist = Most Recently Used
|
||||
1,1,1,0 ,len LONGREP[1] dist = 2nd Most Recently Used
|
||||
1,1,1,1,0 ,len LONGREP[2] dist = 3rd Most Recently Used
|
||||
1,1,1,1,1 ,len LONGREP[3] dist = 4th Most Recently Used
|
||||
|
||||
The length encoding:
|
||||
|
||||
Symbols Value
|
||||
0 ,3_byms Ranges from 2 ..= 9
|
||||
1,0 ,3_byms Ranges from 10 ..= 17
|
||||
1,1 ,8_byms Ranges from 18 ..= 273
|
||||
|
||||
The distance encoding starts with a 6-bym "Slot" value, which determines how
|
||||
many further byms are needed. For small Slot values, there are up to 5 extra
|
||||
byms, all context-encoded like the rest of LZMA. For large Slot values, there
|
||||
are N extra byms. The first (N - 4) of them are encoded with a fixed 50%
|
||||
probability and the remaining 4 byms are context-encoded. The largest encodable
|
||||
distance-biased-by-1 is `0xFFFF_FFFF`, a (2 + 26 + 4) bit number.
|
||||
|
||||
Slot (decimal) Distance (binary), biased by 1 Extra byms
|
||||
0 0 0
|
||||
1 1 0
|
||||
2 10 0
|
||||
3 11 0
|
||||
4 10 x 1
|
||||
5 11 x 1
|
||||
6 10 xx 2
|
||||
7 11 xx 2
|
||||
8 10 xxx 3
|
||||
9 11 xxx 4
|
||||
10 10 xxxx 5
|
||||
11 11 xxxx 4
|
||||
12 10 xxxxx 5
|
||||
13 11 xxxxx 5
|
||||
14 10 yy zzzz 2+4
|
||||
15 11 yy zzzz 2+4
|
||||
16 10 yyy zzzz 3+4
|
||||
17 11 yyy zzzz 3+4
|
||||
18 10 yyyy zzzz 4+4
|
||||
... ... ...
|
||||
61 11 yyyyyyyyyyyyyyyyyyyyyyyyy zzzz 25+4
|
||||
62 10 yyyyyyyyyyyyyyyyyyyyyyyyyy zzzz 26+4
|
||||
63 11 yyyyyyyyyyyyyyyyyyyyyyyyyy zzzz 26+4
|
||||
|
||||
"xxxx" means up-to-5 byms are encoded with a "reverse" binary tree. Each Slot
|
||||
has its own binary tree probabilities.
|
||||
|
||||
"yyyy" means up-to-26 byms. Each has a fixed 50% probability.
|
||||
|
||||
"zzzz" means four byms encoded with a "reverse" binary tree. All Slots use the
|
||||
same "align" binary tree probabilities.
|
||||
|
||||
"Biased by 1" means that slot=2 implies biasedDistance=2 so distance=3. A
|
||||
biasedDistance of `0xFFFF_FFFF` means the End of Stream. Otherwise, the
|
||||
corrected (unbiased) distance ranges in `[1 ..= 0xFFFF_FFFF]`.
|
||||
|
||||
Distance is also capped by the dictionary size, stated in the LZMA header.
|
||||
|
||||
|
||||
## State
|
||||
|
||||
In addition to the hundreds of contextual probabilities (see below), there's
|
||||
also a "State" variable with 12 possible values. The initial State is zero.
|
||||
Each packet causes a state transtition. The left-most column is the current
|
||||
State, the other columns hold the next State, depending on the packet:
|
||||
|
||||
State LITERAL MATCH LONGREP SHORTREP
|
||||
0 0 7 8 9
|
||||
1 0 7 8 9
|
||||
2 0 7 8 9
|
||||
3 0 7 8 9
|
||||
4 1 7 8 9
|
||||
5 2 7 8 9
|
||||
6 3 7 8 9
|
||||
7 4 10 11 11
|
||||
8 5 10 11 11
|
||||
9 6 10 11 11
|
||||
10 4 10 11 11
|
||||
11 5 10 11 11
|
||||
|
||||
Equivalently, but looking backwards instead of forwards, each State embodies
|
||||
the 1st, 2nd, 3rd and 4th MRUP (Most Recently Used Packet). The ? question mark
|
||||
means every possible packet. Some States (2, 5 and 11) have two rows - multiple
|
||||
possible histories could lead to that State:
|
||||
|
||||
State 1MRUP 2MRUP 3MRUP 4MRUP
|
||||
0 LITERAL LITERAL LITERAL ?
|
||||
1 LITERAL LITERAL MATCH ?
|
||||
2a LITERAL LITERAL LONGREP ?
|
||||
2b LITERAL LITERAL SHORTREP NON-LITERAL
|
||||
3 LITERAL LITERAL SHORTREP LITERAL
|
||||
4 LITERAL MATCH ? ?
|
||||
5a LITERAL LONGREP ? ?
|
||||
5b LITERAL SHORTREP NON-LITERAL ?
|
||||
6 LITERAL SHORTREP LITERAL ?
|
||||
7 MATCH LITERAL ? ?
|
||||
8 LONGREP LITERAL ? ?
|
||||
9 SHORTREP LITERAL ? ?
|
||||
10 MATCH NON-LITERAL ? ?
|
||||
11a LONGREP NON-LITERAL ? ?
|
||||
11b SHORTREP NON-LITERAL ? ?
|
||||
|
||||
A State's 12 possible values can also be aggregated into whether the State is
|
||||
less than or at least 7: whether the last packet was a LITERAL or a NON-LITERAL
|
||||
(a Lempel-Ziv copy-from-history). When decoding a LITERAL after a NON-LITERAL
|
||||
(as opposed to a LITERAL after a LITERAL, i.e. having `decodeLiteral()` branch
|
||||
on `State < 7`), there is information in the next historical byte after the
|
||||
previous NON-LITERAL packet's copy-source. That byte almost always does not
|
||||
equal the about-to-be-decoded literal byte, because if it did equal, the copy
|
||||
would have been longer.
|
||||
|
||||
|
||||
## Algorithm Overview
|
||||
|
||||
The core loop's body (with AlgOveNN line numbers for others to reference) looks
|
||||
conceptually like this:
|
||||
|
||||
AlgOve00 if decodeTheNextBym() == 0 {
|
||||
AlgOve01 // Decode a LITERAL.
|
||||
AlgOve02 literal = decodeLiteral()
|
||||
AlgOve03 emitLiteral(literal)
|
||||
AlgOve04 continue
|
||||
AlgOve..
|
||||
AlgOve20 } else if decodeTheNextBym() == 0 {
|
||||
AlgOve21 // Decode a MATCH.
|
||||
AlgOve22 len = decodeLen()
|
||||
AlgOve23 slot = decodeSlot(min(len-2, 3))
|
||||
AlgOve24 distBiasedBy1 = decodeDistBiasedBy1(slot)
|
||||
AlgOve25 if distBiasedBy1 == 0xFFFF_FFFF {
|
||||
AlgOve26 break // End of Stream.
|
||||
AlgOve27 }
|
||||
AlgOve28 mrud = (1 + distBiasedBy1, mrud[0], mrud[1], mrud[2])
|
||||
AlgOve29 goto labelDoTheLZCopy
|
||||
AlgOve..
|
||||
AlgOve40 } else if decodeTheNextBym() == 0 {
|
||||
AlgOve41 if decodeTheNextBym() == 0 {
|
||||
AlgOve42 // Decode a SHORTREP.
|
||||
AlgOve43 len = 1
|
||||
AlgOve44 goto labelDoTheLZCopy
|
||||
AlgOve45 }
|
||||
AlgOve46 // Decode a LONGREP[0].
|
||||
AlgOve..
|
||||
AlgOve60 } else if decodeTheNextBym() == 0 {
|
||||
AlgOve61 // Decode a LONGREP[1].
|
||||
AlgOve62 mrud = (mrud[1], mrud[0], mrud[2], mrud[3])
|
||||
AlgOve63 } else if decodeTheNextBym() == 0 {
|
||||
AlgOve64 // Decode a LONGREP[2].
|
||||
AlgOve65 mrud = (mrud[2], mrud[0], mrud[1], mrud[3])
|
||||
AlgOve66 } else {
|
||||
AlgOve67 // Decode a LONGREP[3].
|
||||
AlgOve68 mrud = (mrud[3], mrud[0], mrud[1], mrud[2])
|
||||
AlgOve69 }
|
||||
AlgOve..
|
||||
AlgOve80 len = decodeLen()
|
||||
AlgOve..
|
||||
AlgOve90 labelDoTheLZCopy:
|
||||
AlgOve91 // mrud[0] has been set to what will be (after the emitCopy
|
||||
AlgOve92 // call) the most recently used distance. mrud[1] is the 2nd
|
||||
AlgOve93 // most recently used, mrud[2] is the 3rd, mrud[3] is the 4th.
|
||||
AlgOve94 emitCopy(len, mrud[0])
|
||||
|
||||
Conceptually means that some details have been elided. The `State` variable
|
||||
needs updating after each iteration, but that's not shown. `decodeTheNextBym()`
|
||||
also depends not only on the `State` but also which line number you're at. The
|
||||
probabilities used for "is it a LITERAL or NON-LITERAL" are different from the
|
||||
probabilities used for "is it a LONGREP[2] or LONGREP[3]".
|
||||
|
||||
`decodeLen` expands to:
|
||||
|
||||
AlgOveNN.0 if decodeTheNextBym() == 0 {
|
||||
AlgOveNN.1 // Decode a low length.
|
||||
AlgOveNN.2 len = decodeMultipleByms(3) + 2
|
||||
AlgOveNN.3 } else if decodeTheNextBym() == 0 {
|
||||
AlgOveNN.4 // Decode a middle length.
|
||||
AlgOveNN.5 len = decodeMultipleByms(3) + 10
|
||||
AlgOveNN.6 } else {
|
||||
AlgOveNN.7 // Decode a high length.
|
||||
AlgOveNN.8 len = decodeMultipleByms(8) + 18
|
||||
AlgOveNN.9 }
|
||||
|
||||
|
||||
## Range Coding and `decodeTheNextBym`
|
||||
|
||||
The codec also tracks two `uint32` variables, called `bits` and `range`, that
|
||||
represent an interval (a position and width) on the number line between zero
|
||||
and one. The literal bitstream (the 0s and 1s in the file, read in MSB to LSB
|
||||
order) is translated into a `bym` stream, where each `bym` is either 0 or 1. If
|
||||
both `bym` values have equal (50%) probability then the `bym` stream is
|
||||
basically the same as the bitstream. If symbols have unequal probability then
|
||||
we can achieve compression: the literal bitstream can be shorter (in terms of
|
||||
number of bits) then the `bym` stream.
|
||||
|
||||
Specifically, if `prob` is the probability (scaled so that `(1 << 11) = 2048`
|
||||
means 100% probability and so `1024` means 50% probability) that the next `bym`
|
||||
is 0, and `range` is at least `(1 << 24)`, then (to over-simplify for now)
|
||||
`decodeTheNextBym()` is:
|
||||
|
||||
threshold = (range >> 11) * prob
|
||||
if bits < threshold {
|
||||
bym = 0
|
||||
} else {
|
||||
bym = 1
|
||||
}
|
||||
|
||||
The probability `prob` depends on the `State` variable as well as additional
|
||||
context, such as the high bits of the most recent decoded byte and the low bits
|
||||
of the number of decoded bytes. Implementations maintain an array with hundreds
|
||||
of contextual probabilities (each a `uint16` in the range `1 ..= 2047`),
|
||||
indexed by a `prob_index` variable (calculated from the `State` and other
|
||||
factors). Expanding (marked by ¶) the over-simplified pseudo-code above:
|
||||
|
||||
prob = probs_array[prob_index] // ¶
|
||||
threshold = (range >> 11) * prob
|
||||
if bits < threshold {
|
||||
bym = 0
|
||||
} else {
|
||||
bym = 1
|
||||
}
|
||||
|
||||
LZMA probabilties also adapt. Producing a 0 (or 1) `bym` increases (or
|
||||
decreases) the relevant contextual probability: the prediction that, the next
|
||||
time we're in the same context, that next `bym` is 0. Expanding again:
|
||||
|
||||
prob = probs_array[prob_index]
|
||||
threshold = (range >> 11) * prob
|
||||
if bits < threshold {
|
||||
bym = 0
|
||||
prob += (2048 - prob) >> 5 // ¶
|
||||
probs_array[prob_index] = prob // ¶
|
||||
} else {
|
||||
bym = 1
|
||||
prob -= prob >> 5 // ¶
|
||||
probs_array[prob_index] = prob // ¶
|
||||
}
|
||||
|
||||
We also need to update the `bits` and `range`. The `range` shrinks every time
|
||||
we decode a `bym` and, if small enough, then grows by reading the next source
|
||||
byte. Expanding one last time, `decodeTheNextBym()` (which also updates `bits`,
|
||||
`range` and the relevant contextual probability) is:
|
||||
|
||||
prob = probs_array[prob_index]
|
||||
threshold = (range >> 11) * prob
|
||||
if bits < threshold {
|
||||
bym = 0
|
||||
range = threshold // ¶
|
||||
prob += (2048 - prob) >> 5
|
||||
probs_array[prob_index] = prob
|
||||
} else {
|
||||
bym = 1
|
||||
bits -= threshold // ¶
|
||||
range -= threshold // ¶
|
||||
prob -= prob >> 5
|
||||
probs_array[prob_index] = prob
|
||||
}
|
||||
if (range >> 24) == 0 { // ¶
|
||||
bits = (bits << 8) | src.read_byte() // ¶
|
||||
range <<= 8 // ¶
|
||||
} // ¶
|
||||
|
||||
|
||||
## Binary Trees and `decodeMultipleByms`
|
||||
|
||||
Decoding N byms (e.g. decoding a literal, a length, a slot or a distance) is
|
||||
basically N sequential calls to `decodeTheNextBym`, using `((1 << N) - 1)`
|
||||
different probabilties. This can be visualized as a balanced binary tree with
|
||||
`((1 << N) - 1)` branch nodes and `(1 << N)` leaf nodes. Each branch node has
|
||||
its own probability for taking one or the other of its two child nodes.
|
||||
|
||||
- There's 1 probability for the first bym.
|
||||
- There's 2 probabilities for the second bym. The one that is used depends on
|
||||
the value of the first bym.
|
||||
- There's 4 probabilities for the third bym. The one that is used depends on
|
||||
the values of the first two byms.
|
||||
- Etc.
|
||||
- There's `(1 << (N - 1))` probabilities for the Nth bym. The one that is used
|
||||
depends on the values of all previous byms.
|
||||
- There's `(1 << N)` leaf nodes, one for each possible N-bit value.
|
||||
|
||||
These probabilities can be flattened to a `(1 << N)` element array, whose first
|
||||
element is unused (or available for repurposing, such as for what the reference
|
||||
implementation calls the "choice" probabilities). For example, if N is 3 then
|
||||
the 8-element array could be labeled as `u1223333`, where `u` is unused, `1`
|
||||
marks the probability for the first bym, `2` marks the probabilities for the
|
||||
second bym, etc.
|
||||
|
||||
Algorithmically, we loop N times, walking the tree from the root to a leaf. The
|
||||
final N-bit value is captured in the tree node number (after applying a bit
|
||||
mask or, equivalently, a subtraction):
|
||||
|
||||
tree_node = 1
|
||||
while tree_node < (1 << N) {
|
||||
bym = decodeTheNextBym() // Using prob_index = tree_node.
|
||||
tree_node = (tree_node << 1) | bym
|
||||
}
|
||||
tree_node &= ((1 << N) - 1) // Equivalent to "tree_node -= (1 << N)".
|
||||
|
||||
That's a "forward" binary tree, where the bits occur in MSB to LSB order. A
|
||||
"reverse" binary tree uses the opposite order.
|
||||
|
||||
|
||||
## Further Reading
|
||||
|
||||
A longer discussion of LZMA compression, including range coding and the XZ
|
||||
container format, is at [XZ/LZMA Worked
|
||||
Example](https://nigeltao.github.io/blog/2024/xz-lzma-part-1-range-coding.html).
|
||||
@@ -0,0 +1,1024 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// The AlgOveNN line numbers refer to the ./README.md file.
|
||||
//
|
||||
// Most LZMA C/C++ implementations use macros for the "decodeTheNextBym()" code
|
||||
// fragment in that "Algorithm Overview" section, repeated multiple times in
|
||||
// the decoding algorithm. Wuffs does not have macros (or inline functions), so
|
||||
// its LZMA implementation looks relatively verbose and repetitive (even though
|
||||
// it's equivalent to the C/C++ code, at the machine code level).
|
||||
|
||||
pri func decoder.decode_bitstream_fast!(dst: base.io_writer, src: base.io_reader, workbuf: roslice base.u8) base.status {
|
||||
var c8 : base.u8
|
||||
|
||||
var bits : base.u32
|
||||
var range : base.u32
|
||||
|
||||
var state : base.u32[..= 11]
|
||||
|
||||
// repN is what the "Algorithm Overview" calls (mrud[N] - 1). The minimum
|
||||
// distance is 1.
|
||||
var rep0 : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep1 : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep2 : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep3 : base.u32[..= 0xFFFF_FFFE]
|
||||
var reptmp : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep : base.u32
|
||||
|
||||
var pos : base.u64
|
||||
var pos_end : base.u64
|
||||
|
||||
var lc : base.u32[..= 8]
|
||||
var lp_mask : base.u64[..= 15]
|
||||
var pb_mask : base.u64[..= 15]
|
||||
|
||||
var prob : base.u32
|
||||
var threshold : base.u32
|
||||
var tree_node : base.u32[..= 0x1FF]
|
||||
var prev_byte : base.u8
|
||||
var match_byte : base.u32
|
||||
var match_cusp : base.u32[..= 0xFFFF]
|
||||
var len_state : base.u32[..= 3] // Equals min(len-2, 3) when in a MATCH.
|
||||
var slot : base.u32[..= 0x7F]
|
||||
var len : base.u32[..= 273]
|
||||
|
||||
// LANL stands for Literal After Non-Literal. These variables are used when
|
||||
// decoding a LITERAL and state >= 7.
|
||||
var lanl_offset : base.u32[..= 0x100]
|
||||
var lanl_old_offset : base.u32[..= 0x100]
|
||||
var lanl_index : base.u32[..= 0x2FF]
|
||||
|
||||
var num_extra_bits : base.u32[..= 30]
|
||||
var dist_extra_bits : base.u32
|
||||
var high_bit_was_on : base.u32
|
||||
var i : base.u32
|
||||
|
||||
var index_ao00 : base.u32[..= (12 << 4) - 1]
|
||||
var index_ao41 : base.u32[..= (12 << 4) - 1]
|
||||
var index_lit : base.u32[..= (1 << 4) - 1]
|
||||
var index_len : base.u32[..= (1 << 4) - 1]
|
||||
|
||||
var index_small_dist_base : base.u32
|
||||
var index_small_dist_extra : base.u32
|
||||
var index_small_dist : base.u32[..= 127]
|
||||
|
||||
var index_large_dist : base.u32[..= 15]
|
||||
|
||||
// dist is part of the Lempel-Ziv (length, distance) pair. When dist is at
|
||||
// or below the args.dst history length then the LZ copy can be resolved
|
||||
// just from args.dst (and adj_dist and wb_index are unused). Otherwise, if
|
||||
// e.g. dist was 100 and args.dst.history_length() was 40 then adj_dist
|
||||
// would be 60: the LZ copy starts 60 bytes before the end of the
|
||||
// args.workbuf ringbuffer. wb_index is that start index, equal to
|
||||
// ((this.dict_workbuf_index ~mod- adj_dist) modulo this.dict_size).
|
||||
var dist : base.u32
|
||||
var adj_dist : base.u32
|
||||
var wb_index : base.u64
|
||||
|
||||
prev_byte = this.stashed_bytes[0]
|
||||
match_byte = this.stashed_bytes[1] as base.u32
|
||||
bits = this.stashed_bits
|
||||
range = this.stashed_range
|
||||
state = this.stashed_state
|
||||
rep0 = this.stashed_rep0
|
||||
rep1 = this.stashed_rep1
|
||||
rep2 = this.stashed_rep2
|
||||
rep3 = this.stashed_rep3
|
||||
pos = this.stashed_pos
|
||||
pos_end = this.stashed_pos_end
|
||||
|
||||
lc = this.lc
|
||||
lp_mask = ((1 as base.u64) << this.lp) - 1
|
||||
pb_mask = ((1 as base.u64) << this.pb) - 1
|
||||
|
||||
// "outer" is the core loop discussed in README.md's "Algorithm Overview".
|
||||
while.outer(args.dst.length() >= 282) and (args.src.length() >= 48) {
|
||||
if pos >= pos_end {
|
||||
this.end_of_chunk = true
|
||||
break.outer
|
||||
}
|
||||
|
||||
// AlgOve00 if decodeTheNextBym() == 0
|
||||
index_ao00 = (state << 4) | ((pos & pb_mask) as base.u32)
|
||||
prob = this.probs_ao00[index_ao00] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao00[index_ao00] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve01 // Decode a LITERAL.
|
||||
// AlgOve02 literal = decodeLiteral()
|
||||
|
||||
index_lit = 15 & (
|
||||
(((pos & lp_mask) as base.u32) << lc) |
|
||||
((prev_byte as base.u32) >> (8 - lc)))
|
||||
|
||||
lanl_offset = 0
|
||||
if state >= 7 {
|
||||
lanl_offset = 0x100
|
||||
}
|
||||
|
||||
tree_node = 1
|
||||
while tree_node < 0x100,
|
||||
inv args.dst.length() >= 282,
|
||||
{
|
||||
match_byte ~mod<<= 1
|
||||
lanl_old_offset = lanl_offset
|
||||
lanl_offset &= match_byte
|
||||
lanl_index = lanl_offset + lanl_old_offset + tree_node
|
||||
|
||||
prob = this.probs_lit[index_lit][lanl_index] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
lanl_offset = (lanl_offset ^ lanl_old_offset) & 0x100
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_lit[index_lit][lanl_index] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_lit[index_lit][lanl_index] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
|
||||
assert args.dst.length() >= 282
|
||||
|
||||
// AlgOve03 emitLiteral(literal)
|
||||
// AlgOve04 continue
|
||||
prev_byte = (tree_node & 0xFF) as base.u8
|
||||
args.dst.write_u8_fast!(a: prev_byte)
|
||||
pos ~mod+= 1
|
||||
state = STATE_TRANSITION_LITERAL[state] as base.u32
|
||||
continue.outer
|
||||
}
|
||||
|
||||
// AlgOve00a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao00[index_ao00] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
} else {
|
||||
assert args.src.length() >= 47
|
||||
}
|
||||
|
||||
while.goto_do_the_lz_copy true,
|
||||
pre args.src.length() >= 47,
|
||||
inv args.dst.length() >= 282,
|
||||
post len >= 1,
|
||||
{{
|
||||
// AlgOve20 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao20[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao20[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
} else {
|
||||
assert args.src.length() >= 46
|
||||
}
|
||||
|
||||
// AlgOve21 // Decode a MATCH.
|
||||
|
||||
while.goto_have_len true,
|
||||
pre args.src.length() >= 46,
|
||||
inv args.dst.length() >= 282,
|
||||
post len >= 1,
|
||||
{{
|
||||
// AlgOve22 len = decodeLen()
|
||||
|
||||
// AlgOve22.0 if decodeTheNextBym() == 0
|
||||
prob = this.probs_match_len_low[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.1 // Decode a low length.
|
||||
// AlgOve22.2 len = decodeMultipleByms(3) + 2
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08,
|
||||
inv args.dst.length() >= 282,
|
||||
{
|
||||
prob = this.probs_match_len_low[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len_state = CLAMP_NO_MORE_THAN_3[tree_node & 0x07] as base.u32
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
break.goto_have_len // goto AlgOve23.
|
||||
}
|
||||
|
||||
// AlgOve22.0a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.3 if decodeTheNextBym() == 0
|
||||
prob = this.probs_match_len_mid[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.4 // Decode a middle length.
|
||||
// AlgOve22.5 len = decodeMultipleByms(3) + 10
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08,
|
||||
inv args.dst.length() >= 282,
|
||||
{
|
||||
prob = this.probs_match_len_mid[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
break.goto_have_len // goto AlgOve23.
|
||||
}
|
||||
|
||||
// AlgOve22.3a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.7 // Decode a high length.
|
||||
// AlgOve22.8 len = decodeMultipleByms(8) + 18
|
||||
tree_node = 1
|
||||
while tree_node < 0x100,
|
||||
inv args.dst.length() >= 282,
|
||||
{
|
||||
prob = this.probs_match_len_high[0][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
break.goto_have_len
|
||||
}}.goto_have_len
|
||||
|
||||
// AlgOve23 slot = decodeSlot(min(len-2, 3))
|
||||
slot = 1
|
||||
while slot < 0x40,
|
||||
inv args.dst.length() >= 282,
|
||||
inv len >= 1,
|
||||
{
|
||||
prob = this.probs_slot[len_state][slot] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_slot[len_state][slot] = (prob & 0xFFFF) as base.u16
|
||||
slot = (slot << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_slot[len_state][slot] = (prob & 0xFFFF) as base.u16
|
||||
slot = (slot << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
slot &= 0x3F
|
||||
|
||||
// AlgOve24 distBiasedBy1 = decodeDistBiasedBy1(slot)
|
||||
rep = slot
|
||||
if slot < 4 {
|
||||
// No-op.
|
||||
|
||||
} else if slot < 14 {
|
||||
num_extra_bits = (slot >> 1) - 1
|
||||
rep = (2 | (slot & 1)) << num_extra_bits
|
||||
|
||||
// Read num_extra_bits "xxxx" bits.
|
||||
index_small_dist_base = rep ~mod- slot
|
||||
index_small_dist_extra = 1
|
||||
dist_extra_bits = 0
|
||||
i = 0
|
||||
while i < num_extra_bits,
|
||||
inv args.dst.length() >= 282,
|
||||
inv len >= 1,
|
||||
{
|
||||
assert i < 30 via "a < b: a < c; c <= b"(c: num_extra_bits)
|
||||
index_small_dist = (index_small_dist_base ~mod+ index_small_dist_extra) & 127
|
||||
prob = this.probs_small_dist[index_small_dist] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_small_dist[index_small_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_small_dist_extra = (index_small_dist_extra ~mod<< 1)
|
||||
i += 1
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_small_dist[index_small_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_small_dist_extra = (index_small_dist_extra ~mod<< 1) | 1
|
||||
dist_extra_bits |= (1 as base.u32) << i
|
||||
i += 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
|
||||
} else {
|
||||
num_extra_bits = (slot >> 1) - 1
|
||||
assert num_extra_bits >= 6
|
||||
assert num_extra_bits <= 30
|
||||
rep = (2 | (slot & 1)) << num_extra_bits
|
||||
|
||||
// Read (num_extra_bits - 4) "yyyy" bits.
|
||||
dist_extra_bits = 0
|
||||
while true,
|
||||
pre num_extra_bits > 4,
|
||||
inv args.dst.length() >= 282,
|
||||
inv len >= 1,
|
||||
post num_extra_bits > 0,
|
||||
post num_extra_bits <= 4,
|
||||
{
|
||||
range >>= 1
|
||||
bits ~mod-= range
|
||||
high_bit_was_on = 0 ~mod- (bits >> 31)
|
||||
bits ~mod+= range & high_bit_was_on
|
||||
dist_extra_bits = (dist_extra_bits ~mod<< 1) | ((high_bit_was_on ~mod+ 1) & 1)
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
num_extra_bits -= 1
|
||||
if num_extra_bits <= 4 {
|
||||
break
|
||||
}
|
||||
}
|
||||
dist_extra_bits ~mod<<= 4
|
||||
|
||||
// Read 4 "zzzz" bits.
|
||||
index_large_dist = 1
|
||||
while true,
|
||||
pre num_extra_bits > 0,
|
||||
pre num_extra_bits <= 4,
|
||||
inv args.dst.length() >= 282,
|
||||
inv len >= 1,
|
||||
{
|
||||
prob = this.probs_large_dist[index_large_dist] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_large_dist[index_large_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_large_dist = 15 & ((index_large_dist ~mod<< 1))
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_large_dist[index_large_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_large_dist = 15 & ((index_large_dist ~mod<< 1) | 1)
|
||||
dist_extra_bits |= (1 as base.u32) << (4 - num_extra_bits)
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
num_extra_bits -= 1
|
||||
if num_extra_bits <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
}
|
||||
|
||||
// AlgOve25 if distBiasedBy1 == 0xFFFF_FFFF
|
||||
if rep >= 0xFFFF_FFFF {
|
||||
// AlgOve26 break
|
||||
this.end_of_chunk = true
|
||||
break.outer
|
||||
}
|
||||
|
||||
// AlgOve28 mrud = (1 + distBiasedBy1, mrud[0], mrud[1], mrud[2])
|
||||
rep3 = rep2
|
||||
rep2 = rep1
|
||||
rep1 = rep0
|
||||
rep0 = rep
|
||||
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_MATCH[state] as base.u32
|
||||
break.goto_do_the_lz_copy // goto AlgOve90.
|
||||
}
|
||||
assert args.src.length() >= 47
|
||||
|
||||
// AlgOve20a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao20[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
} else {
|
||||
assert args.src.length() >= 46
|
||||
}
|
||||
|
||||
// AlgOve40 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao40[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao40[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
} else {
|
||||
assert args.src.length() >= 45
|
||||
}
|
||||
|
||||
// AlgOve41 if decodeTheNextBym() == 0
|
||||
index_ao41 = (state << 4) | ((pos & pb_mask) as base.u32)
|
||||
prob = this.probs_ao41[index_ao41] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao41[index_ao41] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve42 // Decode a SHORTREP.
|
||||
// AlgOve43 len = 1
|
||||
len = 1
|
||||
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_SHORTREP[state] as base.u32
|
||||
break.goto_do_the_lz_copy // goto AlgOve90.
|
||||
}
|
||||
|
||||
// AlgOve41a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao41[index_ao41] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve46 // Decode a LONGREP[0].
|
||||
|
||||
} else {
|
||||
// AlgOve40a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao40[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
} else {
|
||||
assert args.src.length() >= 45
|
||||
}
|
||||
|
||||
// AlgOve60 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao60[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao60[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve61 // Decode a LONGREP[1].
|
||||
// AlgOve62 mrud = (mrud[1], mrud[0], mrud[2], mrud[3])
|
||||
reptmp = rep1
|
||||
rep1 = rep0
|
||||
rep0 = reptmp
|
||||
|
||||
} else {
|
||||
// AlgOve60a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao60[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
} else {
|
||||
assert args.src.length() >= 44
|
||||
}
|
||||
|
||||
// AlgOve63 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao63[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao63[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve64 // Decode a LONGREP[2].
|
||||
// AlgOve65 mrud = (mrud[2], mrud[0], mrud[1], mrud[3])
|
||||
reptmp = rep2
|
||||
rep2 = rep1
|
||||
rep1 = rep0
|
||||
rep0 = reptmp
|
||||
|
||||
} else {
|
||||
// AlgOve63a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao63[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve67 // Decode a LONGREP[3].
|
||||
// AlgOve68 mrud = (mrud[3], mrud[0], mrud[1], mrud[2])
|
||||
reptmp = rep3
|
||||
rep3 = rep2
|
||||
rep2 = rep1
|
||||
rep1 = rep0
|
||||
rep0 = reptmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AlgOve80 len = decodeLen()
|
||||
while.goto_after_decode_len true,
|
||||
inv args.dst.length() >= 282,
|
||||
post len >= 1,
|
||||
{{
|
||||
// AlgOve80.0 if decodeTheNextBym() == 0
|
||||
prob = this.probs_longrep_len_low[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.1 // Decode a low length.
|
||||
// AlgOve80.2 len = decodeMultipleByms(3) + 2
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08,
|
||||
inv args.dst.length() >= 282,
|
||||
{
|
||||
prob = this.probs_longrep_len_low[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
break.goto_after_decode_len
|
||||
}
|
||||
|
||||
// AlgOve80.0a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.3 if decodeTheNextBym() == 0
|
||||
prob = this.probs_longrep_len_mid[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.4 // Decode a middle length.
|
||||
// AlgOve80.5 len = decodeMultipleByms(3) + 10
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08,
|
||||
inv args.dst.length() >= 282,
|
||||
{
|
||||
prob = this.probs_longrep_len_mid[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
break.goto_after_decode_len
|
||||
}
|
||||
|
||||
// AlgOve80.3a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.7 // Decode a high length.
|
||||
// AlgOve80.8 len = decodeMultipleByms(8) + 18
|
||||
tree_node = 1
|
||||
while tree_node < 0x100,
|
||||
inv args.dst.length() >= 282,
|
||||
{
|
||||
prob = this.probs_longrep_len_high[0][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
if args.src.length() <= 0 {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
|
||||
break.goto_after_decode_len
|
||||
}}.goto_after_decode_len
|
||||
break.goto_do_the_lz_copy
|
||||
}}.goto_do_the_lz_copy
|
||||
assert args.dst.length() >= 282
|
||||
|
||||
// AlgOve90 labelDoTheLZCopy:
|
||||
// AlgOve94 emitCopy(len, mrud[0])
|
||||
|
||||
assert len >= 1
|
||||
dist = rep0 + 1
|
||||
assert dist >= 1
|
||||
if ((dist as base.u64) > pos) or
|
||||
((dist as base.u64) > (this.dict_size as base.u64)) {
|
||||
return "#bad distance"
|
||||
}
|
||||
pos ~mod+= len as base.u64
|
||||
assert (len as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 282)
|
||||
assert ((len + 8) as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 282)
|
||||
|
||||
// Copy from the args.workbuf history, if necessary.
|
||||
if (dist as base.u64) > args.dst.history_length() {
|
||||
adj_dist = (((dist as base.u64) - args.dst.history_length()) & 0xFFFF_FFFF) as base.u32
|
||||
if adj_dist > this.dict_seen {
|
||||
return "#bad distance"
|
||||
}
|
||||
wb_index = (this.dict_workbuf_index as base.u64) ~mod- (adj_dist as base.u64)
|
||||
while wb_index >= 0x8000_0000_0000_0000,
|
||||
inv dist >= 1,
|
||||
{
|
||||
wb_index ~mod+= this.dict_size as base.u64
|
||||
}
|
||||
if wb_index >= args.workbuf.length() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
|
||||
if len < adj_dist {
|
||||
// Copy len bytes of history and one more byte for the later
|
||||
// half of the two-byte cusp, all from args.workbuf.
|
||||
args.dst.limited_copy_u32_from_slice!(up_to: len + 1, s: args.workbuf[wb_index ..])
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
match_byte = args.dst.peek_undo_byte() as base.u32
|
||||
args.dst.undo_byte!()
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
prev_byte = args.dst.peek_undo_byte()
|
||||
continue.outer
|
||||
} else if len == adj_dist {
|
||||
// Like above, copy len bytes of history and one more byte for
|
||||
// the later half of the two-byte cusp, but the copy-source
|
||||
// crosses over from args.workbuf to args.dst.
|
||||
args.dst.limited_copy_u32_from_slice!(up_to: len, s: args.workbuf[wb_index ..])
|
||||
args.dst.limited_copy_u32_from_history!(up_to: 1, distance: dist)
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
match_byte = args.dst.peek_undo_byte() as base.u32
|
||||
args.dst.undo_byte!()
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
prev_byte = args.dst.peek_undo_byte()
|
||||
continue.outer
|
||||
}
|
||||
args.dst.limited_copy_u32_from_slice!(up_to: adj_dist, s: args.workbuf[wb_index ..])
|
||||
len -= adj_dist
|
||||
assert len >= 1
|
||||
if ((len as base.u64) > args.dst.length()) or
|
||||
(((len + 8) as base.u64) > args.dst.length()) or
|
||||
((dist as base.u64) > args.dst.history_length()) {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
}
|
||||
|
||||
// Copy from the args.dst history.
|
||||
assert len >= 1
|
||||
assert dist >= 1
|
||||
assert (len as base.u64) <= args.dst.length()
|
||||
assert ((len + 8) as base.u64) <= args.dst.length()
|
||||
assert (dist as base.u64) <= args.dst.history_length()
|
||||
if dist >= 8 {
|
||||
match_cusp = args.dst.limited_copy_u32_from_history_8_byte_chunks_fast_return_cusp!(
|
||||
up_to: len, distance: dist)
|
||||
match_byte = match_cusp >> 8
|
||||
prev_byte = (match_cusp & 0xFF) as base.u8
|
||||
} else {
|
||||
match_cusp = args.dst.limited_copy_u32_from_history_fast_return_cusp!(
|
||||
up_to: len, distance: dist)
|
||||
match_byte = match_cusp >> 8
|
||||
prev_byte = (match_cusp & 0xFF) as base.u8
|
||||
}
|
||||
}.outer
|
||||
|
||||
this.stashed_bytes[0] = prev_byte
|
||||
this.stashed_bytes[1] = (match_byte & 0xFF) as base.u8
|
||||
this.stashed_bits = bits
|
||||
this.stashed_range = range
|
||||
this.stashed_state = state
|
||||
this.stashed_rep0 = rep0
|
||||
this.stashed_rep1 = rep1
|
||||
this.stashed_rep2 = rep2
|
||||
this.stashed_rep3 = rep3
|
||||
this.stashed_pos = pos
|
||||
this.stashed_pos_end = pos_end
|
||||
}
|
||||
@@ -0,0 +1,950 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// The AlgOveNN line numbers refer to the ./README.md file.
|
||||
//
|
||||
// Most LZMA C/C++ implementations use macros for the "decodeTheNextBym()" code
|
||||
// fragment in that "Algorithm Overview" section, repeated multiple times in
|
||||
// the decoding algorithm. Wuffs does not have macros (or inline functions), so
|
||||
// its LZMA implementation looks relatively verbose and repetitive (even though
|
||||
// it's equivalent to the C/C++ code, at the machine code level).
|
||||
|
||||
pri func decoder.decode_bitstream_slow?(dst: base.io_writer, src: base.io_reader, workbuf: roslice base.u8) {
|
||||
var c8 : base.u8
|
||||
|
||||
var bits : base.u32
|
||||
var range : base.u32
|
||||
|
||||
var state : base.u32[..= 11]
|
||||
|
||||
// repN is what the "Algorithm Overview" calls (mrud[N] - 1). The minimum
|
||||
// distance is 1.
|
||||
var rep0 : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep1 : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep2 : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep3 : base.u32[..= 0xFFFF_FFFE]
|
||||
var reptmp : base.u32[..= 0xFFFF_FFFE]
|
||||
var rep : base.u32
|
||||
|
||||
var pos : base.u64
|
||||
var pos_end : base.u64
|
||||
|
||||
var lc : base.u32[..= 8]
|
||||
var lp_mask : base.u64[..= 15]
|
||||
var pb_mask : base.u64[..= 15]
|
||||
|
||||
var prob : base.u32
|
||||
var threshold : base.u32
|
||||
var tree_node : base.u32[..= 0x1FF]
|
||||
var prev_byte : base.u8
|
||||
var match_byte : base.u32
|
||||
var match_cusp : base.u32[..= 0xFFFF]
|
||||
var len_state : base.u32[..= 3] // Equals min(len-2, 3) when in a MATCH.
|
||||
var slot : base.u32[..= 0x7F]
|
||||
var len : base.u32[..= 273]
|
||||
|
||||
// LANL stands for Literal After Non-Literal. These variables are used when
|
||||
// decoding a LITERAL and state >= 7.
|
||||
var lanl_offset : base.u32[..= 0x100]
|
||||
var lanl_old_offset : base.u32[..= 0x100]
|
||||
var lanl_index : base.u32[..= 0x2FF]
|
||||
|
||||
var num_extra_bits : base.u32[..= 30]
|
||||
var dist_extra_bits : base.u32
|
||||
var high_bit_was_on : base.u32
|
||||
var i : base.u32
|
||||
|
||||
var index_ao00 : base.u32[..= (12 << 4) - 1]
|
||||
var index_ao41 : base.u32[..= (12 << 4) - 1]
|
||||
var index_lit : base.u32[..= (1 << 4) - 1]
|
||||
var index_len : base.u32[..= (1 << 4) - 1]
|
||||
|
||||
var index_small_dist_base : base.u32
|
||||
var index_small_dist_extra : base.u32
|
||||
var index_small_dist : base.u32[..= 127]
|
||||
|
||||
var index_large_dist : base.u32[..= 15]
|
||||
|
||||
// dist is part of the Lempel-Ziv (length, distance) pair. When dist is at
|
||||
// or below the args.dst history length then the LZ copy can be resolved
|
||||
// just from args.dst (and adj_dist and wb_index are unused). Otherwise, if
|
||||
// e.g. dist was 100 and args.dst.history_length() was 40 then adj_dist
|
||||
// would be 60: the LZ copy starts 60 bytes before the end of the
|
||||
// args.workbuf ringbuffer. wb_index is that start index, equal to
|
||||
// ((this.dict_workbuf_index ~mod- adj_dist) modulo this.dict_size).
|
||||
var dist : base.u32
|
||||
var adj_dist : base.u32
|
||||
var wb_index : base.u64
|
||||
|
||||
prev_byte = this.stashed_bytes[0]
|
||||
match_byte = this.stashed_bytes[1] as base.u32
|
||||
bits = this.stashed_bits
|
||||
range = this.stashed_range
|
||||
state = this.stashed_state
|
||||
rep0 = this.stashed_rep0
|
||||
rep1 = this.stashed_rep1
|
||||
rep2 = this.stashed_rep2
|
||||
rep3 = this.stashed_rep3
|
||||
pos = this.stashed_pos
|
||||
pos_end = this.stashed_pos_end
|
||||
|
||||
lc = this.lc
|
||||
lp_mask = ((1 as base.u64) << this.lp) - 1
|
||||
pb_mask = ((1 as base.u64) << this.pb) - 1
|
||||
|
||||
// "outer" is the core loop discussed in README.md's "Algorithm Overview".
|
||||
while.outer not coroutine_resumed {
|
||||
if pos >= pos_end {
|
||||
this.end_of_chunk = true
|
||||
break.outer
|
||||
}
|
||||
|
||||
// AlgOve00 if decodeTheNextBym() == 0
|
||||
index_ao00 = (state << 4) | ((pos & pb_mask) as base.u32)
|
||||
prob = this.probs_ao00[index_ao00] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao00[index_ao00] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve01 // Decode a LITERAL.
|
||||
// AlgOve02 literal = decodeLiteral()
|
||||
|
||||
index_lit = 15 & (
|
||||
(((pos & lp_mask) as base.u32) << lc) |
|
||||
((prev_byte as base.u32) >> (8 - lc)))
|
||||
|
||||
if state >= 7 {
|
||||
// We are decoding an 8-bit LITERAL, and (state >= 7) means
|
||||
// that we most recently decoded a NON-LITERAL. The
|
||||
// this.probs_lit[index_lit] array has 0x300 elements: three
|
||||
// banks of 0x100.
|
||||
//
|
||||
// For (state < 7), we only use the first bank (and we run the
|
||||
// while.low_state loop instead). This is equivalent to running
|
||||
// the while.high_state loop where lanl_offset starts at and
|
||||
// stays at zero for the entire loop. match_byte is ignored.
|
||||
//
|
||||
// For (state >= 7), we start by using the two later banks, but
|
||||
// as we are decoding those 8 bits (from MSB to LSB order), we
|
||||
// drop down to the first bank (and stay there) if and when the
|
||||
// decoded bit doesn't equal the corresponding bit (in the same
|
||||
// MSB to LSB order) in the match_byte variable.
|
||||
//
|
||||
// lanl_offset stays at 0x100 until that "if and when" point
|
||||
// (which typically happens; if all 8 bits were equal then the
|
||||
// previous NON-LITERAL copy could often just have been
|
||||
// longer), when lanl_offset then drops down to zero. We then
|
||||
// effectively run the remaining (8 - I) iterations in the
|
||||
// while.low_state loop, where I is the iteration count.
|
||||
//
|
||||
// Whether we use the 0x100 or 0x200 bank, out of the two later
|
||||
// banks, depends on the match_byte's I'th bit (MSB to LSB).
|
||||
// match_byte is conceptually a base.u8 (it is <= 0xFF outside
|
||||
// of this code fragment) but the intermediate computation is
|
||||
// simpler as a base.u32 (ignoring the high 23 bits).
|
||||
lanl_offset = 0x100
|
||||
|
||||
tree_node = 1
|
||||
while.high_state tree_node < 0x100 {
|
||||
match_byte ~mod<<= 1
|
||||
lanl_old_offset = lanl_offset
|
||||
lanl_offset &= match_byte
|
||||
lanl_index = lanl_offset + lanl_old_offset + tree_node
|
||||
|
||||
prob = this.probs_lit[index_lit][lanl_index] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
lanl_offset = (lanl_offset ^ lanl_old_offset) & 0x100
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_lit[index_lit][lanl_index] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_lit[index_lit][lanl_index] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}.high_state
|
||||
|
||||
} else {
|
||||
tree_node = 1
|
||||
while.low_state tree_node < 0x100 {
|
||||
prob = this.probs_lit[index_lit][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_lit[index_lit][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_lit[index_lit][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}.low_state
|
||||
}
|
||||
|
||||
// AlgOve03 emitLiteral(literal)
|
||||
// AlgOve04 continue
|
||||
prev_byte = (tree_node & 0xFF) as base.u8
|
||||
args.dst.write_u8?(a: prev_byte)
|
||||
pos ~mod+= 1
|
||||
state = STATE_TRANSITION_LITERAL[state] as base.u32
|
||||
continue.outer
|
||||
}
|
||||
|
||||
// AlgOve00a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao00[index_ao00] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
while.goto_do_the_lz_copy true,
|
||||
post len >= 1,
|
||||
{{
|
||||
// AlgOve20 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao20[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao20[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve21 // Decode a MATCH.
|
||||
|
||||
while.goto_have_len true,
|
||||
post len >= 1,
|
||||
{{
|
||||
// AlgOve22 len = decodeLen()
|
||||
|
||||
// AlgOve22.0 if decodeTheNextBym() == 0
|
||||
prob = this.probs_match_len_low[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.1 // Decode a low length.
|
||||
// AlgOve22.2 len = decodeMultipleByms(3) + 2
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08 {
|
||||
prob = this.probs_match_len_low[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len_state = CLAMP_NO_MORE_THAN_3[tree_node & 0x07] as base.u32
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
break.goto_have_len // goto AlgOve23.
|
||||
}
|
||||
|
||||
// AlgOve22.0a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.3 if decodeTheNextBym() == 0
|
||||
prob = this.probs_match_len_mid[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.4 // Decode a middle length.
|
||||
// AlgOve22.5 len = decodeMultipleByms(3) + 10
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08 {
|
||||
prob = this.probs_match_len_mid[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
break.goto_have_len // goto AlgOve23.
|
||||
}
|
||||
|
||||
// AlgOve22.3a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve22.7 // Decode a high length.
|
||||
// AlgOve22.8 len = decodeMultipleByms(8) + 18
|
||||
tree_node = 1
|
||||
while tree_node < 0x100 {
|
||||
prob = this.probs_match_len_high[0][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_match_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_match_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
len_state = 3
|
||||
break.goto_have_len
|
||||
}}.goto_have_len
|
||||
|
||||
// AlgOve23 slot = decodeSlot(min(len-2, 3))
|
||||
slot = 1
|
||||
while slot < 0x40,
|
||||
inv len >= 1,
|
||||
{
|
||||
prob = this.probs_slot[len_state][slot] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_slot[len_state][slot] = (prob & 0xFFFF) as base.u16
|
||||
slot = (slot << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_slot[len_state][slot] = (prob & 0xFFFF) as base.u16
|
||||
slot = (slot << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
slot &= 0x3F
|
||||
|
||||
// AlgOve24 distBiasedBy1 = decodeDistBiasedBy1(slot)
|
||||
rep = slot
|
||||
if slot < 4 {
|
||||
// No-op.
|
||||
|
||||
} else if slot < 14 {
|
||||
num_extra_bits = (slot >> 1) - 1
|
||||
rep = (2 | (slot & 1)) << num_extra_bits
|
||||
|
||||
// Read num_extra_bits "xxxx" bits.
|
||||
index_small_dist_base = rep ~mod- slot
|
||||
index_small_dist_extra = 1
|
||||
dist_extra_bits = 0
|
||||
i = 0
|
||||
while i < num_extra_bits,
|
||||
inv len >= 1,
|
||||
{
|
||||
assert i < 30 via "a < b: a < c; c <= b"(c: num_extra_bits)
|
||||
index_small_dist = (index_small_dist_base ~mod+ index_small_dist_extra) & 127
|
||||
prob = this.probs_small_dist[index_small_dist] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_small_dist[index_small_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_small_dist_extra = (index_small_dist_extra ~mod<< 1)
|
||||
i += 1
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_small_dist[index_small_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_small_dist_extra = (index_small_dist_extra ~mod<< 1) | 1
|
||||
dist_extra_bits |= (1 as base.u32) << i
|
||||
i += 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
|
||||
} else {
|
||||
num_extra_bits = (slot >> 1) - 1
|
||||
assert num_extra_bits >= 6
|
||||
assert num_extra_bits <= 30
|
||||
rep = (2 | (slot & 1)) << num_extra_bits
|
||||
|
||||
// Read (num_extra_bits - 4) "yyyy" bits.
|
||||
dist_extra_bits = 0
|
||||
while true,
|
||||
pre num_extra_bits > 4,
|
||||
inv len >= 1,
|
||||
post num_extra_bits > 0,
|
||||
post num_extra_bits <= 4,
|
||||
{
|
||||
range >>= 1
|
||||
bits ~mod-= range
|
||||
high_bit_was_on = 0 ~mod- (bits >> 31)
|
||||
bits ~mod+= range & high_bit_was_on
|
||||
dist_extra_bits = (dist_extra_bits ~mod<< 1) | ((high_bit_was_on ~mod+ 1) & 1)
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
num_extra_bits -= 1
|
||||
if num_extra_bits <= 4 {
|
||||
break
|
||||
}
|
||||
}
|
||||
dist_extra_bits ~mod<<= 4
|
||||
|
||||
// Read 4 "zzzz" bits.
|
||||
index_large_dist = 1
|
||||
while true,
|
||||
pre num_extra_bits > 0,
|
||||
pre num_extra_bits <= 4,
|
||||
inv len >= 1,
|
||||
{
|
||||
prob = this.probs_large_dist[index_large_dist] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_large_dist[index_large_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_large_dist = 15 & ((index_large_dist ~mod<< 1))
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_large_dist[index_large_dist] = (prob & 0xFFFF) as base.u16
|
||||
index_large_dist = 15 & ((index_large_dist ~mod<< 1) | 1)
|
||||
dist_extra_bits |= (1 as base.u32) << (4 - num_extra_bits)
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
num_extra_bits -= 1
|
||||
if num_extra_bits <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
rep ~mod+= dist_extra_bits
|
||||
}
|
||||
|
||||
// AlgOve25 if distBiasedBy1 == 0xFFFF_FFFF
|
||||
if rep >= 0xFFFF_FFFF {
|
||||
// AlgOve26 break
|
||||
this.end_of_chunk = true
|
||||
break.outer
|
||||
}
|
||||
|
||||
// AlgOve28 mrud = (1 + distBiasedBy1, mrud[0], mrud[1], mrud[2])
|
||||
rep3 = rep2
|
||||
rep2 = rep1
|
||||
rep1 = rep0
|
||||
rep0 = rep
|
||||
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_MATCH[state] as base.u32
|
||||
break.goto_do_the_lz_copy // goto AlgOve90.
|
||||
}
|
||||
|
||||
// AlgOve20a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao20[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve40 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao40[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao40[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve41 if decodeTheNextBym() == 0
|
||||
index_ao41 = (state << 4) | ((pos & pb_mask) as base.u32)
|
||||
prob = this.probs_ao41[index_ao41] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao41[index_ao41] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve42 // Decode a SHORTREP.
|
||||
// AlgOve43 len = 1
|
||||
len = 1
|
||||
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_SHORTREP[state] as base.u32
|
||||
break.goto_do_the_lz_copy // goto AlgOve90.
|
||||
}
|
||||
|
||||
// AlgOve41a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao41[index_ao41] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve46 // Decode a LONGREP[0].
|
||||
|
||||
} else {
|
||||
// AlgOve40a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao40[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve60 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao60[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao60[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve61 // Decode a LONGREP[1].
|
||||
// AlgOve62 mrud = (mrud[1], mrud[0], mrud[2], mrud[3])
|
||||
reptmp = rep1
|
||||
rep1 = rep0
|
||||
rep0 = reptmp
|
||||
|
||||
} else {
|
||||
// AlgOve60a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao60[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve63 if decodeTheNextBym() == 0
|
||||
prob = this.probs_ao63[state] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_ao63[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve64 // Decode a LONGREP[2].
|
||||
// AlgOve65 mrud = (mrud[2], mrud[0], mrud[1], mrud[3])
|
||||
reptmp = rep2
|
||||
rep2 = rep1
|
||||
rep1 = rep0
|
||||
rep0 = reptmp
|
||||
|
||||
} else {
|
||||
// AlgOve63a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_ao63[state] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve67 // Decode a LONGREP[3].
|
||||
// AlgOve68 mrud = (mrud[3], mrud[0], mrud[1], mrud[2])
|
||||
reptmp = rep3
|
||||
rep3 = rep2
|
||||
rep2 = rep1
|
||||
rep1 = rep0
|
||||
rep0 = reptmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AlgOve80 len = decodeLen()
|
||||
while.goto_after_decode_len true,
|
||||
post len >= 1,
|
||||
{{
|
||||
// AlgOve80.0 if decodeTheNextBym() == 0
|
||||
prob = this.probs_longrep_len_low[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.1 // Decode a low length.
|
||||
// AlgOve80.2 len = decodeMultipleByms(3) + 2
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08 {
|
||||
prob = this.probs_longrep_len_low[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_low[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0x07) + 2
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
break.goto_after_decode_len
|
||||
}
|
||||
|
||||
// AlgOve80.0a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_low[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.3 if decodeTheNextBym() == 0
|
||||
prob = this.probs_longrep_len_mid[0][0] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.4 // Decode a middle length.
|
||||
// AlgOve80.5 len = decodeMultipleByms(3) + 10
|
||||
index_len = (pos & pb_mask) as base.u32
|
||||
tree_node = 1
|
||||
while tree_node < 0x08 {
|
||||
prob = this.probs_longrep_len_mid[index_len][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_mid[index_len][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0x07) + 10
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
break.goto_after_decode_len
|
||||
}
|
||||
|
||||
// AlgOve80.3a if decodeTheNextBym() == 0 // If-false branch.
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_mid[0][0] = (prob & 0xFFFF) as base.u16
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
|
||||
// AlgOve80.7 // Decode a high length.
|
||||
// AlgOve80.8 len = decodeMultipleByms(8) + 18
|
||||
tree_node = 1
|
||||
while tree_node < 0x100 {
|
||||
prob = this.probs_longrep_len_high[0][tree_node] as base.u32
|
||||
threshold = (range >> 11) ~mod* prob
|
||||
if bits < threshold {
|
||||
range = threshold
|
||||
prob ~mod+= (2048 ~mod- prob) >> 5
|
||||
this.probs_longrep_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1)
|
||||
} else {
|
||||
bits ~mod-= threshold
|
||||
range ~mod-= threshold
|
||||
prob ~mod-= prob >> 5
|
||||
this.probs_longrep_len_high[0][tree_node] = (prob & 0xFFFF) as base.u16
|
||||
tree_node = (tree_node << 1) | 1
|
||||
}
|
||||
if (range >> 24) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
bits = (bits ~mod<< 8) | (c8 as base.u32)
|
||||
range ~mod<<= 8
|
||||
}
|
||||
}
|
||||
len = (tree_node & 0xFF) + 18
|
||||
assert len >= 1
|
||||
state = STATE_TRANSITION_LONGREP[state] as base.u32
|
||||
|
||||
break.goto_after_decode_len
|
||||
}}.goto_after_decode_len
|
||||
break.goto_do_the_lz_copy
|
||||
}}.goto_do_the_lz_copy
|
||||
|
||||
// AlgOve90 labelDoTheLZCopy:
|
||||
// AlgOve94 emitCopy(len, mrud[0])
|
||||
|
||||
assert len >= 1
|
||||
dist = rep0 + 1
|
||||
assert dist >= 1
|
||||
if ((dist as base.u64) > pos) or
|
||||
((dist as base.u64) > (this.dict_size as base.u64)) {
|
||||
return "#bad distance"
|
||||
}
|
||||
pos ~mod+= len as base.u64
|
||||
// 274 is at least (len + 1). A limited_copy_u32_from_slice call below
|
||||
// passes "up_to: len + 1". It's simpler if it's always a full copy.
|
||||
while 274 > args.dst.length(),
|
||||
inv len >= 1,
|
||||
inv dist >= 1,
|
||||
post 274 <= args.dst.length(),
|
||||
{
|
||||
yield? base."$short write"
|
||||
}
|
||||
assert (len as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 274)
|
||||
|
||||
// Copy from the args.workbuf history, if necessary.
|
||||
if (dist as base.u64) > args.dst.history_length() {
|
||||
adj_dist = (((dist as base.u64) - args.dst.history_length()) & 0xFFFF_FFFF) as base.u32
|
||||
if adj_dist > this.dict_seen {
|
||||
return "#bad distance"
|
||||
}
|
||||
wb_index = (this.dict_workbuf_index as base.u64) ~mod- (adj_dist as base.u64)
|
||||
while wb_index >= 0x8000_0000_0000_0000,
|
||||
inv dist >= 1,
|
||||
{
|
||||
wb_index ~mod+= this.dict_size as base.u64
|
||||
}
|
||||
if wb_index >= args.workbuf.length() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
|
||||
if len < adj_dist {
|
||||
// Copy len bytes of history and one more byte for the later
|
||||
// half of the two-byte cusp, all from args.workbuf.
|
||||
args.dst.limited_copy_u32_from_slice!(up_to: len + 1, s: args.workbuf[wb_index ..])
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
match_byte = args.dst.peek_undo_byte() as base.u32
|
||||
args.dst.undo_byte!()
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
prev_byte = args.dst.peek_undo_byte()
|
||||
continue.outer
|
||||
} else if len == adj_dist {
|
||||
// Like above, copy len bytes of history and one more byte for
|
||||
// the later half of the two-byte cusp, but the copy-source
|
||||
// crosses over from args.workbuf to args.dst.
|
||||
args.dst.limited_copy_u32_from_slice!(up_to: len, s: args.workbuf[wb_index ..])
|
||||
args.dst.limited_copy_u32_from_history!(up_to: 1, distance: dist)
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
match_byte = args.dst.peek_undo_byte() as base.u32
|
||||
args.dst.undo_byte!()
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
prev_byte = args.dst.peek_undo_byte()
|
||||
continue.outer
|
||||
}
|
||||
args.dst.limited_copy_u32_from_slice!(up_to: adj_dist, s: args.workbuf[wb_index ..])
|
||||
len -= adj_dist
|
||||
assert len >= 1
|
||||
if ((len as base.u64) > args.dst.length()) or
|
||||
((dist as base.u64) > args.dst.history_length()) {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
}
|
||||
|
||||
// Copy from the args.dst history.
|
||||
assert len >= 1
|
||||
assert dist >= 1
|
||||
assert (len as base.u64) <= args.dst.length()
|
||||
assert (dist as base.u64) <= args.dst.history_length()
|
||||
match_cusp = args.dst.limited_copy_u32_from_history_fast_return_cusp!(
|
||||
up_to: len, distance: dist)
|
||||
match_byte = match_cusp >> 8
|
||||
prev_byte = (match_cusp & 0xFF) as base.u8
|
||||
}.outer
|
||||
|
||||
this.stashed_bytes[0] = prev_byte
|
||||
this.stashed_bytes[1] = (match_byte & 0xFF) as base.u8
|
||||
this.stashed_bits = bits
|
||||
this.stashed_range = range
|
||||
this.stashed_state = state
|
||||
this.stashed_rep0 = rep0
|
||||
this.stashed_rep1 = rep1
|
||||
this.stashed_rep2 = rep2
|
||||
this.stashed_rep3 = rep3
|
||||
this.stashed_pos = pos
|
||||
this.stashed_pos_end = pos_end
|
||||
}
|
||||
@@ -0,0 +1,816 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pub status "#bad LZMA2 header"
|
||||
pub status "#bad bitstream trailer"
|
||||
pub status "#bad code"
|
||||
pub status "#bad decoded length"
|
||||
pub status "#bad distance"
|
||||
pub status "#bad header"
|
||||
pub status "#truncated input"
|
||||
pub status "#unsupported decoded length"
|
||||
pub status "#unsupported properties"
|
||||
|
||||
pri status "#internal error: inconsistent I/O"
|
||||
pri status "#internal error: inconsistent dictionary state"
|
||||
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0xFFFF_FFFF + 273
|
||||
|
||||
pub struct decoder? implements base.io_transformer(
|
||||
// In theory, lc ranges in [0 ..= 8]. In practice, to keep the
|
||||
// worst-case size of the statically allocated probs_lit array
|
||||
// managable, we only support configurations where ((lc + lp) <= 4) and
|
||||
// otherwise return "#unsupported properties".
|
||||
//
|
||||
// This matches "LZMA2's limited property condition" described at:
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/781863cdf592da3e97420f50de5dac056ad352a5/DOC/lzma-specification.txt#L192
|
||||
lc : base.u32[..= 4], // The number of Literal Context bits. Default: 3.
|
||||
lp : base.u32[..= 4], // The number of Literal Position bits. Default: 0.
|
||||
pb : base.u32[..= 4], // The number of Position Bits. Default: 2.
|
||||
|
||||
format_extension : base.u32,
|
||||
|
||||
// dict_size is the nominal size of the args.workbuf ringbuffer that
|
||||
// holds historical decoded bytes. The workbuf_len is a little larger:
|
||||
// see "ML" below.
|
||||
dict_size : base.u32,
|
||||
|
||||
// dict_workbuf_index indexes the args.workbuf ringbuffer, pointing to
|
||||
// where add_history will next write to.
|
||||
dict_workbuf_index : base.u32,
|
||||
|
||||
// dict_seen is the cumulative sum (saturating at 0xFFFF_FFFF) of the
|
||||
// number of bytes passed to add_history.
|
||||
dict_seen : base.u32,
|
||||
|
||||
decoded_length : base.u64,
|
||||
|
||||
lzma2_encoded_length_have : base.u64,
|
||||
lzma2_encoded_length_want : base.u64,
|
||||
lzma2_need_prob_reset : base.bool,
|
||||
lzma2_need_properties : base.bool,
|
||||
lzma2_need_dict_reset : base.bool,
|
||||
|
||||
prev_lzma2_chunk_was_uncompressed : base.bool,
|
||||
|
||||
allow_non_zero_initial_byte : base.bool,
|
||||
|
||||
end_of_chunk : base.bool,
|
||||
|
||||
stashed_bytes : array[2] base.u8, // 0 is prev_byte, 1 is match_byte.
|
||||
stashed_bits : base.u32,
|
||||
stashed_range : base.u32,
|
||||
stashed_state : base.u32[..= 11],
|
||||
stashed_rep0 : base.u32[..= 0xFFFF_FFFE],
|
||||
stashed_rep1 : base.u32[..= 0xFFFF_FFFE],
|
||||
stashed_rep2 : base.u32[..= 0xFFFF_FFFE],
|
||||
stashed_rep3 : base.u32[..= 0xFFFF_FFFE],
|
||||
stashed_pos : base.u64,
|
||||
stashed_pos_end : base.u64,
|
||||
|
||||
util : base.utility,
|
||||
) + (
|
||||
// 12 is the number of states. 4 is the pb inclusive maximum.
|
||||
//
|
||||
// The AlgOveNN line numbers refer to the ./README.md file.
|
||||
probs_ao00 : array[12 << 4] base.u16, // AlgOve00.
|
||||
probs_ao20 : array[12] base.u16, // AlgOve20.
|
||||
probs_ao40 : array[12] base.u16, // AlgOve40.
|
||||
probs_ao41 : array[12 << 4] base.u16, // AlgOve41.
|
||||
probs_ao60 : array[12] base.u16, // AlgOve60.
|
||||
probs_ao63 : array[12] base.u16, // AlgOve63.
|
||||
|
||||
// AlgOve22 and what "decodeLen expands to".
|
||||
probs_match_len_low : array[1 << 4] array[1 << 3] base.u16,
|
||||
probs_match_len_mid : array[1 << 4] array[1 << 3] base.u16,
|
||||
probs_match_len_high : array[1 << 0] array[1 << 8] base.u16,
|
||||
|
||||
// AlgOve80 and what "decodeLen expands to".
|
||||
probs_longrep_len_low : array[1 << 4] array[1 << 3] base.u16,
|
||||
probs_longrep_len_mid : array[1 << 4] array[1 << 3] base.u16,
|
||||
probs_longrep_len_high : array[1 << 0] array[1 << 8] base.u16,
|
||||
|
||||
// AlgOve23. The first index is min(len-2, 3). There are then 64
|
||||
// possible slots, so a 6-bit binary tree.
|
||||
probs_slot : array[4] array[1 << 6] base.u16,
|
||||
|
||||
// This holds the "xxxx" binary trees, packed per below. The first
|
||||
// element and last 13 elements are unused. The index_small_dist_base
|
||||
// constant is set to (Low - 1) and index_small_dist_extra variable
|
||||
// starts at 1. (index_small_dist_base + index_small_dist_extra) ranges
|
||||
// in Low .. High during the "decode a binary tree" loop.
|
||||
//
|
||||
// Slot Low .. High H-L NumberOfXByms
|
||||
// 4 1 .. 2 1 1
|
||||
// 5 2 .. 3 1 1
|
||||
// 6 3 .. 6 3 2
|
||||
// 7 6 .. 9 3 2
|
||||
// 8 9 .. 16 7 3
|
||||
// 9 16 .. 23 7 3
|
||||
// 10 23 .. 38 15 4
|
||||
// 11 38 .. 53 15 4
|
||||
// 12 53 .. 84 31 5
|
||||
// 13 84 .. 115 31 5
|
||||
probs_small_dist : array[128] base.u16,
|
||||
|
||||
// This holds the "zzzz" binary tree.
|
||||
probs_large_dist : array[1 << 4] base.u16,
|
||||
|
||||
// 4 is the (lc + lp) inclusive maximum. The 0x300 holds three 8-bit
|
||||
// binary trees. The first is for (state < 7), when the previous packet
|
||||
// was a LITERAL. The other two trees are for (state >= 7), when it was
|
||||
// an LZ-copy. Which tree gets used depends on the bits in the next
|
||||
// historical byte after the LZ-copy-source, up until the point where
|
||||
// those bits don't match the currently decoded literal byte, when it
|
||||
// drops back to the first tree.
|
||||
probs_lit : array[1 << 4] array[0x300] base.u16,
|
||||
|
||||
// Here's the size (and cumulative size) of each probs_etc array. This
|
||||
// is in number of u16 elements, so multiply by 2 for byte size:
|
||||
//
|
||||
// probs_ao00 192 192
|
||||
// probs_ao20 12 204
|
||||
// probs_ao40 12 216
|
||||
// probs_ao41 192 408
|
||||
// probs_ao60 12 420
|
||||
// probs_ao63 12 432
|
||||
// probs_match_len_low 128 560
|
||||
// probs_match_len_mid 128 688
|
||||
// probs_match_len_high 256 944
|
||||
// probs_longrep_len_low 128 1072
|
||||
// probs_longrep_len_mid 128 1200
|
||||
// probs_longrep_len_high 256 1456
|
||||
// probs_slot 256 1712
|
||||
// probs_small_dist 128 1840
|
||||
// probs_large_dist 16 1856
|
||||
// probs_lit 12288 14144
|
||||
//
|
||||
// 1856 is the properties-independent portion of "the number of
|
||||
// probabilities we need to track". The properties-dependent
|
||||
// proportion, the probs_lit array, could in theory be dynamically
|
||||
// sized, depending on (lc + lp). For simplicity, it's statically sized
|
||||
// here, large enough for the worst case, subject to ((lc + lp) <= 4)
|
||||
// per the "LZMA2's limited property condition" comment above. Static
|
||||
// (worst case) allocation is also what XZ-embedded does [Ref0].
|
||||
//
|
||||
// 1856 is slightly smaller than the 1984 (also called NUM_BASE_PROBS)
|
||||
// used in the current (as of 2024; version 18.05) version of the LZMA
|
||||
// SDK [Ref1]. The difference of (2 * ((16 - 12) << 4)) is because the
|
||||
// LZMA SDK uses what it calls (kNumStates2 << kNumPosBitsMax) instead
|
||||
// of (kNumStates << kNumPosBitsMax) for its IsMatch and IsRep0Long
|
||||
// portions (what Wuffs calls probs_ao00 and probs_ao41), and
|
||||
// (kNumStates2 - kNumStates) = (16 - 12). LZMA (the file format) only
|
||||
// has 12 states, so enlarging to 16 is redundant (and consumes more
|
||||
// memory). It's not immediately obvious why the memory layout was
|
||||
// re-arranged, but the layout is shared with LZMA SDK asm code.
|
||||
//
|
||||
// 1856 is slightly larger than the 1846 mentioned in both the current
|
||||
// (2024) version of the LZMA SDK spec [Ref2] and as what an old (2004)
|
||||
// version of the LZMA SDK code calls LZMA_BASE_SIZE [Ref3]. The
|
||||
// difference of (14 - (2 * 2)) has two parts. 14 comes from the "first
|
||||
// element and last 13 elements are unused" probs_small_dist comment
|
||||
// above, so that the LZMA SDK code can pack their probs array tighter.
|
||||
// 2 (twice, for AlgOve22 'match' and AlgOve80 'longrep') comes from
|
||||
// moving what the LZMA SDK calls "Choice" and "Choice2" probabilties,
|
||||
// repurposing what this decoder calls the otherwise-unused
|
||||
// probs_etc_len_low[0][0] and probs_etc_len_mid[0][0] elements.
|
||||
//
|
||||
// [Ref0]
|
||||
// https://github.com/torvalds/linux/blob/052d534373b7ed33712a63d5e17b2b6cdbce84fd/lib/xz/xz_dec_lzma2.c#L211
|
||||
//
|
||||
// [Ref1]
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/781863cdf592da3e97420f50de5dac056ad352a5/C/LzmaDec.c#L151
|
||||
//
|
||||
// [Ref2]
|
||||
// https://raw.githubusercontent.com/jljusten/LZMA-SDK/781863cdf592da3e97420f50de5dac056ad352a5/DOC/lzma-specification.txt
|
||||
//
|
||||
// [Ref3]
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/f287b63f6bb8b88e281f18a9295340c732245167/Source/LzmaDecode.h#L48
|
||||
)
|
||||
|
||||
pri func decoder.add_history!(hist: slice base.u8, workbuf: slice base.u8) base.status {
|
||||
var dict_workbuf_index : base.u64[..= 0xFFFF_FFFF]
|
||||
var dict_size : base.u64[..= 0xFFFF_FFFF]
|
||||
var hist_length : base.u64
|
||||
var s : slice base.u8
|
||||
var n_copied : base.u64
|
||||
var n : base.u64
|
||||
|
||||
dict_workbuf_index = this.dict_workbuf_index as base.u64
|
||||
dict_size = this.dict_size as base.u64
|
||||
if args.hist.length() == 0 {
|
||||
return ok
|
||||
}
|
||||
|
||||
// 273 is ML, where ML is the Maximum Length of an LZMA Lempel-Ziv (length,
|
||||
// distance) pair. After an add_history call, args.workbuf[dict_size ..
|
||||
// (dict_size + ML)] duplicates args.workbuf[.. ML]. This simplifies
|
||||
// copying up to (ML + 1) bytes from the ringbuffer, as there is no need to
|
||||
// split the copy around the dict_size boundary.
|
||||
//
|
||||
// This technique is similar to the one used in the std/deflate package
|
||||
// (although that package uses a different value of ML, 258). That package
|
||||
// also extends the nominal dict_size by (ML - 1), not ML as is done here,
|
||||
// because std/deflate copies up to ML bytes, but std/lzma copies up to (ML
|
||||
// + 1) bytes. std/lzma also needs to know the later half of the two-byte
|
||||
// cusp: the first byte after the copied history.
|
||||
if args.workbuf.length() < (dict_size + 273) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
assert args.workbuf.length() >= dict_size via "a >= b: a >= (b + c); 0 <= c"(c: 273)
|
||||
assert dict_size <= args.workbuf.length() via "a <= b: b >= a"()
|
||||
|
||||
hist_length = args.hist.length()
|
||||
if hist_length > 0xFFFF_FFFF {
|
||||
this.dict_seen = 0xFFFF_FFFF
|
||||
} else {
|
||||
this.dict_seen ~sat+= hist_length as base.u32
|
||||
}
|
||||
|
||||
s = args.hist
|
||||
if s.length() >= dict_size {
|
||||
s = s.suffix(up_to: dict_size)
|
||||
args.workbuf.copy_from_slice!(s: s)
|
||||
this.dict_workbuf_index = 0
|
||||
|
||||
} else if dict_workbuf_index > dict_size {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
|
||||
} else {
|
||||
n_copied = args.workbuf[dict_workbuf_index .. dict_size].copy_from_slice!(s: s)
|
||||
if n_copied < s.length() {
|
||||
n = args.workbuf.copy_from_slice!(s: s[n_copied ..])
|
||||
this.dict_workbuf_index = (n & 0xFFFF_FFFF) as base.u32
|
||||
} else {
|
||||
n = dict_workbuf_index ~mod+ n_copied
|
||||
if n < dict_size {
|
||||
assert n < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: dict_size)
|
||||
this.dict_workbuf_index = n as base.u32
|
||||
} else {
|
||||
this.dict_workbuf_index = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Have the tail duplicate the head.
|
||||
if (273 > dict_size) or (dict_size > args.workbuf.length()) {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
assert 273 <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: dict_size)
|
||||
args.workbuf[dict_size ..].copy_from_slice!(s: args.workbuf[.. 273])
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if args.key == QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE {
|
||||
if this.allow_non_zero_initial_byte {
|
||||
return 1
|
||||
}
|
||||
|
||||
} else if args.key == QUIRK_FORMAT_EXTENSION {
|
||||
return this.format_extension as base.u64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
var v : base.u32
|
||||
var n : base.u32
|
||||
|
||||
if args.key == QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE {
|
||||
this.allow_non_zero_initial_byte = args.value > 0
|
||||
|
||||
} else if args.key == QUIRK_FORMAT_EXTENSION {
|
||||
if args.value == 0 {
|
||||
this.format_extension = 0
|
||||
return ok
|
||||
|
||||
} else if (args.value & 0xFF) == 1 {
|
||||
if (args.value >> 8) <= 0xFF {
|
||||
this.format_extension = (args.value & 0xFFFF_FFFF) as base.u32
|
||||
v = this.format_extension >> 8
|
||||
n = (1 as base.u32) << (v & 0x1F)
|
||||
n ~sat-= (n >> 4) * ((v >> 5) & 7)
|
||||
if (n < (1 << 12)) or ((1 << 29) < n) {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.dict_size = n
|
||||
return ok
|
||||
}
|
||||
|
||||
} else if (args.value & 0xFF) == 2 {
|
||||
if (args.value >> 8) <= 40 {
|
||||
this.format_extension = (args.value & 0xFFFF_FFFF) as base.u32
|
||||
v = this.format_extension >> 8
|
||||
if v < 40 {
|
||||
this.dict_size = (2 | (v & 1)) << ((v >> 1) + 11)
|
||||
} else {
|
||||
this.dict_size = 0xFFFF_FFFF
|
||||
}
|
||||
return ok
|
||||
}
|
||||
}
|
||||
|
||||
return base."#bad argument"
|
||||
}
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.util.make_optional_u63(has_value: true, value: 0)
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
var m : base.u64
|
||||
|
||||
if this.dict_size == 0 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
m = (this.dict_size as base.u64) + 273
|
||||
return this.util.make_range_ii_u64(min_incl: m, max_incl: m)
|
||||
}
|
||||
|
||||
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var mark : base.u64
|
||||
var dti_status : base.status
|
||||
var ah_status : base.status
|
||||
|
||||
while true {
|
||||
mark = args.dst.mark()
|
||||
dti_status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if not dti_status.is_suspension() {
|
||||
return dti_status
|
||||
} else if (dti_status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
ah_status = this.add_history!(hist: args.dst.since(mark: mark), workbuf: args.workbuf)
|
||||
if ah_status.is_error() {
|
||||
return ah_status
|
||||
}
|
||||
yield? dti_status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: roslice base.u8) {
|
||||
var header_byte : base.u8
|
||||
var c8 : base.u8
|
||||
var c32 : base.u32
|
||||
var prop_byte : base.u8
|
||||
|
||||
var lc : base.u32[..= 8]
|
||||
var lp : base.u32[..= 4]
|
||||
var pb : base.u32[..= 4]
|
||||
|
||||
var length : base.u32
|
||||
var n_copied : base.u32
|
||||
|
||||
var smark : base.u64
|
||||
var status : base.status
|
||||
|
||||
this.lzma2_need_prob_reset = true
|
||||
this.lzma2_need_properties = true
|
||||
this.lzma2_need_dict_reset = true
|
||||
|
||||
// Loop over chunks. LZMA1 has only one (implicit) chunk. For LZMA2's chunk
|
||||
// header, see
|
||||
// https://github.com/jljusten/LZMA-SDK/blob/781863cdf592da3e97420f50de5dac056ad352a5/C/Lzma2Dec.c#L17-L23
|
||||
while true {
|
||||
if (this.format_extension & 0xFF) == 0 { // LZMA1.
|
||||
prop_byte = args.src.read_u8?()
|
||||
if prop_byte >= 225 {
|
||||
return "#bad header"
|
||||
}
|
||||
lc = (prop_byte % 9) as base.u32
|
||||
prop_byte /= 9
|
||||
lp = (prop_byte % 5) as base.u32
|
||||
pb = (prop_byte / 5) as base.u32
|
||||
if (lc + lp) > 4 {
|
||||
return "#unsupported properties"
|
||||
}
|
||||
this.lc = lc.min(no_more_than: 4)
|
||||
this.lp = lp
|
||||
this.pb = pb
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
this.dict_size = c32.max(no_less_than: 4096)
|
||||
|
||||
this.decoded_length = args.src.read_u64le?()
|
||||
if (this.decoded_length >= 0x8000_0000_0000_0000) and
|
||||
(this.decoded_length <> 0xFFFF_FFFF_FFFF_FFFF) {
|
||||
return "#unsupported decoded length"
|
||||
}
|
||||
|
||||
this.initialize_probs!()
|
||||
|
||||
} else if (this.format_extension & 0xFF) == 1 { // Lzip.
|
||||
this.lc = 3
|
||||
this.lp = 0
|
||||
this.pb = 2
|
||||
this.decoded_length = 0xFFFF_FFFF_FFFF_FFFF
|
||||
this.initialize_probs!()
|
||||
|
||||
} else { // LZMA2.
|
||||
while args.src.length() <= 0,
|
||||
post args.src.length() > 0,
|
||||
{
|
||||
yield? base."$short read"
|
||||
}
|
||||
|
||||
if args.src.peek_u8() == 0x00 {
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
break
|
||||
}
|
||||
|
||||
header_byte = args.src.read_u8?()
|
||||
if header_byte < 0x80 {
|
||||
if header_byte < 0x02 {
|
||||
this.lzma2_need_prob_reset = true
|
||||
this.lzma2_need_properties = true
|
||||
this.lzma2_need_dict_reset = false
|
||||
this.initialize_dict!()
|
||||
} else if (header_byte > 0x02) or this.lzma2_need_dict_reset {
|
||||
return "#bad LZMA2 header"
|
||||
}
|
||||
this.prev_lzma2_chunk_was_uncompressed = true
|
||||
|
||||
c32 = args.src.read_u16be_as_u32?()
|
||||
length = 1 + c32
|
||||
|
||||
while true {
|
||||
n_copied = args.dst.limited_copy_u32_from_reader!(up_to: length, r: args.src)
|
||||
this.stashed_pos ~sat+= n_copied as base.u64
|
||||
if length <= n_copied {
|
||||
break
|
||||
}
|
||||
length -= n_copied
|
||||
if args.dst.length() == 0 {
|
||||
yield? base."$short write"
|
||||
} else {
|
||||
yield? base."$short read"
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
this.decoded_length = header_byte as base.u64
|
||||
|
||||
c32 = args.src.read_u16be_as_u32?()
|
||||
this.decoded_length = ((this.decoded_length & 0x1F) << 16) + ((1 + c32) as base.u64)
|
||||
|
||||
c32 = args.src.read_u16be_as_u32?()
|
||||
this.lzma2_encoded_length_want = (1 + c32) as base.u64
|
||||
|
||||
if header_byte >= 0xA0 {
|
||||
this.initialize_probs!()
|
||||
this.lzma2_need_prob_reset = false
|
||||
}
|
||||
|
||||
if header_byte >= 0xC0 {
|
||||
prop_byte = args.src.read_u8?()
|
||||
if prop_byte >= 225 {
|
||||
return "#bad LZMA2 header"
|
||||
}
|
||||
lc = (prop_byte % 9) as base.u32
|
||||
prop_byte /= 9
|
||||
lp = (prop_byte % 5) as base.u32
|
||||
pb = (prop_byte / 5) as base.u32
|
||||
if (lc + lp) > 4 {
|
||||
return "#bad LZMA2 header"
|
||||
}
|
||||
this.lc = lc.min(no_more_than: 4)
|
||||
this.lp = lp
|
||||
this.pb = pb
|
||||
this.lzma2_need_properties = false
|
||||
}
|
||||
|
||||
if header_byte >= 0xE0 {
|
||||
this.lzma2_need_dict_reset = false
|
||||
this.initialize_dict!()
|
||||
} else if this.prev_lzma2_chunk_was_uncompressed {
|
||||
// Update the stashed prev_byte and matched_byte. We've copied
|
||||
// an uncompressed chunk since the last compressed chunk.
|
||||
this.update_stashed_bytes?(dst: args.dst, workbuf: args.workbuf)
|
||||
}
|
||||
this.prev_lzma2_chunk_was_uncompressed = false
|
||||
|
||||
if this.lzma2_need_prob_reset or this.lzma2_need_properties or this.lzma2_need_dict_reset {
|
||||
return "#bad LZMA2 header"
|
||||
}
|
||||
}
|
||||
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 <> 0x00) and not this.allow_non_zero_initial_byte {
|
||||
return "#bad code"
|
||||
}
|
||||
this.stashed_bits = args.src.read_u32be?()
|
||||
if this.stashed_bits == 0xFFFF_FFFF {
|
||||
return "#bad code"
|
||||
}
|
||||
this.stashed_range = 0xFFFF_FFFF
|
||||
this.stashed_pos_end = this.stashed_pos ~sat+ this.decoded_length
|
||||
if (this.stashed_pos_end == 0xFFFF_FFFF_FFFF_FFFF) and
|
||||
(this.decoded_length <> 0xFFFF_FFFF_FFFF_FFFF) {
|
||||
return "#unsupported decoded length"
|
||||
}
|
||||
this.lzma2_encoded_length_have = 5
|
||||
|
||||
while args.workbuf.length() < ((this.dict_size as base.u64) + 273) {
|
||||
yield? base."$short workbuf"
|
||||
}
|
||||
|
||||
while true {
|
||||
smark = args.src.mark()
|
||||
status =? this.decode_bitstream?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
this.lzma2_encoded_length_have ~sat+= args.src.count_since(mark: smark)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
if this.decoded_length == 0xFFFF_FFFF_FFFF_FFFF {
|
||||
if this.stashed_bits <> 0 {
|
||||
return "#bad bitstream trailer"
|
||||
}
|
||||
} else if this.stashed_pos <> this.stashed_pos_end {
|
||||
return "#bad decoded length"
|
||||
} else if this.stashed_bits <> 0 {
|
||||
// Almost all LZMA chunks have either an explicit decoded_length or
|
||||
// an End of Stream marker. It is legitimate, though, for a chunk
|
||||
// to have both. We cater for that here.
|
||||
this.decode_optional_end_of_stream?(src: args.src, workbuf: args.workbuf)
|
||||
|
||||
if this.stashed_bits <> 0 {
|
||||
return "#bad bitstream trailer"
|
||||
}
|
||||
}
|
||||
|
||||
if (this.format_extension & 0xFF) < 2 {
|
||||
break
|
||||
} else if this.lzma2_encoded_length_have <> this.lzma2_encoded_length_want {
|
||||
return "#bad LZMA2 header"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_bitstream?(dst: base.io_writer, src: base.io_reader, workbuf: roslice base.u8) {
|
||||
var status : base.status
|
||||
|
||||
this.end_of_chunk = false
|
||||
while true {
|
||||
status = this.decode_bitstream_fast!(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if status.is_error() {
|
||||
return status
|
||||
}
|
||||
if this.end_of_chunk {
|
||||
break
|
||||
}
|
||||
this.decode_bitstream_slow?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if this.end_of_chunk {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.update_stashed_bytes?(dst: base.io_writer, workbuf: roslice base.u8) {
|
||||
var dist : base.u32
|
||||
var which : base.u32
|
||||
var adj_dist : base.u32
|
||||
var wb_index : base.u64
|
||||
|
||||
while args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
}
|
||||
|
||||
dist = 1
|
||||
which = 0
|
||||
while which < 2 {
|
||||
if (dist as base.u64) <= args.dst.history_length() {
|
||||
args.dst.limited_copy_u32_from_history!(up_to: 1, distance: dist)
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
this.stashed_bytes[which] = args.dst.peek_undo_byte()
|
||||
args.dst.undo_byte!()
|
||||
|
||||
} else {
|
||||
adj_dist = (((dist as base.u64) - args.dst.history_length()) & 0xFFFF_FFFF) as base.u32
|
||||
wb_index = (this.dict_workbuf_index as base.u64) ~mod- (adj_dist as base.u64)
|
||||
while wb_index >= 0x8000_0000_0000_0000,
|
||||
inv which < 2,
|
||||
{
|
||||
wb_index ~mod+= this.dict_size as base.u64
|
||||
}
|
||||
if wb_index >= args.workbuf.length() {
|
||||
return "#internal error: inconsistent dictionary state"
|
||||
}
|
||||
this.stashed_bytes[which] = args.workbuf[wb_index]
|
||||
}
|
||||
|
||||
dist = 1 + this.stashed_rep0
|
||||
which += 1
|
||||
}
|
||||
}
|
||||
|
||||
// Preconditions:
|
||||
// - this.stashed_pos == this.stashed_pos_end
|
||||
// - this.stashed_pos_end < 0xFFFF_FFFF_FFFF_FFFF
|
||||
pri func decoder.decode_optional_end_of_stream?(src: base.io_reader, workbuf: roslice base.u8) {
|
||||
var w : base.io_writer
|
||||
var status : base.status
|
||||
|
||||
this.stashed_pos_end = 0xFFFF_FFFF_FFFF_FFFF
|
||||
while true {
|
||||
io_bind (io: w, data: this.util.empty_slice_u8(), history_position: 0) {
|
||||
status =? this.decode_bitstream_slow?(dst: w, src: args.src, workbuf: args.workbuf)
|
||||
}
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if status == base."$short write" {
|
||||
return "#bad bitstream trailer"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
this.stashed_pos_end = this.stashed_pos
|
||||
}
|
||||
|
||||
pri func decoder.initialize_dict!() {
|
||||
this.dict_workbuf_index = 0
|
||||
this.dict_seen = 0
|
||||
this.stashed_bytes[0] = 0
|
||||
this.stashed_bytes[1] = 0
|
||||
this.stashed_pos = 0
|
||||
}
|
||||
|
||||
// initialize_probs sets all of the probs_foo[i][j] values to 1024.
|
||||
pri func decoder.initialize_probs!() {
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
|
||||
i = 0
|
||||
while i < (12 << 4) {
|
||||
this.probs_ao00[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao20[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao40[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < (12 << 4) {
|
||||
this.probs_ao41[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao60[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 12 {
|
||||
this.probs_ao63[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
j = 0
|
||||
while j < 8,
|
||||
inv i < 16,
|
||||
{
|
||||
this.probs_match_len_low[i][j] = 1024
|
||||
j += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
j = 0
|
||||
while j < 8,
|
||||
inv i < 16,
|
||||
{
|
||||
this.probs_match_len_mid[i][j] = 1024
|
||||
j += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.probs_match_len_high[0][i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
j = 0
|
||||
while j < 8,
|
||||
inv i < 16,
|
||||
{
|
||||
this.probs_longrep_len_low[i][j] = 1024
|
||||
j += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
j = 0
|
||||
while j < 8,
|
||||
inv i < 16,
|
||||
{
|
||||
this.probs_longrep_len_mid[i][j] = 1024
|
||||
j += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 256 {
|
||||
this.probs_longrep_len_high[0][i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 4 {
|
||||
j = 0
|
||||
while j < 64,
|
||||
inv i < 4,
|
||||
{
|
||||
this.probs_slot[i][j] = 1024
|
||||
j += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 128 {
|
||||
this.probs_small_dist[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
this.probs_large_dist[i] = 1024
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 16 {
|
||||
j = 0
|
||||
while j < 0x300,
|
||||
inv i < 16,
|
||||
{
|
||||
this.probs_lit[i][j] = 1024
|
||||
j += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
// Reset some other LZMA state too. They're not probabilities, but they
|
||||
// need resetting whenever the probabilities do.
|
||||
this.stashed_state = 0
|
||||
this.stashed_rep0 = 0
|
||||
this.stashed_rep1 = 0
|
||||
this.stashed_rep2 = 0
|
||||
this.stashed_rep3 = 0
|
||||
}
|
||||
|
||||
pri const STATE_TRANSITION_LITERAL : roarray[12] base.u8[..= 11] = [
|
||||
0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x4, 0x5,
|
||||
]
|
||||
|
||||
pri const STATE_TRANSITION_MATCH : roarray[12] base.u8[..= 11] = [
|
||||
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0xA, 0xA, 0xA, 0xA, 0xA,
|
||||
]
|
||||
|
||||
pri const STATE_TRANSITION_LONGREP : roarray[12] base.u8[..= 11] = [
|
||||
0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0xB, 0xB, 0xB, 0xB, 0xB,
|
||||
]
|
||||
|
||||
pri const STATE_TRANSITION_SHORTREP : roarray[12] base.u8[..= 11] = [
|
||||
0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xB, 0xB, 0xB, 0xB, 0xB,
|
||||
]
|
||||
|
||||
pri const CLAMP_NO_MORE_THAN_3 : roarray[8] base.u8[..= 3] = [
|
||||
0, 1, 2, 3, 3, 3, 3, 3,
|
||||
]
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// Quirks are discussed in (/doc/note/quirks.md).
|
||||
//
|
||||
// The base38 encoding of "lzma" is 0x141638. Left shifting by 10 gives
|
||||
// 0x5058_E000.
|
||||
pri const QUIRKS_BASE : base.u32 = 0x5058_E000
|
||||
|
||||
// --------
|
||||
|
||||
// When this quirk is set, a positive or zero value ignores or enforces the "If
|
||||
// initial byte [after properties or other headers] is not equal to ZERO, the
|
||||
// LZMA Decoder must stop decoding and report error" from the spec
|
||||
// https://raw.githubusercontent.com/jljusten/LZMA-SDK/781863cdf592da3e97420f50de5dac056ad352a5/DOC/lzma-specification.txt
|
||||
pub const QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE : base.u32 = 0x5058_E000 | 0x00
|
||||
|
||||
// When this quirk is set, a positive value indicates an extension to the LZMA
|
||||
// format. Zero means to use the default LZMA format.
|
||||
//
|
||||
// When positive, the low byte of the u64 value indicates the extension.
|
||||
// Currently, the only valid extensions are:
|
||||
// - 0x01 indicates Lzip.
|
||||
// - 0x02 indicates LZMA2.
|
||||
//
|
||||
// For Lzip, the high 7 bytes (shifted right by 8) must be less than or equal
|
||||
// to 0xFF and indicates the dictionary size. See section "6 File format" of
|
||||
// https://www.nongnu.org/lzip/manual/lzip_manual.html
|
||||
//
|
||||
// For LZMA2, the high 7 bytes (shifted right by 8) must be less than or equal
|
||||
// to 40 and indicates the dictionary size. See section "5.3.1. LZMA2" of
|
||||
// https://tukaani.org/xz/xz-file-format.txt
|
||||
pub const QUIRK_FORMAT_EXTENSION : base.u32 = 0x5058_E000 | 0x01
|
||||
@@ -13,7 +13,7 @@ pub status "#truncated input"
|
||||
|
||||
pri status "#internal error: inconsistent I/O"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
// TODO: move bulk data buffers like decoder.suffixes or decoder.output into
|
||||
// the workbuf? The first attempt at this was a performance regression for
|
||||
@@ -86,8 +86,8 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.util.make_optional_u63(has_value: true, value: 0)
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
@@ -117,7 +117,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
this.lm1s[i] = 0
|
||||
this.suffixes[i][0] = i as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
while true {
|
||||
this.read_from!(src: args.src)
|
||||
@@ -139,7 +139,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.read_from!(src: base.io_reader) {
|
||||
@@ -292,7 +292,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
||||
// in practice, but is necessary for the overflow checker.
|
||||
o = (o ~mod- 8) & 8191
|
||||
c = this.prefixes[c] as base.u32
|
||||
} endwhile
|
||||
}
|
||||
first_byte = this.suffixes[c][0]
|
||||
|
||||
if code == save_code {
|
||||
@@ -333,7 +333,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
||||
this.read_from_return_value = 1
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Rewind args.src, if we're not in "$short read" and we've read too many
|
||||
// bits.
|
||||
@@ -346,7 +346,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
||||
this.read_from_return_value = 5
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.save_code = save_code
|
||||
@@ -374,7 +374,7 @@ pri func decoder.write_to?(dst: base.io_writer) {
|
||||
}
|
||||
this.output_ri = (this.output_ri ~mod+ ((n & 0xFFFF_FFFF) as base.u32)) & 8191
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated. Use transform_io and an io_writer instead.
|
||||
|
||||
@@ -14,8 +14,7 @@ pub status "#unsupported Netpbm file"
|
||||
|
||||
pri status "@internal note: short read"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
pixfmt : base.u32,
|
||||
@@ -54,143 +53,143 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var n : base.u32
|
||||
var c8 : base.u8
|
||||
var n : base.u32
|
||||
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if c <> 'P' {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 'P' {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if (c < '1') or ('7' < c) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 < '1') or ('7' < c8) {
|
||||
return "#bad header"
|
||||
} else if c == '5' {
|
||||
} else if c8 == '5' {
|
||||
this.pixfmt = base.PIXEL_FORMAT__Y
|
||||
} else if c == '6' {
|
||||
} else if c8 == '6' {
|
||||
this.pixfmt = base.PIXEL_FORMAT__RGB
|
||||
} else {
|
||||
return "#unsupported Netpbm file"
|
||||
}
|
||||
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0x0A {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x0A {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
// Decode width.
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if (c == ' ') or (c == 0x09) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) {
|
||||
continue
|
||||
} else if c == '#' {
|
||||
} else if c8 == '#' {
|
||||
// Consume a "#...\n" comment.
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c == 0x0A {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0x0A {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
} else if (c < '0') or ('9' < c) {
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.width = ((c - '0') as base.u32)
|
||||
this.width = ((c8 - '0') as base.u32)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if (c == ' ') or (c == 0x09) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) {
|
||||
break
|
||||
} else if (c < '0') or ('9' < c) {
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
n = (10 * this.width) + ((c - '0') as base.u32)
|
||||
n = (10 * this.width) + ((c8 - '0') as base.u32)
|
||||
if n > 0xFF_FFFF {
|
||||
return "#unsupported Netpbm file"
|
||||
}
|
||||
this.width = n
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Decode height.
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if (c == ' ') or (c == 0x09) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) {
|
||||
continue
|
||||
} else if c == '#' {
|
||||
} else if c8 == '#' {
|
||||
// Consume a "#...\n" comment.
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c == 0x0A {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0x0A {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
} else if (c < '0') or ('9' < c) {
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.height = ((c - '0') as base.u32)
|
||||
this.height = ((c8 - '0') as base.u32)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if (c == ' ') or (c == 0x09) or (c == 0x0D) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) or (c8 == 0x0D) {
|
||||
continue
|
||||
} else if c == 0x0A {
|
||||
} else if c8 == 0x0A {
|
||||
break
|
||||
} else if (c < '0') or ('9' < c) {
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
n = (10 * this.height) + ((c - '0') as base.u32)
|
||||
n = (10 * this.height) + ((c8 - '0') as base.u32)
|
||||
if n > 0xFF_FFFF {
|
||||
return "#unsupported Netpbm file"
|
||||
}
|
||||
this.height = n
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Decode max_value.
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if (c == ' ') or (c == 0x09) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) {
|
||||
continue
|
||||
} else if c == '#' {
|
||||
} else if c8 == '#' {
|
||||
// Consume a "#...\n" comment.
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if c == 0x0A {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0x0A {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
continue
|
||||
} else if (c < '0') or ('9' < c) {
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
this.max_value = ((c - '0') as base.u32)
|
||||
this.max_value = ((c8 - '0') as base.u32)
|
||||
break
|
||||
} endwhile
|
||||
}
|
||||
while true {
|
||||
c = args.src.read_u8?()
|
||||
if (c == ' ') or (c == 0x09) or (c == 0x0D) {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 == ' ') or (c8 == 0x09) or (c8 == 0x0D) {
|
||||
continue
|
||||
} else if c == 0x0A {
|
||||
} else if c8 == 0x0A {
|
||||
break
|
||||
} else if (c < '0') or ('9' < c) {
|
||||
} else if (c8 < '0') or ('9' < c8) {
|
||||
return "#bad header"
|
||||
}
|
||||
n = (10 * this.max_value) + ((c - '0') as base.u32)
|
||||
n = (10 * this.max_value) + ((c8 - '0') as base.u32)
|
||||
if n > 0xFF_FFFF {
|
||||
return "#unsupported Netpbm file"
|
||||
}
|
||||
this.max_value = n
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.max_value <> 255 {
|
||||
return "#unsupported Netpbm file"
|
||||
@@ -220,7 +219,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -266,7 +265,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -301,7 +300,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
@@ -360,7 +359,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
}
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
@@ -368,7 +367,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
@@ -379,7 +378,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -429,10 +428,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -14,8 +14,7 @@ pub status "#unsupported NIE file"
|
||||
|
||||
pri status "@internal note: short read"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
pixfmt : base.u32,
|
||||
@@ -50,7 +49,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -116,7 +115,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -162,7 +161,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -197,7 +196,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
@@ -256,7 +255,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
}
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
@@ -264,7 +263,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
}
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
@@ -275,7 +274,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
return "@internal note: short read"
|
||||
}
|
||||
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -325,10 +324,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -22,12 +22,10 @@ pub status "#unsupported PNG file"
|
||||
|
||||
pri status "#internal error: inconsistent I/O"
|
||||
pri status "#internal error: inconsistent chunk type"
|
||||
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_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x0007_FFFF_F100_0007
|
||||
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.
|
||||
|
||||
@@ -32,9 +32,9 @@ pri func decoder.filter_1!(curr: slice base.u8),
|
||||
args.curr[i] = args.curr[i] ~mod+ fa
|
||||
fa = args.curr[i]
|
||||
i ~mod+= filter_distance
|
||||
} endwhile
|
||||
}
|
||||
i_start += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.filter_1_distance_3_fallback!(curr: slice base.u8) {
|
||||
@@ -91,7 +91,7 @@ pri func decoder.filter_2!(curr: slice base.u8, prev: slice base.u8) {
|
||||
assert i < args.prev.length() via "a < b: a < c; c <= b"(c: n)
|
||||
args.curr[i] = args.curr[i] ~mod+ (args.prev[i])
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
// Filter 3: Average.
|
||||
@@ -115,7 +115,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
|
||||
args.curr[i] = args.curr[i] ~mod+ (args.curr[i - filter_distance] / 2)
|
||||
i += 1
|
||||
assert i >= filter_distance via "a >= b: a >= (b + c); 0 <= c"(c: 1)
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
n = args.curr.length().min(no_more_than: args.prev.length())
|
||||
@@ -129,7 +129,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
|
||||
assert i < args.prev.length() via "a < b: a < c; c <= b"(c: n)
|
||||
args.curr[i] = args.curr[i] ~mod+ (args.prev[i] / 2)
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = filter_distance
|
||||
assert i >= filter_distance via "a >= b: a == b"()
|
||||
@@ -147,7 +147,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
|
||||
(args.prev[i] as base.u32)) / 2) as base.u8)
|
||||
i += 1
|
||||
assert i >= filter_distance via "a >= b: a >= (b + c); 0 <= c"(c: 1)
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ pri func decoder.filter_4!(curr: slice base.u8, prev: slice base.u8),
|
||||
assert i < args.prev.length() via "a < b: a < c; c <= b"(c: n)
|
||||
args.curr[i] = args.curr[i] ~mod+ args.prev[i]
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
i = filter_distance
|
||||
assert i >= filter_distance via "a >= b: a == b"()
|
||||
@@ -285,7 +285,7 @@ pri func decoder.filter_4!(curr: slice base.u8, prev: slice base.u8),
|
||||
args.curr[i] = args.curr[i] ~mod+ ((fa & 0xFF) as base.u8)
|
||||
i += 1
|
||||
assert i >= filter_distance via "a >= b: a >= (b + c); 0 <= c"(c: 1)
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.filter_4_distance_3_fallback!(curr: slice base.u8, prev: slice base.u8) {
|
||||
|
||||
+68
-64
@@ -174,7 +174,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
@@ -218,7 +218,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Verify CRC-32 checksum.
|
||||
checksum_want = args.src.read_u32be?()
|
||||
@@ -283,7 +283,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// If we have metadata, delay reading (skipping) the ancillary chunk's
|
||||
// CRC-32 checksum until the end of tell_me_more.
|
||||
@@ -297,7 +297,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
(checksum_have <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if (this.color_type == 3) and (not this.seen_plte) {
|
||||
return "#missing palette"
|
||||
@@ -455,10 +455,9 @@ pri func decoder.assign_filter_distance!() {
|
||||
|
||||
} else if this.color_type == 4 {
|
||||
if this.depth == 8 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__YA_NONPREMUL
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__YA_NONPREMUL
|
||||
this.filter_distance = 2
|
||||
choose filter_and_swizzle = [filter_and_swizzle_tricky]
|
||||
} else if this.depth == 16 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
@@ -618,11 +617,20 @@ pri func decoder.decode_other_chunk?(src: base.io_reader, framy: base.bool) {
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'tRNS'le {
|
||||
if this.seen_trns or (this.color_type > 3) or
|
||||
if this.seen_trns or
|
||||
((this.color_type == 3) and (not this.seen_plte)) {
|
||||
return "#bad chunk"
|
||||
} else if this.color_type > 3 {
|
||||
// No-op, ignoring the chunk. The PNG spec section "11.3.2.1
|
||||
// tRNS Transparency" says that "A tRNS chunk shall not appear
|
||||
// for colour types 4 and 6, since a full alpha channel is
|
||||
// already present in those cases." However, some real-world
|
||||
// PNG images (incorrectly) have these. libpng treats this as a
|
||||
// "benign error", not a fatal one. See
|
||||
// https://github.com/google/wuffs/issues/146
|
||||
} else {
|
||||
this.decode_trns?(src: args.src)
|
||||
}
|
||||
this.decode_trns?(src: args.src)
|
||||
this.seen_trns = true
|
||||
}
|
||||
}
|
||||
@@ -790,7 +798,7 @@ pri func decoder.decode_gama?(src: base.io_reader) {
|
||||
}
|
||||
|
||||
pri func decoder.decode_iccp?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
|
||||
// Skip the NUL-terminated color profile name.
|
||||
while true {
|
||||
@@ -798,19 +806,19 @@ pri func decoder.decode_iccp?(src: base.io_reader) {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Compression method.
|
||||
if this.chunk_length <= 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0 {
|
||||
return "#unsupported PNG compression method"
|
||||
}
|
||||
|
||||
@@ -844,7 +852,7 @@ pri func decoder.decode_plte?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
|
||||
this.src_palette[(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Set the remaining palette entries to opaque black.
|
||||
while i < 256 {
|
||||
@@ -853,7 +861,7 @@ pri func decoder.decode_plte?(src: base.io_reader) {
|
||||
this.src_palette[(4 * i) + 2] = 0x00
|
||||
this.src_palette[(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_srgb?(src: base.io_reader) {
|
||||
@@ -937,7 +945,7 @@ pri func decoder.decode_trns?(src: base.io_reader) {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c: n)
|
||||
this.src_palette[(4 * i) + 3] = args.src.read_u8?()
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
return "#bad chunk"
|
||||
@@ -953,7 +961,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -1021,7 +1029,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
}
|
||||
args.src.skip_u32?(n: 4) // Skip the checksum.
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
@@ -1103,7 +1111,7 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
// +12 for chunk length, chunk type and checksum.
|
||||
args.src.skip?(n: (this.chunk_length as base.u64) + 12)
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
this.call_sequence = 0x20
|
||||
@@ -1118,7 +1126,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -1182,7 +1190,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
// +12 for chunk length, chunk type and checksum.
|
||||
args.src.skip?(n: (this.chunk_length as base.u64) + 12)
|
||||
this.chunk_length = 0
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.zlib_is_dirty {
|
||||
this.zlib.reset!()
|
||||
@@ -1238,7 +1246,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
status = this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
@@ -1250,7 +1258,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
break
|
||||
}
|
||||
this.interlace_pass += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.num_decoded_frames_value ~sat+= 1
|
||||
this.call_sequence = 0x20
|
||||
@@ -1346,7 +1354,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
return "#internal error: zlib decoder did not exhaust its input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.workbuf_wi <> this.pass_workbuf_length {
|
||||
return base."#not enough data"
|
||||
@@ -1422,12 +1430,12 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var c2 : base.u16
|
||||
var c8 : base.u8
|
||||
var c16 : base.u16
|
||||
var w : base.io_writer
|
||||
var num_written : base.u64
|
||||
var w_mark : base.u64
|
||||
@@ -1459,7 +1467,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
}
|
||||
this.metadata_y = this.metadata_z
|
||||
yield? base."$even more information"
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
if this.metadata_is_zlib_compressed {
|
||||
@@ -1548,25 +1556,25 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
// Drain this.dst_palette, converting from Latin-1 to UTF-8.
|
||||
while this.ztxt_ri < this.ztxt_wi {
|
||||
assert this.ztxt_ri < 1024 via "a < b: a < c; c <= b"(c: this.ztxt_wi)
|
||||
c2 = LATIN_1[this.dst_palette[this.ztxt_ri]]
|
||||
if c2 == 0 {
|
||||
c16 = LATIN_1[this.dst_palette[this.ztxt_ri]]
|
||||
if c16 == 0 {
|
||||
return "#bad text chunk (not Latin-1)"
|
||||
} else if c2 <= 0x7F {
|
||||
} else if c16 <= 0x7F {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue.loop
|
||||
}
|
||||
this.ztxt_ri += 1
|
||||
args.dst.write_u8_fast!(a: c2 as base.u8)
|
||||
args.dst.write_u8_fast!(a: c16 as base.u8)
|
||||
} else {
|
||||
if args.dst.length() <= 1 {
|
||||
yield? base."$short write"
|
||||
continue.loop
|
||||
}
|
||||
this.ztxt_ri += 1
|
||||
args.dst.write_u16le_fast!(a: c2)
|
||||
args.dst.write_u16le_fast!(a: c16)
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if zlib_status.is_ok() {
|
||||
this.metadata_is_zlib_compressed = false
|
||||
@@ -1596,10 +1604,10 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
continue.loop
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
c = args.src.peek_u8()
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_u8_fast!(a: c)
|
||||
} endwhile
|
||||
args.dst.write_u8_fast!(a: c8)
|
||||
}
|
||||
|
||||
} else {
|
||||
// Other uncompressed keys and values are Latin-1.
|
||||
@@ -1614,23 +1622,23 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
yield? base."$short read"
|
||||
continue.loop
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
if c == 0 {
|
||||
c8 = args.src.peek_u8()
|
||||
if c8 == 0 {
|
||||
this.chunk_length -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
break.loop
|
||||
}
|
||||
c2 = LATIN_1[c]
|
||||
if c2 == 0 {
|
||||
c16 = LATIN_1[c8]
|
||||
if c16 == 0 {
|
||||
return "#bad text chunk (not Latin-1)"
|
||||
} else if c2 <= 0x7F {
|
||||
} else if c16 <= 0x7F {
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue.loop
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_u8_fast!(a: c2 as base.u8)
|
||||
args.dst.write_u8_fast!(a: c16 as base.u8)
|
||||
} else {
|
||||
if args.dst.length() <= 1 {
|
||||
yield? base."$short write"
|
||||
@@ -1638,11 +1646,11 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_u16le_fast!(a: c2)
|
||||
args.dst.write_u16le_fast!(a: c16)
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
} endwhile.loop
|
||||
}.loop
|
||||
|
||||
// Key-value pairs come in... pairs.
|
||||
if this.metadata_fourcc == 'KVPK'be {
|
||||
@@ -1653,16 +1661,16 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.chunk_length -= 2
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0 {
|
||||
this.metadata_is_zlib_compressed = false
|
||||
} else if c == 1 {
|
||||
} else if c8 == 1 {
|
||||
this.metadata_is_zlib_compressed = true
|
||||
} else {
|
||||
return "#bad chunk"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if (c <> 0) and this.metadata_is_zlib_compressed {
|
||||
c8 = args.src.read_u8?()
|
||||
if (c8 <> 0) and this.metadata_is_zlib_compressed {
|
||||
return "#unsupported PNG compression method"
|
||||
}
|
||||
|
||||
@@ -1676,12 +1684,12 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'zTXt'le {
|
||||
// Compression method.
|
||||
@@ -1689,8 +1697,8 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0 {
|
||||
return "#unsupported PNG compression method"
|
||||
}
|
||||
this.metadata_is_zlib_compressed = true
|
||||
@@ -1700,7 +1708,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
return ok
|
||||
}
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
}}.goto_done
|
||||
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
@@ -1719,10 +1727,6 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: this.overall_workbuf_length,
|
||||
|
||||
@@ -97,7 +97,7 @@ pri func decoder.filter_and_swizzle!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
|
||||
prev_row = curr_row
|
||||
y += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -101,20 +101,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.frame_rect_x1)
|
||||
i = (x as base.u64) * dst_bytes_per_pixel
|
||||
if i <= dst.length() {
|
||||
if this.color_type == 4 {
|
||||
if 2 <= s.length() {
|
||||
bits_unpacked[0] = s[0]
|
||||
bits_unpacked[1] = s[0]
|
||||
bits_unpacked[2] = s[0]
|
||||
bits_unpacked[3] = s[1]
|
||||
s = s[2 ..]
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: bits_unpacked[.. 4])
|
||||
}
|
||||
|
||||
} else if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) <> 0 {
|
||||
if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) <> 0 {
|
||||
if this.color_type == 0 {
|
||||
if 1 <= s.length() {
|
||||
bits_unpacked[0] = s[0]
|
||||
@@ -170,7 +157,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
}
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else if this.depth < 8 {
|
||||
multiplier = 1
|
||||
@@ -223,7 +210,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
}
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
} else {
|
||||
while x < this.frame_rect_x1,
|
||||
@@ -327,12 +314,12 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
src: bits_unpacked[.. 8])
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
prev_row = curr_row
|
||||
y += (1 as base.u32) << INTERLACING[this.interlace_pass][3]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
@@ -0,0 +1,414 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pub status "#bad footer"
|
||||
pub status "#bad header"
|
||||
pub status "#truncated input"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
pixfmt : base.u32,
|
||||
width : base.u32[..= 0xFF_FFFF],
|
||||
height : base.u32[..= 0xFF_FFFF],
|
||||
|
||||
remaining_pixels_times_4 : base.u64,
|
||||
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
buffer_index : base.u32[..= 8192],
|
||||
|
||||
dst_x : base.u32,
|
||||
dst_y : base.u32,
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
util : base.utility,
|
||||
) + (
|
||||
pixel : array[4] base.u8,
|
||||
cache : array[256] base.u8,
|
||||
buffer : array[8192 + 4] base.u8,
|
||||
)
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_decode_image_config?(dst: args.dst, src: args.src)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var a : base.u32
|
||||
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
a = args.src.read_u32le?()
|
||||
if a <> 'qoif'le {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
a = args.src.read_u32be?()
|
||||
if a > 0xFF_FFFF {
|
||||
return base."#unsupported image dimension"
|
||||
}
|
||||
this.width = a
|
||||
|
||||
a = args.src.read_u32be?()
|
||||
if a > 0xFF_FFFF {
|
||||
return base."#unsupported image dimension"
|
||||
}
|
||||
this.height = a
|
||||
|
||||
a = args.src.read_u8_as_u32?()
|
||||
if a == 3 {
|
||||
this.pixfmt = base.PIXEL_FORMAT__BGRX
|
||||
} else if a == 4 {
|
||||
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
} else {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
args.src.skip?(n: 1)
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(
|
||||
pixfmt: this.pixfmt,
|
||||
pixsub: 0,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
first_frame_io_position: 14,
|
||||
first_frame_is_opaque: this.pixfmt == base.PIXEL_FORMAT__BGRX)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.do_decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if 16 <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(bounds: this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height),
|
||||
duration: 0,
|
||||
index: 0,
|
||||
io_position: 14,
|
||||
disposal: 0,
|
||||
opaque_within_bounds: this.pixfmt == base.PIXEL_FORMAT__BGRX,
|
||||
overwrite_instead_of_blend: false,
|
||||
background_color: 0x0000_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var status : base.status
|
||||
var c64 : base.u64
|
||||
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.do_decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
status = this.swizzler.prepare!(
|
||||
dst_pixfmt: args.dst.pixel_format(),
|
||||
dst_palette: args.dst.palette(),
|
||||
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
|
||||
src_palette: this.util.empty_slice_u8(),
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
this.dst_x = 0
|
||||
this.dst_y = 0
|
||||
this.pixel[0] = 0x00
|
||||
this.pixel[1] = 0x00
|
||||
this.pixel[2] = 0x00
|
||||
this.pixel[3] = 0xFF
|
||||
this.cache[.. 256].bulk_memset!(byte_value: 0)
|
||||
|
||||
this.remaining_pixels_times_4 = (this.width as base.u64) * (this.height as base.u64) * 4
|
||||
while this.remaining_pixels_times_4 > 0 {
|
||||
this.from_src_to_buffer?(src: args.src)
|
||||
if this.remaining_pixels_times_4 < (this.buffer_index as base.u64) {
|
||||
return base."#too much data"
|
||||
}
|
||||
this.remaining_pixels_times_4 -= this.buffer_index as base.u64
|
||||
status = this.from_buffer_to_dst!(dst: args.dst)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
c64 = args.src.read_u64be?()
|
||||
if c64 <> 1 {
|
||||
return "#bad footer"
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.from_src_to_buffer?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var dg : base.u8
|
||||
var bi : base.u32[..= 8192]
|
||||
var bj : base.u32[..= 8188]
|
||||
var bk : base.u32[..= 7936]
|
||||
var ci : base.u32[..= 252]
|
||||
var hash4 : base.u32[..= 252]
|
||||
|
||||
bk = 7936 // 4 * (2048 - 64), so we always have room for a QOI_OP_RUN.
|
||||
if this.remaining_pixels_times_4 < 7936 {
|
||||
bk = this.remaining_pixels_times_4 as base.u32
|
||||
}
|
||||
|
||||
while bi < bk {
|
||||
assert bi < 7936 via "a < b: a < c; c <= b"(c: bk)
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0xFE { // QOI_OP_RGB.
|
||||
this.pixel[2] = args.src.read_u8?()
|
||||
this.pixel[1] = args.src.read_u8?()
|
||||
this.pixel[0] = args.src.read_u8?()
|
||||
|
||||
} else if c8 == 0xFF { // QOI_OP_RGBA.
|
||||
this.pixel[2] = args.src.read_u8?()
|
||||
this.pixel[1] = args.src.read_u8?()
|
||||
this.pixel[0] = args.src.read_u8?()
|
||||
this.pixel[3] = args.src.read_u8?()
|
||||
|
||||
} else if (c8 >> 6) == 0 { // QOI_OP_INDEX.
|
||||
ci = 4 * ((c8 & 0x3F) as base.u32)
|
||||
this.pixel[0] = this.cache[ci + 0]
|
||||
this.pixel[1] = this.cache[ci + 1]
|
||||
this.pixel[2] = this.cache[ci + 2]
|
||||
this.pixel[3] = this.cache[ci + 3]
|
||||
this.buffer[bi + 0] = this.pixel[0]
|
||||
this.buffer[bi + 1] = this.pixel[1]
|
||||
this.buffer[bi + 2] = this.pixel[2]
|
||||
this.buffer[bi + 3] = this.pixel[3]
|
||||
bi += 4
|
||||
continue
|
||||
|
||||
} else if (c8 >> 6) == 1 { // QOI_OP_DIFF.
|
||||
this.pixel[2] ~mod+= ((c8 >> 4) & 0x03) ~mod+ 0xFE
|
||||
this.pixel[1] ~mod+= ((c8 >> 2) & 0x03) ~mod+ 0xFE
|
||||
this.pixel[0] ~mod+= ((c8 >> 0) & 0x03) ~mod+ 0xFE
|
||||
|
||||
} else if (c8 >> 6) == 2 { // QOI_OP_LUMA.
|
||||
dg = (c8 & 0x3F) ~mod+ 0xE0
|
||||
c8 = args.src.read_u8?()
|
||||
this.pixel[2] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 4))
|
||||
this.pixel[1] ~mod+= dg
|
||||
this.pixel[0] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 0))
|
||||
|
||||
} else { // QOI_OP_RUN.
|
||||
bj = bi + (4 * (0x3F & (1 + (c8 as base.u32))))
|
||||
while bi < bj {
|
||||
assert bi < 8188 via "a < b: a < c; c <= b"(c: bj)
|
||||
this.buffer[bi + 0] = this.pixel[0]
|
||||
this.buffer[bi + 1] = this.pixel[1]
|
||||
this.buffer[bi + 2] = this.pixel[2]
|
||||
this.buffer[bi + 3] = this.pixel[3]
|
||||
bi += 4
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
hash4 = 4 * (63 & (
|
||||
((this.pixel[2] as base.u32) * 3) +
|
||||
((this.pixel[1] as base.u32) * 5) +
|
||||
((this.pixel[0] as base.u32) * 7) +
|
||||
((this.pixel[3] as base.u32) * 11)))
|
||||
this.cache[hash4 + 0] = this.pixel[0]
|
||||
this.cache[hash4 + 1] = this.pixel[1]
|
||||
this.cache[hash4 + 2] = this.pixel[2]
|
||||
this.cache[hash4 + 3] = this.pixel[3]
|
||||
|
||||
this.buffer[bi + 0] = this.pixel[0]
|
||||
this.buffer[bi + 1] = this.pixel[1]
|
||||
this.buffer[bi + 2] = this.pixel[2]
|
||||
this.buffer[bi + 3] = this.pixel[3]
|
||||
bi += 4
|
||||
}
|
||||
|
||||
this.buffer_index = bi
|
||||
}
|
||||
|
||||
pri func decoder.from_buffer_to_dst!(dst: ptr base.pixel_buffer) base.status {
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||
var dst_bytes_per_row : base.u64
|
||||
var tab : table base.u8
|
||||
var bi : base.u32
|
||||
var rem_x : base.u32[..= 0xFF_FFFF]
|
||||
var dst : slice base.u8
|
||||
var src : slice base.u8
|
||||
var src_length : base.u32
|
||||
var i : base.u64
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
dst_pixfmt = args.dst.pixel_format()
|
||||
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
|
||||
if (dst_bits_per_pixel & 7) <> 0 {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||
tab = args.dst.plane(p: 0)
|
||||
|
||||
while bi < this.buffer_index {
|
||||
assert bi < 8192 via "a < b: a < c; c <= b"(c: this.buffer_index)
|
||||
|
||||
if this.width <= this.dst_x {
|
||||
this.dst_x = 0
|
||||
this.dst_y ~mod+= 1
|
||||
if this.dst_y >= this.height {
|
||||
break
|
||||
}
|
||||
rem_x = this.width
|
||||
} else {
|
||||
rem_x = this.width - this.dst_x
|
||||
}
|
||||
|
||||
src = this.buffer[bi .. this.buffer_index]
|
||||
if ((4 * rem_x) as base.u64) < src.length() {
|
||||
src = src[.. (4 * rem_x) as base.u64]
|
||||
}
|
||||
src_length = (src.length() & 0xFFFF_FFFF) as base.u32
|
||||
bi ~mod+= src_length
|
||||
|
||||
dst = tab.row_u32(y: this.dst_y)
|
||||
if dst_bytes_per_row < dst.length() {
|
||||
dst = dst[.. dst_bytes_per_row]
|
||||
}
|
||||
|
||||
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
|
||||
this.dst_x ~mod+= src_length / 4
|
||||
if i < dst.length() {
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: args.dst.palette(),
|
||||
src: src)
|
||||
}
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
return this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height)
|
||||
}
|
||||
|
||||
pub func decoder.num_animation_loops() base.u32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 0x20 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 0x40 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if (args.index <> 0) or (args.io_position <> 14) {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 0x28
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
// No-op. QOI doesn't support metadata.
|
||||
}
|
||||
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -0,0 +1,452 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// INITIAL_SHA256_H comes from section "5.3.3 SHA-256" of
|
||||
// https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
|
||||
pri const INITIAL_SHA256_H : roarray[8] base.u32 = [
|
||||
0x6A09_E667, 0xBB67_AE85, 0x3C6E_F372, 0xA54F_F53A,
|
||||
0x510E_527F, 0x9B05_688C, 0x1F83_D9AB, 0x5BE0_CD19,
|
||||
]
|
||||
|
||||
// K comes from section "4.2.2 SHA-224 and SHA-256 Constants" of
|
||||
// https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
|
||||
pri const K : roarray[64] base.u32 = [
|
||||
0x428A_2F98, 0x7137_4491, 0xB5C0_FBCF, 0xE9B5_DBA5,
|
||||
0x3956_C25B, 0x59F1_11F1, 0x923F_82A4, 0xAB1C_5ED5,
|
||||
0xD807_AA98, 0x1283_5B01, 0x2431_85BE, 0x550C_7DC3,
|
||||
0x72BE_5D74, 0x80DE_B1FE, 0x9BDC_06A7, 0xC19B_F174,
|
||||
0xE49B_69C1, 0xEFBE_4786, 0x0FC1_9DC6, 0x240C_A1CC,
|
||||
0x2DE9_2C6F, 0x4A74_84AA, 0x5CB0_A9DC, 0x76F9_88DA,
|
||||
0x983E_5152, 0xA831_C66D, 0xB003_27C8, 0xBF59_7FC7,
|
||||
0xC6E0_0BF3, 0xD5A7_9147, 0x06CA_6351, 0x1429_2967,
|
||||
0x27B7_0A85, 0x2E1B_2138, 0x4D2C_6DFC, 0x5338_0D13,
|
||||
0x650A_7354, 0x766A_0ABB, 0x81C2_C92E, 0x9272_2C85,
|
||||
0xA2BF_E8A1, 0xA81A_664B, 0xC24B_8B70, 0xC76C_51A3,
|
||||
0xD192_E819, 0xD699_0624, 0xF40E_3585, 0x106A_A070,
|
||||
0x19A4_C116, 0x1E37_6C08, 0x2748_774C, 0x34B0_BCB5,
|
||||
0x391C_0CB3, 0x4ED8_AA4A, 0x5B9C_CA4F, 0x682E_6FF3,
|
||||
0x748F_82EE, 0x78A5_636F, 0x84C8_7814, 0x8CC7_0208,
|
||||
0x90BE_FFFA, 0xA450_6CEB, 0xBEF9_A3F7, 0xC671_78F2,
|
||||
]
|
||||
|
||||
pub struct hasher? implements base.hasher_bitvec256(
|
||||
length_modulo_u64 : base.u64,
|
||||
length_overflows_u64 : base.bool,
|
||||
|
||||
padding0 : base.u8,
|
||||
padding1 : base.u8,
|
||||
padding2 : base.u8,
|
||||
|
||||
buf_len : base.u32[..= 64],
|
||||
buf_data : array[64] base.u8,
|
||||
|
||||
h0 : base.u32,
|
||||
h1 : base.u32,
|
||||
h2 : base.u32,
|
||||
h3 : base.u32,
|
||||
h4 : base.u32,
|
||||
h5 : base.u32,
|
||||
h6 : base.u32,
|
||||
h7 : base.u32,
|
||||
|
||||
util : base.utility,
|
||||
)
|
||||
|
||||
pub func hasher.get_quirk(key: base.u32) base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func hasher.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func hasher.update!(x: roslice base.u8) {
|
||||
var new_lmu : base.u64
|
||||
|
||||
if (this.length_modulo_u64 == 0) and not this.length_overflows_u64 {
|
||||
this.h0 = INITIAL_SHA256_H[0]
|
||||
this.h1 = INITIAL_SHA256_H[1]
|
||||
this.h2 = INITIAL_SHA256_H[2]
|
||||
this.h3 = INITIAL_SHA256_H[3]
|
||||
this.h4 = INITIAL_SHA256_H[4]
|
||||
this.h5 = INITIAL_SHA256_H[5]
|
||||
this.h6 = INITIAL_SHA256_H[6]
|
||||
this.h7 = INITIAL_SHA256_H[7]
|
||||
}
|
||||
|
||||
new_lmu = this.length_modulo_u64 ~mod+ args.x.length()
|
||||
this.length_overflows_u64 = (new_lmu < this.length_modulo_u64) or this.length_overflows_u64
|
||||
this.length_modulo_u64 = new_lmu
|
||||
|
||||
// Align to a block boundary before calling this.up.
|
||||
if this.buf_len <> 0 {
|
||||
while this.buf_len < 64 {
|
||||
if args.x.length() <= 0 {
|
||||
return nothing
|
||||
}
|
||||
this.buf_data[this.buf_len] = args.x[0]
|
||||
this.buf_len += 1
|
||||
args.x = args.x[1 ..]
|
||||
}
|
||||
this.buf_len = 0
|
||||
this.up!(x: this.buf_data[..])
|
||||
}
|
||||
|
||||
this.up!(x: args.x)
|
||||
}
|
||||
|
||||
pub func hasher.update_bitvec256!(x: roslice base.u8) base.bitvec256 {
|
||||
this.update!(x: args.x)
|
||||
return this.checksum_bitvec256()
|
||||
}
|
||||
|
||||
pri func hasher.up!(x: roslice base.u8) {
|
||||
var p : roslice base.u8
|
||||
|
||||
var w : array[64] base.u32
|
||||
|
||||
var w2 : base.u32
|
||||
var w15 : base.u32
|
||||
var s0 : base.u32
|
||||
var s1 : base.u32
|
||||
var t1 : base.u32
|
||||
var t2 : base.u32
|
||||
|
||||
var a : base.u32
|
||||
var b : base.u32
|
||||
var c : base.u32
|
||||
var d : base.u32
|
||||
var e : base.u32
|
||||
var f : base.u32
|
||||
var g : base.u32
|
||||
var h : base.u32
|
||||
|
||||
var i : base.u32
|
||||
|
||||
var buf_len : base.u32[..= 63]
|
||||
|
||||
a = this.h0
|
||||
b = this.h1
|
||||
c = this.h2
|
||||
d = this.h3
|
||||
e = this.h4
|
||||
f = this.h5
|
||||
g = this.h6
|
||||
h = this.h7
|
||||
|
||||
iterate (p = args.x)(length: 64, advance: 64, unroll: 1) {
|
||||
w[0x00] = ((p[0x00] as base.u32) << 24) | ((p[0x01] as base.u32) << 16) |
|
||||
((p[0x02] as base.u32) << 8) | ((p[0x03] as base.u32))
|
||||
w[0x01] = ((p[0x04] as base.u32) << 24) | ((p[0x05] as base.u32) << 16) |
|
||||
((p[0x06] as base.u32) << 8) | ((p[0x07] as base.u32))
|
||||
w[0x02] = ((p[0x08] as base.u32) << 24) | ((p[0x09] as base.u32) << 16) |
|
||||
((p[0x0A] as base.u32) << 8) | ((p[0x0B] as base.u32))
|
||||
w[0x03] = ((p[0x0C] as base.u32) << 24) | ((p[0x0D] as base.u32) << 16) |
|
||||
((p[0x0E] as base.u32) << 8) | ((p[0x0F] as base.u32))
|
||||
w[0x04] = ((p[0x10] as base.u32) << 24) | ((p[0x11] as base.u32) << 16) |
|
||||
((p[0x12] as base.u32) << 8) | ((p[0x13] as base.u32))
|
||||
w[0x05] = ((p[0x14] as base.u32) << 24) | ((p[0x15] as base.u32) << 16) |
|
||||
((p[0x16] as base.u32) << 8) | ((p[0x17] as base.u32))
|
||||
w[0x06] = ((p[0x18] as base.u32) << 24) | ((p[0x19] as base.u32) << 16) |
|
||||
((p[0x1A] as base.u32) << 8) | ((p[0x1B] as base.u32))
|
||||
w[0x07] = ((p[0x1C] as base.u32) << 24) | ((p[0x1D] as base.u32) << 16) |
|
||||
((p[0x1E] as base.u32) << 8) | ((p[0x1F] as base.u32))
|
||||
w[0x08] = ((p[0x20] as base.u32) << 24) | ((p[0x21] as base.u32) << 16) |
|
||||
((p[0x22] as base.u32) << 8) | ((p[0x23] as base.u32))
|
||||
w[0x09] = ((p[0x24] as base.u32) << 24) | ((p[0x25] as base.u32) << 16) |
|
||||
((p[0x26] as base.u32) << 8) | ((p[0x27] as base.u32))
|
||||
w[0x0A] = ((p[0x28] as base.u32) << 24) | ((p[0x29] as base.u32) << 16) |
|
||||
((p[0x2A] as base.u32) << 8) | ((p[0x2B] as base.u32))
|
||||
w[0x0B] = ((p[0x2C] as base.u32) << 24) | ((p[0x2D] as base.u32) << 16) |
|
||||
((p[0x2E] as base.u32) << 8) | ((p[0x2F] as base.u32))
|
||||
w[0x0C] = ((p[0x30] as base.u32) << 24) | ((p[0x31] as base.u32) << 16) |
|
||||
((p[0x32] as base.u32) << 8) | ((p[0x33] as base.u32))
|
||||
w[0x0D] = ((p[0x34] as base.u32) << 24) | ((p[0x35] as base.u32) << 16) |
|
||||
((p[0x36] as base.u32) << 8) | ((p[0x37] as base.u32))
|
||||
w[0x0E] = ((p[0x38] as base.u32) << 24) | ((p[0x39] as base.u32) << 16) |
|
||||
((p[0x3A] as base.u32) << 8) | ((p[0x3B] as base.u32))
|
||||
w[0x0F] = ((p[0x3C] as base.u32) << 24) | ((p[0x3D] as base.u32) << 16) |
|
||||
((p[0x3E] as base.u32) << 8) | ((p[0x3F] as base.u32))
|
||||
|
||||
i = 16
|
||||
while i < 64,
|
||||
inv i >= 16,
|
||||
{
|
||||
w2 = w[i - 2]
|
||||
s1 = (w2 >> 10) ^
|
||||
((w2 ~mod<< 15) | (w2 >> 17)) ^
|
||||
((w2 ~mod<< 13) | (w2 >> 19))
|
||||
w15 = w[i - 15]
|
||||
s0 = (w15 >> 3) ^
|
||||
((w15 ~mod<< 25) | (w15 >> 7)) ^
|
||||
((w15 ~mod<< 14) | (w15 >> 18))
|
||||
w[i] = ((s1 ~mod+ w[i - 7]) ~mod+ s0) ~mod+ w[i - 16]
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 64 {
|
||||
t1 = h
|
||||
t1 ~mod+= ((e ~mod<< 26) | (e >> 6)) ^
|
||||
((e ~mod<< 21) | (e >> 11)) ^
|
||||
((e ~mod<< 7) | (e >> 25))
|
||||
t1 ~mod+= (e & f) ^ ((0xFFFF_FFFF ^ e) & g)
|
||||
t1 ~mod+= K[i]
|
||||
t1 ~mod+= w[i]
|
||||
|
||||
t2 = ((a ~mod<< 30) | (a >> 2)) ^
|
||||
((a ~mod<< 19) | (a >> 13)) ^
|
||||
((a ~mod<< 10) | (a >> 22))
|
||||
t2 ~mod+= (a & b) ^ (a & c) ^ (b & c)
|
||||
|
||||
h = g
|
||||
g = f
|
||||
f = e
|
||||
e = d ~mod+ t1
|
||||
d = c
|
||||
c = b
|
||||
b = a
|
||||
a = t1 ~mod+ t2
|
||||
|
||||
i += 1
|
||||
}
|
||||
|
||||
a ~mod+= this.h0
|
||||
this.h0 = a
|
||||
b ~mod+= this.h1
|
||||
this.h1 = b
|
||||
c ~mod+= this.h2
|
||||
this.h2 = c
|
||||
d ~mod+= this.h3
|
||||
this.h3 = d
|
||||
e ~mod+= this.h4
|
||||
this.h4 = e
|
||||
f ~mod+= this.h5
|
||||
this.h5 = f
|
||||
g ~mod+= this.h6
|
||||
this.h6 = g
|
||||
h ~mod+= this.h7
|
||||
this.h7 = h
|
||||
|
||||
} else (length: 1, advance: 1, unroll: 1) {
|
||||
this.buf_data[buf_len] = p[0]
|
||||
buf_len = (buf_len + 1) & 63
|
||||
}
|
||||
this.buf_len = (args.x.length() & 63) as base.u32
|
||||
}
|
||||
|
||||
pub func hasher.checksum_bitvec256() base.bitvec256 {
|
||||
var buf_len : base.u32[..= 64]
|
||||
var buf_data : array[64] base.u8
|
||||
|
||||
var length_in_bits : base.u64
|
||||
|
||||
var w : array[64] base.u32
|
||||
|
||||
var w2 : base.u32
|
||||
var w15 : base.u32
|
||||
var s0 : base.u32
|
||||
var s1 : base.u32
|
||||
var t1 : base.u32
|
||||
var t2 : base.u32
|
||||
|
||||
var h0 : base.u32
|
||||
var h1 : base.u32
|
||||
var h2 : base.u32
|
||||
var h3 : base.u32
|
||||
var h4 : base.u32
|
||||
var h5 : base.u32
|
||||
var h6 : base.u32
|
||||
var h7 : base.u32
|
||||
|
||||
var a : base.u32
|
||||
var b : base.u32
|
||||
var c : base.u32
|
||||
var d : base.u32
|
||||
var e : base.u32
|
||||
var f : base.u32
|
||||
var g : base.u32
|
||||
var h : base.u32
|
||||
|
||||
var i : base.u32
|
||||
|
||||
var final_block : base.bool
|
||||
|
||||
i = 0
|
||||
while i < 64 {
|
||||
buf_data[i] = this.buf_data[i]
|
||||
i += 1
|
||||
}
|
||||
|
||||
// Pad with a 1 bit and then zero or more 0 bits, until we're at 56 bytes
|
||||
// (448 bits), modulo 64 bytes (512 bits).
|
||||
buf_len = this.buf_len & 63
|
||||
if buf_len < 56 {
|
||||
buf_data[buf_len] = 0x80
|
||||
buf_len += 1
|
||||
while buf_len < 56 {
|
||||
buf_data[buf_len] = 0x00
|
||||
buf_len += 1
|
||||
}
|
||||
final_block = true
|
||||
|
||||
} else {
|
||||
assert buf_len <= 63
|
||||
buf_data[buf_len] = 0x80
|
||||
buf_len += 1
|
||||
while buf_len < 64 {
|
||||
buf_data[buf_len] = 0x00
|
||||
buf_len += 1
|
||||
}
|
||||
}
|
||||
|
||||
h0 = this.h0
|
||||
a = h0
|
||||
h1 = this.h1
|
||||
b = h1
|
||||
h2 = this.h2
|
||||
c = h2
|
||||
h3 = this.h3
|
||||
d = h3
|
||||
h4 = this.h4
|
||||
e = h4
|
||||
h5 = this.h5
|
||||
f = h5
|
||||
h6 = this.h6
|
||||
g = h6
|
||||
h7 = this.h7
|
||||
h = h7
|
||||
|
||||
while true {
|
||||
if final_block {
|
||||
// The final block ends with the total length (in bits).
|
||||
length_in_bits = this.length_modulo_u64 ~mod* 8
|
||||
buf_data[56] = ((length_in_bits >> 56) & 0xFF) as base.u8
|
||||
buf_data[57] = ((length_in_bits >> 48) & 0xFF) as base.u8
|
||||
buf_data[58] = ((length_in_bits >> 40) & 0xFF) as base.u8
|
||||
buf_data[59] = ((length_in_bits >> 32) & 0xFF) as base.u8
|
||||
buf_data[60] = ((length_in_bits >> 24) & 0xFF) as base.u8
|
||||
buf_data[61] = ((length_in_bits >> 16) & 0xFF) as base.u8
|
||||
buf_data[62] = ((length_in_bits >> 8) & 0xFF) as base.u8
|
||||
buf_data[63] = ((length_in_bits) & 0xFF) as base.u8
|
||||
}
|
||||
|
||||
w[0x00] = ((buf_data[0x00] as base.u32) << 24) | ((buf_data[0x01] as base.u32) << 16) |
|
||||
((buf_data[0x02] as base.u32) << 8) | ((buf_data[0x03] as base.u32))
|
||||
w[0x01] = ((buf_data[0x04] as base.u32) << 24) | ((buf_data[0x05] as base.u32) << 16) |
|
||||
((buf_data[0x06] as base.u32) << 8) | ((buf_data[0x07] as base.u32))
|
||||
w[0x02] = ((buf_data[0x08] as base.u32) << 24) | ((buf_data[0x09] as base.u32) << 16) |
|
||||
((buf_data[0x0A] as base.u32) << 8) | ((buf_data[0x0B] as base.u32))
|
||||
w[0x03] = ((buf_data[0x0C] as base.u32) << 24) | ((buf_data[0x0D] as base.u32) << 16) |
|
||||
((buf_data[0x0E] as base.u32) << 8) | ((buf_data[0x0F] as base.u32))
|
||||
w[0x04] = ((buf_data[0x10] as base.u32) << 24) | ((buf_data[0x11] as base.u32) << 16) |
|
||||
((buf_data[0x12] as base.u32) << 8) | ((buf_data[0x13] as base.u32))
|
||||
w[0x05] = ((buf_data[0x14] as base.u32) << 24) | ((buf_data[0x15] as base.u32) << 16) |
|
||||
((buf_data[0x16] as base.u32) << 8) | ((buf_data[0x17] as base.u32))
|
||||
w[0x06] = ((buf_data[0x18] as base.u32) << 24) | ((buf_data[0x19] as base.u32) << 16) |
|
||||
((buf_data[0x1A] as base.u32) << 8) | ((buf_data[0x1B] as base.u32))
|
||||
w[0x07] = ((buf_data[0x1C] as base.u32) << 24) | ((buf_data[0x1D] as base.u32) << 16) |
|
||||
((buf_data[0x1E] as base.u32) << 8) | ((buf_data[0x1F] as base.u32))
|
||||
w[0x08] = ((buf_data[0x20] as base.u32) << 24) | ((buf_data[0x21] as base.u32) << 16) |
|
||||
((buf_data[0x22] as base.u32) << 8) | ((buf_data[0x23] as base.u32))
|
||||
w[0x09] = ((buf_data[0x24] as base.u32) << 24) | ((buf_data[0x25] as base.u32) << 16) |
|
||||
((buf_data[0x26] as base.u32) << 8) | ((buf_data[0x27] as base.u32))
|
||||
w[0x0A] = ((buf_data[0x28] as base.u32) << 24) | ((buf_data[0x29] as base.u32) << 16) |
|
||||
((buf_data[0x2A] as base.u32) << 8) | ((buf_data[0x2B] as base.u32))
|
||||
w[0x0B] = ((buf_data[0x2C] as base.u32) << 24) | ((buf_data[0x2D] as base.u32) << 16) |
|
||||
((buf_data[0x2E] as base.u32) << 8) | ((buf_data[0x2F] as base.u32))
|
||||
w[0x0C] = ((buf_data[0x30] as base.u32) << 24) | ((buf_data[0x31] as base.u32) << 16) |
|
||||
((buf_data[0x32] as base.u32) << 8) | ((buf_data[0x33] as base.u32))
|
||||
w[0x0D] = ((buf_data[0x34] as base.u32) << 24) | ((buf_data[0x35] as base.u32) << 16) |
|
||||
((buf_data[0x36] as base.u32) << 8) | ((buf_data[0x37] as base.u32))
|
||||
w[0x0E] = ((buf_data[0x38] as base.u32) << 24) | ((buf_data[0x39] as base.u32) << 16) |
|
||||
((buf_data[0x3A] as base.u32) << 8) | ((buf_data[0x3B] as base.u32))
|
||||
w[0x0F] = ((buf_data[0x3C] as base.u32) << 24) | ((buf_data[0x3D] as base.u32) << 16) |
|
||||
((buf_data[0x3E] as base.u32) << 8) | ((buf_data[0x3F] as base.u32))
|
||||
|
||||
i = 16
|
||||
while i < 64,
|
||||
inv i >= 16,
|
||||
{
|
||||
w2 = w[i - 2]
|
||||
s1 = (w2 >> 10) ^
|
||||
((w2 ~mod<< 15) | (w2 >> 17)) ^
|
||||
((w2 ~mod<< 13) | (w2 >> 19))
|
||||
w15 = w[i - 15]
|
||||
s0 = (w15 >> 3) ^
|
||||
((w15 ~mod<< 25) | (w15 >> 7)) ^
|
||||
((w15 ~mod<< 14) | (w15 >> 18))
|
||||
w[i] = ((s1 ~mod+ w[i - 7]) ~mod+ s0) ~mod+ w[i - 16]
|
||||
i += 1
|
||||
}
|
||||
|
||||
i = 0
|
||||
while i < 64 {
|
||||
t1 = h
|
||||
t1 ~mod+= ((e ~mod<< 26) | (e >> 6)) ^
|
||||
((e ~mod<< 21) | (e >> 11)) ^
|
||||
((e ~mod<< 7) | (e >> 25))
|
||||
t1 ~mod+= (e & f) ^ ((0xFFFF_FFFF ^ e) & g)
|
||||
t1 ~mod+= K[i]
|
||||
t1 ~mod+= w[i]
|
||||
|
||||
t2 = ((a ~mod<< 30) | (a >> 2)) ^
|
||||
((a ~mod<< 19) | (a >> 13)) ^
|
||||
((a ~mod<< 10) | (a >> 22))
|
||||
t2 ~mod+= (a & b) ^ (a & c) ^ (b & c)
|
||||
|
||||
h = g
|
||||
g = f
|
||||
f = e
|
||||
e = d ~mod+ t1
|
||||
d = c
|
||||
c = b
|
||||
b = a
|
||||
a = t1 ~mod+ t2
|
||||
|
||||
i += 1
|
||||
}
|
||||
|
||||
a ~mod+= h0
|
||||
b ~mod+= h1
|
||||
c ~mod+= h2
|
||||
d ~mod+= h3
|
||||
e ~mod+= h4
|
||||
f ~mod+= h5
|
||||
g ~mod+= h6
|
||||
h ~mod+= h7
|
||||
|
||||
if final_block {
|
||||
break
|
||||
}
|
||||
final_block = true
|
||||
|
||||
h0 = a
|
||||
h1 = b
|
||||
h2 = c
|
||||
h3 = d
|
||||
h4 = e
|
||||
h5 = f
|
||||
h6 = g
|
||||
h7 = h
|
||||
|
||||
buf_len = 0
|
||||
while buf_len < 56 {
|
||||
buf_data[buf_len] = 0x00
|
||||
buf_len += 1
|
||||
}
|
||||
}
|
||||
|
||||
return this.util.make_bitvec256(
|
||||
e00: (h as base.u64) | ((g as base.u64) << 32),
|
||||
e01: (f as base.u64) | ((e as base.u64) << 32),
|
||||
e02: (d as base.u64) | ((c as base.u64) << 32),
|
||||
e03: (b as base.u64) | ((a as base.u64) << 32))
|
||||
}
|
||||
+34
-39
@@ -13,8 +13,7 @@ pub status "#bad run length encoding"
|
||||
pub status "#truncated input"
|
||||
pub status "#unsupported TGA file"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0xFFFF],
|
||||
@@ -66,13 +65,13 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
var i : base.u32
|
||||
var c32 : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
var i : base.u32
|
||||
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
@@ -191,38 +190,38 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
while i < (this.header_color_map_length as base.u32) {
|
||||
assert i <= 0xFFFF via "a <= b: a <= c; c <= b"(c: this.header_color_map_length as base.u32)
|
||||
if this.header_color_map_entry_size == 0x18 {
|
||||
c = args.src.read_u24le_as_u32?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c >> 0x10) & 0xFF) as base.u8
|
||||
c32 = args.src.read_u24le_as_u32?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c32 >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c32 >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c32 >> 0x10) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = 0xFF
|
||||
} else if this.header_color_map_entry_size == 0x20 {
|
||||
c = args.src.read_u32le?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c >> 0x10) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = ((c >> 0x18) & 0xFF) as base.u8
|
||||
c32 = args.src.read_u32le?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c32 >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c32 >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c32 >> 0x10) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = ((c32 >> 0x18) & 0xFF) as base.u8
|
||||
} else {
|
||||
// Expand 15-bit or 16-bit color map entries.
|
||||
c = args.src.read_u16le_as_u32?()
|
||||
c5 = 0x1F & (c >> 0)
|
||||
c32 = args.src.read_u16le_as_u32?()
|
||||
c5 = 0x1F & (c32 >> 0)
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
c5 = 0x1F & (c32 >> 5)
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
c5 = 0x1F & (c32 >> 10)
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = 0xFF
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
while i < 0x100 {
|
||||
this.src_palette[(i * 4) + 0] = 0x00
|
||||
this.src_palette[(i * 4) + 1] = 0x00
|
||||
this.src_palette[(i * 4) + 2] = 0x00
|
||||
this.src_palette[(i * 4) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
@@ -249,7 +248,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -295,7 +294,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -317,7 +316,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
var run_length : base.u32[..= 0xFFFF]
|
||||
var num_dst_bytes : base.u64[..= 0x1F_FFE0]
|
||||
var num_src_bytes : base.u32[..= 0x3_FFFC]
|
||||
var c : base.u32
|
||||
var c32 : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
|
||||
if this.call_sequence == 0x40 {
|
||||
@@ -478,13 +477,13 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
c = args.src.peek_u16le_as_u32()
|
||||
c32 = args.src.peek_u16le_as_u32()
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
c5 = 0x1F & (c >> 0)
|
||||
c5 = 0x1F & (c32 >> 0)
|
||||
this.scratch[0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
c5 = 0x1F & (c32 >> 5)
|
||||
this.scratch[1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
c5 = 0x1F & (c32 >> 10)
|
||||
this.scratch[2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.scratch[3] = 0xFF
|
||||
@@ -529,13 +528,13 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
c = args.src.peek_u16le_as_u32()
|
||||
c32 = args.src.peek_u16le_as_u32()
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
c5 = 0x1F & (c >> 0)
|
||||
c5 = 0x1F & (c32 >> 0)
|
||||
this.scratch[0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
c5 = 0x1F & (c32 >> 5)
|
||||
this.scratch[1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
c5 = 0x1F & (c32 >> 10)
|
||||
this.scratch[2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.scratch[3] = 0xFF
|
||||
@@ -546,7 +545,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
}
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
dst_x = 0
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
@@ -559,9 +558,9 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
// effectively literals.
|
||||
lit_length = this.width
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
break.resume
|
||||
} endwhile.resume
|
||||
}.resume
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
@@ -612,10 +611,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// This code is a placeholder. std/webp depends on std/vp8 (a lossy image
|
||||
// codec) even though, in the very short term, std/webp only implements the
|
||||
// lossless VP8L format. In the medium term, though, std/webp will also support
|
||||
// VP8 and the resultant code changes will be smaller and simpler if std/webp
|
||||
// depends on std/vp8 right from the start.
|
||||
//
|
||||
// Also, a std/webm package does not exist yet, but might in the future. If it
|
||||
// does, it will also depend on std/vp8 (but not std/webp).
|
||||
|
||||
pub struct placeholder?(
|
||||
placeholder : base.u32,
|
||||
)
|
||||
+23
-28
@@ -11,8 +11,7 @@
|
||||
pub status "#bad header"
|
||||
pub status "#truncated input"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0xFF_FFFF],
|
||||
@@ -45,13 +44,13 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var i : base.u32
|
||||
var p : base.u32[..= 0xFF_FFFF]
|
||||
var c8 : base.u8
|
||||
var i : base.u32
|
||||
var p : base.u32[..= 0xFF_FFFF]
|
||||
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
@@ -60,12 +59,12 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
// TypeField, FixHeaderField.
|
||||
i = 0
|
||||
while i < 2 {
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0 {
|
||||
return "#bad header"
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
// Width, height.
|
||||
i = 0
|
||||
@@ -75,15 +74,15 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
while true,
|
||||
inv i < 2,
|
||||
{
|
||||
c = args.src.read_u8?()
|
||||
p |= (c & 0x7F) as base.u32
|
||||
if (c >> 7) == 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
p |= (c8 & 0x7F) as base.u32
|
||||
if (c8 >> 7) == 0 {
|
||||
break
|
||||
} else if p > 0x1_FFFF {
|
||||
return base."#unsupported image dimension"
|
||||
}
|
||||
p <<= 7
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if i == 0 {
|
||||
this.width = p
|
||||
@@ -91,7 +90,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
this.height = p
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
@@ -117,7 +116,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
@@ -163,7 +162,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
@@ -177,7 +176,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
var tab : table base.u8
|
||||
var dst : slice base.u8
|
||||
var src : array[1] base.u8
|
||||
var c : base.u8
|
||||
var c8 : base.u8
|
||||
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
@@ -232,21 +231,21 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
if dst_x_in_bytes <= dst.length() {
|
||||
dst = dst[dst_x_in_bytes ..]
|
||||
}
|
||||
} endwhile
|
||||
c = args.src.peek_u8()
|
||||
}
|
||||
c8 = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
}
|
||||
if (c & 0x80) == 0 {
|
||||
if (c8 & 0x80) == 0 {
|
||||
src[0] = 0x00
|
||||
} else {
|
||||
src[0] = 0xFF
|
||||
}
|
||||
// TODO: this should just be "c ~mod<<= 1", but that generates:
|
||||
// TODO: this should just be "c8 ~mod<<= 1", but that generates:
|
||||
//
|
||||
// error: conversion to ‘uint8_t {aka unsigned char}’ from
|
||||
// ‘int’ may alter its value [-Werror=conversion]
|
||||
// v_c <<= 1;
|
||||
c = (((c as base.u32) << 1) & 0xFF) as base.u8
|
||||
c8 = (((c8 as base.u32) << 1) & 0xFF) as base.u8
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst, dst_palette: this.util.empty_slice_u8(), src: src[..])
|
||||
@@ -256,9 +255,9 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
|
||||
dst_x += 1
|
||||
} endwhile
|
||||
}
|
||||
dst_y += 1
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
@@ -310,10 +309,6 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -0,0 +1,531 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_huffman_groups?(src: base.io_reader, n_huffman_groups: base.u32[..= 256]) {
|
||||
var hg : base.u32
|
||||
var ht : base.u32
|
||||
|
||||
hg = 0
|
||||
while hg < args.n_huffman_groups {
|
||||
assert hg < 256 via "a < b: a < c; c <= b"(c: args.n_huffman_groups)
|
||||
ht = 0
|
||||
while ht < 5,
|
||||
inv hg < 256,
|
||||
{
|
||||
this.decode_huffman_tree?(src: args.src, hg: hg, ht: ht)
|
||||
ht += 1
|
||||
}
|
||||
hg += 1
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_huffman_tree?(src: base.io_reader, hg: base.u32[..= 255], ht: base.u32[..= 4]) {
|
||||
var c8 : base.u8
|
||||
var use_simple : base.u32[..= 1]
|
||||
var status : base.status
|
||||
|
||||
if args.ht >= 4 {
|
||||
this.ht_n_symbols = 40
|
||||
} else if args.ht > 0 {
|
||||
this.ht_n_symbols = 256
|
||||
} else if this.color_cache_bits == 0 {
|
||||
this.ht_n_symbols = 280
|
||||
} else {
|
||||
this.ht_n_symbols = 280 + ((1 as base.u32) << this.color_cache_bits)
|
||||
}
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_simple = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if use_simple <> 0 {
|
||||
this.decode_huffman_tree_simple?(src: args.src, hg: args.hg, ht: args.ht)
|
||||
|
||||
} else {
|
||||
this.decode_code_length_code_lengths?(src: args.src)
|
||||
|
||||
status = this.build_code_lengths_huffman_nodes!()
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
this.build_code_lengths?(src: args.src)
|
||||
|
||||
status = this.build_huffman_nodes!(hg: args.hg, ht: args.ht)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_huffman_tree_simple?(src: base.io_reader, hg: base.u32[..= 255], ht: base.u32[..= 4]) {
|
||||
var c8 : base.u8
|
||||
var use_second_symbol : base.u32[..= 1]
|
||||
var first_symbol_n_bits : base.u32[..= 8]
|
||||
var symbol0 : base.u32[..= 0xFF]
|
||||
var symbol1 : base.u32[..= 0xFF]
|
||||
var base_offset : base.u32[..= 0x064C]
|
||||
|
||||
if this.n_bits < 2 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 2 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 2
|
||||
}
|
||||
use_second_symbol = this.bits & 1
|
||||
first_symbol_n_bits = (((this.bits & 2) >> 1) * 7) + 1
|
||||
this.bits >>= 2
|
||||
this.n_bits -= 2
|
||||
|
||||
if this.n_bits < first_symbol_n_bits {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= first_symbol_n_bits {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
assert this.n_bits < 8 via "a < b: a < c; c <= b"(c: first_symbol_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 8
|
||||
assert first_symbol_n_bits <= this.n_bits via "a <= b: a <= c; c <= b"(c: 8)
|
||||
assert this.n_bits >= first_symbol_n_bits via "a >= b: b <= a"()
|
||||
}
|
||||
symbol0 = this.bits & (((1 as base.u32) << first_symbol_n_bits) - 1)
|
||||
this.bits >>= first_symbol_n_bits
|
||||
this.n_bits -= first_symbol_n_bits
|
||||
|
||||
base_offset = HUFFMAN_TABLE_BASE_OFFSETS[args.ht] as base.u32
|
||||
|
||||
if use_second_symbol <> 0 {
|
||||
if this.n_bits < 8 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 8 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 8
|
||||
}
|
||||
symbol1 = this.bits & 0xFF
|
||||
this.bits >>= 8
|
||||
this.n_bits -= 8
|
||||
|
||||
this.huffman_nodes[args.hg][base_offset + 0] = (base_offset + 1) as base.u16
|
||||
this.huffman_nodes[args.hg][base_offset + 1] = (symbol0 | 0x8000) as base.u16
|
||||
this.huffman_nodes[args.hg][base_offset + 2] = (symbol1 | 0x8000) as base.u16
|
||||
|
||||
} else {
|
||||
this.huffman_nodes[args.hg][base_offset] = (symbol0 | 0x8000) as base.u16
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_code_length_code_lengths?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var n_codes : base.u32[..= 19]
|
||||
var i : base.u32
|
||||
|
||||
if this.n_bits < 4 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 4 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 4
|
||||
}
|
||||
n_codes = (this.bits & 15) + 4
|
||||
this.bits >>= 4
|
||||
this.n_bits -= 4
|
||||
|
||||
i = 0
|
||||
while i < n_codes {
|
||||
assert i < 19 via "a < b: a < c; c <= b"(c: n_codes)
|
||||
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
this.code_length_code_lengths[CODE_LENGTH_CODE_ORDER[i]] = (this.bits & 7) as base.u8
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
i += 1
|
||||
}
|
||||
while i < 19 {
|
||||
this.code_length_code_lengths[CODE_LENGTH_CODE_ORDER[i]] = 0
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.build_code_lengths_huffman_nodes!() base.status {
|
||||
var code_bits : base.u32
|
||||
var code_len : base.u32[..= 7] // The "code length code length".
|
||||
var symbol : base.u32[..= 19] // The "code length or 16, 17, 18".
|
||||
|
||||
var histogram : array[8] base.u32
|
||||
var n_used_symbols : base.u32
|
||||
var last_used_symbol : base.u32[..= 18]
|
||||
|
||||
var subscription_weight : base.u32[..= 0x8000]
|
||||
var subscription_total : base.u32
|
||||
var curr_code : base.u32
|
||||
var next_codes : array[9] base.u32
|
||||
|
||||
var n_branches : base.u32
|
||||
var h : base.u32[..= 36]
|
||||
var children : base.u32
|
||||
var node : base.u16
|
||||
|
||||
symbol = 0
|
||||
while symbol < 19 {
|
||||
code_len = this.code_length_code_lengths[symbol] as base.u32
|
||||
if code_len <> 0 {
|
||||
histogram[code_len] ~mod+= 1
|
||||
n_used_symbols ~mod+= 1
|
||||
last_used_symbol = symbol
|
||||
}
|
||||
symbol += 1
|
||||
}
|
||||
|
||||
if n_used_symbols < 1 {
|
||||
return "#bad Huffman code"
|
||||
} else if n_used_symbols == 1 {
|
||||
this.code_lengths_huffman_nodes[0] = (last_used_symbol | 0x8000) as base.u16
|
||||
return ok
|
||||
}
|
||||
|
||||
subscription_weight = 1 << 14
|
||||
code_len = 1
|
||||
while true {
|
||||
curr_code = (curr_code ~mod+ histogram[code_len]) ~mod<< 1
|
||||
next_codes[code_len + 1] = curr_code
|
||||
subscription_total ~mod+= subscription_weight ~mod* histogram[code_len]
|
||||
subscription_weight >>= 1
|
||||
if code_len >= 7 {
|
||||
break
|
||||
}
|
||||
code_len += 1
|
||||
}
|
||||
|
||||
if subscription_total > (1 << 15) {
|
||||
return "#bad Huffman code (over-subscribed)"
|
||||
} else if subscription_total < (1 << 15) {
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
|
||||
this.code_lengths_huffman_nodes[0] = 0
|
||||
symbol = 0
|
||||
while symbol < 19 {
|
||||
code_len = this.code_length_code_lengths[symbol] as base.u32
|
||||
if code_len > 0 {
|
||||
code_bits = next_codes[code_len]
|
||||
next_codes[code_len] ~mod+= 1
|
||||
|
||||
// Insert {symbol, code_bits, code_len} into the node tree.
|
||||
code_bits ~mod<<= 32 - code_len
|
||||
h = 0
|
||||
while code_len > 0,
|
||||
inv symbol < 19,
|
||||
{
|
||||
node = this.code_lengths_huffman_nodes[h]
|
||||
if node == 0 {
|
||||
children = 1 ~mod+ (2 ~mod* n_branches)
|
||||
children = children.min(no_more_than: 35)
|
||||
this.code_lengths_huffman_nodes[h] = children as base.u16
|
||||
this.code_lengths_huffman_nodes[children + 0] = 0
|
||||
this.code_lengths_huffman_nodes[children + 1] = 0
|
||||
h = children + (code_bits >> 31)
|
||||
n_branches ~mod+= 1
|
||||
} else {
|
||||
children = node as base.u32
|
||||
h = children.min(no_more_than: 35) + (code_bits >> 31)
|
||||
}
|
||||
code_bits ~mod<<= 1
|
||||
code_len -= 1
|
||||
}
|
||||
this.code_lengths_huffman_nodes[h] = (symbol | 0x8000) as base.u16
|
||||
}
|
||||
symbol += 1
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
pri func decoder.build_huffman_nodes!(hg: base.u32[..= 255], ht: base.u32[..= 4]) base.status {
|
||||
var base_offset : base.u32[..= 0x064C]
|
||||
|
||||
var code_bits : base.u32
|
||||
var code_len : base.u32[..= 15]
|
||||
var symbol : base.u32[..= 2328]
|
||||
|
||||
var histogram : array[16] base.u32
|
||||
var n_used_symbols : base.u32
|
||||
var last_used_symbol : base.u32[..= 2328]
|
||||
|
||||
var subscription_weight : base.u32[..= 0x8000]
|
||||
var subscription_total : base.u32
|
||||
var curr_code : base.u32
|
||||
var next_codes : array[17] base.u32
|
||||
|
||||
var n_branches : base.u32
|
||||
var h : base.u32[..= 0x187A]
|
||||
var children : base.u32
|
||||
var node : base.u16
|
||||
|
||||
base_offset = HUFFMAN_TABLE_BASE_OFFSETS[args.ht] as base.u32
|
||||
|
||||
symbol = 0
|
||||
while symbol < this.ht_n_symbols {
|
||||
assert symbol < 2328 via "a < b: a < c; c <= b"(c: this.ht_n_symbols)
|
||||
code_len = (this.code_lengths[symbol] & 15) as base.u32
|
||||
if code_len <> 0 {
|
||||
histogram[code_len] ~mod+= 1
|
||||
n_used_symbols ~mod+= 1
|
||||
last_used_symbol = symbol
|
||||
}
|
||||
symbol += 1
|
||||
}
|
||||
|
||||
if n_used_symbols < 1 {
|
||||
return "#bad Huffman code"
|
||||
} else if n_used_symbols == 1 {
|
||||
this.huffman_nodes[args.hg][base_offset] = (last_used_symbol | 0x8000) as base.u16
|
||||
return ok
|
||||
}
|
||||
|
||||
subscription_weight = 1 << 14
|
||||
code_len = 1
|
||||
while true {
|
||||
curr_code = (curr_code ~mod+ histogram[code_len]) ~mod<< 1
|
||||
next_codes[code_len + 1] = curr_code
|
||||
subscription_total ~mod+= subscription_weight ~mod* histogram[code_len]
|
||||
subscription_weight >>= 1
|
||||
if code_len >= 15 {
|
||||
break
|
||||
}
|
||||
code_len += 1
|
||||
}
|
||||
|
||||
if subscription_total > (1 << 15) {
|
||||
return "#bad Huffman code (over-subscribed)"
|
||||
} else if subscription_total < (1 << 15) {
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
|
||||
this.huffman_nodes[args.hg][base_offset] = 0
|
||||
symbol = 0
|
||||
while symbol < this.ht_n_symbols {
|
||||
assert symbol < 2328 via "a < b: a < c; c <= b"(c: this.ht_n_symbols)
|
||||
code_len = (this.code_lengths[symbol] & 15) as base.u32
|
||||
if code_len <> 0 {
|
||||
code_bits = next_codes[code_len]
|
||||
next_codes[code_len] ~mod+= 1
|
||||
|
||||
// Insert {symbol, code_bits, code_len} into the node tree.
|
||||
code_bits ~mod<<= 32 - code_len
|
||||
h = base_offset
|
||||
while code_len > 0,
|
||||
inv symbol < 2328,
|
||||
{
|
||||
node = this.huffman_nodes[args.hg][h]
|
||||
if node == 0 {
|
||||
children = base_offset ~mod+ (1 ~mod+ (2 ~mod* n_branches))
|
||||
children = children.min(no_more_than: 0x1879)
|
||||
this.huffman_nodes[args.hg][h] = children as base.u16
|
||||
this.huffman_nodes[args.hg][children + 0] = 0
|
||||
this.huffman_nodes[args.hg][children + 1] = 0
|
||||
h = children + (code_bits >> 31)
|
||||
n_branches ~mod+= 1
|
||||
} else {
|
||||
children = node as base.u32
|
||||
h = children.min(no_more_than: 0x1879) + (code_bits >> 31)
|
||||
}
|
||||
code_bits ~mod<<= 1
|
||||
code_len -= 1
|
||||
}
|
||||
this.huffman_nodes[args.hg][h] = (symbol | 0x8000) as base.u16
|
||||
}
|
||||
symbol += 1
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
pri func decoder.build_code_lengths?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var use_length : base.u32[..= 1]
|
||||
var length_n_bits : base.u32[..= 16]
|
||||
var length : base.u32[..= 65537]
|
||||
var prev_code_length : base.u16[..= 15]
|
||||
var h : base.u32[..= 36]
|
||||
var s : base.u32[..= 2328]
|
||||
var s_max : base.u32
|
||||
var node : base.u16
|
||||
var symbol : base.u32[..= 0x7FFF]
|
||||
var repeat_value : base.u16[..= 15]
|
||||
var repeat_n_bits : base.u32[..= 7]
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_length = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
this.ht_code_lengths_remaining = this.ht_n_symbols
|
||||
if use_length <> 0 {
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
length_n_bits = ((this.bits & 7) * 2) + 2
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
while this.n_bits < length_n_bits,
|
||||
post this.n_bits >= length_n_bits,
|
||||
{
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= length_n_bits {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
assert this.n_bits < 16 via "a < b: a < c; c <= b"(c: length_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
}
|
||||
length = (this.bits & (((1 as base.u32) << length_n_bits) - 1)) + 2
|
||||
this.bits >>= length_n_bits
|
||||
this.n_bits -= length_n_bits
|
||||
|
||||
if length > this.ht_n_symbols {
|
||||
return "#bad Huffman code"
|
||||
}
|
||||
this.ht_code_lengths_remaining = length
|
||||
}
|
||||
|
||||
prev_code_length = 8
|
||||
while s < this.ht_n_symbols {
|
||||
assert s < 2328 via "a < b: a < c; c <= b"(c: this.ht_n_symbols)
|
||||
|
||||
if this.ht_code_lengths_remaining <= 0 {
|
||||
while s < this.ht_n_symbols {
|
||||
assert s < 2328 via "a < b: a < c; c <= b"(c: this.ht_n_symbols)
|
||||
this.code_lengths[s] = 0
|
||||
s += 1
|
||||
}
|
||||
break
|
||||
}
|
||||
this.ht_code_lengths_remaining -= 1
|
||||
|
||||
h = 0
|
||||
while true,
|
||||
inv s < 2328,
|
||||
{
|
||||
node = this.code_lengths_huffman_nodes[h]
|
||||
if node >= 0x8000 {
|
||||
break
|
||||
} else if node > 35 {
|
||||
return "#internal error: inconsistent Huffman code"
|
||||
}
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
h = (node as base.u32) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
}
|
||||
|
||||
symbol = (node & 0x7FFF) as base.u32
|
||||
if symbol == 0 {
|
||||
this.code_lengths[s] = 0
|
||||
s += 1
|
||||
continue
|
||||
} else if symbol < 16 {
|
||||
prev_code_length = symbol as base.u16
|
||||
this.code_lengths[s] = prev_code_length
|
||||
s += 1
|
||||
continue
|
||||
} else if symbol == 16 {
|
||||
repeat_value = prev_code_length
|
||||
} else {
|
||||
repeat_value = 0
|
||||
}
|
||||
|
||||
repeat_n_bits = REPEAT_N_BITS[symbol & 3] as base.u32
|
||||
s_max = (REPEAT_COUNTS[symbol & 3] as base.u32) ~mod+ s
|
||||
|
||||
if this.n_bits < repeat_n_bits {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= repeat_n_bits {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
assert this.n_bits < 7 via "a < b: a < c; c <= b"(c: repeat_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 8
|
||||
assert repeat_n_bits <= this.n_bits via "a <= b: a <= c; c <= b"(c: 8)
|
||||
assert this.n_bits >= repeat_n_bits via "a >= b: b <= a"()
|
||||
}
|
||||
s_max ~mod+= this.bits & (((1 as base.u32) << repeat_n_bits) - 1)
|
||||
this.bits >>= repeat_n_bits
|
||||
this.n_bits -= repeat_n_bits
|
||||
|
||||
if s_max > this.ht_n_symbols {
|
||||
return "#bad Huffman code"
|
||||
}
|
||||
assert s_max <= 2328 via "a <= b: a <= c; c <= b"(c: this.ht_n_symbols)
|
||||
while s < s_max,
|
||||
inv s_max <= 2328,
|
||||
{
|
||||
assert s < 2328 via "a < b: a < c; c <= b"(c: s_max)
|
||||
this.code_lengths[s] = repeat_value
|
||||
s += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri const CODE_LENGTH_CODE_ORDER : roarray[19] base.u8[..= 18] = [
|
||||
17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
]
|
||||
|
||||
pri const REPEAT_N_BITS : roarray[4] base.u8[..= 7] = [2, 3, 7, 0]
|
||||
|
||||
pri const REPEAT_COUNTS : roarray[4] base.u8[..= 11] = [3, 3, 11, 0]
|
||||
|
||||
// See the decoder.huffman_nodes comment re five (5) Huffman trees.
|
||||
pri const HUFFMAN_TABLE_BASE_OFFSETS : roarray[5] base.u16[..= 0x064C] = [
|
||||
0x064C,
|
||||
0x0000,
|
||||
0x01FF,
|
||||
0x03FE,
|
||||
0x05FD,
|
||||
]
|
||||
@@ -0,0 +1,308 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_pixels_slow?(dst: slice base.u8, src: base.io_reader, width: base.u32[..= 0x4000], height: base.u32[..= 0x4000], tile_data: roslice base.u8, tile_size_log2: base.u32[..= 9]) {
|
||||
var c8 : base.u8
|
||||
|
||||
var p : base.u64
|
||||
var p_max : base.u64[..= 0x4000_0000]
|
||||
|
||||
var tile_size_log2 : base.u32[..= 31]
|
||||
var width_in_tiles : base.u32[..= 0x20FF]
|
||||
|
||||
var x : base.u32
|
||||
var y : base.u32
|
||||
var i : base.u32
|
||||
|
||||
var hg : base.u32[..= 0xFF]
|
||||
var h : base.u32[..= 0x187A]
|
||||
var node : base.u16
|
||||
|
||||
var pixel_g : base.u32[..= 0x7FFF]
|
||||
var color : base.u32 // u32 0xAARR_GGBB, non-premultiplied alpha.
|
||||
var dst_pixel : slice base.u8
|
||||
|
||||
var back_ref_len_n_bits : base.u32[..= 11]
|
||||
var back_ref_len_minus_1 : base.u32[..= 0x1FFF] // 0x1FFF = 8191.
|
||||
var back_ref_dist_n_bits : base.u32[..= 18]
|
||||
var back_ref_dist_sym : base.u32[..= 0x7FFF]
|
||||
var back_ref_dist_premap_minus_1 : base.u32[..= 0xF_FFFF] // 0xF_FFFF = 1048575.
|
||||
var back_ref_dist_minus_1 : base.u32
|
||||
|
||||
var dm : base.u32[..= 0xFF]
|
||||
var dx : base.u32
|
||||
var dy : base.u32
|
||||
|
||||
var p_end : base.u64[..= 0x4000_8000]
|
||||
var dist4 : base.u64
|
||||
var q : base.u64
|
||||
|
||||
var color_cache_pixels : slice base.u8
|
||||
var color_cache_p : base.u64
|
||||
var color_cache_shift : base.u32[..= 31]
|
||||
|
||||
p_max = (4 * args.width * args.height) as base.u64
|
||||
if args.dst.length() < p_max {
|
||||
return "#internal error: inconsistent dst buffer"
|
||||
}
|
||||
|
||||
if args.tile_size_log2 <> 0 {
|
||||
tile_size_log2 = args.tile_size_log2
|
||||
width_in_tiles = (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
} else {
|
||||
tile_size_log2 = 31
|
||||
width_in_tiles = 1
|
||||
}
|
||||
|
||||
while p < p_max {
|
||||
// The "~mod+ 1" selects the green pixel of the BGRA 4-byte group.
|
||||
i = ((((y >> tile_size_log2) ~mod* width_in_tiles) ~mod+ (x >> tile_size_log2)) ~mod* 4) ~mod+ 1
|
||||
if (i as base.u64) < args.tile_data.length() {
|
||||
hg = args.tile_data[i as base.u64] as base.u32
|
||||
}
|
||||
|
||||
// Decode the Green+etc symbol.
|
||||
h = HUFFMAN_TABLE_BASE_OFFSETS[0] as base.u32
|
||||
while true,
|
||||
inv p < p_max,
|
||||
{
|
||||
node = this.huffman_nodes[hg][h]
|
||||
if node >= 0x8000 {
|
||||
break
|
||||
} else if node > 0x1879 {
|
||||
return "#internal error: inconsistent Huffman code"
|
||||
}
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
h = (node as base.u32) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
}
|
||||
pixel_g = (node & 0x7FFF) as base.u32
|
||||
|
||||
if pixel_g < 0x100 { // Literal pixel.
|
||||
color = pixel_g << 8
|
||||
|
||||
// Decode the Red symbol.
|
||||
h = HUFFMAN_TABLE_BASE_OFFSETS[1] as base.u32
|
||||
while true,
|
||||
inv p < p_max,
|
||||
{
|
||||
node = this.huffman_nodes[hg][h]
|
||||
if node >= 0x8000 {
|
||||
break
|
||||
}
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
}
|
||||
color |= ((node & 0xFF) as base.u32) << 16
|
||||
|
||||
// Decode the Blue symbol.
|
||||
h = HUFFMAN_TABLE_BASE_OFFSETS[2] as base.u32
|
||||
while true,
|
||||
inv p < p_max,
|
||||
{
|
||||
node = this.huffman_nodes[hg][h]
|
||||
if node >= 0x8000 {
|
||||
break
|
||||
}
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
}
|
||||
color |= ((node & 0xFF) as base.u32) << 0
|
||||
|
||||
// Decode the Alpha symbol.
|
||||
h = HUFFMAN_TABLE_BASE_OFFSETS[3] as base.u32
|
||||
while true,
|
||||
inv p < p_max,
|
||||
{
|
||||
node = this.huffman_nodes[hg][h]
|
||||
if node >= 0x8000 {
|
||||
break
|
||||
}
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
}
|
||||
color |= ((node & 0xFF) as base.u32) << 24
|
||||
|
||||
} else if pixel_g < 0x118 { // Back-ref pixel.
|
||||
// Decode the back-ref length.
|
||||
if pixel_g < 0x104 {
|
||||
back_ref_len_minus_1 = pixel_g - 0x100
|
||||
} else {
|
||||
back_ref_len_n_bits = (pixel_g - 0x102) >> 1
|
||||
back_ref_len_minus_1 = ((2 as base.u32) + (pixel_g & 1)) << back_ref_len_n_bits
|
||||
assert back_ref_len_minus_1 <= 6144
|
||||
while this.n_bits < back_ref_len_n_bits,
|
||||
inv p < p_max,
|
||||
inv back_ref_len_minus_1 <= 6144,
|
||||
post this.n_bits >= back_ref_len_n_bits,
|
||||
{
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= back_ref_len_n_bits {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
assert this.n_bits < 12 via "a < b: a < c; c <= b"(c: back_ref_len_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
}
|
||||
back_ref_len_minus_1 += this.bits & (((1 as base.u32) << back_ref_len_n_bits) - 1)
|
||||
this.bits >>= back_ref_len_n_bits
|
||||
this.n_bits -= back_ref_len_n_bits
|
||||
}
|
||||
|
||||
// Decode the back-ref distance.
|
||||
|
||||
h = HUFFMAN_TABLE_BASE_OFFSETS[4] as base.u32
|
||||
while true,
|
||||
inv p < p_max,
|
||||
{
|
||||
node = this.huffman_nodes[hg][h]
|
||||
if node >= 0x8000 {
|
||||
break
|
||||
}
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
h = ((node as base.u32) & 0xFFF) + (this.bits & 1)
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
}
|
||||
back_ref_dist_sym = (node & 0x7FFF) as base.u32
|
||||
|
||||
if back_ref_dist_sym < 4 {
|
||||
back_ref_dist_premap_minus_1 = back_ref_dist_sym
|
||||
} else if back_ref_dist_sym < 40 {
|
||||
back_ref_dist_n_bits = (back_ref_dist_sym - 2) >> 1
|
||||
back_ref_dist_premap_minus_1 = ((2 as base.u32) + (back_ref_dist_sym & 1)) << back_ref_dist_n_bits
|
||||
assert back_ref_dist_premap_minus_1 <= 786432
|
||||
while this.n_bits < back_ref_dist_n_bits,
|
||||
inv p < p_max,
|
||||
inv back_ref_dist_premap_minus_1 <= 786432,
|
||||
post this.n_bits >= back_ref_dist_n_bits,
|
||||
{
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= back_ref_dist_n_bits {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
assert this.n_bits < 24 via "a < b: a < c; c <= b"(c: back_ref_dist_n_bits)
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
}
|
||||
back_ref_dist_premap_minus_1 += this.bits & (((1 as base.u32) << back_ref_dist_n_bits) - 1)
|
||||
this.bits >>= back_ref_dist_n_bits
|
||||
this.n_bits -= back_ref_dist_n_bits
|
||||
}
|
||||
|
||||
if back_ref_dist_premap_minus_1 >= 120 {
|
||||
back_ref_dist_minus_1 = back_ref_dist_premap_minus_1 - 120
|
||||
} else {
|
||||
dm = DISTANCE_MAP[back_ref_dist_premap_minus_1] as base.u32
|
||||
dy = dm >> 4
|
||||
dx = 7 ~mod- (dm & 15)
|
||||
back_ref_dist_minus_1 = (args.width * dy) ~mod+ dx
|
||||
}
|
||||
|
||||
// Apply the (back_ref_len_minus_1, back_ref_dist_minus_1) pair.
|
||||
assert p < 0x4000_0000 via "a < b: a < c; c <= b"(c: p_max)
|
||||
p_end = p + (((back_ref_len_minus_1 + 1) * 4) as base.u64)
|
||||
dist4 = ((back_ref_dist_minus_1 as base.u64) * 4) + 4
|
||||
if (p_end > p_max) or (p_end > args.dst.length()) or (p < dist4) {
|
||||
return "#bad back-reference"
|
||||
}
|
||||
q = p - dist4
|
||||
while (q < p) and (p < p_end),
|
||||
inv p_end <= args.dst.length(),
|
||||
{
|
||||
assert q < p_end via "a < b: a < c; c < b"(c: p)
|
||||
assert p < 0x4000_8000 via "a < b: a < c; c <= b"(c: p_end)
|
||||
assert q < 0x4000_8000 via "a < b: a < c; c <= b"(c: p_end)
|
||||
assert p < args.dst.length() via "a < b: a < c; c <= b"(c: p_end)
|
||||
assert q < args.dst.length() via "a < b: a < c; c <= b"(c: p_end)
|
||||
args.dst[p] = args.dst[q]
|
||||
p += 1
|
||||
q += 1
|
||||
}
|
||||
|
||||
// Update (x, y).
|
||||
x ~mod+= back_ref_len_minus_1 + 1
|
||||
while x >= args.width {
|
||||
x -= args.width
|
||||
y ~mod+= 1
|
||||
}
|
||||
continue
|
||||
|
||||
} else { // Color cache pixel.
|
||||
// Insert previous pixels into this.color_cache.
|
||||
if (color_cache_p > p) or (p > args.dst.length()) {
|
||||
return "#internal error: inconsistent dst buffer"
|
||||
}
|
||||
color_cache_pixels = args.dst[color_cache_p .. p]
|
||||
color_cache_p = p
|
||||
color_cache_shift = (32 - this.color_cache_bits) & 31
|
||||
while color_cache_pixels.length() >= 4,
|
||||
inv pixel_g >= 0x118,
|
||||
{
|
||||
color = color_cache_pixels.peek_u32le()
|
||||
this.color_cache[((color ~mod* 0x1E35_A7BD) >> color_cache_shift) & 2047] = color
|
||||
color_cache_pixels = color_cache_pixels[4 ..]
|
||||
}
|
||||
|
||||
// Look up this.color_cache.
|
||||
color = this.color_cache[(pixel_g - 0x118) & 2047]
|
||||
}
|
||||
|
||||
// Set the dst pixel to the color.
|
||||
if p > args.dst.length() {
|
||||
return "#internal error: inconsistent dst buffer"
|
||||
}
|
||||
dst_pixel = args.dst[p ..]
|
||||
if dst_pixel.length() < 4 {
|
||||
return "#internal error: inconsistent dst buffer"
|
||||
}
|
||||
dst_pixel.poke_u32le!(a: color)
|
||||
p ~mod+= 4
|
||||
|
||||
// Update (x, y).
|
||||
x ~mod+= 1
|
||||
if x == args.width {
|
||||
x = 0
|
||||
y ~mod+= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,438 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: roslice base.u8) {
|
||||
var w4 : base.u64[..= 0x1_0000]
|
||||
var prev_row : roslice base.u8
|
||||
var curr_row : slice base.u8
|
||||
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var tiles_per_row : base.u32[..= 16895]
|
||||
var mask : base.u32
|
||||
var y : base.u32[..= 0x4000]
|
||||
var x : base.u32[..= 0x4000]
|
||||
var t : base.u64
|
||||
var tile_data : roslice base.u8
|
||||
var mode : base.u8[..= 0x0F]
|
||||
|
||||
var l0 : base.u32[..= 0xFF]
|
||||
var l1 : base.u32[..= 0xFF]
|
||||
var l2 : base.u32[..= 0xFF]
|
||||
var l3 : base.u32[..= 0xFF]
|
||||
var c0 : base.u32[..= 0xFF]
|
||||
var c1 : base.u32[..= 0xFF]
|
||||
var c2 : base.u32[..= 0xFF]
|
||||
var c3 : base.u32[..= 0xFF]
|
||||
var t0 : base.u32[..= 0xFF]
|
||||
var t1 : base.u32[..= 0xFF]
|
||||
var t2 : base.u32[..= 0xFF]
|
||||
var t3 : base.u32[..= 0xFF]
|
||||
var sum_l : base.u32
|
||||
var sum_t : base.u32
|
||||
|
||||
if (this.width <= 0) or (this.height <= 0) {
|
||||
return nothing
|
||||
}
|
||||
|
||||
w4 = (this.width * 4) as base.u64
|
||||
curr_row = this.util.empty_slice_u8()
|
||||
if w4 <= args.pix.length() {
|
||||
curr_row = args.pix[.. w4]
|
||||
}
|
||||
|
||||
// The first pixel's predictor is mode 0 (opaque black).
|
||||
if curr_row.length() >= 4 {
|
||||
curr_row[3] ~mod+= 0xFF
|
||||
}
|
||||
|
||||
// The rest of the first row's predictor is mode 1 (L).
|
||||
while curr_row.length() >= 8 {
|
||||
curr_row[4] ~mod+= curr_row[0]
|
||||
curr_row[5] ~mod+= curr_row[1]
|
||||
curr_row[6] ~mod+= curr_row[2]
|
||||
curr_row[7] ~mod+= curr_row[3]
|
||||
curr_row = curr_row[4 ..]
|
||||
}
|
||||
|
||||
tile_size_log2 = this.transform_tile_size_log2[0] as base.u32
|
||||
tiles_per_row = (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
mask = ((1 as base.u32) << tile_size_log2) - 1
|
||||
|
||||
y = 1
|
||||
while y < this.height {
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
t = (4 * (y >> tile_size_log2) * tiles_per_row) as base.u64
|
||||
tile_data = this.util.empty_slice_u8()
|
||||
if t <= args.tile_data.length() {
|
||||
tile_data = args.tile_data[t ..]
|
||||
if tile_data.length() >= 4 {
|
||||
mode = tile_data[1] & 0x0F
|
||||
tile_data = tile_data[4 ..]
|
||||
}
|
||||
}
|
||||
|
||||
if w4 <= args.pix.length() {
|
||||
prev_row = args.pix
|
||||
args.pix = args.pix[w4 ..]
|
||||
curr_row = args.pix
|
||||
}
|
||||
|
||||
// The first column's predictor is mode 2 (T).
|
||||
if (prev_row.length() >= 4) and (curr_row.length() >= 4) {
|
||||
curr_row[0] ~mod+= prev_row[0]
|
||||
curr_row[1] ~mod+= prev_row[1]
|
||||
curr_row[2] ~mod+= prev_row[2]
|
||||
curr_row[3] ~mod+= prev_row[3]
|
||||
}
|
||||
|
||||
x = 1
|
||||
while x < this.width,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
if ((x & mask) == 0) and (tile_data.length() >= 4) {
|
||||
mode = tile_data[1] & 0x0F
|
||||
tile_data = tile_data[4 ..]
|
||||
}
|
||||
|
||||
if (prev_row.length() < 12) or (curr_row.length() < 8) {
|
||||
break
|
||||
}
|
||||
|
||||
if mode == 0 { // Opaque black.
|
||||
curr_row[7] ~mod+= 0xFF
|
||||
|
||||
} else if mode == 1 { // L
|
||||
curr_row[4] ~mod+= curr_row[0]
|
||||
curr_row[5] ~mod+= curr_row[1]
|
||||
curr_row[6] ~mod+= curr_row[2]
|
||||
curr_row[7] ~mod+= curr_row[3]
|
||||
|
||||
} else if mode == 2 { // T
|
||||
curr_row[4] ~mod+= prev_row[4]
|
||||
curr_row[5] ~mod+= prev_row[5]
|
||||
curr_row[6] ~mod+= prev_row[6]
|
||||
curr_row[7] ~mod+= prev_row[7]
|
||||
|
||||
} else if mode == 3 { // TR
|
||||
curr_row[4] ~mod+= prev_row[8]
|
||||
curr_row[5] ~mod+= prev_row[9]
|
||||
curr_row[6] ~mod+= prev_row[10]
|
||||
curr_row[7] ~mod+= prev_row[11]
|
||||
|
||||
} else if mode == 4 { // TL
|
||||
curr_row[4] ~mod+= prev_row[0]
|
||||
curr_row[5] ~mod+= prev_row[1]
|
||||
curr_row[6] ~mod+= prev_row[2]
|
||||
curr_row[7] ~mod+= prev_row[3]
|
||||
|
||||
} else if mode == 5 { // Average2(Average2(L, TR), T).
|
||||
l0 = ((curr_row[0] as base.u32) + (prev_row[8] as base.u32)) / 2
|
||||
l1 = ((curr_row[1] as base.u32) + (prev_row[9] as base.u32)) / 2
|
||||
l2 = ((curr_row[2] as base.u32) + (prev_row[10] as base.u32)) / 2
|
||||
l3 = ((curr_row[3] as base.u32) + (prev_row[11] as base.u32)) / 2
|
||||
curr_row[4] ~mod+= ((l0 + (prev_row[4] as base.u32)) / 2) as base.u8
|
||||
curr_row[5] ~mod+= ((l1 + (prev_row[5] as base.u32)) / 2) as base.u8
|
||||
curr_row[6] ~mod+= ((l2 + (prev_row[6] as base.u32)) / 2) as base.u8
|
||||
curr_row[7] ~mod+= ((l3 + (prev_row[7] as base.u32)) / 2) as base.u8
|
||||
|
||||
} else if mode == 6 { // Average2(L, TL).
|
||||
curr_row[4] ~mod+= (((curr_row[0] as base.u32) + (prev_row[0] as base.u32)) / 2) as base.u8
|
||||
curr_row[5] ~mod+= (((curr_row[1] as base.u32) + (prev_row[1] as base.u32)) / 2) as base.u8
|
||||
curr_row[6] ~mod+= (((curr_row[2] as base.u32) + (prev_row[2] as base.u32)) / 2) as base.u8
|
||||
curr_row[7] ~mod+= (((curr_row[3] as base.u32) + (prev_row[3] as base.u32)) / 2) as base.u8
|
||||
|
||||
} else if mode == 7 { // Average2(L, T).
|
||||
curr_row[4] ~mod+= (((curr_row[0] as base.u32) + (prev_row[4] as base.u32)) / 2) as base.u8
|
||||
curr_row[5] ~mod+= (((curr_row[1] as base.u32) + (prev_row[5] as base.u32)) / 2) as base.u8
|
||||
curr_row[6] ~mod+= (((curr_row[2] as base.u32) + (prev_row[6] as base.u32)) / 2) as base.u8
|
||||
curr_row[7] ~mod+= (((curr_row[3] as base.u32) + (prev_row[7] as base.u32)) / 2) as base.u8
|
||||
|
||||
} else if mode == 8 { // Average2(TL, T).
|
||||
curr_row[4] ~mod+= (((prev_row[0] as base.u32) + (prev_row[4] as base.u32)) / 2) as base.u8
|
||||
curr_row[5] ~mod+= (((prev_row[1] as base.u32) + (prev_row[5] as base.u32)) / 2) as base.u8
|
||||
curr_row[6] ~mod+= (((prev_row[2] as base.u32) + (prev_row[6] as base.u32)) / 2) as base.u8
|
||||
curr_row[7] ~mod+= (((prev_row[3] as base.u32) + (prev_row[7] as base.u32)) / 2) as base.u8
|
||||
|
||||
} else if mode == 9 { // Average2(T, TR).
|
||||
curr_row[4] ~mod+= (((prev_row[4] as base.u32) + (prev_row[8] as base.u32)) / 2) as base.u8
|
||||
curr_row[5] ~mod+= (((prev_row[5] as base.u32) + (prev_row[9] as base.u32)) / 2) as base.u8
|
||||
curr_row[6] ~mod+= (((prev_row[6] as base.u32) + (prev_row[10] as base.u32)) / 2) as base.u8
|
||||
curr_row[7] ~mod+= (((prev_row[7] as base.u32) + (prev_row[11] as base.u32)) / 2) as base.u8
|
||||
|
||||
} else if mode == 10 { // Average2(Average2(L, TL), Average2(T, TR)).
|
||||
l0 = ((curr_row[0] as base.u32) + (prev_row[0] as base.u32)) / 2
|
||||
l1 = ((curr_row[1] as base.u32) + (prev_row[1] as base.u32)) / 2
|
||||
l2 = ((curr_row[2] as base.u32) + (prev_row[2] as base.u32)) / 2
|
||||
l3 = ((curr_row[3] as base.u32) + (prev_row[3] as base.u32)) / 2
|
||||
t0 = ((prev_row[4] as base.u32) + (prev_row[8] as base.u32)) / 2
|
||||
t1 = ((prev_row[5] as base.u32) + (prev_row[9] as base.u32)) / 2
|
||||
t2 = ((prev_row[6] as base.u32) + (prev_row[10] as base.u32)) / 2
|
||||
t3 = ((prev_row[7] as base.u32) + (prev_row[11] as base.u32)) / 2
|
||||
curr_row[4] ~mod+= ((l0 + t0) / 2) as base.u8
|
||||
curr_row[5] ~mod+= ((l1 + t1) / 2) as base.u8
|
||||
curr_row[6] ~mod+= ((l2 + t2) / 2) as base.u8
|
||||
curr_row[7] ~mod+= ((l3 + t3) / 2) as base.u8
|
||||
|
||||
} else if mode == 11 { // Select(L, T, TL).
|
||||
l0 = curr_row[0] as base.u32
|
||||
l1 = curr_row[1] as base.u32
|
||||
l2 = curr_row[2] as base.u32
|
||||
l3 = curr_row[3] as base.u32
|
||||
c0 = prev_row[0] as base.u32
|
||||
c1 = prev_row[1] as base.u32
|
||||
c2 = prev_row[2] as base.u32
|
||||
c3 = prev_row[3] as base.u32
|
||||
t0 = prev_row[4] as base.u32
|
||||
t1 = prev_row[5] as base.u32
|
||||
t2 = prev_row[6] as base.u32
|
||||
t3 = prev_row[7] as base.u32
|
||||
sum_l = this.absolute_difference(a: c0, b: t0) +
|
||||
this.absolute_difference(a: c1, b: t1) +
|
||||
this.absolute_difference(a: c2, b: t2) +
|
||||
this.absolute_difference(a: c3, b: t3)
|
||||
sum_t = this.absolute_difference(a: c0, b: l0) +
|
||||
this.absolute_difference(a: c1, b: l1) +
|
||||
this.absolute_difference(a: c2, b: l2) +
|
||||
this.absolute_difference(a: c3, b: l3)
|
||||
if sum_l < sum_t {
|
||||
curr_row[4] ~mod+= l0 as base.u8
|
||||
curr_row[5] ~mod+= l1 as base.u8
|
||||
curr_row[6] ~mod+= l2 as base.u8
|
||||
curr_row[7] ~mod+= l3 as base.u8
|
||||
} else {
|
||||
curr_row[4] ~mod+= t0 as base.u8
|
||||
curr_row[5] ~mod+= t1 as base.u8
|
||||
curr_row[6] ~mod+= t2 as base.u8
|
||||
curr_row[7] ~mod+= t3 as base.u8
|
||||
}
|
||||
|
||||
} else if mode == 12 { // ClampAddSubtractFull(L, T, TL).
|
||||
curr_row[4] ~mod+= this.mode12(l: curr_row[0], t: prev_row[4], tl: prev_row[0])
|
||||
curr_row[5] ~mod+= this.mode12(l: curr_row[1], t: prev_row[5], tl: prev_row[1])
|
||||
curr_row[6] ~mod+= this.mode12(l: curr_row[2], t: prev_row[6], tl: prev_row[2])
|
||||
curr_row[7] ~mod+= this.mode12(l: curr_row[3], t: prev_row[7], tl: prev_row[3])
|
||||
|
||||
} else if mode == 13 { // ClampAddSubtractHalf(Average2(L, T), TL).
|
||||
curr_row[4] ~mod+= this.mode13(l: curr_row[0], t: prev_row[4], tl: prev_row[0])
|
||||
curr_row[5] ~mod+= this.mode13(l: curr_row[1], t: prev_row[5], tl: prev_row[1])
|
||||
curr_row[6] ~mod+= this.mode13(l: curr_row[2], t: prev_row[6], tl: prev_row[2])
|
||||
curr_row[7] ~mod+= this.mode13(l: curr_row[3], t: prev_row[7], tl: prev_row[3])
|
||||
}
|
||||
|
||||
curr_row = curr_row[4 ..]
|
||||
prev_row = prev_row[4 ..]
|
||||
x += 1
|
||||
}
|
||||
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.absolute_difference(a: base.u32[..= 0xFF], b: base.u32[..= 0xFF]) base.u32[..= 0xFF] {
|
||||
if args.a < args.b {
|
||||
assert args.b > args.a via "a > b: b < a"()
|
||||
return args.b - args.a
|
||||
}
|
||||
return args.a - args.b
|
||||
}
|
||||
|
||||
pri func decoder.mode12(l: base.u8, t: base.u8, tl: base.u8) base.u8 {
|
||||
var v : base.u32
|
||||
|
||||
v = ((args.l as base.u32) + (args.t as base.u32)) ~mod- (args.tl as base.u32)
|
||||
|
||||
// Return clamp(v), where v is a signed i32.
|
||||
if v < 256 {
|
||||
return v as base.u8
|
||||
} else if v < 512 {
|
||||
return 255
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pri func decoder.mode13(l: base.u8, t: base.u8, tl: base.u8) base.u8 {
|
||||
var x : base.u32[..= 0xFF]
|
||||
var y : base.u32[..= 0xFF]
|
||||
var z : base.u32
|
||||
var v : base.u32
|
||||
|
||||
x = ((args.l as base.u32) + (args.t as base.u32)) / 2
|
||||
y = args.tl as base.u32
|
||||
|
||||
// Calculate "v = x + ((x - y) / 2)" but using signed (i32) arithmetic
|
||||
// instead of unsigned (u32) arithmetic.
|
||||
z = x ~mod- y
|
||||
v = x ~mod+ this.util.sign_extend_rshift_u32(a: z ~mod+ (z >> 31), n: 1)
|
||||
|
||||
// Return clamp(v), where v is a signed i32.
|
||||
if v < 256 {
|
||||
return v as base.u8
|
||||
} else if v < 512 {
|
||||
return 255
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: roslice base.u8) {
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var tiles_per_row : base.u32[..= 16895]
|
||||
var mask : base.u32
|
||||
var y : base.u32[..= 0x4000]
|
||||
var x : base.u32[..= 0x4000]
|
||||
var t : base.u64
|
||||
var tile_data : roslice base.u8
|
||||
|
||||
var g2r : base.u32
|
||||
var g2b : base.u32
|
||||
var r2b : base.u32
|
||||
|
||||
var b : base.u8
|
||||
var g : base.u8
|
||||
var r : base.u8
|
||||
|
||||
tile_size_log2 = this.transform_tile_size_log2[1] as base.u32
|
||||
tiles_per_row = (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
mask = ((1 as base.u32) << tile_size_log2) - 1
|
||||
|
||||
y = 0
|
||||
while y < this.height {
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
t = (4 * (y >> tile_size_log2) * tiles_per_row) as base.u64
|
||||
tile_data = this.util.empty_slice_u8()
|
||||
if t <= args.tile_data.length() {
|
||||
tile_data = args.tile_data[t ..]
|
||||
}
|
||||
|
||||
x = 0
|
||||
while x < this.width,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
if ((x & mask) == 0) and (tile_data.length() >= 4) {
|
||||
g2r = this.util.sign_extend_convert_u8_u32(a: tile_data[0])
|
||||
g2b = this.util.sign_extend_convert_u8_u32(a: tile_data[1])
|
||||
r2b = this.util.sign_extend_convert_u8_u32(a: tile_data[2])
|
||||
tile_data = tile_data[4 ..]
|
||||
}
|
||||
|
||||
if args.pix.length() >= 4 {
|
||||
b = args.pix[0]
|
||||
g = args.pix[1]
|
||||
r = args.pix[2]
|
||||
r ~mod+= (((this.util.sign_extend_convert_u8_u32(a: g) ~mod* g2r) >> 5) & 0xFF) as base.u8
|
||||
b ~mod+= (((this.util.sign_extend_convert_u8_u32(a: g) ~mod* g2b) >> 5) & 0xFF) as base.u8
|
||||
b ~mod+= (((this.util.sign_extend_convert_u8_u32(a: r) ~mod* r2b) >> 5) & 0xFF) as base.u8
|
||||
args.pix[0] = b
|
||||
args.pix[2] = r
|
||||
args.pix = args.pix[4 ..]
|
||||
}
|
||||
|
||||
x += 1
|
||||
}
|
||||
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.apply_transform_subtract_green!(pix: slice base.u8) {
|
||||
var p : slice base.u8
|
||||
var g : base.u8
|
||||
|
||||
iterate (p = args.pix)(length: 4, advance: 4, unroll: 1) {
|
||||
g = p[1]
|
||||
p[0] ~mod+= g
|
||||
p[2] ~mod+= g
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.apply_transform_color_indexing!(pix: slice base.u8) {
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var bits_per_pixel : base.u32[..= 8]
|
||||
var x_mask : base.u32
|
||||
var s_mask : base.u32[..= 0xFF]
|
||||
var src_index : base.u64
|
||||
|
||||
var y : base.u32[..= 0x4000]
|
||||
var di : base.u64
|
||||
var dj : base.u64
|
||||
var dst : slice base.u8
|
||||
var x : base.u32
|
||||
var s : base.u32[..= 0xFF]
|
||||
|
||||
var p : base.u32[..= 0x3FC]
|
||||
var p0 : base.u8
|
||||
var p1 : base.u8
|
||||
var p2 : base.u8
|
||||
var p3 : base.u8
|
||||
|
||||
tile_size_log2 = this.transform_tile_size_log2[3] as base.u32
|
||||
if tile_size_log2 == 0 {
|
||||
iterate (dst = args.pix)(length: 4, advance: 4, unroll: 1) {
|
||||
p = (dst[1] as base.u32) * 4
|
||||
p0 = this.palette[p + 0]
|
||||
p1 = this.palette[p + 1]
|
||||
p2 = this.palette[p + 2]
|
||||
p3 = this.palette[p + 3]
|
||||
dst[0] = p0
|
||||
dst[1] = p1
|
||||
dst[2] = p2
|
||||
dst[3] = p3
|
||||
}
|
||||
return nothing
|
||||
}
|
||||
|
||||
bits_per_pixel = (8 as base.u32) >> tile_size_log2
|
||||
x_mask = ((1 as base.u32) << tile_size_log2) - 1
|
||||
s_mask = ((1 as base.u32) << bits_per_pixel) - 1
|
||||
|
||||
// The "+ 1" selects the green pixel of the BGRA 4-byte group.
|
||||
src_index = (this.workbuf_offset_for_color_indexing + 1) as base.u64
|
||||
|
||||
y = 0
|
||||
while y < this.height {
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
di = (4 * (y + 0) * this.width) as base.u64
|
||||
dj = (4 * (y + 1) * this.width) as base.u64
|
||||
if (di > dj) or (dj > args.pix.length()) {
|
||||
break
|
||||
}
|
||||
dst = args.pix[di .. dj]
|
||||
|
||||
x = 0
|
||||
while dst.length() >= 4,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
if ((x & x_mask) == 0) and (src_index < args.pix.length()) {
|
||||
s = args.pix[src_index] as base.u32
|
||||
src_index ~mod+= 4
|
||||
}
|
||||
p = (s & s_mask) * 4
|
||||
s >>= bits_per_pixel
|
||||
p0 = this.palette[p + 0]
|
||||
p1 = this.palette[p + 1]
|
||||
p2 = this.palette[p + 2]
|
||||
p3 = this.palette[p + 3]
|
||||
dst[0] = p0
|
||||
dst[1] = p1
|
||||
dst[2] = p2
|
||||
dst[3] = p3
|
||||
dst = dst[4 ..]
|
||||
x ~mod+= 1
|
||||
}
|
||||
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,876 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
use "std/vp8"
|
||||
|
||||
pub status "#bad Huffman code (over-subscribed)"
|
||||
pub status "#bad Huffman code (under-subscribed)"
|
||||
pub status "#bad Huffman code"
|
||||
pub status "#bad back-reference"
|
||||
pub status "#bad color cache"
|
||||
pub status "#bad header"
|
||||
pub status "#bad transform"
|
||||
pub status "#short chunk"
|
||||
pub status "#truncated input"
|
||||
pub status "#unsupported number of Huffman groups"
|
||||
pub status "#unsupported transform after color indexing transform"
|
||||
pub status "#unsupported WebP file"
|
||||
|
||||
pri status "#internal error: inconsistent Huffman code"
|
||||
pri status "#internal error: inconsistent dst buffer"
|
||||
pri status "#internal error: inconsistent n_bits"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
pixfmt : base.u32,
|
||||
width : base.u32[..= 0x4000],
|
||||
height : base.u32[..= 0x4000],
|
||||
|
||||
// The call sequence state machine is discussed in
|
||||
// (/doc/std/image-decoders-call-sequence.md).
|
||||
call_sequence : base.u8,
|
||||
|
||||
code_length_code_lengths : array[19] base.u8[..= 7],
|
||||
|
||||
sub_chunk_has_padding : base.bool,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
riff_chunk_length : base.u32,
|
||||
sub_chunk_length : base.u32,
|
||||
|
||||
bits : base.u32,
|
||||
n_bits : base.u32[..= 31],
|
||||
|
||||
seen_transform : array[4] base.bool,
|
||||
transform_type : array[4] base.u8[..= 3],
|
||||
transform_tile_size_log2 : array[4] base.u8[..= 9],
|
||||
n_transforms : base.u32[..= 4],
|
||||
|
||||
color_cache_bits : base.u32[..= 11],
|
||||
overall_color_cache_bits : base.u32[..= 11],
|
||||
overall_tile_size_log2 : base.u32[..= 9],
|
||||
overall_n_huffman_groups : base.u32[..= 256],
|
||||
|
||||
ht_n_symbols : base.u32[..= 2328],
|
||||
ht_code_lengths_remaining : base.u32,
|
||||
|
||||
color_indexing_palette_size : base.u32[..= 256],
|
||||
color_indexing_width : base.u32[..= 0x4000],
|
||||
|
||||
// The 0th element is for the Meta (Huffman Group) selectors.
|
||||
// The 1st element is for the Predictor transform.
|
||||
// The 2nd element is for the Cross Color transform.
|
||||
// The 3rd element is overall workbuf length.
|
||||
workbuf_offset_for_transform : array[4] base.u32[..= 0x4C00_0000],
|
||||
|
||||
// If the Color Indexing transform is present then workbuf[i .. j]
|
||||
// holds the pre-transformed pixel data (the Green component of the
|
||||
// pixel's bgra data holds color indexes) and workbuf[0 .. j] holds the
|
||||
// post-transformed data:
|
||||
//
|
||||
// - i is workbuf_offset_for_color_indexing
|
||||
// - j is workbuf_offset_for_transform[0]
|
||||
//
|
||||
// i is calculated as:
|
||||
//
|
||||
// - if there are 8 bits per color index then i is 0.
|
||||
// - if there are 4 bits per color index then i is j*1/2, roughly.
|
||||
// - if there are 2 bits per color index then i is j*3/4, roughly.
|
||||
// - if there are 1 bits per color index then i is j*7/8, roughly.
|
||||
//
|
||||
// The two slices (workbuf[i .. j] and workbuf[0 .. j]) overlap.
|
||||
// apply_transform_color_indexing modifies the pixel buffer in-place.
|
||||
workbuf_offset_for_color_indexing : base.u32[..= 0x4000_0000],
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
util : base.utility,
|
||||
) + (
|
||||
palette : array[4 * 256] base.u8,
|
||||
color_cache : array[2048] base.u32,
|
||||
|
||||
codes : array[2328] base.u16,
|
||||
code_lengths : array[2328] base.u16,
|
||||
|
||||
// Each node is a base.u16 whose bit patterns are:
|
||||
//
|
||||
// - 0000_0000_0000_0000 Invalid.
|
||||
// - 0CCC_CCCC_CCCC_CCCC Branch node (children_offset is CCC).
|
||||
// - 1SSS_SSSS_SSSS_SSSS Leaf node (symbol is SSS, it may be zero).
|
||||
code_lengths_huffman_nodes : array[37] base.u16,
|
||||
|
||||
// A Huffman group has five (5) Huffman trees.
|
||||
//
|
||||
// Start .. End Size
|
||||
// 0x064C .. 0x187B 0x122F (1) Green, back-ref length, color cache.
|
||||
// 0x0000 .. 0x01FF 0x01FF (2) Red.
|
||||
// 0x01FF .. 0x03FE 0x01FF (3) Blue.
|
||||
// 0x03FE .. 0x05FD 0x01FF (4) Alpha.
|
||||
// 0x05FD .. 0x064C 0x004F (5) Back-ref distance.
|
||||
//
|
||||
// The Green+etc tree is last (in terms of start offset) because it's
|
||||
// by far the largest (worst case) and its color cache component has
|
||||
// variable length.
|
||||
//
|
||||
// 0x122F = 4655 = ((2 * 2328) - 1) and the same 2328 turns up in func
|
||||
// decoder.decode_huffman_tree.
|
||||
//
|
||||
// 2328 is (256 + 24 + 2048), combining 256 Green values, 24 back-ref
|
||||
// lengths and up to 2048 = (1 << 11) color cache keys.
|
||||
//
|
||||
// 0x01FF = 511 = ((2 * 256) - 1) is for 256 Red (Blue, Alpha) values.
|
||||
//
|
||||
// 0x004F = 79 = ((2 * 40) - 1) is for 40 back-ref distances.
|
||||
//
|
||||
// 0x187B = 6267 and (0x187B * sizeof(u16)) = 12534. Overall, this
|
||||
// field takes 0x30_F600 = 3_208704 bytes of memory.
|
||||
//
|
||||
// The base.u16's bits are the same as for code_lengths_huffman_nodes.
|
||||
huffman_nodes : array[256] array[0x187B] base.u16,
|
||||
)
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_decode_image_config?(dst: args.dst, src: args.src)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c32 : base.u32
|
||||
var r_mark : base.u64
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence <> 0x00 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if c32 <> 'RIFF'le {
|
||||
return "#bad header"
|
||||
}
|
||||
this.riff_chunk_length = args.src.read_u32le?()
|
||||
if (this.riff_chunk_length & 1) <> 0 {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
while true {
|
||||
io_limit (io: args.src, limit: this.riff_chunk_length as base.u64) {
|
||||
r_mark = args.src.mark()
|
||||
status =? this.do_decode_image_config_limited?(src: args.src)
|
||||
this.riff_chunk_length ~sat-=
|
||||
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if not status.is_suspension() {
|
||||
return status
|
||||
} else if (status == base."$short read") and (this.riff_chunk_length == 0) {
|
||||
return "#short chunk"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(
|
||||
pixfmt: this.pixfmt,
|
||||
pixsub: 0,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
first_frame_io_position: this.frame_config_io_position,
|
||||
first_frame_is_opaque: false)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config_limited?(src: base.io_reader) {
|
||||
var c32 : base.u32
|
||||
var r_mark : base.u64
|
||||
var status : base.status
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if c32 <> 'WEBP'le {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if c32 == 'VP8 'le {
|
||||
return "#unsupported WebP file"
|
||||
|
||||
} else if c32 == 'VP8L'le {
|
||||
this.sub_chunk_length = args.src.read_u32le?()
|
||||
if this.sub_chunk_length < 4 {
|
||||
return "#bad header"
|
||||
}
|
||||
this.sub_chunk_has_padding = (this.sub_chunk_length & 1) <> 0
|
||||
|
||||
while true {
|
||||
io_limit (io: args.src, limit: this.sub_chunk_length as base.u64) {
|
||||
r_mark = args.src.mark()
|
||||
status =? this.do_decode_image_config_limited_vp8l?(src: args.src)
|
||||
this.sub_chunk_length ~sat-=
|
||||
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if not status.is_suspension() {
|
||||
return status
|
||||
} else if (status == base."$short read") and (this.sub_chunk_length == 0) {
|
||||
return "#short chunk"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
} else if c32 == 'VP8X'le {
|
||||
return "#unsupported WebP file"
|
||||
|
||||
} else {
|
||||
return "#bad header"
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config_limited_vp8l?(src: base.io_reader) {
|
||||
var c32 : base.u32
|
||||
var transform_size : base.u32[..= 0x400_0000]
|
||||
|
||||
c32 = args.src.read_u8_as_u32?()
|
||||
if c32 <> 0x2F {
|
||||
return "#bad header"
|
||||
}
|
||||
c32 = args.src.read_u32le?()
|
||||
this.width = (c32 & 0x3FFF) + 1
|
||||
c32 >>= 14
|
||||
this.height = (c32 & 0x3FFF) + 1
|
||||
c32 >>= 14
|
||||
this.pixfmt = base.PIXEL_FORMAT__BGRX
|
||||
if (c32 & 1) <> 0 {
|
||||
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
}
|
||||
c32 >>= 1
|
||||
if c32 <> 0 {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
transform_size = 4 * ((this.width + 3) >> 2) * ((this.height + 3) >> 2)
|
||||
this.workbuf_offset_for_transform[0] = (4 * this.width * this.height) + (0 * transform_size)
|
||||
this.workbuf_offset_for_transform[1] = (4 * this.width * this.height) + (1 * transform_size)
|
||||
this.workbuf_offset_for_transform[2] = (4 * this.width * this.height) + (2 * transform_size)
|
||||
this.workbuf_offset_for_transform[3] = (4 * this.width * this.height) + (3 * transform_size)
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
this.do_decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 0x28 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 0x40 {
|
||||
this.call_sequence = 0x60
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(bounds: this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height),
|
||||
duration: 0,
|
||||
index: 0,
|
||||
io_position: this.frame_config_io_position,
|
||||
disposal: 0,
|
||||
opaque_within_bounds: false,
|
||||
overwrite_instead_of_blend: false,
|
||||
background_color: 0x0000_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x40
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var c8 : base.u8
|
||||
var has_more : base.u32[..= 1]
|
||||
var width : base.u32[..= 0x4000]
|
||||
var dst : slice base.u8
|
||||
var tile_data : roslice base.u8
|
||||
var status : base.status
|
||||
var pix : slice base.u8
|
||||
var which : base.u32[..= 4]
|
||||
var transform_type : base.u32[..= 3]
|
||||
var ti : base.u64
|
||||
var tj : base.u64
|
||||
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x40 {
|
||||
this.do_decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
this.seen_transform[0] = false
|
||||
this.seen_transform[1] = false
|
||||
this.seen_transform[2] = false
|
||||
this.seen_transform[3] = false
|
||||
this.n_transforms = 0
|
||||
|
||||
while true {
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
has_more = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if has_more == 0 {
|
||||
break
|
||||
}
|
||||
this.decode_transform?(src: args.src, workbuf: args.workbuf)
|
||||
}
|
||||
|
||||
width = this.width
|
||||
if this.seen_transform[3] {
|
||||
width = this.color_indexing_width
|
||||
}
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.overall_color_cache_bits = this.color_cache_bits
|
||||
this.decode_hg_table?(src: args.src, width: width, workbuf: args.workbuf)
|
||||
this.color_cache_bits = this.overall_color_cache_bits
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: this.overall_n_huffman_groups)
|
||||
|
||||
while true {
|
||||
if ((this.workbuf_offset_for_color_indexing as base.u64) > (this.workbuf_offset_for_transform[0] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) or
|
||||
((this.workbuf_offset_for_transform[0] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
dst = args.workbuf[
|
||||
(this.workbuf_offset_for_color_indexing as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[0] as base.u64)]
|
||||
tile_data = args.workbuf[
|
||||
(this.workbuf_offset_for_transform[0] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[1] as base.u64)]
|
||||
status =? this.decode_pixels?(
|
||||
dst: dst,
|
||||
src: args.src,
|
||||
width: width,
|
||||
height: this.height,
|
||||
tile_data: tile_data,
|
||||
tile_size_log2: this.overall_tile_size_log2)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
if (this.workbuf_offset_for_transform[0] as base.u64) > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
pix = args.workbuf[.. (this.workbuf_offset_for_transform[0] as base.u64)]
|
||||
|
||||
which = this.n_transforms
|
||||
while which > 0 {
|
||||
which -= 1
|
||||
transform_type = this.transform_type[which] as base.u32
|
||||
|
||||
tile_data = this.util.empty_slice_u8()
|
||||
if transform_type < 2 {
|
||||
ti = this.workbuf_offset_for_transform[transform_type + 1] as base.u64
|
||||
tj = this.workbuf_offset_for_transform[transform_type + 2] as base.u64
|
||||
if (ti <= tj) and (tj <= args.workbuf.length()) {
|
||||
tile_data = args.workbuf[ti .. tj]
|
||||
}
|
||||
}
|
||||
|
||||
if transform_type == 0 {
|
||||
this.apply_transform_predictor!(pix: pix, tile_data: tile_data)
|
||||
} else if transform_type == 1 {
|
||||
this.apply_transform_cross_color!(pix: pix, tile_data: tile_data)
|
||||
} else if transform_type == 2 {
|
||||
this.apply_transform_subtract_green!(pix: pix)
|
||||
} else {
|
||||
this.apply_transform_color_indexing!(pix: pix)
|
||||
width = this.width
|
||||
}
|
||||
}
|
||||
|
||||
status = this.swizzle!(
|
||||
dst: args.dst,
|
||||
src: pix,
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.decode_transform?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
var c8 : base.u8
|
||||
var transform_type : base.u32[..= 3]
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var p : slice base.u8
|
||||
|
||||
if this.n_bits < 2 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 2 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 2
|
||||
}
|
||||
transform_type = this.bits & 3
|
||||
this.bits >>= 2
|
||||
this.n_bits -= 2
|
||||
|
||||
if this.seen_transform[transform_type] or (this.n_transforms >= 4) {
|
||||
return "#bad transform"
|
||||
} else if this.seen_transform[3] {
|
||||
return "#unsupported transform after color indexing transform"
|
||||
}
|
||||
this.seen_transform[transform_type] = true
|
||||
this.transform_type[this.n_transforms] = transform_type as base.u8
|
||||
this.n_transforms += 1
|
||||
|
||||
if transform_type < 2 { // Predictor, Cross Color transform.
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
tile_size_log2 = (this.bits & 7) + 2
|
||||
this.transform_tile_size_log2[transform_type] = tile_size_log2 as base.u8
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
|
||||
while true,
|
||||
inv transform_type < 2,
|
||||
inv tile_size_log2 >= 2,
|
||||
{
|
||||
if ((this.workbuf_offset_for_transform[transform_type + 1] as base.u64) > (this.workbuf_offset_for_transform[transform_type + 2] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[transform_type + 2] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
status =? this.decode_pixels?(
|
||||
dst: args.workbuf[
|
||||
(this.workbuf_offset_for_transform[transform_type + 1] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[transform_type + 2] as base.u64)],
|
||||
src: args.src,
|
||||
width: (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
height: (this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
} else if transform_type == 2 { // Subtract Green transform.
|
||||
// No-op.
|
||||
|
||||
} else { // Color Indexing transform.
|
||||
if this.n_bits < 8 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 8 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 8
|
||||
}
|
||||
this.color_indexing_palette_size = (this.bits & 0xFF) + 1
|
||||
this.bits >>= 8
|
||||
this.n_bits -= 8
|
||||
|
||||
if this.color_indexing_palette_size <= 2 {
|
||||
this.color_indexing_width = (this.width + 7) / 8
|
||||
this.transform_tile_size_log2[3] = 3
|
||||
} else if this.color_indexing_palette_size <= 4 {
|
||||
this.color_indexing_width = (this.width + 3) / 4
|
||||
this.transform_tile_size_log2[3] = 2
|
||||
} else if this.color_indexing_palette_size <= 16 {
|
||||
this.color_indexing_width = (this.width + 1) / 2
|
||||
this.transform_tile_size_log2[3] = 1
|
||||
} else {
|
||||
this.color_indexing_width = this.width
|
||||
this.transform_tile_size_log2[3] = 0
|
||||
}
|
||||
|
||||
if this.width >= this.color_indexing_width {
|
||||
this.workbuf_offset_for_color_indexing = 4 * (this.width - this.color_indexing_width) * this.height
|
||||
}
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
|
||||
this.decode_pixels?(
|
||||
dst: this.palette[.. 4 * this.color_indexing_palette_size],
|
||||
src: args.src,
|
||||
width: this.color_indexing_palette_size,
|
||||
height: 1,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
this.palette[4 * this.color_indexing_palette_size .. 1024].bulk_memset!(byte_value: 0)
|
||||
|
||||
p = this.palette[.. 4 * this.color_indexing_palette_size]
|
||||
while p.length() >= 8 {
|
||||
p[4] ~mod+= p[0]
|
||||
p[5] ~mod+= p[1]
|
||||
p[6] ~mod+= p[2]
|
||||
p[7] ~mod+= p[3]
|
||||
p = p[4 ..]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_color_cache_parameters?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var use_color_cache : base.u32[..= 1]
|
||||
var color_cache_bits : base.u32[..= 15]
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_color_cache = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
this.color_cache_bits = 0
|
||||
if use_color_cache <> 0 {
|
||||
if this.n_bits < 4 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 4 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 4
|
||||
}
|
||||
color_cache_bits = this.bits & 15
|
||||
this.bits >>= 4
|
||||
this.n_bits -= 4
|
||||
|
||||
if (color_cache_bits < 1) or (11 < color_cache_bits) {
|
||||
return "#bad color cache"
|
||||
}
|
||||
this.color_cache_bits = color_cache_bits
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_hg_table?(src: base.io_reader, width: base.u32[..= 0x4000], workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
var c8 : base.u8
|
||||
var use_hg_table : base.u32[..= 1]
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var hg_pixels : slice base.u8
|
||||
var n : base.u64
|
||||
var p : roslice base.u8
|
||||
var hg_plus_1 : base.u32[..= 256]
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_hg_table = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if use_hg_table == 0 {
|
||||
this.overall_n_huffman_groups = 1
|
||||
this.overall_tile_size_log2 = 0
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
hg_pixels = args.workbuf[
|
||||
this.workbuf_offset_for_transform[0] as base.u64 ..
|
||||
this.workbuf_offset_for_transform[1] as base.u64]
|
||||
if hg_pixels.length() >= 4 {
|
||||
hg_pixels[0] = 0x00
|
||||
hg_pixels[1] = 0x00
|
||||
hg_pixels[2] = 0x00
|
||||
hg_pixels[3] = 0x00
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
tile_size_log2 = (this.bits & 7) + 2
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
this.overall_tile_size_log2 = tile_size_log2
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
while true,
|
||||
inv tile_size_log2 >= 2,
|
||||
{
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
status =? this.decode_pixels?(
|
||||
dst: args.workbuf[
|
||||
(this.workbuf_offset_for_transform[0] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[1] as base.u64)],
|
||||
src: args.src,
|
||||
width: (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
height: (this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
this.overall_n_huffman_groups = 1
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
hg_pixels = args.workbuf[
|
||||
this.workbuf_offset_for_transform[0] as base.u64 ..
|
||||
this.workbuf_offset_for_transform[1] as base.u64]
|
||||
n = (((args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2) *
|
||||
((this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2) *
|
||||
4) as base.u64
|
||||
if n > hg_pixels.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
p = hg_pixels[.. n]
|
||||
while p.length() >= 4 {
|
||||
if p[2] <> 0 {
|
||||
return "#unsupported number of Huffman groups"
|
||||
}
|
||||
hg_plus_1 = (p[1] as base.u32) + 1
|
||||
if this.overall_n_huffman_groups < hg_plus_1 {
|
||||
this.overall_n_huffman_groups = hg_plus_1
|
||||
}
|
||||
p = p[4 ..]
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_pixels?(dst: slice base.u8, src: base.io_reader, width: base.u32[..= 0x4000], height: base.u32[..= 0x4000], tile_data: roslice base.u8, tile_size_log2: base.u32[..= 9]) {
|
||||
var i : base.u32
|
||||
var n : base.u32[..= 2048]
|
||||
|
||||
i = 0
|
||||
n = (1 as base.u32) << this.color_cache_bits
|
||||
while i < n {
|
||||
assert i < 2048 via "a < b: a < c; c <= b"(c: n)
|
||||
this.color_cache[i] = 0
|
||||
i += 1
|
||||
}
|
||||
|
||||
this.decode_pixels_slow?(
|
||||
dst: args.dst,
|
||||
src: args.src,
|
||||
width: args.width,
|
||||
height: args.height,
|
||||
tile_data: args.tile_data,
|
||||
tile_size_log2: args.tile_size_log2)
|
||||
}
|
||||
|
||||
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: roslice base.u8, blend: base.pixel_blend) base.status {
|
||||
var status : base.status
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||
var dst_bytes_per_row : base.u64
|
||||
var dst_palette : slice base.u8
|
||||
var tab : table base.u8
|
||||
var src_bytes_per_row : base.u64
|
||||
var dst : slice base.u8
|
||||
var y : base.u32
|
||||
|
||||
status = this.swizzler.prepare!(
|
||||
dst_pixfmt: args.dst.pixel_format(),
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.palette[..]),
|
||||
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
|
||||
src_palette: this.util.empty_slice_u8(),
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
dst_pixfmt = args.dst.pixel_format()
|
||||
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
|
||||
if (dst_bits_per_pixel & 7) <> 0 {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||
dst_palette = args.dst.palette_or_else(fallback: this.palette[..])
|
||||
tab = args.dst.plane(p: 0)
|
||||
src_bytes_per_row = (this.width * 4) as base.u64
|
||||
|
||||
while src_bytes_per_row <= args.src.length() {
|
||||
dst = tab.row_u32(y: y)
|
||||
if dst_bytes_per_row < dst.length() {
|
||||
dst = dst[.. dst_bytes_per_row]
|
||||
}
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: args.src[.. src_bytes_per_row])
|
||||
|
||||
args.src = args.src[src_bytes_per_row ..]
|
||||
y ~mod+= 1
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
return this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height)
|
||||
}
|
||||
|
||||
pub func decoder.num_animation_loops() base.u32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 0x20 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 0x40 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 0x20 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if (args.index <> 0) or (args.io_position <> this.frame_config_io_position) {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 0x28
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: this.workbuf_offset_for_transform[3] as base.u64,
|
||||
max_incl: this.workbuf_offset_for_transform[3] as base.u64)
|
||||
}
|
||||
|
||||
pri const DISTANCE_MAP : roarray[120] base.u8 = [
|
||||
0x18, 0x07, 0x17, 0x19, 0x28, 0x06, 0x27, 0x29, 0x16, 0x1A,
|
||||
0x26, 0x2A, 0x38, 0x05, 0x37, 0x39, 0x15, 0x1B, 0x36, 0x3A,
|
||||
0x25, 0x2B, 0x48, 0x04, 0x47, 0x49, 0x14, 0x1C, 0x35, 0x3B,
|
||||
0x46, 0x4A, 0x24, 0x2C, 0x58, 0x45, 0x4B, 0x34, 0x3C, 0x03,
|
||||
0x57, 0x59, 0x13, 0x1D, 0x56, 0x5A, 0x23, 0x2D, 0x44, 0x4C,
|
||||
0x55, 0x5B, 0x33, 0x3D, 0x68, 0x02, 0x67, 0x69, 0x12, 0x1E,
|
||||
0x66, 0x6A, 0x22, 0x2E, 0x54, 0x5C, 0x43, 0x4D, 0x65, 0x6B,
|
||||
0x32, 0x3E, 0x78, 0x01, 0x77, 0x79, 0x53, 0x5D, 0x11, 0x1F,
|
||||
0x64, 0x6C, 0x42, 0x4E, 0x76, 0x7A, 0x21, 0x2F, 0x75, 0x7B,
|
||||
0x31, 0x3F, 0x63, 0x6D, 0x52, 0x5E, 0x00, 0x74, 0x7C, 0x41,
|
||||
0x4F, 0x10, 0x20, 0x62, 0x6E, 0x30, 0x73, 0x7D, 0x51, 0x5F,
|
||||
0x40, 0x72, 0x7E, 0x61, 0x6F, 0x50, 0x71, 0x7F, 0x60, 0x70,
|
||||
]
|
||||
@@ -69,7 +69,7 @@ pub func hasher.update!(x: roslice base.u8) {
|
||||
this.up!(x: args.x)
|
||||
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
@@ -135,7 +135,7 @@ pri func hasher.up!(x: roslice base.u8) {
|
||||
this.buf_data[this.buf_len] = args.x[0]
|
||||
this.buf_len += 1
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
buf_len = (this.buf_len & 15) as base.u32
|
||||
v0 = this.v0
|
||||
@@ -249,7 +249,7 @@ pub func hasher.checksum_u32() base.u32 {
|
||||
ret ~mod*= XXH_PRIME32_1
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
ret ^= ret >> 15
|
||||
ret ~mod*= XXH_PRIME32_2
|
||||
|
||||
@@ -138,7 +138,7 @@ pri func hasher.up!(x: roslice base.u8) {
|
||||
this.buf_data[this.buf_len] = args.x[0]
|
||||
this.buf_len += 1
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
buf_len = this.buf_len & 31
|
||||
v0 = this.v0
|
||||
@@ -330,7 +330,7 @@ pub func hasher.checksum_u64() base.u64 {
|
||||
ret ~mod*= XXH_PRIME64_1
|
||||
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
ret ^= ret >> 33
|
||||
ret ~mod*= XXH_PRIME64_2
|
||||
|
||||
@@ -0,0 +1,544 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.apply_non_final_filters!(dst_slice: slice base.u8) base.u8,
|
||||
choosy,
|
||||
{
|
||||
var f : base.u32[..= 2]
|
||||
var i : base.u64
|
||||
var filter_id : base.u32[..= 0x7F]
|
||||
var delta_dist : base.u32[..= 0x100]
|
||||
var delta_pos : base.u32
|
||||
var c8 : base.u8
|
||||
|
||||
if this.num_non_final_filters <= 0 {
|
||||
return 0
|
||||
}
|
||||
f = this.num_non_final_filters - 1
|
||||
|
||||
while true {
|
||||
filter_id = this.filters[f] & 0x7F
|
||||
if filter_id == 0x03 { // Delta.
|
||||
delta_dist = ((this.filters[f] >> 8) & 0xFF) + 1
|
||||
delta_pos = this.filters[f] >> 24
|
||||
i = 0
|
||||
while i < args.dst_slice.length() {
|
||||
assert i < 0xFFFF_FFFF_FFFF_FFFF via "a < b: a < c; c <= b"(c: args.dst_slice.length())
|
||||
c8 = args.dst_slice[i]
|
||||
c8 ~mod+= this.filter_data[f][(delta_dist ~mod+ delta_pos) & 0xFF]
|
||||
this.filter_data[f][delta_pos & 0xFF] = c8
|
||||
delta_pos ~mod-= 1
|
||||
args.dst_slice[i] = c8
|
||||
i += 1
|
||||
}
|
||||
this.filters[f] &= 0xFFFF
|
||||
this.filters[f] |= (delta_pos ~mod<< 24)
|
||||
}
|
||||
|
||||
if f <= 0 {
|
||||
break
|
||||
}
|
||||
f -= 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pri const FILTER_04_X86_MASK_TO_ALLOWED_STATUS : roarray[8] base.bool = [
|
||||
true, true, true, false, true, false, false, false,
|
||||
]
|
||||
|
||||
pri const FILTER_04_X86_MASK_TO_BIT_NUM : roarray[8] base.u8[..= 3] = [
|
||||
0, 1, 2, 2, 3, 3, 3, 3,
|
||||
]
|
||||
|
||||
pri const FILTER_04_X86_MASK_TO_XOR_OPERAND : roarray[8] base.u32 = [
|
||||
0xFFFF_FFFF,
|
||||
0x00FF_FFFF,
|
||||
0x0000_FFFF,
|
||||
0x0000_FFFF,
|
||||
0x0000_00FF,
|
||||
0x0000_00FF,
|
||||
0x0000_00FF,
|
||||
0x0000_00FF,
|
||||
]
|
||||
|
||||
pri func decoder.apply_filter_04_x86!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
|
||||
var i : base.u64
|
||||
var prev_pos : base.u64
|
||||
var prev_mask : base.u32
|
||||
var c8 : base.u8
|
||||
var src : base.u32
|
||||
var dst : base.u32
|
||||
var bit_num : base.u32[..= 3]
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos ~mod+ 5
|
||||
|
||||
prev_pos = 0xFFFF_FFFF_FFFF_FFFF
|
||||
prev_mask = this.bcj_x86_prev_mask
|
||||
|
||||
while s.length() >= 5,
|
||||
post s.length() < 5,
|
||||
{
|
||||
if (s[0] & 0xFE) <> 0xE8 {
|
||||
i ~mod+= 1
|
||||
p ~mod+= 1
|
||||
s = s[1 ..]
|
||||
continue
|
||||
}
|
||||
|
||||
prev_pos = i ~mod- prev_pos
|
||||
if prev_pos > 3 {
|
||||
prev_mask = 0
|
||||
} else if prev_pos > 0 {
|
||||
prev_mask = (prev_mask ~mod<< (prev_pos - 1)) & 7
|
||||
if prev_mask <> 0 {
|
||||
c8 = s[4 - FILTER_04_X86_MASK_TO_BIT_NUM[prev_mask & 7]]
|
||||
if (not FILTER_04_X86_MASK_TO_ALLOWED_STATUS[prev_mask & 7]) or
|
||||
(c8 == 0x00) or (c8 == 0xFF) {
|
||||
prev_pos = i
|
||||
prev_mask = (prev_mask ~mod<< 1) | 1
|
||||
i ~mod+= 1
|
||||
p ~mod+= 1
|
||||
s = s[1 ..]
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prev_pos = i
|
||||
|
||||
c8 = s[4]
|
||||
if (c8 <> 0x00) and (c8 <> 0xFF) {
|
||||
prev_mask = (prev_mask ~mod<< 1) | 1
|
||||
i ~mod+= 1
|
||||
p ~mod+= 1
|
||||
s = s[1 ..]
|
||||
continue
|
||||
}
|
||||
|
||||
src = ((s[1] as base.u32) << 0x00) |
|
||||
((s[2] as base.u32) << 0x08) |
|
||||
((s[3] as base.u32) << 0x10) |
|
||||
((s[4] as base.u32) << 0x18)
|
||||
|
||||
while true,
|
||||
inv s.length() >= 5,
|
||||
{
|
||||
dst = src ~mod- p
|
||||
if prev_mask == 0 {
|
||||
break
|
||||
}
|
||||
bit_num = FILTER_04_X86_MASK_TO_BIT_NUM[prev_mask & 7] as base.u32
|
||||
c8 = ((dst >> (24 - (bit_num * 8))) & 0xFF) as base.u8
|
||||
if (c8 <> 0x00) and (c8 <> 0xFF) {
|
||||
break
|
||||
}
|
||||
src = dst ^ FILTER_04_X86_MASK_TO_XOR_OPERAND[prev_mask & 7]
|
||||
}
|
||||
|
||||
dst &= 0x01FF_FFFF
|
||||
dst |= 0 ~mod- (dst & 0x0100_0000)
|
||||
s[1] = ((dst >> 0x00) & 0xFF) as base.u8
|
||||
s[2] = ((dst >> 0x08) & 0xFF) as base.u8
|
||||
s[3] = ((dst >> 0x10) & 0xFF) as base.u8
|
||||
s[4] = ((dst >> 0x18) & 0xFF) as base.u8
|
||||
|
||||
i ~mod+= 5
|
||||
p ~mod+= 5
|
||||
s = s[5 ..]
|
||||
}
|
||||
|
||||
prev_pos = i ~mod- prev_pos
|
||||
if prev_pos > 3 {
|
||||
this.bcj_x86_prev_mask = 0
|
||||
} else if prev_pos > 0 {
|
||||
this.bcj_x86_prev_mask = prev_mask ~mod<< (prev_pos - 1)
|
||||
}
|
||||
|
||||
this.bcj_pos = p ~mod- 5
|
||||
return s.length() as base.u8
|
||||
}
|
||||
|
||||
pri func decoder.apply_filter_05_powerpc!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
var x : base.u32
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos
|
||||
|
||||
while s.length() >= 4,
|
||||
post s.length() < 4,
|
||||
{
|
||||
x = ((s[0] as base.u32) << 0x18) |
|
||||
((s[1] as base.u32) << 0x10) |
|
||||
((s[2] as base.u32) << 0x08) |
|
||||
((s[3] as base.u32) << 0x00)
|
||||
if (x & 0xFC00_0003) == 0x4800_0001 {
|
||||
x = (((x & 0x03FF_FFFC) ~mod- p) & 0x03FF_FFFC) | 0x4800_0001
|
||||
s[0] = ((x >> 0x18) & 0xFF) as base.u8
|
||||
s[1] = ((x >> 0x10) & 0xFF) as base.u8
|
||||
s[2] = ((x >> 0x08) & 0xFF) as base.u8
|
||||
s[3] = ((x >> 0x00) & 0xFF) as base.u8
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
}
|
||||
|
||||
pri const FILTER_06_IA64_BRANCH_TABLE : roarray[32] base.u8[..= 7] = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 4, 6, 6, 0, 0, 7, 7,
|
||||
4, 4, 0, 0, 4, 4, 0, 0,
|
||||
]
|
||||
|
||||
pri func decoder.apply_filter_06_ia64!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
var mask : base.u32[..= 7]
|
||||
var slot : base.u32[..= 2]
|
||||
var bit_pos : base.u32[..= 87]
|
||||
var byte_pos : base.u32[..= 10]
|
||||
var bit_res : base.u32[..= 7]
|
||||
var x : base.u64
|
||||
var j : base.u32
|
||||
var norm : base.u64
|
||||
var addr : base.u32
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos
|
||||
|
||||
while s.length() >= 16,
|
||||
post s.length() < 16,
|
||||
{
|
||||
mask = FILTER_06_IA64_BRANCH_TABLE[s[0] & 0x1F] as base.u32
|
||||
|
||||
slot = 0
|
||||
while true,
|
||||
inv s.length() >= 16,
|
||||
{
|
||||
while.goto_done true,
|
||||
inv s.length() >= 16,
|
||||
{{
|
||||
if ((mask >> slot) & 1) == 0 {
|
||||
break.goto_done
|
||||
}
|
||||
|
||||
bit_pos = (slot * 41) + 5
|
||||
byte_pos = bit_pos >> 3
|
||||
bit_res = bit_pos & 7
|
||||
|
||||
x = 0
|
||||
j = 0
|
||||
while j < 6,
|
||||
inv s.length() >= 16,
|
||||
{
|
||||
x |= (s[j + byte_pos] as base.u64) << (8 * j)
|
||||
j += 1
|
||||
}
|
||||
|
||||
norm = x >> bit_res
|
||||
if (((norm >> 37) & 0x0F) <> 0x05) or
|
||||
(((norm >> 9) & 0x07) <> 0x00) {
|
||||
break.goto_done
|
||||
}
|
||||
|
||||
addr = ((norm >> 13) & 0x0F_FFFF) as base.u32
|
||||
addr |= (((norm >> 36) & 1) as base.u32) << 20
|
||||
addr <<= 4
|
||||
addr ~mod-= p
|
||||
addr >>= 4
|
||||
|
||||
norm &= 0xFFFF_FFEE_0000_1FFF
|
||||
norm |= ((addr & 0x0F_FFFF) as base.u64) << 13
|
||||
norm |= ((addr & 0x10_0000) as base.u64) << (36 - 20)
|
||||
|
||||
x &= ((1 as base.u64) << bit_res) - 1
|
||||
x |= norm ~mod<< bit_res
|
||||
j = 0
|
||||
while j < 6,
|
||||
inv s.length() >= 16,
|
||||
{
|
||||
s[j + byte_pos] = ((x >> (8 * j)) & 0xFF) as base.u8
|
||||
j += 1
|
||||
}
|
||||
|
||||
break.goto_done
|
||||
}}.goto_done
|
||||
|
||||
if slot >= 2 {
|
||||
break
|
||||
}
|
||||
slot += 1
|
||||
}
|
||||
|
||||
p ~mod+= 16
|
||||
s = s[16 ..]
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
}
|
||||
|
||||
pri func decoder.apply_filter_07_arm!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
var x : base.u32
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos ~mod+ 8
|
||||
|
||||
while s.length() >= 4,
|
||||
post s.length() < 4,
|
||||
{
|
||||
if s[3] == 0xEB {
|
||||
x = ((s[0] as base.u32) << 0x00) |
|
||||
((s[1] as base.u32) << 0x08) |
|
||||
((s[2] as base.u32) << 0x10) |
|
||||
((s[3] as base.u32) << 0x18)
|
||||
x = (((x & 0xFF_FFFF) << 2) ~mod- p) >> 2
|
||||
s[0] = ((x >> 0x00) & 0xFF) as base.u8
|
||||
s[1] = ((x >> 0x08) & 0xFF) as base.u8
|
||||
s[2] = ((x >> 0x10) & 0xFF) as base.u8
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
}
|
||||
|
||||
this.bcj_pos = p ~mod- 8
|
||||
return s.length() as base.u8
|
||||
}
|
||||
|
||||
pri func decoder.apply_filter_08_armthumb!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
var x : base.u32
|
||||
var y : base.u32
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos ~mod+ 4
|
||||
|
||||
while s.length() >= 4,
|
||||
post s.length() < 4,
|
||||
{
|
||||
x = ((s[0] as base.u32) << 0x00) |
|
||||
((s[1] as base.u32) << 0x08) |
|
||||
((s[2] as base.u32) << 0x10) |
|
||||
((s[3] as base.u32) << 0x18)
|
||||
if (x & 0xF800_F800) <> 0xF800_F000 {
|
||||
p ~mod+= 2
|
||||
s = s[2 ..]
|
||||
continue
|
||||
}
|
||||
y = (((s[0] & 0xFF) as base.u32) << 0x0B) |
|
||||
(((s[1] & 0x07) as base.u32) << 0x13) |
|
||||
(((s[2] & 0xFF) as base.u32) << 0x00) |
|
||||
(((s[3] & 0x07) as base.u32) << 0x08)
|
||||
y = ((y ~mod<< 1) ~mod- p) >> 1
|
||||
s[0] = (((y >> 0x0B) & 0xFF)) as base.u8
|
||||
s[1] = (((y >> 0x13) & 0x07) | 0xF0) as base.u8
|
||||
s[2] = (((y >> 0x00) & 0xFF)) as base.u8
|
||||
s[3] = (((y >> 0x08) & 0x07) | 0xF8) as base.u8
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
}
|
||||
|
||||
this.bcj_pos = p ~mod- 4
|
||||
return s.length() as base.u8
|
||||
}
|
||||
|
||||
pri func decoder.apply_filter_09_sparc!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
var x : base.u32
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos
|
||||
|
||||
while s.length() >= 4,
|
||||
post s.length() < 4,
|
||||
{
|
||||
x = ((s[0] as base.u32) << 0x18) |
|
||||
((s[1] as base.u32) << 0x10) |
|
||||
((s[2] as base.u32) << 0x08) |
|
||||
((s[3] as base.u32) << 0x00)
|
||||
if ((x >> 22) == 0x100) or ((x >> 22) == 0x1FF) {
|
||||
x = ((x ~mod<< 2) ~mod- p) >> 2
|
||||
x = (0x4000_0000 - (x & 0x40_0000)) | 0x4000_0000 | (x & 0x3F_FFFF)
|
||||
s[0] = ((x >> 0x18) & 0xFF) as base.u8
|
||||
s[1] = ((x >> 0x10) & 0xFF) as base.u8
|
||||
s[2] = ((x >> 0x08) & 0xFF) as base.u8
|
||||
s[3] = ((x >> 0x00) & 0xFF) as base.u8
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
}
|
||||
|
||||
pri func decoder.apply_filter_0a_arm64!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
var x : base.u32
|
||||
var y : base.u32
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos
|
||||
|
||||
while s.length() >= 4,
|
||||
post s.length() < 4,
|
||||
{
|
||||
x = ((s[0] as base.u32) << 0x00) |
|
||||
((s[1] as base.u32) << 0x08) |
|
||||
((s[2] as base.u32) << 0x10) |
|
||||
((s[3] as base.u32) << 0x18)
|
||||
if (x >> 26) == 0x25 {
|
||||
// Arm64 BL instruction.
|
||||
y = x ~mod- (p >> 2)
|
||||
x = 0x9400_0000 | (y & 0x03FF_FFFF)
|
||||
s[0] = ((x >> 0x00) & 0xFF) as base.u8
|
||||
s[1] = ((x >> 0x08) & 0xFF) as base.u8
|
||||
s[2] = ((x >> 0x10) & 0xFF) as base.u8
|
||||
s[3] = ((x >> 0x18) & 0xFF) as base.u8
|
||||
} else if (x & 0x9F00_0000) == 0x9000_0000 {
|
||||
// Arm64 ADRP instruction. We only modify relative addresses in the
|
||||
// range +/-512 MiB.
|
||||
y = ((x >> 29) & 0x03) | ((x >> 3) & 0x1F_FFFC)
|
||||
if ((y ~mod+ 0x02_0000) & 0x1C_0000) == 0 {
|
||||
y ~mod-= p >> 12
|
||||
x &= 0x9000_001F
|
||||
x |= (y & 3) << 29
|
||||
x |= (y & 0x03_FFFC) << 3
|
||||
x |= (0 ~mod- (y & 0x02_0000)) & 0xE0_0000
|
||||
s[0] = ((x >> 0x00) & 0xFF) as base.u8
|
||||
s[1] = ((x >> 0x08) & 0xFF) as base.u8
|
||||
s[2] = ((x >> 0x10) & 0xFF) as base.u8
|
||||
s[3] = ((x >> 0x18) & 0xFF) as base.u8
|
||||
}
|
||||
}
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
}
|
||||
|
||||
pri func decoder.apply_filter_0b_riscv!(dst_slice: slice base.u8) base.u8 {
|
||||
var s : slice base.u8
|
||||
var p : base.u32
|
||||
var x : base.u32
|
||||
var x27 : base.u32[..= 31]
|
||||
var y : base.u32
|
||||
var addr : base.u32
|
||||
|
||||
s = args.dst_slice
|
||||
p = this.bcj_pos
|
||||
|
||||
while s.length() >= 8,
|
||||
post s.length() < 8,
|
||||
{
|
||||
if s[0] == 0xEF {
|
||||
// RISC-V JAL instruction.
|
||||
if (s[1] & 0x0D) <> 0x00 {
|
||||
p ~mod+= 2
|
||||
s = s[2 ..]
|
||||
continue
|
||||
}
|
||||
addr = (((s[1] & 0xF0) as base.u32) << 13) |
|
||||
((s[2] as base.u32) << 9) |
|
||||
((s[3] as base.u32) << 1)
|
||||
addr ~mod-= p
|
||||
s[1] = (s[1] & 0x0F) |
|
||||
(((addr >> 8) & 0xF0) as base.u8)
|
||||
s[2] = (((addr >> 16) & 0x0F) |
|
||||
((addr >> 7) & 0x10) |
|
||||
((addr ~mod<< 4) & 0xE0)) as base.u8
|
||||
s[3] = (((addr >> 4) & 0x7F) |
|
||||
((addr >> 13) & 0x80)) as base.u8
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
continue
|
||||
|
||||
} else if (s[0] & 0x7F) == 0x17 {
|
||||
// RISC-V AUIPC instruction.
|
||||
x = ((s[0] as base.u32) << 0x00) |
|
||||
((s[1] as base.u32) << 0x08) |
|
||||
((s[2] as base.u32) << 0x10) |
|
||||
((s[3] as base.u32) << 0x18)
|
||||
|
||||
if (x & 0xE80) <> 0 {
|
||||
y = ((s[4] as base.u32) << 0x00) |
|
||||
((s[5] as base.u32) << 0x08) |
|
||||
((s[6] as base.u32) << 0x10) |
|
||||
((s[7] as base.u32) << 0x18)
|
||||
if (((x ~mod<< 8) ^ (y ~mod- 3)) & 0x000F_8003) <> 0 {
|
||||
p ~mod+= 6
|
||||
s = s[6 ..]
|
||||
continue
|
||||
}
|
||||
addr = (x & 0xFFFF_F000) | (y >> 20)
|
||||
x = 0x117 | (y ~mod<< 12)
|
||||
s[0] = ((x >> 0x00) & 0xFF) as base.u8
|
||||
s[1] = ((x >> 0x08) & 0xFF) as base.u8
|
||||
s[2] = ((x >> 0x10) & 0xFF) as base.u8
|
||||
s[3] = ((x >> 0x18) & 0xFF) as base.u8
|
||||
s[4] = ((addr >> 0x00) & 0xFF) as base.u8
|
||||
s[5] = ((addr >> 0x08) & 0xFF) as base.u8
|
||||
s[6] = ((addr >> 0x10) & 0xFF) as base.u8
|
||||
s[7] = ((addr >> 0x18) & 0xFF) as base.u8
|
||||
p ~mod+= 8
|
||||
s = s[8 ..]
|
||||
continue
|
||||
}
|
||||
|
||||
x27 = x >> 27
|
||||
if ((x ~mod- 0x3117) ~mod<< 18) >= (x27 & 0x1D) {
|
||||
p ~mod+= 4
|
||||
s = s[4 ..]
|
||||
continue
|
||||
}
|
||||
addr = ((s[4] as base.u32) << 0x18) |
|
||||
((s[5] as base.u32) << 0x10) |
|
||||
((s[6] as base.u32) << 0x08) |
|
||||
((s[7] as base.u32) << 0x00)
|
||||
addr ~mod-= p
|
||||
y = (x >> 12) | (addr ~mod<< 20)
|
||||
x = 0x17 | (x27 << 7) | ((addr ~mod+ 0x800) & 0xFFFF_F000)
|
||||
s[0] = ((x >> 0x00) & 0xFF) as base.u8
|
||||
s[1] = ((x >> 0x08) & 0xFF) as base.u8
|
||||
s[2] = ((x >> 0x10) & 0xFF) as base.u8
|
||||
s[3] = ((x >> 0x18) & 0xFF) as base.u8
|
||||
s[4] = ((y >> 0x00) & 0xFF) as base.u8
|
||||
s[5] = ((y >> 0x08) & 0xFF) as base.u8
|
||||
s[6] = ((y >> 0x10) & 0xFF) as base.u8
|
||||
s[7] = ((y >> 0x18) & 0xFF) as base.u8
|
||||
p ~mod+= 8
|
||||
s = s[8 ..]
|
||||
continue
|
||||
}
|
||||
|
||||
p ~mod+= 2
|
||||
s = s[2 ..]
|
||||
}
|
||||
|
||||
this.bcj_pos = p
|
||||
return s.length() as base.u8
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// Quirks are discussed in (/doc/note/quirks.md).
|
||||
//
|
||||
// The base38 encoding of "xz " is 0x1E1EBC. Left shifting by 10 gives
|
||||
// 0x787A_F000.
|
||||
pri const QUIRKS_BASE : base.u32 = 0x787A_F000
|
||||
|
||||
// --------
|
||||
|
||||
// When this quirk is set, a positive value means to allow one or more Streams
|
||||
// (which can have trailing Stream Padding). Zero means exactly one Stream (and
|
||||
// decoding stops at the end of that Stream; no Stream Padding is consumed).
|
||||
//
|
||||
// The XZ spec (section 2. Overall Structure of .xz File) says:
|
||||
//
|
||||
// While a typical file contains only one Stream and no Stream Padding, a
|
||||
// decoder handling standalone .xz files SHOULD support files that have more
|
||||
// than one Stream or Stream Padding.
|
||||
//
|
||||
// In contrast to standalone .xz files, when the .xz file format is used as
|
||||
// an internal part of some other file format or communication protocol, it
|
||||
// usually is expected that the decoder stops after the first Stream, and
|
||||
// doesn't look for Stream Padding or possibly other Streams.
|
||||
//
|
||||
// For Wuffs, the quirk value is zero by default, which means to decode the
|
||||
// XZ-as-part-of-something-else format, not the XZ-standalone format. Like most
|
||||
// of Wuffs' other std/foobar quirks, decoding a more lenient variant of the
|
||||
// foobar format is opt-in, not opt-out.
|
||||
pub const QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS : base.u32 = 0x787A_F000 | 0x00
|
||||
@@ -0,0 +1,829 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// --------
|
||||
|
||||
// See https://tukaani.org/xz/xz-file-format.txt
|
||||
|
||||
use "std/crc32"
|
||||
use "std/crc64"
|
||||
use "std/lzma"
|
||||
use "std/sha256"
|
||||
|
||||
pub status "#bad BCJ offset"
|
||||
pub status "#bad block header"
|
||||
pub status "#bad checksum"
|
||||
pub status "#bad filter"
|
||||
pub status "#bad footer"
|
||||
pub status "#bad header"
|
||||
pub status "#bad header (concatenated stream)"
|
||||
pub status "#bad index"
|
||||
pub status "#bad padding"
|
||||
pub status "#truncated input"
|
||||
pub status "#unsupported checksum algorithm"
|
||||
pub status "#unsupported filter"
|
||||
pub status "#unsupported filter combination"
|
||||
|
||||
pri status "#internal error: inconsistent BCJ filter state"
|
||||
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0xFFFF_FFFF + 273
|
||||
|
||||
pub struct decoder? implements base.io_transformer(
|
||||
filters : array[3] base.u32,
|
||||
num_non_final_filters : base.u32[..= 3],
|
||||
|
||||
// 0: None.
|
||||
// 1: CRC-32.
|
||||
// 2: CRC-64.
|
||||
// 3: SHA-256.
|
||||
checksummer : base.u8[..= 3],
|
||||
|
||||
ignore_checksum : base.bool,
|
||||
standalone_format : base.bool,
|
||||
|
||||
lzma_needs_reset : base.bool,
|
||||
|
||||
block_has_compressed_size : base.bool,
|
||||
block_has_uncompressed_size : base.bool,
|
||||
|
||||
bcj_undo_index : base.u8,
|
||||
bcj_pos : base.u32,
|
||||
bcj_x86_prev_mask : base.u32,
|
||||
|
||||
block_compressed_size : base.u64,
|
||||
block_uncompressed_size : base.u64,
|
||||
compressed_size_for_index : base.u64,
|
||||
|
||||
// Strictly speaking, we should verify that each block's compressed and
|
||||
// uncompressed sizes (as it is encountered during decoding the stream)
|
||||
// equals the per-block pair of sizes listed in the index at the end of
|
||||
// the file.
|
||||
//
|
||||
// This requires O(N) memory, where N is the number of blocks. Instead
|
||||
// (and the spec's "4.3. List of Records" suggests doing this), we can
|
||||
// use O(1) memory by just comparing a hash (and a total) of the
|
||||
// compressed and uncompressed sizes.
|
||||
//
|
||||
// This implementation uses a Murmur inspired hash function. It's given
|
||||
// u64 values (not u8) and the final mixing step is not required.
|
||||
//
|
||||
// For the array indexes: 0 is compressed, 1 is uncompressed.
|
||||
verification_have_hashed_sizes : array[2] base.u32,
|
||||
verification_want_hashed_sizes : array[2] base.u32,
|
||||
verification_have_total_sizes : array[2] base.u64,
|
||||
verification_want_total_sizes : array[2] base.u64,
|
||||
|
||||
num_actual_blocks : base.u64,
|
||||
num_index_blocks : base.u64,
|
||||
|
||||
index_block_compressed_size : base.u64,
|
||||
index_block_uncompressed_size : base.u64,
|
||||
|
||||
backwards_size : base.u64,
|
||||
|
||||
started_verify_index : base.bool,
|
||||
|
||||
flags : base.u16,
|
||||
|
||||
util : base.utility,
|
||||
) + (
|
||||
filter_data : array[3] array[256] base.u8,
|
||||
|
||||
crc32 : crc32.ieee_hasher,
|
||||
crc64 : crc64.ecma_hasher,
|
||||
sha256 : sha256.hasher,
|
||||
|
||||
lzma : lzma.decoder,
|
||||
)
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if args.key == base.QUIRK_IGNORE_CHECKSUM {
|
||||
if this.ignore_checksum {
|
||||
return 1
|
||||
}
|
||||
} else if args.key == QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS {
|
||||
if this.standalone_format {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
if args.key == base.QUIRK_IGNORE_CHECKSUM {
|
||||
this.ignore_checksum = args.value > 0
|
||||
return ok
|
||||
} else if args.key == QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS {
|
||||
this.standalone_format = args.value > 0
|
||||
return ok
|
||||
}
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.lzma.dst_history_retain_length()
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.lzma.workbuf_len()
|
||||
}
|
||||
|
||||
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var header_magic : base.u64
|
||||
var dmark : base.u64
|
||||
var smark : base.u64
|
||||
var i8 : base.u8
|
||||
var status : base.status
|
||||
var checksum32_have : base.u32
|
||||
var checksum32_want : base.u32
|
||||
var checksum64_have : base.u64
|
||||
var checksum64_want : base.u64
|
||||
var checksum256_have : base.bitvec256
|
||||
var compressed_size : base.u64
|
||||
var uncompressed_size : base.u64
|
||||
var hash : base.u32
|
||||
var c8 : base.u8
|
||||
var c32 : base.u32
|
||||
var footer_magic : base.u16
|
||||
|
||||
while.streams true {
|
||||
header_magic = args.src.read_u48le_as_u64?()
|
||||
if header_magic <> '\xFD\x37\x7A\x58\x5A\x00'le {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
// Read the 2-byte flags and the 4-byte CRC-32 checksum of those 2 bytes.
|
||||
header_magic = args.src.read_u48le_as_u64?()
|
||||
if header_magic == '\x00\x00\xFF\x12\xD9\x41'le {
|
||||
this.checksummer = 0 // None.
|
||||
} else if header_magic == '\x00\x01\x69\x22\xDE\x36'le {
|
||||
this.checksummer = 1 // CRC-32.
|
||||
} else if header_magic == '\x00\x04\xE6\xD6\xB4\x46'le {
|
||||
this.checksummer = 2 // CRC-64.
|
||||
} else if header_magic == '\x00\x0A\xE1\xFB\x0C\xA1'le {
|
||||
this.checksummer = 3 // SHA-256.
|
||||
} else if (header_magic & 0xF0FF) <> 0 {
|
||||
// Section 2.1.1.2. Stream Flags: "If any reserved bit is set, the
|
||||
// decoder MUST indicate an error."
|
||||
return "#bad header"
|
||||
} else {
|
||||
header_magic = 0xF & (header_magic >> 8)
|
||||
if (header_magic <> 0x0) and (header_magic <> 0x1) and (header_magic <> 0x4) and (header_magic <> 0xA) {
|
||||
return "#unsupported checksum algorithm"
|
||||
}
|
||||
return "#bad checksum"
|
||||
}
|
||||
this.flags = (header_magic & 0xFFFF) as base.u16
|
||||
|
||||
this.num_actual_blocks = 0
|
||||
while.blocks true {
|
||||
if args.src.length() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue.blocks
|
||||
} else if args.src.peek_u8() == 0x00 {
|
||||
// We've hit the Index instead of a Block.
|
||||
break.blocks
|
||||
}
|
||||
this.num_actual_blocks ~mod+= 1
|
||||
|
||||
if not this.ignore_checksum {
|
||||
this.crc32.reset!()
|
||||
}
|
||||
|
||||
this.compressed_size_for_index = 4 // For the upcoming 4-byte CRC-32.
|
||||
while true {
|
||||
smark = args.src.mark()
|
||||
status =? this.decode_block_header_with_padding?(src: args.src)
|
||||
this.compressed_size_for_index ~sat+= args.src.count_since(mark: smark)
|
||||
if not this.ignore_checksum {
|
||||
checksum32_have = this.crc32.update_u32!(x: args.src.since(mark: smark))
|
||||
}
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
checksum32_want = args.src.read_u32le?()
|
||||
if this.ignore_checksum {
|
||||
// No-op.
|
||||
} else if checksum32_have <> checksum32_want {
|
||||
return "#bad checksum"
|
||||
} else {
|
||||
this.crc32.reset!()
|
||||
this.crc64.reset!()
|
||||
this.sha256.reset!()
|
||||
}
|
||||
|
||||
compressed_size = 0
|
||||
uncompressed_size = 0
|
||||
while true {
|
||||
if (this.bcj_undo_index as base.u64) > args.dst.length() {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
}
|
||||
|
||||
dmark = args.dst.mark()
|
||||
smark = args.src.mark()
|
||||
if this.num_non_final_filters == 0 {
|
||||
status =? this.lzma.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
} else {
|
||||
if this.bcj_undo_index > 0 {
|
||||
args.dst.copy_from_slice!(s: this.filter_data[0][.. this.bcj_undo_index])
|
||||
this.bcj_undo_index = 0
|
||||
}
|
||||
|
||||
// The non-final filters will modify the args.dst contents so
|
||||
// that its history isn't what this.lzma considers its
|
||||
// (unfiltered) history.
|
||||
io_forget_history (io: args.dst) {
|
||||
status =? this.lzma.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
}
|
||||
|
||||
this.bcj_undo_index = this.apply_non_final_filters!(dst_slice: args.dst.since(mark: dmark))
|
||||
if (this.bcj_undo_index > 0) and (not status.is_ok()) {
|
||||
i8 = this.bcj_undo_index - 1
|
||||
while true {
|
||||
if not args.dst.can_undo_byte() {
|
||||
return "#internal error: inconsistent BCJ filter state"
|
||||
}
|
||||
this.filter_data[0][i8] = args.dst.peek_undo_byte()
|
||||
args.dst.undo_byte!()
|
||||
if i8 <= 0 {
|
||||
break
|
||||
}
|
||||
i8 -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
compressed_size ~mod+= args.src.count_since(mark: smark)
|
||||
uncompressed_size ~mod+= args.dst.count_since(mark: dmark)
|
||||
|
||||
if this.ignore_checksum {
|
||||
// No-op.
|
||||
} else if this.checksummer == 1 {
|
||||
this.crc32.update!(x: args.dst.since(mark: dmark))
|
||||
} else if this.checksummer == 2 {
|
||||
this.crc64.update!(x: args.dst.since(mark: dmark))
|
||||
} else if this.checksummer == 3 {
|
||||
this.sha256.update!(x: args.dst.since(mark: dmark))
|
||||
}
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
if (this.block_has_compressed_size and (this.block_compressed_size <> compressed_size)) or
|
||||
(this.block_has_uncompressed_size and (this.block_uncompressed_size <> uncompressed_size)) {
|
||||
return "#bad block header"
|
||||
}
|
||||
|
||||
// A block's 'compressed size' (as measured here) needs to match what's
|
||||
// listed in the index at the end of the XZ file. Per the XZ file
|
||||
// format specification, a block is:
|
||||
//
|
||||
// +==============+=================+===============+=======+
|
||||
// | Block Header | Compressed Data | Block Padding | Check |
|
||||
// +==============+=================+===============+=======+
|
||||
//
|
||||
// The compressed_size variable only measures the "Compressed Data"
|
||||
// portion. The 'compressed size for indexing purposes' needs to add
|
||||
// the size of the Block Header and the Check (but not the Block
|
||||
// Padding). this.compressed_size_for_index was initialized and
|
||||
// accumulated above to, at this point in time, hold the size of the
|
||||
// Block Header. We need to add the other two parts.
|
||||
this.compressed_size_for_index ~sat+= compressed_size
|
||||
this.compressed_size_for_index ~sat+= CHECKSUM_LENGTH[this.checksummer] as base.u64
|
||||
|
||||
// Update the verification_have_etc values. The hash function is
|
||||
// loosely based on https://en.wikipedia.org/wiki/MurmurHash#Algorithm
|
||||
this.verification_have_total_sizes[0] ~mod+= this.compressed_size_for_index
|
||||
hash = ((this.compressed_size_for_index ^ (this.compressed_size_for_index >> 32)) & 0xFFFF_FFFF) as base.u32
|
||||
hash ~mod*= 0xCC9E_2D51
|
||||
hash = (hash ~mod<< 15) | (hash >> 17)
|
||||
hash ~mod*= 0x1B87_3593
|
||||
hash ^= this.verification_have_hashed_sizes[0]
|
||||
hash = (hash ~mod<< 13) | (hash >> 19)
|
||||
this.verification_have_hashed_sizes[0] = (hash ~mod* 5) ~mod+ 0xE654_6B64
|
||||
this.verification_have_total_sizes[1] ~mod+= uncompressed_size
|
||||
hash = ((uncompressed_size ^ (uncompressed_size >> 32)) & 0xFFFF_FFFF) as base.u32
|
||||
hash ~mod*= 0xCC9E_2D51
|
||||
hash = (hash ~mod<< 15) | (hash >> 17)
|
||||
hash ~mod*= 0x1B87_3593
|
||||
hash ^= this.verification_have_hashed_sizes[1]
|
||||
hash = (hash ~mod<< 13) | (hash >> 19)
|
||||
this.verification_have_hashed_sizes[1] = (hash ~mod* 5) ~mod+ 0xE654_6B64
|
||||
|
||||
// Consume the "Block Padding".
|
||||
while (compressed_size & 3) <> 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x00 {
|
||||
return "#bad padding"
|
||||
}
|
||||
compressed_size ~mod+= 1
|
||||
}
|
||||
|
||||
this.lzma_needs_reset = true
|
||||
|
||||
if this.ignore_checksum {
|
||||
args.src.skip_u32?(n: CHECKSUM_LENGTH[this.checksummer] as base.u32)
|
||||
|
||||
} else if this.checksummer == 1 {
|
||||
checksum32_want = args.src.read_u32le?()
|
||||
checksum32_have = this.crc32.checksum_u32()
|
||||
if checksum32_have <> checksum32_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
|
||||
} else if this.checksummer == 2 {
|
||||
checksum64_want = args.src.read_u64le?()
|
||||
checksum64_have = this.crc64.checksum_u64()
|
||||
if checksum64_have <> checksum64_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
|
||||
} else if this.checksummer == 3 {
|
||||
checksum256_have = this.sha256.checksum_bitvec256()
|
||||
checksum64_want = args.src.read_u64be?()
|
||||
if checksum256_have.get_u64(i: 3) <> checksum64_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
checksum64_want = args.src.read_u64be?()
|
||||
if checksum256_have.get_u64(i: 2) <> checksum64_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
checksum64_want = args.src.read_u64be?()
|
||||
if checksum256_have.get_u64(i: 1) <> checksum64_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
checksum64_want = args.src.read_u64be?()
|
||||
if checksum256_have.get_u64(i: 0) <> checksum64_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
}.blocks
|
||||
|
||||
// Verify the index.
|
||||
this.backwards_size = 0
|
||||
if not this.ignore_checksum {
|
||||
this.crc32.reset!()
|
||||
}
|
||||
while true {
|
||||
smark = args.src.mark()
|
||||
status =? this.verify_index?(src: args.src)
|
||||
this.backwards_size ~sat+= args.src.count_since(mark: smark)
|
||||
if not this.ignore_checksum {
|
||||
this.crc32.update!(x: args.src.since(mark: smark))
|
||||
}
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
if not this.ignore_checksum {
|
||||
this.crc32.update!(x: ZEROES[.. 3 & (0 ~mod- (3 & this.backwards_size))])
|
||||
}
|
||||
while (this.backwards_size & 3) <> 0 {
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x00 {
|
||||
return "#bad index"
|
||||
}
|
||||
this.backwards_size ~mod+= 1
|
||||
}
|
||||
this.backwards_size >>= 2
|
||||
if (this.backwards_size == 0) or (this.backwards_size > 0xFFFF_FFFF) {
|
||||
return "#bad index"
|
||||
}
|
||||
checksum32_want = args.src.read_u32le?()
|
||||
if this.ignore_checksum {
|
||||
// No-op.
|
||||
} else if checksum32_want <> this.crc32.checksum_u32() {
|
||||
return "#bad checksum"
|
||||
} else {
|
||||
this.crc32.reset!()
|
||||
}
|
||||
|
||||
// Verify the footer.
|
||||
checksum32_want = args.src.read_u32le?()
|
||||
while true {
|
||||
smark = args.src.mark()
|
||||
status =? this.verify_footer?(src: args.src)
|
||||
if not this.ignore_checksum {
|
||||
this.crc32.update!(x: args.src.since(mark: smark))
|
||||
}
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
if (not this.ignore_checksum) and (checksum32_want <> this.crc32.checksum_u32()) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
footer_magic = args.src.read_u16le?()
|
||||
if footer_magic <> '\x59\x5A'le {
|
||||
return "#bad footer"
|
||||
}
|
||||
|
||||
if not this.standalone_format {
|
||||
break.streams
|
||||
}
|
||||
|
||||
// Consume any Stream Padding.
|
||||
while.stream_padding true {
|
||||
while args.src.length() < 4,
|
||||
post args.src.length() >= 4,
|
||||
{
|
||||
if args.src.is_closed() {
|
||||
if args.src.length() == 0 {
|
||||
break.streams
|
||||
} else {
|
||||
return "#truncated input"
|
||||
}
|
||||
}
|
||||
yield? base."$short read"
|
||||
}
|
||||
|
||||
c32 = args.src.peek_u32le()
|
||||
if c32 == '\xFD\x37\x7A\x58'le {
|
||||
break.stream_padding
|
||||
} else if c32 <> 0 {
|
||||
return "#bad header (concatenated stream)"
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
}.stream_padding
|
||||
this.started_verify_index = false
|
||||
}.streams
|
||||
}
|
||||
|
||||
pri func decoder.decode_block_header_with_padding?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var padded_size_have : base.u64
|
||||
var padded_size_want : base.u64
|
||||
var smark : base.u64
|
||||
var status : base.status
|
||||
|
||||
c8 = args.src.read_u8?()
|
||||
padded_size_want = ((c8 as base.u64) * 4) ~mod- 1
|
||||
|
||||
while true {
|
||||
smark = args.src.mark()
|
||||
status =? this.decode_block_header_sans_padding?(src: args.src)
|
||||
padded_size_have ~sat+= args.src.count_since(mark: smark)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
if padded_size_have > padded_size_want {
|
||||
return "#bad block header"
|
||||
}
|
||||
while padded_size_have < padded_size_want {
|
||||
assert padded_size_have < 0xFFFF_FFFF_FFFF_FFFF via "a < b: a < c; c <= b"(c: padded_size_want)
|
||||
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x00 {
|
||||
return "#bad block header"
|
||||
}
|
||||
|
||||
padded_size_have += 1
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_block_header_sans_padding?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var c32 : base.u32
|
||||
var alignment : base.u32
|
||||
var flags : base.u8
|
||||
var filter_id : base.u8
|
||||
var status : base.status
|
||||
var shift : base.u32
|
||||
var f : base.u32
|
||||
var k : base.u32
|
||||
|
||||
flags = args.src.read_u8?()
|
||||
this.num_non_final_filters = (flags & 0x03) as base.u32
|
||||
if (flags & 0x3C) <> 0 {
|
||||
return "#bad block header"
|
||||
}
|
||||
|
||||
this.block_has_compressed_size = (flags & 0x40) <> 0
|
||||
if this.block_has_compressed_size {
|
||||
// Read a uvarint (Unsigned LEB128) as this.block_compressed_size.
|
||||
this.block_compressed_size = 0
|
||||
shift = 0
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if shift <= 56 {
|
||||
this.block_compressed_size |= ((c8 & 0x7F) as base.u64) << shift
|
||||
if c8 >= 0x80 {
|
||||
shift += 7
|
||||
continue
|
||||
} else if (c8 == 0x00) and (shift > 0) {
|
||||
return "#bad block header"
|
||||
}
|
||||
break
|
||||
} else if c8 <> 1 {
|
||||
return "#bad block header"
|
||||
}
|
||||
this.block_compressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.block_has_uncompressed_size = (flags & 0x80) <> 0
|
||||
if this.block_has_uncompressed_size {
|
||||
// Read a uvarint (Unsigned LEB128) as this.block_uncompressed_size.
|
||||
this.block_uncompressed_size = 0
|
||||
shift = 0
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if shift <= 56 {
|
||||
this.block_uncompressed_size |= ((c8 & 0x7F) as base.u64) << shift
|
||||
if c8 >= 0x80 {
|
||||
shift += 7
|
||||
continue
|
||||
} else if (c8 == 0x00) and (shift > 0) {
|
||||
return "#bad block header"
|
||||
}
|
||||
break
|
||||
} else if c8 <> 1 {
|
||||
return "#bad block header"
|
||||
}
|
||||
this.block_uncompressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the non-final filters.
|
||||
|
||||
this.bcj_x86_prev_mask = 0
|
||||
choose apply_non_final_filters = [apply_non_final_filters]
|
||||
f = 0
|
||||
while f < this.num_non_final_filters {
|
||||
assert f < 3 via "a < b: a < c; c <= b"(c: this.num_non_final_filters)
|
||||
filter_id = args.src.read_u8?()
|
||||
if filter_id == 0x21 { // LZMA2
|
||||
return "#bad filter"
|
||||
|
||||
} else if filter_id == 0x03 { // Delta.
|
||||
// Delta's "Size of Properties" should be 1.
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x01 {
|
||||
return "#bad filter"
|
||||
}
|
||||
// Stash that 1 Properties byte on to the LZMA decoder.
|
||||
c8 = args.src.read_u8?()
|
||||
this.filters[f] = ((c8 as base.u32) << 8) | 0x03
|
||||
|
||||
k = 0
|
||||
while k < 0x100,
|
||||
inv f < 3,
|
||||
{
|
||||
this.filter_data[f][k] = 0x00
|
||||
k += 1
|
||||
}
|
||||
|
||||
} else if (filter_id < 0x03) or (0x0B < filter_id) {
|
||||
return "#unsupported filter"
|
||||
} else if f <> 0 {
|
||||
// We only support BCJ (Branch, Call, Jump) filters if they're the
|
||||
// only filter (other than LZMA2). This simplifies their undo_byte
|
||||
// interaction with I/O suspension.
|
||||
return "#unsupported filter combination"
|
||||
} else {
|
||||
this.filters[f] = filter_id as base.u32
|
||||
if filter_id == 0x04 {
|
||||
choose apply_non_final_filters = [apply_filter_04_x86]
|
||||
} else if filter_id == 0x05 {
|
||||
choose apply_non_final_filters = [apply_filter_05_powerpc]
|
||||
} else if filter_id == 0x06 {
|
||||
choose apply_non_final_filters = [apply_filter_06_ia64]
|
||||
} else if filter_id == 0x07 {
|
||||
choose apply_non_final_filters = [apply_filter_07_arm]
|
||||
} else if filter_id == 0x08 {
|
||||
choose apply_non_final_filters = [apply_filter_08_armthumb]
|
||||
} else if filter_id == 0x09 {
|
||||
choose apply_non_final_filters = [apply_filter_09_sparc]
|
||||
} else if filter_id == 0x0A {
|
||||
choose apply_non_final_filters = [apply_filter_0a_arm64]
|
||||
} else {
|
||||
choose apply_non_final_filters = [apply_filter_0b_riscv]
|
||||
}
|
||||
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 == 0x00 {
|
||||
this.bcj_pos = 0
|
||||
} else if c8 == 0x04 {
|
||||
c32 = args.src.read_u32le?()
|
||||
alignment = BCJ_OFFSET_ALIGNMENT[filter_id] as base.u32
|
||||
if alignment > 0 {
|
||||
if (c32 % alignment) <> 0 {
|
||||
return "#bad BCJ offset"
|
||||
}
|
||||
}
|
||||
this.bcj_pos = c32
|
||||
} else {
|
||||
return "#unsupported filter"
|
||||
}
|
||||
}
|
||||
|
||||
f += 1
|
||||
}
|
||||
|
||||
// Configure the final filter (which must be LZMA2).
|
||||
|
||||
filter_id = args.src.read_u8?()
|
||||
if filter_id == 0x21 { // LZMA2
|
||||
if this.lzma_needs_reset {
|
||||
this.lzma.reset!()
|
||||
}
|
||||
// LZMA2's "Size of Properties" should be 1.
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0x01 {
|
||||
return "#bad filter"
|
||||
}
|
||||
// Pass that 1 Properties byte on to the LZMA decoder.
|
||||
c8 = args.src.read_u8?()
|
||||
status = this.lzma.set_quirk!(
|
||||
key: lzma.QUIRK_FORMAT_EXTENSION,
|
||||
value: 0x02 | ((c8 as base.u64) << 8))
|
||||
if not status.is_ok() {
|
||||
return "#bad filter"
|
||||
}
|
||||
|
||||
} else if (filter_id < 0x03) or (0x0B < filter_id) {
|
||||
return "#unsupported filter"
|
||||
|
||||
} else {
|
||||
return "#bad filter"
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.verify_index?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var shift : base.u32
|
||||
var hash : base.u32
|
||||
|
||||
if not this.started_verify_index {
|
||||
this.started_verify_index = true
|
||||
c8 = args.src.read_u8?()
|
||||
if c8 <> 0 {
|
||||
return "#bad index"
|
||||
}
|
||||
|
||||
this.num_index_blocks = 0
|
||||
shift = 0
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if shift <= 56 {
|
||||
this.num_index_blocks |= ((c8 & 0x7F) as base.u64) << shift
|
||||
if c8 >= 0x80 {
|
||||
shift += 7
|
||||
continue
|
||||
} else if (c8 == 0x00) and (shift > 0) {
|
||||
return "#bad index"
|
||||
}
|
||||
break
|
||||
} else if c8 <> 1 {
|
||||
return "#bad index"
|
||||
}
|
||||
this.num_index_blocks |= (1 as base.u64) << 63
|
||||
break
|
||||
}
|
||||
if this.num_index_blocks <> this.num_actual_blocks {
|
||||
return "#bad index"
|
||||
}
|
||||
}
|
||||
|
||||
while this.num_index_blocks > 0 {
|
||||
this.num_index_blocks -= 1
|
||||
|
||||
this.index_block_compressed_size = 0
|
||||
shift = 0
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if shift <= 56 {
|
||||
this.index_block_compressed_size |= ((c8 & 0x7F) as base.u64) << shift
|
||||
if c8 >= 0x80 {
|
||||
shift += 7
|
||||
continue
|
||||
} else if (c8 == 0x00) and (shift > 0) {
|
||||
return "#bad index"
|
||||
}
|
||||
break
|
||||
} else if c8 <> 1 {
|
||||
return "#bad index"
|
||||
}
|
||||
this.index_block_compressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
}
|
||||
|
||||
this.index_block_uncompressed_size = 0
|
||||
shift = 0
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
if shift <= 56 {
|
||||
this.index_block_uncompressed_size |= ((c8 & 0x7F) as base.u64) << shift
|
||||
if c8 >= 0x80 {
|
||||
shift += 7
|
||||
continue
|
||||
} else if (c8 == 0x00) and (shift > 0) {
|
||||
return "#bad index"
|
||||
}
|
||||
break
|
||||
} else if c8 <> 1 {
|
||||
return "#bad index"
|
||||
}
|
||||
this.index_block_uncompressed_size |= (1 as base.u64) << 63
|
||||
break
|
||||
}
|
||||
|
||||
// Update the verification_want_etc values. The hash function is
|
||||
// loosely based on https://en.wikipedia.org/wiki/MurmurHash#Algorithm
|
||||
this.verification_want_total_sizes[0] ~mod+= this.index_block_compressed_size
|
||||
hash = ((this.index_block_compressed_size ^ (this.index_block_compressed_size >> 32)) & 0xFFFF_FFFF) as base.u32
|
||||
hash ~mod*= 0xCC9E_2D51
|
||||
hash = (hash ~mod<< 15) | (hash >> 17)
|
||||
hash ~mod*= 0x1B87_3593
|
||||
hash ^= this.verification_want_hashed_sizes[0]
|
||||
hash = (hash ~mod<< 13) | (hash >> 19)
|
||||
this.verification_want_hashed_sizes[0] = (hash ~mod* 5) ~mod+ 0xE654_6B64
|
||||
this.verification_want_total_sizes[1] ~mod+= this.index_block_uncompressed_size
|
||||
hash = ((this.index_block_uncompressed_size ^ (this.index_block_uncompressed_size >> 32)) & 0xFFFF_FFFF) as base.u32
|
||||
hash ~mod*= 0xCC9E_2D51
|
||||
hash = (hash ~mod<< 15) | (hash >> 17)
|
||||
hash ~mod*= 0x1B87_3593
|
||||
hash ^= this.verification_want_hashed_sizes[1]
|
||||
hash = (hash ~mod<< 13) | (hash >> 19)
|
||||
this.verification_want_hashed_sizes[1] = (hash ~mod* 5) ~mod+ 0xE654_6B64
|
||||
}
|
||||
|
||||
if (this.verification_have_hashed_sizes[0] <> this.verification_want_hashed_sizes[0]) or
|
||||
(this.verification_have_hashed_sizes[1] <> this.verification_want_hashed_sizes[1]) or
|
||||
(this.verification_have_total_sizes[0] <> this.verification_want_total_sizes[0]) or
|
||||
(this.verification_have_total_sizes[1] <> this.verification_want_total_sizes[1]) {
|
||||
return "#bad index"
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.verify_footer?(src: base.io_reader) {
|
||||
var c32 : base.u32
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if c32 <> ((this.backwards_size & 0xFFFF_FFFF) as base.u32) {
|
||||
return "#bad footer"
|
||||
}
|
||||
|
||||
c32 = args.src.read_u16le_as_u32?()
|
||||
if c32 <> (this.flags as base.u32) {
|
||||
return "#bad footer"
|
||||
}
|
||||
}
|
||||
|
||||
pri const CHECKSUM_LENGTH : roarray[4] base.u8 = [
|
||||
0x00, // 0: None.
|
||||
0x04, // 1: CRC-32.
|
||||
0x08, // 2: CRC-64.
|
||||
0x20, // 3: SHA-256.
|
||||
]
|
||||
|
||||
pri const ZEROES : roarray[3] base.u8 = [0, 0, 0]
|
||||
|
||||
// See https://tukaani.org/xz/xz-file-format.txt section 5.3.2.
|
||||
// Branch/Call/Jump Filters for Executables.
|
||||
pri const BCJ_OFFSET_ALIGNMENT : roarray[12] base.u8 = [
|
||||
0x00, // 0x00: Unused.
|
||||
0x00, // 0x01: Unused.
|
||||
0x00, // 0x02: Unused.
|
||||
0x00, // 0x03: Unused.
|
||||
0x01, // 0x04: x86.
|
||||
0x04, // 0x05: powerpc.
|
||||
0x10, // 0x06: ia64.
|
||||
0x04, // 0x07: arm.
|
||||
0x02, // 0x08: armthumb.
|
||||
0x04, // 0x09: sparc.
|
||||
0x04, // 0x0A: arm64.
|
||||
0x02, // 0x0B: riscv.
|
||||
]
|
||||
+12
-12
@@ -20,7 +20,7 @@ pub status "#bad parity check"
|
||||
pub status "#incorrect dictionary"
|
||||
pub status "#truncated input"
|
||||
|
||||
pub const DECODER_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
// TODO: reference deflate.DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE.
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
|
||||
@@ -38,7 +38,7 @@ pub struct decoder? implements base.io_transformer(
|
||||
checksum : adler32.hasher,
|
||||
|
||||
dict_id_hasher : adler32.hasher,
|
||||
dict_id_got : base.u32,
|
||||
dict_id_have : base.u32,
|
||||
dict_id_want : base.u32,
|
||||
|
||||
flate : deflate.decoder,
|
||||
@@ -54,7 +54,7 @@ pub func decoder.add_dictionary!(dict: slice base.u8) {
|
||||
if this.header_complete {
|
||||
this.bad_call_sequence = true
|
||||
} else {
|
||||
this.dict_id_got = this.dict_id_hasher.update_u32!(x: args.dict)
|
||||
this.dict_id_have = this.dict_id_hasher.update_u32!(x: args.dict)
|
||||
this.flate.add_history!(hist: args.dict)
|
||||
}
|
||||
this.got_dictionary = true
|
||||
@@ -93,8 +93,8 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func decoder.history_retain_length() base.u64 {
|
||||
return 0
|
||||
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
||||
return this.util.make_optional_u63(has_value: true, value: 0)
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
@@ -112,12 +112,12 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
var x : base.u16
|
||||
var checksum_got : base.u32
|
||||
var checksum_have : base.u32
|
||||
var status : base.status
|
||||
var checksum_want : base.u32
|
||||
var mark : base.u64
|
||||
@@ -139,13 +139,13 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
}
|
||||
this.want_dictionary = (x & 0x20) <> 0
|
||||
if this.want_dictionary {
|
||||
this.dict_id_got = 1 // Adler-32 initial value.
|
||||
this.dict_id_have = 1 // Adler-32 initial value.
|
||||
this.dict_id_want = args.src.read_u32be?()
|
||||
return "@dictionary required"
|
||||
} else if this.got_dictionary {
|
||||
return "#incorrect dictionary"
|
||||
}
|
||||
} else if this.dict_id_got <> this.dict_id_want {
|
||||
} else if this.dict_id_have <> this.dict_id_want {
|
||||
if this.got_dictionary {
|
||||
return "#incorrect dictionary"
|
||||
}
|
||||
@@ -159,17 +159,17 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
mark = args.dst.mark()
|
||||
status =? this.flate.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if (not this.ignore_checksum) and (not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE]) {
|
||||
checksum_got = this.checksum.update_u32!(x: args.dst.since(mark: mark))
|
||||
checksum_have = this.checksum.update_u32!(x: args.dst.since(mark: mark))
|
||||
}
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
|
||||
checksum_want = args.src.read_u32be?()
|
||||
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
|
||||
if (not this.ignore_checksum) and (checksum_have <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check out a specific commit (from June 2023).
|
||||
git clone --quiet --depth=1 https://github.com/nigeltao/blink-web-tests-images-resources.git
|
||||
# Check out a specific commit (from May 2023).
|
||||
git clone --quiet https://github.com/nigeltao/blink-web-tests-images-resources.git
|
||||
cd blink-web-tests-images-resources
|
||||
git reset --quiet --hard 9c5a6768184e5b45eaddad8f83ffd87dc5dc8f15
|
||||
cd ..
|
||||
|
||||
@@ -18,8 +18,8 @@ if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check out a specific commit (from June 2023).
|
||||
git clone --quiet --depth=1 https://github.com/nigeltao/golang-go-src-image-testdata.git
|
||||
# Check out a specific commit (from May 2023).
|
||||
git clone --quiet https://github.com/nigeltao/golang-go-src-image-testdata.git
|
||||
cd golang-go-src-image-testdata
|
||||
git reset --quiet --hard f2f7970f9054b910148be4e0dbda94b392c58700
|
||||
cd ..
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2024 The Wuffs Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
# option. This file may not be copied, modified, or distributed
|
||||
# except according to those terms.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
# ----------------
|
||||
|
||||
# This script fetches libwebp's test data suite.
|
||||
|
||||
if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
echo "$0 should be run from the Wuffs test/3pdata directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check out a specific commit (from July 2024).
|
||||
git clone --quiet https://github.com/webmproject/libwebp-test-data.git webpsuite
|
||||
cd webpsuite
|
||||
git reset --quiet --hard 260804d686f0491e0326a50eef491829dae09e9e
|
||||
Executable
+105
@@ -0,0 +1,105 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2023 The Wuffs Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
# option. This file may not be copied, modified, or distributed
|
||||
# except according to those terms.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
# ----------------
|
||||
|
||||
# This script fetches xz's tests/files suite.
|
||||
|
||||
if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
echo "$0 should be run from the Wuffs test/3pdata directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check out a specific commit (from February 2024).
|
||||
#
|
||||
# ---
|
||||
#
|
||||
# The remaining comment below was written on 2024-04-05.
|
||||
#
|
||||
# YYYY-MM-DD dates might appear off by one, due to timezones.
|
||||
#
|
||||
# ---
|
||||
#
|
||||
# The nigeltao/xz-tests-files repository is a mirror of binary data (test
|
||||
# files). It combines test files from two git repositories:
|
||||
#
|
||||
# - https://github.com/tukaani-project/xz
|
||||
# - https://www.nongnu.org/lzip/
|
||||
#
|
||||
# ---
|
||||
#
|
||||
# The https://github.com/tukaani-project/xz git repository (a mirror of the
|
||||
# canonical xz repository) was recently taken offline. It was compromised and
|
||||
# contains a backdoor:
|
||||
#
|
||||
# - https://www.openwall.com/lists/oss-security/2024/03/29/4
|
||||
#
|
||||
# The canonical xz git repository is still online at:
|
||||
#
|
||||
# - https://git.tukaani.org/?p=xz.git
|
||||
#
|
||||
# ---
|
||||
#
|
||||
# As of nigeltao/xz-tests-files's 6e0194063a6dc205d4db35e307778efe1c9f1875,
|
||||
# that repo's mirroring of the xz repo's tests/files directory was most
|
||||
# recently updated by d082a076f3e1da05aa478eac4bbba24744b3a1c0 on 2024-02-13,
|
||||
# the commit immediately prior to 6e0194063a6dc205d4db35e307778efe1c9f1875:
|
||||
#
|
||||
# - https://github.com/nigeltao/xz-tests-files/commit/d082a076f3e1da05aa478eac4bbba24744b3a1c0
|
||||
# - https://github.com/nigeltao/xz-tests-files/commit/6e0194063a6dc205d4db35e307778efe1c9f1875
|
||||
#
|
||||
# ---
|
||||
#
|
||||
# nigeltao/xz-tests-files at 6e0194063a6dc205d4db35e307778efe1c9f1875 does
|
||||
# *not* contain the known-to-smuggle-malicious-payloads test files committed by
|
||||
# Jia Tan on 2024-02-23 and 2024-03-09. It also excludes Jia Tan's possibly
|
||||
# harmless update to the RISC-V test files (also on 2024-03-09). Specifically,
|
||||
# nigeltao/xz-tests-files does not contain these five files:
|
||||
#
|
||||
# - tests/files/bad-3-corrupt_lzma2.xz
|
||||
# - tests/files/bad-dict_size.lzma
|
||||
# - tests/files/good-2cat.xz
|
||||
# - tests/files/good-large_compressed.lzma
|
||||
# - tests/files/good-small_compressed.lzma
|
||||
#
|
||||
# They were added and updated to the xz repo by Jia Tan in:
|
||||
#
|
||||
# - https://git.tukaani.org/?p=xz.git;a=commit;h=cf44e4b7f5dfdbf8c78aef377c10f71e274f63c0
|
||||
# - https://git.tukaani.org/?p=xz.git;a=commit;h=6e636819e8f070330d835fce46289a3ff72a7b89
|
||||
#
|
||||
# The possibly-harmless RISC-V test files update was:
|
||||
#
|
||||
# - https://git.tukaani.org/?p=xz.git;a=commit;h=0b4ccc91454dbcf0bf521b9bd51aa270581ee23c
|
||||
#
|
||||
# ---
|
||||
#
|
||||
# nigeltao/xz-tests-files does admittedly contain these two files:
|
||||
#
|
||||
# - tests/files/good-1-riscv-lzma2-1.xz
|
||||
# - tests/files/good-1-riscv-lzma2-2.xz
|
||||
#
|
||||
# They were added and updated to the xz repo by Jia Tan on 2024-01-22 and
|
||||
# 2024-01-23 (and 2024-03-09, as mentioned above, but that's excluded):
|
||||
#
|
||||
# - https://git.tukaani.org/?p=xz.git;a=commit;h=e2870db5be1503e6a489fc3d47daf950d6f62723
|
||||
# - https://git.tukaani.org/?p=xz.git;a=commit;h=3060e1070b2421b26c0e17794c1307ec5622f11d
|
||||
#
|
||||
# These two files (before or after the 0b4ccc91454dbcf0bf521b9bd51aa270581ee23c
|
||||
# 2024-03-09 excluded update) are not believed to be malicious.
|
||||
git clone --quiet https://github.com/nigeltao/xz-tests-files.git
|
||||
cd xz-tests-files
|
||||
git reset --quiet --hard 6e0194063a6dc205d4db35e307778efe1c9f1875
|
||||
cd ..
|
||||
|
||||
# Trim the git metadata.
|
||||
rm -rf xzsuite
|
||||
rm -rf xz-tests-files/.git
|
||||
mv xz-tests-files xzsuite
|
||||
@@ -0,0 +1,80 @@
|
||||
# Generated by script/print-mzcat-checksums.sh
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-block_header-4.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-block_header-5.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-check-crc32-2.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-check-crc32.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-check-crc64.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-check-sha256.xz
|
||||
BAD a3de2f0d test/3pdata/xzsuite/bad-1-lzma2-10.xz
|
||||
BAD 7d14dddd test/3pdata/xzsuite/bad-1-lzma2-11.xz
|
||||
BAD 7759aecd test/3pdata/xzsuite/bad-1-lzma2-2.xz
|
||||
BAD 7759aecd test/3pdata/xzsuite/bad-1-lzma2-3.xz
|
||||
BAD 6fcaba82 test/3pdata/xzsuite/bad-1-lzma2-4.xz
|
||||
BAD 6fcaba82 test/3pdata/xzsuite/bad-1-lzma2-5.xz
|
||||
BAD 31963516 test/3pdata/xzsuite/bad-1-lzma2-6.xz
|
||||
BAD db4847fb test/3pdata/xzsuite/bad-1-lzma2-7.xz
|
||||
BAD 7759aecd test/3pdata/xzsuite/bad-1-lzma2-8.xz
|
||||
BAD 3b80e9ac test/3pdata/xzsuite/bad-1-lzma2-9.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-stream_flags-1.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-stream_flags-3.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-v1-crc32.lz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-v1-member-size.lz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-v1-trailing-magic.lz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-v1-uncomp-size.lz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-1-vli-2.xz
|
||||
BAD 31963516 test/3pdata/xzsuite/bad-2-compressed_data_padding.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-2-index-1.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-2-index-2.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-2-index-3.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-2-index-4.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-2-index-5.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-3-index-uncomp-overflow.xz
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-too_big_size-with_eopm.lzma
|
||||
BAD 77e47a71 test/3pdata/xzsuite/bad-too_small_size-without_eopm-1.lzma
|
||||
BAD dd46b7fb test/3pdata/xzsuite/bad-too_small_size-without_eopm-2.lzma
|
||||
BAD bdc79ef1 test/3pdata/xzsuite/bad-too_small_size-without_eopm-3.lzma
|
||||
BAD 15a2a343 test/3pdata/xzsuite/bad-unknown_size-without_eopm.lzma
|
||||
OK. 00000000 test/3pdata/xzsuite/good-0-empty.xz
|
||||
OK. 00000000 test/3pdata/xzsuite/good-0cat-empty.xz
|
||||
OK. 00000000 test/3pdata/xzsuite/good-0catpad-empty.xz
|
||||
OK. 00000000 test/3pdata/xzsuite/good-0pad-empty.xz
|
||||
OK. db4847fb test/3pdata/xzsuite/good-1-3delta-lzma2.xz
|
||||
OK. d4e17ca0 test/3pdata/xzsuite/good-1-arm64-lzma2-1.xz
|
||||
OK. d4e17ca0 test/3pdata/xzsuite/good-1-arm64-lzma2-2.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-block_header-1.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-block_header-2.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-block_header-3.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-check-crc32.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-check-crc64.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-check-none.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-check-sha256.xz
|
||||
OK. f7c66eb5 test/3pdata/xzsuite/good-1-delta-lzma2.tiff.xz
|
||||
OK. 00000000 test/3pdata/xzsuite/good-1-empty-bcj-lzma2.xz
|
||||
OK. db4847fb test/3pdata/xzsuite/good-1-lzma2-1.xz
|
||||
OK. db4847fb test/3pdata/xzsuite/good-1-lzma2-2.xz
|
||||
OK. db4847fb test/3pdata/xzsuite/good-1-lzma2-3.xz
|
||||
OK. db4847fb test/3pdata/xzsuite/good-1-lzma2-4.xz
|
||||
OK. 00000000 test/3pdata/xzsuite/good-1-lzma2-5.xz
|
||||
OK. 9d269cdc test/3pdata/xzsuite/good-1-riscv-lzma2-1.xz
|
||||
OK. 8d115715 test/3pdata/xzsuite/good-1-riscv-lzma2-2.xz
|
||||
OK. cc270da1 test/3pdata/xzsuite/good-1-sparc-lzma2.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-v1-trailing-1.lz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-v1-trailing-2.lz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-1-v1.lz
|
||||
OK. a3679091 test/3pdata/xzsuite/good-1-x86-lzma2.xz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-2-lzma2.xz
|
||||
BAD 31963516 test/3pdata/xzsuite/good-2-v1-v0.lz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-2-v1-v1.lz
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-known_size-with_eopm.lzma
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-known_size-without_eopm.lzma
|
||||
OK. 15a2a343 test/3pdata/xzsuite/good-unknown_size-with_eopm.lzma
|
||||
OK. eb50cc6a test/3pdata/xzsuite/lzip-testsuite/fox.lz
|
||||
OK. 889dda54 test/3pdata/xzsuite/lzip-testsuite/fox6.lz
|
||||
OK. 889dda54 test/3pdata/xzsuite/lzip-testsuite/fox6_mark.lz
|
||||
BAD eb50cc6a test/3pdata/xzsuite/lzip-testsuite/fox_bcrc.lz
|
||||
BAD eb50cc6a test/3pdata/xzsuite/lzip-testsuite/fox_crc0.lz
|
||||
BAD eb50cc6a test/3pdata/xzsuite/lzip-testsuite/fox_das46.lz
|
||||
BAD 284fd1b0 test/3pdata/xzsuite/lzip-testsuite/fox_de20.lz
|
||||
BAD eb50cc6a test/3pdata/xzsuite/lzip-testsuite/fox_mes81.lz
|
||||
OK. a2930e54 test/3pdata/xzsuite/lzip-testsuite/test.txt.lz
|
||||
OK. a2930e54 test/3pdata/xzsuite/lzip-testsuite/test_em.txt.lz
|
||||
@@ -1,189 +1,191 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
912861f4 test/3pdata/blinksuite/0x0.bmp
|
||||
1283a492 test/3pdata/blinksuite/12-55.jpg
|
||||
69fc7dee test/3pdata/blinksuite/182.jpg
|
||||
09d06f47 test/3pdata/blinksuite/2-comp.jpg
|
||||
1f0a869f test/3pdata/blinksuite/2-dht.jpg
|
||||
d7865c25 test/3pdata/blinksuite/23-55.jpg
|
||||
361f7557 test/3pdata/blinksuite/5000x5000.png
|
||||
4920fb2a test/3pdata/blinksuite/55.jpg
|
||||
e2c0805a test/3pdata/blinksuite/57.jpg
|
||||
1542e2e1 test/3pdata/blinksuite/58.jpg
|
||||
da174c34 test/3pdata/blinksuite/59.jpg
|
||||
89f95c0f test/3pdata/blinksuite/animated-10color-fast.gif
|
||||
824e8906 test/3pdata/blinksuite/animated-10color.gif
|
||||
3332edad test/3pdata/blinksuite/animated-gif-with-offsets.gif
|
||||
c5ed1e55 test/3pdata/blinksuite/animated.gif
|
||||
8a0e1335 test/3pdata/blinksuite/animated2.gif
|
||||
10f62511 test/3pdata/blinksuite/apng00.png
|
||||
3c2e7f59 test/3pdata/blinksuite/apng01.png
|
||||
a6174a21 test/3pdata/blinksuite/apng08-ref.png
|
||||
eb5d9458 test/3pdata/blinksuite/apng18.png
|
||||
41fbee02 test/3pdata/blinksuite/apng24-ref.png
|
||||
f868aa62 test/3pdata/blinksuite/apng24.png
|
||||
e9f8e40c test/3pdata/blinksuite/apng26-ref.png
|
||||
689d3f62 test/3pdata/blinksuite/apng26.png
|
||||
045c6c9d test/3pdata/blinksuite/avif/red.png
|
||||
3ef592d6 test/3pdata/blinksuite/avif/silver.png
|
||||
1a9bf966 test/3pdata/blinksuite/base-test-resources/success.png
|
||||
d9f8441c test/3pdata/blinksuite/blue-10.png
|
||||
267741e0 test/3pdata/blinksuite/blue-100.png
|
||||
89449c01 test/3pdata/blinksuite/blue-wheel-srgb-color-profile.jpg
|
||||
8fce70a9 test/3pdata/blinksuite/blue-wheel-srgb-color-profile.png
|
||||
2d7bad9f test/3pdata/blinksuite/border-image-srgb-color-profile.png
|
||||
9ca73f21 test/3pdata/blinksuite/border-image.png
|
||||
277600f9 test/3pdata/blinksuite/boston.gif
|
||||
ffc8a627 test/3pdata/blinksuite/bug106024.jpg
|
||||
18cee321 test/3pdata/blinksuite/cHRM_color_spin.png
|
||||
3e460fe4 test/3pdata/blinksuite/cat.jpg
|
||||
e9151f0e test/3pdata/blinksuite/cicp_pq.png
|
||||
ab6d7d2e test/3pdata/blinksuite/cmyk-jpeg.jpg
|
||||
5ec78d7c test/3pdata/blinksuite/color-checker-adobe-color-profile.png
|
||||
b3389858 test/3pdata/blinksuite/color-checker-srgb-color-profile.png
|
||||
10721531 test/3pdata/blinksuite/count-down-color-test.gif
|
||||
1abc4dc6 test/3pdata/blinksuite/count-down-color-test.png
|
||||
24ab1efd test/3pdata/blinksuite/crbug779261.gif
|
||||
ae034abe test/3pdata/blinksuite/crbug807324.png
|
||||
4f50fdb0 test/3pdata/blinksuite/crbug827754.png
|
||||
42e5598b test/3pdata/blinksuite/cropped_mandrill.jpg
|
||||
fe2877fe test/3pdata/blinksuite/cs-uma-cmyk-jfif-marker.jpg
|
||||
fe2877fe test/3pdata/blinksuite/cs-uma-cmyk-no-jfif-or-adobe-markers.jpg
|
||||
f8341b72 test/3pdata/blinksuite/cs-uma-cmyk-unknown-transform.jpg
|
||||
fe2877fe test/3pdata/blinksuite/cs-uma-cmyk.jpg
|
||||
1ec303fd test/3pdata/blinksuite/cs-uma-grayscale.jpg
|
||||
c9eafb54 test/3pdata/blinksuite/cs-uma-rgb-non-interleaved.jpg
|
||||
528a67f1 test/3pdata/blinksuite/cs-uma-rgb-unknown-transform.jpg
|
||||
ebd487c5 test/3pdata/blinksuite/cs-uma-rgb.jpg
|
||||
984d8cc3 test/3pdata/blinksuite/cs-uma-ycbcr-410.jpg
|
||||
e43a491e test/3pdata/blinksuite/cs-uma-ycbcr-411.jpg
|
||||
358209c4 test/3pdata/blinksuite/cs-uma-ycbcr-420-both-jfif-adobe.jpg
|
||||
a027c965 test/3pdata/blinksuite/cs-uma-ycbcr-420-non-interleaved.jpg
|
||||
358209c4 test/3pdata/blinksuite/cs-uma-ycbcr-420.jpg
|
||||
3f7bc70f test/3pdata/blinksuite/cs-uma-ycbcr-422.jpg
|
||||
8bd535aa test/3pdata/blinksuite/cs-uma-ycbcr-440.jpg
|
||||
1bc16d1a test/3pdata/blinksuite/cs-uma-ycbcr-444.jpg
|
||||
d97ce4e8 test/3pdata/blinksuite/cs-uma-ycbcr-other.jpg
|
||||
a2a940bc test/3pdata/blinksuite/cs-uma-ycck.jpg
|
||||
b6000be6 test/3pdata/blinksuite/dice.png
|
||||
1023c20a test/3pdata/blinksuite/empty-frame.png
|
||||
eff36075 test/3pdata/blinksuite/flowchart.jpg
|
||||
20ff1df8 test/3pdata/blinksuite/full2loop.gif
|
||||
dc814e29 test/3pdata/blinksuite/gif-loop-count.gif
|
||||
7306cefe test/3pdata/blinksuite/gif-loop-count.png
|
||||
1193bca0 test/3pdata/blinksuite/gracehopper.bmp
|
||||
e3410898 test/3pdata/blinksuite/gracehopper.jpg
|
||||
1193bca0 test/3pdata/blinksuite/gracehopper.png
|
||||
39b58168 test/3pdata/blinksuite/green-10.png
|
||||
1a9bf966 test/3pdata/blinksuite/green-100.png
|
||||
4d7673fc test/3pdata/blinksuite/green-24x24.jpg
|
||||
ea1fe5de test/3pdata/blinksuite/green-256x256.jpg
|
||||
2396f649 test/3pdata/blinksuite/green-half-stripe.png
|
||||
cecaf4f1 test/3pdata/blinksuite/green.jpg
|
||||
985f6273 test/3pdata/blinksuite/green.png
|
||||
2dca380d test/3pdata/blinksuite/grid-large.png
|
||||
7fda6289 test/3pdata/blinksuite/grid-small.png
|
||||
a4d4402b test/3pdata/blinksuite/grid-transparent.png
|
||||
da797012 test/3pdata/blinksuite/half_scan-2.jpg
|
||||
85261e16 test/3pdata/blinksuite/half_scan.jpg
|
||||
95641cb9 test/3pdata/blinksuite/icc-v2-gbr-420-height-not-whole-mcu.jpg
|
||||
93f21c2a test/3pdata/blinksuite/icc-v2-gbr-420-width-not-whole-mcu.jpg
|
||||
f37cea44 test/3pdata/blinksuite/icc-v2-gbr-422-whole-mcus.jpg
|
||||
1de5a906 test/3pdata/blinksuite/icc-v2-gbr.jpg
|
||||
0da5f37e test/3pdata/blinksuite/jpeg-height-exif-orientation.jpg
|
||||
4409dca6 test/3pdata/blinksuite/large-gif-checkerboard.gif
|
||||
2f310e57 test/3pdata/blinksuite/missing-eoi.jpg
|
||||
72bbe2b6 test/3pdata/blinksuite/motion-jpeg-single-frame.jpg
|
||||
0268284a test/3pdata/blinksuite/mu.png
|
||||
741da22b test/3pdata/blinksuite/non-interleaved_progressive-1.jpg
|
||||
7c1387ad test/3pdata/blinksuite/non-interleaved_progressive.jpg
|
||||
96a8bcfd test/3pdata/blinksuite/oval.png
|
||||
918aa35f test/3pdata/blinksuite/palatted-color-png-gamma-one-color-profile.png
|
||||
f5e09699 test/3pdata/blinksuite/pixel-crack-image-background-webkit-transform-scale.png
|
||||
4db38353 test/3pdata/blinksuite/pixelated-hdpi.png
|
||||
0605ee44 test/3pdata/blinksuite/png-16bit/2x2_16bit_AdobeRGB_opaque.png
|
||||
33697cc4 test/3pdata/blinksuite/png-16bit/2x2_16bit_AdobeRGB_transparent.png
|
||||
118c5a6b test/3pdata/blinksuite/png-16bit/2x2_16bit_DisplayP3_opaque.png
|
||||
ec899bcb test/3pdata/blinksuite/png-16bit/2x2_16bit_DisplayP3_transparent.png
|
||||
a3b7d5d8 test/3pdata/blinksuite/png-16bit/2x2_16bit_ProPhoto_opaque.png
|
||||
4eed7588 test/3pdata/blinksuite/png-16bit/2x2_16bit_ProPhoto_transparent.png
|
||||
2fa7c392 test/3pdata/blinksuite/png-16bit/2x2_16bit_Rec2020_opaque.png
|
||||
50738d00 test/3pdata/blinksuite/png-16bit/2x2_16bit_Rec2020_transparent.png
|
||||
190ed790 test/3pdata/blinksuite/png-16bit/2x2_16bit_e-sRGB_opaque.png
|
||||
8d240970 test/3pdata/blinksuite/png-16bit/2x2_16bit_e-sRGB_transparent.png
|
||||
0605ee44 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_AdobeRGB_opaque.png
|
||||
33697cc4 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_AdobeRGB_transparent.png
|
||||
118c5a6b test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_DisplayP3_opaque.png
|
||||
ec899bcb test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_DisplayP3_transparent.png
|
||||
a3b7d5d8 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_ProPhoto_opaque.png
|
||||
4eed7588 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_ProPhoto_transparent.png
|
||||
2fa7c392 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_Rec2020_opaque.png
|
||||
50738d00 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_Rec2020_transparent.png
|
||||
190ed790 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_e-sRGB_opaque.png
|
||||
8d240970 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_e-sRGB_transparent.png
|
||||
ff64600d test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_sRGB_opaque.png
|
||||
9e5a54ad test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_sRGB_transparent.png
|
||||
ff64600d test/3pdata/blinksuite/png-16bit/2x2_16bit_sRGB_opaque.png
|
||||
9e5a54ad test/3pdata/blinksuite/png-16bit/2x2_16bit_sRGB_transparent.png
|
||||
f54babfe test/3pdata/blinksuite/png-16bit/2x2_8bit_AdobeRGB_opaque.png
|
||||
0989c97e test/3pdata/blinksuite/png-16bit/2x2_8bit_AdobeRGB_transparent.png
|
||||
24418795 test/3pdata/blinksuite/png-16bit/2x2_8bit_DisplayP3_opaque.png
|
||||
0da16665 test/3pdata/blinksuite/png-16bit/2x2_8bit_DisplayP3_transparent.png
|
||||
02b4b122 test/3pdata/blinksuite/png-16bit/2x2_8bit_ProPhoto_opaque.png
|
||||
f715e2c9 test/3pdata/blinksuite/png-16bit/2x2_8bit_ProPhoto_transparent.png
|
||||
8388786d test/3pdata/blinksuite/png-16bit/2x2_8bit_Rec2020_opaque.png
|
||||
13ec1bce test/3pdata/blinksuite/png-16bit/2x2_8bit_Rec2020_transparent.png
|
||||
6c64ba21 test/3pdata/blinksuite/png-16bit/2x2_8bit_e-sRGB_opaque.png
|
||||
3ae20cd5 test/3pdata/blinksuite/png-16bit/2x2_8bit_e-sRGB_transparent.png
|
||||
79c50526 test/3pdata/blinksuite/png-16bit/2x2_8bit_sRGB_opaque.png
|
||||
cf95aec4 test/3pdata/blinksuite/png-16bit/2x2_8bit_sRGB_transparent.png
|
||||
e4a2a51c test/3pdata/blinksuite/png-animated-idat-not-part-of-animation.png
|
||||
ea2c8a89 test/3pdata/blinksuite/png-animated-idat-part-of-animation.png
|
||||
2bbe7571 test/3pdata/blinksuite/png-animated-three-independent-frames.png
|
||||
03ae8c06 test/3pdata/blinksuite/png-color-profile-and-gamma-chunk.png
|
||||
ffa30c78 test/3pdata/blinksuite/png-extra-row-crash.png
|
||||
5a8c950e test/3pdata/blinksuite/png-simple.png
|
||||
6dfdd872 test/3pdata/blinksuite/png_per_row_alpha.png
|
||||
9ca73f21 test/3pdata/blinksuite/pngfuzz/border-image.png
|
||||
96a8bcfd test/3pdata/blinksuite/pngfuzz/oval.png
|
||||
e4a2a51c test/3pdata/blinksuite/pngfuzz/png-animated-idat-not-part-of-animation.png
|
||||
ea2c8a89 test/3pdata/blinksuite/pngfuzz/png-animated-idat-part-of-animation.png
|
||||
2bbe7571 test/3pdata/blinksuite/pngfuzz/png-animated-three-independent-frames.png
|
||||
5a8c950e test/3pdata/blinksuite/pngfuzz/png-simple.png
|
||||
53fe9878 test/3pdata/blinksuite/quicksort.gif
|
||||
a199eb62 test/3pdata/blinksuite/red-10.png
|
||||
f5c7ae42 test/3pdata/blinksuite/red-100.png
|
||||
07d18cef test/3pdata/blinksuite/red-at-12-oclock-with-color-profile.jpg
|
||||
07d18cef test/3pdata/blinksuite/red-at-12-oclock-with-color-profile.png
|
||||
e68e3ee4 test/3pdata/blinksuite/red-half-stripe.png
|
||||
aa375741 test/3pdata/blinksuite/rgb-jpeg-blue.jpg
|
||||
724437c7 test/3pdata/blinksuite/rgb-jpeg-green.jpg
|
||||
bfebcca4 test/3pdata/blinksuite/rgb-jpeg-red.jpg
|
||||
6ed3c2e7 test/3pdata/blinksuite/rgb-jpeg-with-adobe-marker-only.jpg
|
||||
cfb6f39d test/3pdata/blinksuite/rgb-png-with-cmyk-color-profile.png
|
||||
a3454fb7 test/3pdata/blinksuite/short-app-extension-string.gif
|
||||
2398258b test/3pdata/blinksuite/size-failure.gif
|
||||
5c4b1a8b test/3pdata/blinksuite/small-square-with-colorspin-profile.jpg
|
||||
44dc95b9 test/3pdata/blinksuite/sprite_all_fragments_same.png
|
||||
9a7e5ec7 test/3pdata/blinksuite/sprite_alternate_fragments_same.png
|
||||
1b1f5f96 test/3pdata/blinksuite/stripes-large.png
|
||||
6b85cdb9 test/3pdata/blinksuite/stripes-small.png
|
||||
16c2c0fe test/3pdata/blinksuite/test-load.jpg
|
||||
ed67a9a5 test/3pdata/blinksuite/wrong-block-length.gif
|
||||
577c5c4c test/3pdata/blinksuite/ycbcr-420-fast-int-progressive.jpg
|
||||
bf4cd8e2 test/3pdata/blinksuite/ycbcr-420-float-progressive.jpg
|
||||
bf4cd8e2 test/3pdata/blinksuite/ycbcr-420-float.jpg
|
||||
35dcc57a test/3pdata/blinksuite/ycbcr-420-progressive-smooth.jpg
|
||||
3eeb7739 test/3pdata/blinksuite/ycbcr-420-progressive.jpg
|
||||
3eeb7739 test/3pdata/blinksuite/ycbcr-420.jpg
|
||||
b9c49d8c test/3pdata/blinksuite/ycbcr-422-float.jpg
|
||||
8cd1fb26 test/3pdata/blinksuite/ycbcr-422.jpg
|
||||
89cabc1f test/3pdata/blinksuite/ycbcr-440-float.jpg
|
||||
73cb2c2d test/3pdata/blinksuite/ycbcr-440.jpg
|
||||
b74f41fa test/3pdata/blinksuite/ycbcr-444-float.jpg
|
||||
eccde117 test/3pdata/blinksuite/ycbcr-444.jpg
|
||||
259ef81b test/3pdata/blinksuite/ycbcr-progressive-000.jpg
|
||||
134d0910 test/3pdata/blinksuite/ycbcr-progressive-001.jpg
|
||||
20a7ef57 test/3pdata/blinksuite/ycbcr-progressive-002.jpg
|
||||
ee45e49a test/3pdata/blinksuite/ycbcr-progressive-003.jpg
|
||||
1ed5667b test/3pdata/blinksuite/ycbcr-with-cmyk-color-profile.jpg
|
||||
c2ae2366 test/3pdata/blinksuite/ycbcr-with-no-color-profile.jpg
|
||||
OK. 912861f4 test/3pdata/blinksuite/0x0.bmp
|
||||
OK. 1283a492 test/3pdata/blinksuite/12-55.jpg
|
||||
OK. 69fc7dee test/3pdata/blinksuite/182.jpg
|
||||
OK. 09d06f47 test/3pdata/blinksuite/2-comp.jpg
|
||||
OK. 1f0a869f test/3pdata/blinksuite/2-dht.jpg
|
||||
OK. d7865c25 test/3pdata/blinksuite/23-55.jpg
|
||||
OK. 361f7557 test/3pdata/blinksuite/5000x5000.png
|
||||
BAD 4920fb2a test/3pdata/blinksuite/55.jpg
|
||||
OK. e2c0805a test/3pdata/blinksuite/57.jpg
|
||||
OK. 1542e2e1 test/3pdata/blinksuite/58.jpg
|
||||
OK. da174c34 test/3pdata/blinksuite/59.jpg
|
||||
OK. 89f95c0f test/3pdata/blinksuite/animated-10color-fast.gif
|
||||
OK. 824e8906 test/3pdata/blinksuite/animated-10color.gif
|
||||
OK. 3332edad test/3pdata/blinksuite/animated-gif-with-offsets.gif
|
||||
OK. c5ed1e55 test/3pdata/blinksuite/animated.gif
|
||||
OK. 8a0e1335 test/3pdata/blinksuite/animated2.gif
|
||||
OK. 10f62511 test/3pdata/blinksuite/apng00.png
|
||||
OK. 3c2e7f59 test/3pdata/blinksuite/apng01.png
|
||||
OK. a6174a21 test/3pdata/blinksuite/apng08-ref.png
|
||||
OK. eb5d9458 test/3pdata/blinksuite/apng18.png
|
||||
OK. 41fbee02 test/3pdata/blinksuite/apng24-ref.png
|
||||
OK. f868aa62 test/3pdata/blinksuite/apng24.png
|
||||
OK. e9f8e40c test/3pdata/blinksuite/apng26-ref.png
|
||||
OK. 689d3f62 test/3pdata/blinksuite/apng26.png
|
||||
OK. 045c6c9d test/3pdata/blinksuite/avif/red.png
|
||||
OK. 3ef592d6 test/3pdata/blinksuite/avif/silver.png
|
||||
OK. 1a9bf966 test/3pdata/blinksuite/base-test-resources/success.png
|
||||
OK. d9f8441c test/3pdata/blinksuite/blue-10.png
|
||||
OK. 267741e0 test/3pdata/blinksuite/blue-100.png
|
||||
OK. 89449c01 test/3pdata/blinksuite/blue-wheel-srgb-color-profile.jpg
|
||||
OK. 8fce70a9 test/3pdata/blinksuite/blue-wheel-srgb-color-profile.png
|
||||
OK. 2d7bad9f test/3pdata/blinksuite/border-image-srgb-color-profile.png
|
||||
OK. 9ca73f21 test/3pdata/blinksuite/border-image.png
|
||||
OK. 277600f9 test/3pdata/blinksuite/boston.gif
|
||||
OK. ffc8a627 test/3pdata/blinksuite/bug106024.jpg
|
||||
OK. 18cee321 test/3pdata/blinksuite/cHRM_color_spin.png
|
||||
OK. 3e460fe4 test/3pdata/blinksuite/cat.jpg
|
||||
OK. e9151f0e test/3pdata/blinksuite/cicp_pq.png
|
||||
OK. ab6d7d2e test/3pdata/blinksuite/cmyk-jpeg.jpg
|
||||
OK. 5ec78d7c test/3pdata/blinksuite/color-checker-adobe-color-profile.png
|
||||
OK. b3389858 test/3pdata/blinksuite/color-checker-srgb-color-profile.png
|
||||
OK. 10721531 test/3pdata/blinksuite/count-down-color-test.gif
|
||||
OK. 1abc4dc6 test/3pdata/blinksuite/count-down-color-test.png
|
||||
OK. 24ab1efd test/3pdata/blinksuite/crbug779261.gif
|
||||
OK. ae034abe test/3pdata/blinksuite/crbug807324.png
|
||||
OK. 4f50fdb0 test/3pdata/blinksuite/crbug827754.png
|
||||
OK. 42e5598b test/3pdata/blinksuite/cropped_mandrill.jpg
|
||||
OK. fe2877fe test/3pdata/blinksuite/cs-uma-cmyk-jfif-marker.jpg
|
||||
OK. fe2877fe test/3pdata/blinksuite/cs-uma-cmyk-no-jfif-or-adobe-markers.jpg
|
||||
OK. f8341b72 test/3pdata/blinksuite/cs-uma-cmyk-unknown-transform.jpg
|
||||
OK. fe2877fe test/3pdata/blinksuite/cs-uma-cmyk.jpg
|
||||
OK. 1ec303fd test/3pdata/blinksuite/cs-uma-grayscale.jpg
|
||||
OK. c9eafb54 test/3pdata/blinksuite/cs-uma-rgb-non-interleaved.jpg
|
||||
OK. 528a67f1 test/3pdata/blinksuite/cs-uma-rgb-unknown-transform.jpg
|
||||
OK. ebd487c5 test/3pdata/blinksuite/cs-uma-rgb.jpg
|
||||
OK. 984d8cc3 test/3pdata/blinksuite/cs-uma-ycbcr-410.jpg
|
||||
OK. e43a491e test/3pdata/blinksuite/cs-uma-ycbcr-411.jpg
|
||||
OK. 358209c4 test/3pdata/blinksuite/cs-uma-ycbcr-420-both-jfif-adobe.jpg
|
||||
OK. a027c965 test/3pdata/blinksuite/cs-uma-ycbcr-420-non-interleaved.jpg
|
||||
OK. 358209c4 test/3pdata/blinksuite/cs-uma-ycbcr-420.jpg
|
||||
OK. 3f7bc70f test/3pdata/blinksuite/cs-uma-ycbcr-422.jpg
|
||||
OK. 8bd535aa test/3pdata/blinksuite/cs-uma-ycbcr-440.jpg
|
||||
OK. 1bc16d1a test/3pdata/blinksuite/cs-uma-ycbcr-444.jpg
|
||||
OK. d97ce4e8 test/3pdata/blinksuite/cs-uma-ycbcr-other.jpg
|
||||
OK. a2a940bc test/3pdata/blinksuite/cs-uma-ycck.jpg
|
||||
OK. b6000be6 test/3pdata/blinksuite/dice.png
|
||||
BAD 1023c20a test/3pdata/blinksuite/empty-frame.png
|
||||
OK. eff36075 test/3pdata/blinksuite/flowchart.jpg
|
||||
OK. 20ff1df8 test/3pdata/blinksuite/full2loop.gif
|
||||
OK. dc814e29 test/3pdata/blinksuite/gif-loop-count.gif
|
||||
OK. 7306cefe test/3pdata/blinksuite/gif-loop-count.png
|
||||
OK. 1193bca0 test/3pdata/blinksuite/gracehopper.bmp
|
||||
OK. e3410898 test/3pdata/blinksuite/gracehopper.jpg
|
||||
OK. 1193bca0 test/3pdata/blinksuite/gracehopper.png
|
||||
OK. 39b58168 test/3pdata/blinksuite/green-10.png
|
||||
OK. 1a9bf966 test/3pdata/blinksuite/green-100.png
|
||||
OK. 4d7673fc test/3pdata/blinksuite/green-24x24.jpg
|
||||
OK. ea1fe5de test/3pdata/blinksuite/green-256x256.jpg
|
||||
OK. 2396f649 test/3pdata/blinksuite/green-half-stripe.png
|
||||
OK. cecaf4f1 test/3pdata/blinksuite/green.jpg
|
||||
OK. 985f6273 test/3pdata/blinksuite/green.png
|
||||
OK. 2dca380d test/3pdata/blinksuite/grid-large.png
|
||||
OK. 7fda6289 test/3pdata/blinksuite/grid-small.png
|
||||
OK. a4d4402b test/3pdata/blinksuite/grid-transparent.png
|
||||
BAD da797012 test/3pdata/blinksuite/half_scan-2.jpg
|
||||
BAD 85261e16 test/3pdata/blinksuite/half_scan.jpg
|
||||
OK. 95641cb9 test/3pdata/blinksuite/icc-v2-gbr-420-height-not-whole-mcu.jpg
|
||||
OK. 93f21c2a test/3pdata/blinksuite/icc-v2-gbr-420-width-not-whole-mcu.jpg
|
||||
OK. f37cea44 test/3pdata/blinksuite/icc-v2-gbr-422-whole-mcus.jpg
|
||||
OK. 1de5a906 test/3pdata/blinksuite/icc-v2-gbr.jpg
|
||||
OK. 0da5f37e test/3pdata/blinksuite/jpeg-height-exif-orientation.jpg
|
||||
OK. 4409dca6 test/3pdata/blinksuite/large-gif-checkerboard.gif
|
||||
BAD 2f310e57 test/3pdata/blinksuite/missing-eoi.jpg
|
||||
OK. 72bbe2b6 test/3pdata/blinksuite/motion-jpeg-single-frame.jpg
|
||||
OK. 0268284a test/3pdata/blinksuite/mu.png
|
||||
BAD 741da22b test/3pdata/blinksuite/non-interleaved_progressive-1.jpg
|
||||
BAD 7c1387ad test/3pdata/blinksuite/non-interleaved_progressive.jpg
|
||||
OK. 96a8bcfd test/3pdata/blinksuite/oval.png
|
||||
OK. 918aa35f test/3pdata/blinksuite/palatted-color-png-gamma-one-color-profile.png
|
||||
OK. f5e09699 test/3pdata/blinksuite/pixel-crack-image-background-webkit-transform-scale.png
|
||||
OK. 4db38353 test/3pdata/blinksuite/pixelated-hdpi.png
|
||||
OK. 0605ee44 test/3pdata/blinksuite/png-16bit/2x2_16bit_AdobeRGB_opaque.png
|
||||
OK. 33697cc4 test/3pdata/blinksuite/png-16bit/2x2_16bit_AdobeRGB_transparent.png
|
||||
OK. 118c5a6b test/3pdata/blinksuite/png-16bit/2x2_16bit_DisplayP3_opaque.png
|
||||
OK. ec899bcb test/3pdata/blinksuite/png-16bit/2x2_16bit_DisplayP3_transparent.png
|
||||
OK. a3b7d5d8 test/3pdata/blinksuite/png-16bit/2x2_16bit_ProPhoto_opaque.png
|
||||
OK. 4eed7588 test/3pdata/blinksuite/png-16bit/2x2_16bit_ProPhoto_transparent.png
|
||||
OK. 2fa7c392 test/3pdata/blinksuite/png-16bit/2x2_16bit_Rec2020_opaque.png
|
||||
OK. 50738d00 test/3pdata/blinksuite/png-16bit/2x2_16bit_Rec2020_transparent.png
|
||||
OK. 190ed790 test/3pdata/blinksuite/png-16bit/2x2_16bit_e-sRGB_opaque.png
|
||||
OK. 8d240970 test/3pdata/blinksuite/png-16bit/2x2_16bit_e-sRGB_transparent.png
|
||||
OK. 0605ee44 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_AdobeRGB_opaque.png
|
||||
OK. 33697cc4 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_AdobeRGB_transparent.png
|
||||
OK. 118c5a6b test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_DisplayP3_opaque.png
|
||||
OK. ec899bcb test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_DisplayP3_transparent.png
|
||||
OK. a3b7d5d8 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_ProPhoto_opaque.png
|
||||
OK. 4eed7588 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_ProPhoto_transparent.png
|
||||
OK. 2fa7c392 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_Rec2020_opaque.png
|
||||
OK. 50738d00 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_Rec2020_transparent.png
|
||||
OK. 190ed790 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_e-sRGB_opaque.png
|
||||
OK. 8d240970 test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_e-sRGB_transparent.png
|
||||
OK. ff64600d test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_sRGB_opaque.png
|
||||
OK. 9e5a54ad test/3pdata/blinksuite/png-16bit/2x2_16bit_interlaced_sRGB_transparent.png
|
||||
OK. ff64600d test/3pdata/blinksuite/png-16bit/2x2_16bit_sRGB_opaque.png
|
||||
OK. 9e5a54ad test/3pdata/blinksuite/png-16bit/2x2_16bit_sRGB_transparent.png
|
||||
OK. f54babfe test/3pdata/blinksuite/png-16bit/2x2_8bit_AdobeRGB_opaque.png
|
||||
OK. 0989c97e test/3pdata/blinksuite/png-16bit/2x2_8bit_AdobeRGB_transparent.png
|
||||
OK. 24418795 test/3pdata/blinksuite/png-16bit/2x2_8bit_DisplayP3_opaque.png
|
||||
OK. 0da16665 test/3pdata/blinksuite/png-16bit/2x2_8bit_DisplayP3_transparent.png
|
||||
OK. 02b4b122 test/3pdata/blinksuite/png-16bit/2x2_8bit_ProPhoto_opaque.png
|
||||
OK. f715e2c9 test/3pdata/blinksuite/png-16bit/2x2_8bit_ProPhoto_transparent.png
|
||||
OK. 8388786d test/3pdata/blinksuite/png-16bit/2x2_8bit_Rec2020_opaque.png
|
||||
OK. 13ec1bce test/3pdata/blinksuite/png-16bit/2x2_8bit_Rec2020_transparent.png
|
||||
OK. 6c64ba21 test/3pdata/blinksuite/png-16bit/2x2_8bit_e-sRGB_opaque.png
|
||||
OK. 3ae20cd5 test/3pdata/blinksuite/png-16bit/2x2_8bit_e-sRGB_transparent.png
|
||||
OK. 79c50526 test/3pdata/blinksuite/png-16bit/2x2_8bit_sRGB_opaque.png
|
||||
OK. cf95aec4 test/3pdata/blinksuite/png-16bit/2x2_8bit_sRGB_transparent.png
|
||||
OK. e4a2a51c test/3pdata/blinksuite/png-animated-idat-not-part-of-animation.png
|
||||
OK. ea2c8a89 test/3pdata/blinksuite/png-animated-idat-part-of-animation.png
|
||||
OK. 2bbe7571 test/3pdata/blinksuite/png-animated-three-independent-frames.png
|
||||
OK. 03ae8c06 test/3pdata/blinksuite/png-color-profile-and-gamma-chunk.png
|
||||
BAD ffa30c78 test/3pdata/blinksuite/png-extra-row-crash.png
|
||||
OK. 5a8c950e test/3pdata/blinksuite/png-simple.png
|
||||
OK. 6dfdd872 test/3pdata/blinksuite/png_per_row_alpha.png
|
||||
OK. 9ca73f21 test/3pdata/blinksuite/pngfuzz/border-image.png
|
||||
OK. 96a8bcfd test/3pdata/blinksuite/pngfuzz/oval.png
|
||||
OK. e4a2a51c test/3pdata/blinksuite/pngfuzz/png-animated-idat-not-part-of-animation.png
|
||||
OK. ea2c8a89 test/3pdata/blinksuite/pngfuzz/png-animated-idat-part-of-animation.png
|
||||
OK. 2bbe7571 test/3pdata/blinksuite/pngfuzz/png-animated-three-independent-frames.png
|
||||
OK. 5a8c950e test/3pdata/blinksuite/pngfuzz/png-simple.png
|
||||
OK. 53fe9878 test/3pdata/blinksuite/quicksort.gif
|
||||
OK. a199eb62 test/3pdata/blinksuite/red-10.png
|
||||
OK. f5c7ae42 test/3pdata/blinksuite/red-100.png
|
||||
OK. 07d18cef test/3pdata/blinksuite/red-at-12-oclock-with-color-profile.jpg
|
||||
OK. 07d18cef test/3pdata/blinksuite/red-at-12-oclock-with-color-profile.png
|
||||
OK. e68e3ee4 test/3pdata/blinksuite/red-half-stripe.png
|
||||
OK. aa375741 test/3pdata/blinksuite/rgb-jpeg-blue.jpg
|
||||
OK. 724437c7 test/3pdata/blinksuite/rgb-jpeg-green.jpg
|
||||
OK. bfebcca4 test/3pdata/blinksuite/rgb-jpeg-red.jpg
|
||||
OK. 6ed3c2e7 test/3pdata/blinksuite/rgb-jpeg-with-adobe-marker-only.jpg
|
||||
OK. cfb6f39d test/3pdata/blinksuite/rgb-png-with-cmyk-color-profile.png
|
||||
OK. a3454fb7 test/3pdata/blinksuite/short-app-extension-string.gif
|
||||
OK. 7c80a001 test/3pdata/blinksuite/size-failure.b186640109.webp
|
||||
BAD 2398258b test/3pdata/blinksuite/size-failure.gif
|
||||
OK. 5c4b1a8b test/3pdata/blinksuite/small-square-with-colorspin-profile.jpg
|
||||
OK. 44dc95b9 test/3pdata/blinksuite/sprite_all_fragments_same.png
|
||||
OK. 9a7e5ec7 test/3pdata/blinksuite/sprite_alternate_fragments_same.png
|
||||
OK. 1b1f5f96 test/3pdata/blinksuite/stripes-large.png
|
||||
OK. 6b85cdb9 test/3pdata/blinksuite/stripes-small.png
|
||||
OK. 16c2c0fe test/3pdata/blinksuite/test-load.jpg
|
||||
OK. 19d3a207 test/3pdata/blinksuite/test3.webp
|
||||
BAD ed67a9a5 test/3pdata/blinksuite/wrong-block-length.gif
|
||||
OK. 577c5c4c test/3pdata/blinksuite/ycbcr-420-fast-int-progressive.jpg
|
||||
OK. bf4cd8e2 test/3pdata/blinksuite/ycbcr-420-float-progressive.jpg
|
||||
OK. bf4cd8e2 test/3pdata/blinksuite/ycbcr-420-float.jpg
|
||||
OK. 35dcc57a test/3pdata/blinksuite/ycbcr-420-progressive-smooth.jpg
|
||||
OK. 3eeb7739 test/3pdata/blinksuite/ycbcr-420-progressive.jpg
|
||||
OK. 3eeb7739 test/3pdata/blinksuite/ycbcr-420.jpg
|
||||
OK. b9c49d8c test/3pdata/blinksuite/ycbcr-422-float.jpg
|
||||
OK. 8cd1fb26 test/3pdata/blinksuite/ycbcr-422.jpg
|
||||
OK. 89cabc1f test/3pdata/blinksuite/ycbcr-440-float.jpg
|
||||
OK. 73cb2c2d test/3pdata/blinksuite/ycbcr-440.jpg
|
||||
OK. b74f41fa test/3pdata/blinksuite/ycbcr-444-float.jpg
|
||||
OK. eccde117 test/3pdata/blinksuite/ycbcr-444.jpg
|
||||
OK. 259ef81b test/3pdata/blinksuite/ycbcr-progressive-000.jpg
|
||||
OK. 134d0910 test/3pdata/blinksuite/ycbcr-progressive-001.jpg
|
||||
OK. 20a7ef57 test/3pdata/blinksuite/ycbcr-progressive-002.jpg
|
||||
OK. ee45e49a test/3pdata/blinksuite/ycbcr-progressive-003.jpg
|
||||
OK. 1ed5667b test/3pdata/blinksuite/ycbcr-with-cmyk-color-profile.jpg
|
||||
OK. c2ae2366 test/3pdata/blinksuite/ycbcr-with-no-color-profile.jpg
|
||||
@@ -1,130 +1,130 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
1aec39e7 test/3pdata/bmpsuite/b/badbitssize.bmp
|
||||
1aec39e7 test/3pdata/bmpsuite/b/baddens1.bmp
|
||||
1aec39e7 test/3pdata/bmpsuite/b/baddens2.bmp
|
||||
1aec39e7 test/3pdata/bmpsuite/b/badfilesize.bmp
|
||||
eddff465 test/3pdata/bmpsuite/b/badpalettesize.bmp
|
||||
c79c1782 test/3pdata/bmpsuite/b/badrle.bmp
|
||||
00abf6b1 test/3pdata/bmpsuite/b/badrle4.bmp
|
||||
6a81ba9f test/3pdata/bmpsuite/b/badrle4bis.bmp
|
||||
6a81ba9f test/3pdata/bmpsuite/b/badrle4ter.bmp
|
||||
3f00bfe6 test/3pdata/bmpsuite/b/badrlebis.bmp
|
||||
3f00bfe6 test/3pdata/bmpsuite/b/badrleter.bmp
|
||||
36f7baa0 test/3pdata/bmpsuite/b/pal8badindex.bmp
|
||||
eddff465 test/3pdata/bmpsuite/b/rletopdown.bmp
|
||||
5736e5c9 test/3pdata/bmpsuite/b/shortfile.bmp
|
||||
50b4e08b test/3pdata/bmpsuite/data/image.jpg
|
||||
75060601 test/3pdata/bmpsuite/data/image.png
|
||||
eee00966 test/3pdata/bmpsuite/data/srgb.icc
|
||||
e44f8a55 test/3pdata/bmpsuite/data/swap-r-g.icc
|
||||
1aec39e7 test/3pdata/bmpsuite/g/pal1.bmp
|
||||
909c4c97 test/3pdata/bmpsuite/g/pal1bg.bmp
|
||||
1aec39e7 test/3pdata/bmpsuite/g/pal1wb.bmp
|
||||
4d469dba test/3pdata/bmpsuite/g/pal4.bmp
|
||||
e13c35dc test/3pdata/bmpsuite/g/pal4gs.bmp
|
||||
4d469dba test/3pdata/bmpsuite/g/pal4rle.bmp
|
||||
eddff465 test/3pdata/bmpsuite/g/pal8-0.bmp
|
||||
eddff465 test/3pdata/bmpsuite/g/pal8.bmp
|
||||
45214efa test/3pdata/bmpsuite/g/pal8gs.bmp
|
||||
b734e840 test/3pdata/bmpsuite/g/pal8nonsquare.bmp
|
||||
eddff465 test/3pdata/bmpsuite/g/pal8os2.bmp
|
||||
eddff465 test/3pdata/bmpsuite/g/pal8rle.bmp
|
||||
eddff465 test/3pdata/bmpsuite/g/pal8topdown.bmp
|
||||
eddff465 test/3pdata/bmpsuite/g/pal8v4.bmp
|
||||
eddff465 test/3pdata/bmpsuite/g/pal8v5.bmp
|
||||
c8250daf test/3pdata/bmpsuite/g/pal8w124.bmp
|
||||
98379ca2 test/3pdata/bmpsuite/g/pal8w125.bmp
|
||||
faeb1685 test/3pdata/bmpsuite/g/pal8w126.bmp
|
||||
1b183dc1 test/3pdata/bmpsuite/g/rgb16-565.bmp
|
||||
1b183dc1 test/3pdata/bmpsuite/g/rgb16-565pal.bmp
|
||||
8579ddaf test/3pdata/bmpsuite/g/rgb16.bmp
|
||||
8579ddaf test/3pdata/bmpsuite/g/rgb16bfdef.bmp
|
||||
75060601 test/3pdata/bmpsuite/g/rgb24.bmp
|
||||
75060601 test/3pdata/bmpsuite/g/rgb24pal.bmp
|
||||
75060601 test/3pdata/bmpsuite/g/rgb32.bmp
|
||||
75060601 test/3pdata/bmpsuite/g/rgb32bf.bmp
|
||||
75060601 test/3pdata/bmpsuite/g/rgb32bfdef.bmp
|
||||
91cd8d0b test/3pdata/bmpsuite/html/bkgd.png
|
||||
2be75470 test/3pdata/bmpsuite/html/fakealpha.png
|
||||
1aec39e7 test/3pdata/bmpsuite/html/pal1.png
|
||||
909c4c97 test/3pdata/bmpsuite/html/pal1bg.png
|
||||
5628bcde test/3pdata/bmpsuite/html/pal1p1.png
|
||||
e0c1e54d test/3pdata/bmpsuite/html/pal2.png
|
||||
0b09d3b2 test/3pdata/bmpsuite/html/pal2color.png
|
||||
4d469dba test/3pdata/bmpsuite/html/pal4.png
|
||||
e13c35dc test/3pdata/bmpsuite/html/pal4gs.png
|
||||
70f35a4b test/3pdata/bmpsuite/html/pal4rlecut-0.png
|
||||
87a1d295 test/3pdata/bmpsuite/html/pal4rlecut-b.png
|
||||
f4b1df15 test/3pdata/bmpsuite/html/pal4rlecut.png
|
||||
79fbbc2e test/3pdata/bmpsuite/html/pal4rletrns-0.png
|
||||
4c725320 test/3pdata/bmpsuite/html/pal4rletrns-b.png
|
||||
b988a431 test/3pdata/bmpsuite/html/pal4rletrns.png
|
||||
eddff465 test/3pdata/bmpsuite/html/pal8.png
|
||||
45214efa test/3pdata/bmpsuite/html/pal8gs.png
|
||||
b734e840 test/3pdata/bmpsuite/html/pal8nonsquare-e.png
|
||||
aacdd756 test/3pdata/bmpsuite/html/pal8nonsquare-v.png
|
||||
b9d48e8d test/3pdata/bmpsuite/html/pal8rlecut-0.png
|
||||
3843191e test/3pdata/bmpsuite/html/pal8rlecut-b.png
|
||||
2c7f45de test/3pdata/bmpsuite/html/pal8rlecut.png
|
||||
d962d5f1 test/3pdata/bmpsuite/html/pal8rletrns-0.png
|
||||
eceb3aff test/3pdata/bmpsuite/html/pal8rletrns-b.png
|
||||
1911cdee test/3pdata/bmpsuite/html/pal8rletrns.png
|
||||
c8250daf test/3pdata/bmpsuite/html/pal8w124.png
|
||||
98379ca2 test/3pdata/bmpsuite/html/pal8w125.png
|
||||
faeb1685 test/3pdata/bmpsuite/html/pal8w126.png
|
||||
db57e11a test/3pdata/bmpsuite/html/rgb16-231.png
|
||||
1146975d test/3pdata/bmpsuite/html/rgb16-3103.png
|
||||
5f733194 test/3pdata/bmpsuite/html/rgb16-565.png
|
||||
3a178cd6 test/3pdata/bmpsuite/html/rgb16-880.png
|
||||
6c90b630 test/3pdata/bmpsuite/html/rgb16.png
|
||||
ae961b51 test/3pdata/bmpsuite/html/rgb16faketrns.png
|
||||
50b4e08b test/3pdata/bmpsuite/html/rgb24.jpg
|
||||
75060601 test/3pdata/bmpsuite/html/rgb24.png
|
||||
464c0212 test/3pdata/bmpsuite/html/rgb32-7187.png
|
||||
ed9d9275 test/3pdata/bmpsuite/html/rgba16-1924.png
|
||||
264bf86f test/3pdata/bmpsuite/html/rgba16-4444.png
|
||||
985e8fbb test/3pdata/bmpsuite/html/rgba16-5551.png
|
||||
4fb41940 test/3pdata/bmpsuite/html/rgba32-1010102.png
|
||||
42e2a973 test/3pdata/bmpsuite/html/rgba32-61754.png
|
||||
4bd457aa test/3pdata/bmpsuite/html/rgba32-81284.png
|
||||
89060da6 test/3pdata/bmpsuite/html/rgba32.png
|
||||
5628bcde test/3pdata/bmpsuite/q/pal1p1.bmp
|
||||
e0c1e54d test/3pdata/bmpsuite/q/pal2.bmp
|
||||
0b09d3b2 test/3pdata/bmpsuite/q/pal2color.bmp
|
||||
87a1d295 test/3pdata/bmpsuite/q/pal4rlecut.bmp
|
||||
4c725320 test/3pdata/bmpsuite/q/pal4rletrns.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8offs.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8os2-hs.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8os2-sz.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8os2sp.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8os2v2-16.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8os2v2-40sz.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8os2v2-sz.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8os2v2.bmp
|
||||
eddff465 test/3pdata/bmpsuite/q/pal8oversizepal.bmp
|
||||
3843191e test/3pdata/bmpsuite/q/pal8rlecut.bmp
|
||||
eceb3aff test/3pdata/bmpsuite/q/pal8rletrns.bmp
|
||||
db57e11a test/3pdata/bmpsuite/q/rgb16-231.bmp
|
||||
fb300729 test/3pdata/bmpsuite/q/rgb16-3103.bmp
|
||||
8579ddaf test/3pdata/bmpsuite/q/rgb16faketrns.bmp
|
||||
50b4e08b test/3pdata/bmpsuite/q/rgb24jpeg.bmp
|
||||
75060601 test/3pdata/bmpsuite/q/rgb24largepal.bmp
|
||||
75060601 test/3pdata/bmpsuite/q/rgb24lprof.bmp
|
||||
75060601 test/3pdata/bmpsuite/q/rgb24png.bmp
|
||||
75060601 test/3pdata/bmpsuite/q/rgb24prof.bmp
|
||||
5aae25cd test/3pdata/bmpsuite/q/rgb24prof2.bmp
|
||||
41299717 test/3pdata/bmpsuite/q/rgb32-111110.bmp
|
||||
464c0212 test/3pdata/bmpsuite/q/rgb32-7187.bmp
|
||||
75060601 test/3pdata/bmpsuite/q/rgb32-xbgr.bmp
|
||||
75060601 test/3pdata/bmpsuite/q/rgb32fakealpha.bmp
|
||||
75060601 test/3pdata/bmpsuite/q/rgb32h52.bmp
|
||||
9d5e24fd test/3pdata/bmpsuite/q/rgba16-1924.bmp
|
||||
56884ee7 test/3pdata/bmpsuite/q/rgba16-4444.bmp
|
||||
844d1335 test/3pdata/bmpsuite/q/rgba16-5551.bmp
|
||||
277ef135 test/3pdata/bmpsuite/q/rgba32-1.bmp
|
||||
b4db4238 test/3pdata/bmpsuite/q/rgba32-1010102.bmp
|
||||
277ef135 test/3pdata/bmpsuite/q/rgba32-2.bmp
|
||||
9d08e5fe test/3pdata/bmpsuite/q/rgba32-61754.bmp
|
||||
943e1b27 test/3pdata/bmpsuite/q/rgba32-81284.bmp
|
||||
277ef135 test/3pdata/bmpsuite/q/rgba32abf.bmp
|
||||
277ef135 test/3pdata/bmpsuite/q/rgba32h56.bmp
|
||||
OK. 1aec39e7 test/3pdata/bmpsuite/b/badbitssize.bmp
|
||||
OK. 1aec39e7 test/3pdata/bmpsuite/b/baddens1.bmp
|
||||
OK. 1aec39e7 test/3pdata/bmpsuite/b/baddens2.bmp
|
||||
OK. 1aec39e7 test/3pdata/bmpsuite/b/badfilesize.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/b/badpalettesize.bmp
|
||||
BAD c79c1782 test/3pdata/bmpsuite/b/badrle.bmp
|
||||
BAD 00abf6b1 test/3pdata/bmpsuite/b/badrle4.bmp
|
||||
BAD 6a81ba9f test/3pdata/bmpsuite/b/badrle4bis.bmp
|
||||
BAD 6a81ba9f test/3pdata/bmpsuite/b/badrle4ter.bmp
|
||||
BAD 3f00bfe6 test/3pdata/bmpsuite/b/badrlebis.bmp
|
||||
BAD 3f00bfe6 test/3pdata/bmpsuite/b/badrleter.bmp
|
||||
OK. 36f7baa0 test/3pdata/bmpsuite/b/pal8badindex.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/b/rletopdown.bmp
|
||||
BAD 5736e5c9 test/3pdata/bmpsuite/b/shortfile.bmp
|
||||
OK. 50b4e08b test/3pdata/bmpsuite/data/image.jpg
|
||||
OK. 75060601 test/3pdata/bmpsuite/data/image.png
|
||||
BAD eee00966 test/3pdata/bmpsuite/data/srgb.icc
|
||||
OK. e44f8a55 test/3pdata/bmpsuite/data/swap-r-g.icc
|
||||
OK. 1aec39e7 test/3pdata/bmpsuite/g/pal1.bmp
|
||||
OK. 909c4c97 test/3pdata/bmpsuite/g/pal1bg.bmp
|
||||
OK. 1aec39e7 test/3pdata/bmpsuite/g/pal1wb.bmp
|
||||
OK. 4d469dba test/3pdata/bmpsuite/g/pal4.bmp
|
||||
OK. e13c35dc test/3pdata/bmpsuite/g/pal4gs.bmp
|
||||
OK. 4d469dba test/3pdata/bmpsuite/g/pal4rle.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/g/pal8-0.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/g/pal8.bmp
|
||||
OK. 45214efa test/3pdata/bmpsuite/g/pal8gs.bmp
|
||||
OK. b734e840 test/3pdata/bmpsuite/g/pal8nonsquare.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/g/pal8os2.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/g/pal8rle.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/g/pal8topdown.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/g/pal8v4.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/g/pal8v5.bmp
|
||||
OK. c8250daf test/3pdata/bmpsuite/g/pal8w124.bmp
|
||||
OK. 98379ca2 test/3pdata/bmpsuite/g/pal8w125.bmp
|
||||
OK. faeb1685 test/3pdata/bmpsuite/g/pal8w126.bmp
|
||||
OK. 1b183dc1 test/3pdata/bmpsuite/g/rgb16-565.bmp
|
||||
OK. 1b183dc1 test/3pdata/bmpsuite/g/rgb16-565pal.bmp
|
||||
OK. 8579ddaf test/3pdata/bmpsuite/g/rgb16.bmp
|
||||
OK. 8579ddaf test/3pdata/bmpsuite/g/rgb16bfdef.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/g/rgb24.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/g/rgb24pal.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/g/rgb32.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/g/rgb32bf.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/g/rgb32bfdef.bmp
|
||||
OK. 91cd8d0b test/3pdata/bmpsuite/html/bkgd.png
|
||||
OK. 2be75470 test/3pdata/bmpsuite/html/fakealpha.png
|
||||
OK. 1aec39e7 test/3pdata/bmpsuite/html/pal1.png
|
||||
OK. 909c4c97 test/3pdata/bmpsuite/html/pal1bg.png
|
||||
OK. 5628bcde test/3pdata/bmpsuite/html/pal1p1.png
|
||||
OK. e0c1e54d test/3pdata/bmpsuite/html/pal2.png
|
||||
OK. 0b09d3b2 test/3pdata/bmpsuite/html/pal2color.png
|
||||
OK. 4d469dba test/3pdata/bmpsuite/html/pal4.png
|
||||
OK. e13c35dc test/3pdata/bmpsuite/html/pal4gs.png
|
||||
OK. 70f35a4b test/3pdata/bmpsuite/html/pal4rlecut-0.png
|
||||
OK. 87a1d295 test/3pdata/bmpsuite/html/pal4rlecut-b.png
|
||||
OK. f4b1df15 test/3pdata/bmpsuite/html/pal4rlecut.png
|
||||
OK. 79fbbc2e test/3pdata/bmpsuite/html/pal4rletrns-0.png
|
||||
OK. 4c725320 test/3pdata/bmpsuite/html/pal4rletrns-b.png
|
||||
OK. b988a431 test/3pdata/bmpsuite/html/pal4rletrns.png
|
||||
OK. eddff465 test/3pdata/bmpsuite/html/pal8.png
|
||||
OK. 45214efa test/3pdata/bmpsuite/html/pal8gs.png
|
||||
OK. b734e840 test/3pdata/bmpsuite/html/pal8nonsquare-e.png
|
||||
OK. aacdd756 test/3pdata/bmpsuite/html/pal8nonsquare-v.png
|
||||
OK. b9d48e8d test/3pdata/bmpsuite/html/pal8rlecut-0.png
|
||||
OK. 3843191e test/3pdata/bmpsuite/html/pal8rlecut-b.png
|
||||
OK. 2c7f45de test/3pdata/bmpsuite/html/pal8rlecut.png
|
||||
OK. d962d5f1 test/3pdata/bmpsuite/html/pal8rletrns-0.png
|
||||
OK. eceb3aff test/3pdata/bmpsuite/html/pal8rletrns-b.png
|
||||
OK. 1911cdee test/3pdata/bmpsuite/html/pal8rletrns.png
|
||||
OK. c8250daf test/3pdata/bmpsuite/html/pal8w124.png
|
||||
OK. 98379ca2 test/3pdata/bmpsuite/html/pal8w125.png
|
||||
OK. faeb1685 test/3pdata/bmpsuite/html/pal8w126.png
|
||||
OK. db57e11a test/3pdata/bmpsuite/html/rgb16-231.png
|
||||
OK. 1146975d test/3pdata/bmpsuite/html/rgb16-3103.png
|
||||
OK. 5f733194 test/3pdata/bmpsuite/html/rgb16-565.png
|
||||
OK. 3a178cd6 test/3pdata/bmpsuite/html/rgb16-880.png
|
||||
OK. 6c90b630 test/3pdata/bmpsuite/html/rgb16.png
|
||||
OK. ae961b51 test/3pdata/bmpsuite/html/rgb16faketrns.png
|
||||
OK. 50b4e08b test/3pdata/bmpsuite/html/rgb24.jpg
|
||||
OK. 75060601 test/3pdata/bmpsuite/html/rgb24.png
|
||||
OK. 464c0212 test/3pdata/bmpsuite/html/rgb32-7187.png
|
||||
OK. ed9d9275 test/3pdata/bmpsuite/html/rgba16-1924.png
|
||||
OK. 264bf86f test/3pdata/bmpsuite/html/rgba16-4444.png
|
||||
OK. 985e8fbb test/3pdata/bmpsuite/html/rgba16-5551.png
|
||||
OK. 4fb41940 test/3pdata/bmpsuite/html/rgba32-1010102.png
|
||||
OK. 42e2a973 test/3pdata/bmpsuite/html/rgba32-61754.png
|
||||
OK. 4bd457aa test/3pdata/bmpsuite/html/rgba32-81284.png
|
||||
OK. 89060da6 test/3pdata/bmpsuite/html/rgba32.png
|
||||
OK. 5628bcde test/3pdata/bmpsuite/q/pal1p1.bmp
|
||||
OK. e0c1e54d test/3pdata/bmpsuite/q/pal2.bmp
|
||||
OK. 0b09d3b2 test/3pdata/bmpsuite/q/pal2color.bmp
|
||||
OK. 87a1d295 test/3pdata/bmpsuite/q/pal4rlecut.bmp
|
||||
OK. 4c725320 test/3pdata/bmpsuite/q/pal4rletrns.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8offs.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8os2-hs.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8os2-sz.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8os2sp.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8os2v2-16.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8os2v2-40sz.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8os2v2-sz.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8os2v2.bmp
|
||||
OK. eddff465 test/3pdata/bmpsuite/q/pal8oversizepal.bmp
|
||||
OK. 3843191e test/3pdata/bmpsuite/q/pal8rlecut.bmp
|
||||
OK. eceb3aff test/3pdata/bmpsuite/q/pal8rletrns.bmp
|
||||
OK. db57e11a test/3pdata/bmpsuite/q/rgb16-231.bmp
|
||||
OK. fb300729 test/3pdata/bmpsuite/q/rgb16-3103.bmp
|
||||
OK. 8579ddaf test/3pdata/bmpsuite/q/rgb16faketrns.bmp
|
||||
OK. 50b4e08b test/3pdata/bmpsuite/q/rgb24jpeg.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/q/rgb24largepal.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/q/rgb24lprof.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/q/rgb24png.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/q/rgb24prof.bmp
|
||||
OK. 5aae25cd test/3pdata/bmpsuite/q/rgb24prof2.bmp
|
||||
OK. 41299717 test/3pdata/bmpsuite/q/rgb32-111110.bmp
|
||||
OK. 464c0212 test/3pdata/bmpsuite/q/rgb32-7187.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/q/rgb32-xbgr.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/q/rgb32fakealpha.bmp
|
||||
OK. 75060601 test/3pdata/bmpsuite/q/rgb32h52.bmp
|
||||
OK. 9d5e24fd test/3pdata/bmpsuite/q/rgba16-1924.bmp
|
||||
OK. 56884ee7 test/3pdata/bmpsuite/q/rgba16-4444.bmp
|
||||
OK. 844d1335 test/3pdata/bmpsuite/q/rgba16-5551.bmp
|
||||
OK. 277ef135 test/3pdata/bmpsuite/q/rgba32-1.bmp
|
||||
OK. b4db4238 test/3pdata/bmpsuite/q/rgba32-1010102.bmp
|
||||
OK. 277ef135 test/3pdata/bmpsuite/q/rgba32-2.bmp
|
||||
OK. 9d08e5fe test/3pdata/bmpsuite/q/rgba32-61754.bmp
|
||||
OK. 943e1b27 test/3pdata/bmpsuite/q/rgba32-81284.bmp
|
||||
OK. 277ef135 test/3pdata/bmpsuite/q/rgba32abf.bmp
|
||||
OK. 277ef135 test/3pdata/bmpsuite/q/rgba32h56.bmp
|
||||
@@ -1,37 +1,37 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
0e9336e8 test/3pdata/golangsuite/triangle-001.gif
|
||||
f47bba01 test/3pdata/golangsuite/video-001.221212.jpeg
|
||||
f887663d test/3pdata/golangsuite/video-001.221212.png
|
||||
9db259ab test/3pdata/golangsuite/video-001.5bpp.gif
|
||||
7b281f70 test/3pdata/golangsuite/video-001.cmyk.jpeg
|
||||
f543e98a test/3pdata/golangsuite/video-001.cmyk.png
|
||||
0548cd56 test/3pdata/golangsuite/video-001.gif
|
||||
0548cd56 test/3pdata/golangsuite/video-001.interlaced.gif
|
||||
0a53abfa test/3pdata/golangsuite/video-001.jpeg
|
||||
3007a29c test/3pdata/golangsuite/video-001.png
|
||||
0a53abfa test/3pdata/golangsuite/video-001.progressive.jpeg
|
||||
eb488d9d test/3pdata/golangsuite/video-001.progressive.truncated.jpeg
|
||||
2ab9f15a test/3pdata/golangsuite/video-001.progressive.truncated.png
|
||||
984fd1dc test/3pdata/golangsuite/video-001.q50.410.jpeg
|
||||
984fd1dc test/3pdata/golangsuite/video-001.q50.410.progressive.jpeg
|
||||
79620b83 test/3pdata/golangsuite/video-001.q50.411.jpeg
|
||||
79620b83 test/3pdata/golangsuite/video-001.q50.411.progressive.jpeg
|
||||
bbfa93c7 test/3pdata/golangsuite/video-001.q50.420.jpeg
|
||||
bbfa93c7 test/3pdata/golangsuite/video-001.q50.420.progressive.jpeg
|
||||
d8657741 test/3pdata/golangsuite/video-001.q50.422.jpeg
|
||||
d8657741 test/3pdata/golangsuite/video-001.q50.422.progressive.jpeg
|
||||
2fdb8a91 test/3pdata/golangsuite/video-001.q50.440.jpeg
|
||||
2fdb8a91 test/3pdata/golangsuite/video-001.q50.440.progressive.jpeg
|
||||
efee4983 test/3pdata/golangsuite/video-001.q50.444.jpeg
|
||||
efee4983 test/3pdata/golangsuite/video-001.q50.444.progressive.jpeg
|
||||
27869749 test/3pdata/golangsuite/video-001.rgb.jpeg
|
||||
67b4d82f test/3pdata/golangsuite/video-001.rgb.png
|
||||
f295069f test/3pdata/golangsuite/video-001.separate.dc.progression.jpeg
|
||||
f295069f test/3pdata/golangsuite/video-001.separate.dc.progression.progressive.jpeg
|
||||
5ad62b1c test/3pdata/golangsuite/video-005.gray.gif
|
||||
1eb446be test/3pdata/golangsuite/video-005.gray.jpeg
|
||||
0e0cf8a7 test/3pdata/golangsuite/video-005.gray.png
|
||||
4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.2x2.jpeg
|
||||
4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.2x2.progressive.jpeg
|
||||
4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.jpeg
|
||||
4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.progressive.jpeg
|
||||
OK. 0e9336e8 test/3pdata/golangsuite/triangle-001.gif
|
||||
OK. f47bba01 test/3pdata/golangsuite/video-001.221212.jpeg
|
||||
OK. f887663d test/3pdata/golangsuite/video-001.221212.png
|
||||
OK. 9db259ab test/3pdata/golangsuite/video-001.5bpp.gif
|
||||
OK. 7b281f70 test/3pdata/golangsuite/video-001.cmyk.jpeg
|
||||
OK. f543e98a test/3pdata/golangsuite/video-001.cmyk.png
|
||||
OK. 0548cd56 test/3pdata/golangsuite/video-001.gif
|
||||
OK. 0548cd56 test/3pdata/golangsuite/video-001.interlaced.gif
|
||||
OK. 0a53abfa test/3pdata/golangsuite/video-001.jpeg
|
||||
OK. 3007a29c test/3pdata/golangsuite/video-001.png
|
||||
OK. 0a53abfa test/3pdata/golangsuite/video-001.progressive.jpeg
|
||||
OK. eb488d9d test/3pdata/golangsuite/video-001.progressive.truncated.jpeg
|
||||
OK. 2ab9f15a test/3pdata/golangsuite/video-001.progressive.truncated.png
|
||||
OK. 984fd1dc test/3pdata/golangsuite/video-001.q50.410.jpeg
|
||||
OK. 984fd1dc test/3pdata/golangsuite/video-001.q50.410.progressive.jpeg
|
||||
OK. 79620b83 test/3pdata/golangsuite/video-001.q50.411.jpeg
|
||||
OK. 79620b83 test/3pdata/golangsuite/video-001.q50.411.progressive.jpeg
|
||||
OK. bbfa93c7 test/3pdata/golangsuite/video-001.q50.420.jpeg
|
||||
OK. bbfa93c7 test/3pdata/golangsuite/video-001.q50.420.progressive.jpeg
|
||||
OK. d8657741 test/3pdata/golangsuite/video-001.q50.422.jpeg
|
||||
OK. d8657741 test/3pdata/golangsuite/video-001.q50.422.progressive.jpeg
|
||||
OK. 2fdb8a91 test/3pdata/golangsuite/video-001.q50.440.jpeg
|
||||
OK. 2fdb8a91 test/3pdata/golangsuite/video-001.q50.440.progressive.jpeg
|
||||
OK. efee4983 test/3pdata/golangsuite/video-001.q50.444.jpeg
|
||||
OK. efee4983 test/3pdata/golangsuite/video-001.q50.444.progressive.jpeg
|
||||
OK. 27869749 test/3pdata/golangsuite/video-001.rgb.jpeg
|
||||
OK. 67b4d82f test/3pdata/golangsuite/video-001.rgb.png
|
||||
OK. f295069f test/3pdata/golangsuite/video-001.separate.dc.progression.jpeg
|
||||
OK. f295069f test/3pdata/golangsuite/video-001.separate.dc.progression.progressive.jpeg
|
||||
OK. 5ad62b1c test/3pdata/golangsuite/video-005.gray.gif
|
||||
OK. 1eb446be test/3pdata/golangsuite/video-005.gray.jpeg
|
||||
OK. 0e0cf8a7 test/3pdata/golangsuite/video-005.gray.png
|
||||
OK. 4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.2x2.jpeg
|
||||
OK. 4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.2x2.progressive.jpeg
|
||||
OK. 4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.jpeg
|
||||
OK. 4a578fc0 test/3pdata/golangsuite/video-005.gray.q50.progressive.jpeg
|
||||
@@ -1,164 +1,164 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
aac44167 test/3pdata/pngsuite/PngSuite.png
|
||||
926d3aa2 test/3pdata/pngsuite/basi0g01.png
|
||||
8f50bdc6 test/3pdata/pngsuite/basi0g02.png
|
||||
6d612626 test/3pdata/pngsuite/basi0g04.png
|
||||
024cf410 test/3pdata/pngsuite/basi0g08.png
|
||||
bb956205 test/3pdata/pngsuite/basi0g16.png
|
||||
d1ae61d3 test/3pdata/pngsuite/basi2c08.png
|
||||
84bc9be8 test/3pdata/pngsuite/basi2c16.png
|
||||
49bc6b98 test/3pdata/pngsuite/basi3p01.png
|
||||
ad12897b test/3pdata/pngsuite/basi3p02.png
|
||||
81c22b59 test/3pdata/pngsuite/basi3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/basi3p08.png
|
||||
1b468494 test/3pdata/pngsuite/basi4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/basi4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/basi6a08.png
|
||||
b039babf test/3pdata/pngsuite/basi6a16.png
|
||||
926d3aa2 test/3pdata/pngsuite/basn0g01.png
|
||||
8f50bdc6 test/3pdata/pngsuite/basn0g02.png
|
||||
6d612626 test/3pdata/pngsuite/basn0g04.png
|
||||
024cf410 test/3pdata/pngsuite/basn0g08.png
|
||||
bb956205 test/3pdata/pngsuite/basn0g16.png
|
||||
d1ae61d3 test/3pdata/pngsuite/basn2c08.png
|
||||
84bc9be8 test/3pdata/pngsuite/basn2c16.png
|
||||
49bc6b98 test/3pdata/pngsuite/basn3p01.png
|
||||
ad12897b test/3pdata/pngsuite/basn3p02.png
|
||||
81c22b59 test/3pdata/pngsuite/basn3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/basn3p08.png
|
||||
1b468494 test/3pdata/pngsuite/basn4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/basn4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/basn6a08.png
|
||||
b039babf test/3pdata/pngsuite/basn6a16.png
|
||||
1b468494 test/3pdata/pngsuite/bgai4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/bgai4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/bgan6a08.png
|
||||
b039babf test/3pdata/pngsuite/bgan6a16.png
|
||||
1b468494 test/3pdata/pngsuite/bgbn4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/bggn4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/bgwn6a08.png
|
||||
b039babf test/3pdata/pngsuite/bgyn6a16.png
|
||||
b58985e2 test/3pdata/pngsuite/ccwn2c08.png
|
||||
b7f7127d test/3pdata/pngsuite/ccwn3p08.png
|
||||
c7b4c0fa test/3pdata/pngsuite/cdfn2c08.png
|
||||
dabf7a40 test/3pdata/pngsuite/cdhn2c08.png
|
||||
8491ddf5 test/3pdata/pngsuite/cdsn2c08.png
|
||||
d9282a90 test/3pdata/pngsuite/cdun2c08.png
|
||||
81c22b59 test/3pdata/pngsuite/ch1n3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/ch2n3p08.png
|
||||
b3334ede test/3pdata/pngsuite/cm0n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/cm7n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/cm9n0g04.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs3n2c16.png
|
||||
d565507c test/3pdata/pngsuite/cs3n3p08.png
|
||||
2f5a21b9 test/3pdata/pngsuite/cs5n2c08.png
|
||||
2f5a21b9 test/3pdata/pngsuite/cs5n3p08.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs8n2c08.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs8n3p08.png
|
||||
b3334ede test/3pdata/pngsuite/ct0n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/ct1n0g04.png
|
||||
1bfcb6e6 test/3pdata/pngsuite/cten0g04.png
|
||||
8e493daf test/3pdata/pngsuite/ctfn0g04.png
|
||||
417a539e test/3pdata/pngsuite/ctgn0g04.png
|
||||
28033324 test/3pdata/pngsuite/cthn0g04.png
|
||||
71a82501 test/3pdata/pngsuite/ctjn0g04.png
|
||||
b3334ede test/3pdata/pngsuite/ctzn0g04.png
|
||||
aa5328d3 test/3pdata/pngsuite/exif2c08.png
|
||||
b81f03cc test/3pdata/pngsuite/f00n0g08.png
|
||||
4a12368c test/3pdata/pngsuite/f00n2c08.png
|
||||
7fe4a9d8 test/3pdata/pngsuite/f01n0g08.png
|
||||
36758edc test/3pdata/pngsuite/f01n2c08.png
|
||||
e0ab5774 test/3pdata/pngsuite/f02n0g08.png
|
||||
5e613513 test/3pdata/pngsuite/f02n2c08.png
|
||||
0719e3fa test/3pdata/pngsuite/f03n0g08.png
|
||||
c4709cc1 test/3pdata/pngsuite/f03n2c08.png
|
||||
457f1dab test/3pdata/pngsuite/f04n0g08.png
|
||||
7ec3c986 test/3pdata/pngsuite/f04n2c08.png
|
||||
1f319e46 test/3pdata/pngsuite/f99n0g04.png
|
||||
6000bb5b test/3pdata/pngsuite/g03n0g16.png
|
||||
aa019a24 test/3pdata/pngsuite/g03n2c08.png
|
||||
8f0a3383 test/3pdata/pngsuite/g03n3p04.png
|
||||
f3a44153 test/3pdata/pngsuite/g04n0g16.png
|
||||
3e852c56 test/3pdata/pngsuite/g04n2c08.png
|
||||
edb3555b test/3pdata/pngsuite/g04n3p04.png
|
||||
6b105de1 test/3pdata/pngsuite/g05n0g16.png
|
||||
938803a0 test/3pdata/pngsuite/g05n2c08.png
|
||||
9f7ad612 test/3pdata/pngsuite/g05n3p04.png
|
||||
28816978 test/3pdata/pngsuite/g07n0g16.png
|
||||
fedb8920 test/3pdata/pngsuite/g07n2c08.png
|
||||
9373010e test/3pdata/pngsuite/g07n3p04.png
|
||||
58eb5aca test/3pdata/pngsuite/g10n0g16.png
|
||||
8c5550d0 test/3pdata/pngsuite/g10n2c08.png
|
||||
a6120550 test/3pdata/pngsuite/g10n3p04.png
|
||||
14cc7e1c test/3pdata/pngsuite/g25n0g16.png
|
||||
fd0f349f test/3pdata/pngsuite/g25n2c08.png
|
||||
eb13812a test/3pdata/pngsuite/g25n3p04.png
|
||||
bb956205 test/3pdata/pngsuite/oi1n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi1n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi2n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi2n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi4n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi4n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi9n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi9n2c16.png
|
||||
84bc9be8 test/3pdata/pngsuite/pp0n2c16.png
|
||||
8ed1f246 test/3pdata/pngsuite/pp0n6a08.png
|
||||
024cf410 test/3pdata/pngsuite/ps1n0g08.png
|
||||
84bc9be8 test/3pdata/pngsuite/ps1n2c16.png
|
||||
024cf410 test/3pdata/pngsuite/ps2n0g08.png
|
||||
84bc9be8 test/3pdata/pngsuite/ps2n2c16.png
|
||||
7cf2b7b2 test/3pdata/pngsuite/s01i3p01.png
|
||||
7cf2b7b2 test/3pdata/pngsuite/s01n3p01.png
|
||||
ffa30c78 test/3pdata/pngsuite/s02i3p01.png
|
||||
ffa30c78 test/3pdata/pngsuite/s02n3p01.png
|
||||
ad298c62 test/3pdata/pngsuite/s03i3p01.png
|
||||
ad298c62 test/3pdata/pngsuite/s03n3p01.png
|
||||
2c30132c test/3pdata/pngsuite/s04i3p01.png
|
||||
2c30132c test/3pdata/pngsuite/s04n3p01.png
|
||||
5fb20358 test/3pdata/pngsuite/s05i3p02.png
|
||||
5fb20358 test/3pdata/pngsuite/s05n3p02.png
|
||||
764e90bd test/3pdata/pngsuite/s06i3p02.png
|
||||
764e90bd test/3pdata/pngsuite/s06n3p02.png
|
||||
9eebca92 test/3pdata/pngsuite/s07i3p02.png
|
||||
9eebca92 test/3pdata/pngsuite/s07n3p02.png
|
||||
d57f2e84 test/3pdata/pngsuite/s08i3p02.png
|
||||
d57f2e84 test/3pdata/pngsuite/s08n3p02.png
|
||||
7585127f test/3pdata/pngsuite/s09i3p02.png
|
||||
7585127f test/3pdata/pngsuite/s09n3p02.png
|
||||
034051a8 test/3pdata/pngsuite/s32i3p04.png
|
||||
034051a8 test/3pdata/pngsuite/s32n3p04.png
|
||||
a377dcdd test/3pdata/pngsuite/s33i3p04.png
|
||||
a377dcdd test/3pdata/pngsuite/s33n3p04.png
|
||||
5bcd998d test/3pdata/pngsuite/s34i3p04.png
|
||||
5bcd998d test/3pdata/pngsuite/s34n3p04.png
|
||||
1cefbbe2 test/3pdata/pngsuite/s35i3p04.png
|
||||
1cefbbe2 test/3pdata/pngsuite/s35n3p04.png
|
||||
97c763a3 test/3pdata/pngsuite/s36i3p04.png
|
||||
97c763a3 test/3pdata/pngsuite/s36n3p04.png
|
||||
2d6bd687 test/3pdata/pngsuite/s37i3p04.png
|
||||
2d6bd687 test/3pdata/pngsuite/s37n3p04.png
|
||||
169951e5 test/3pdata/pngsuite/s38i3p04.png
|
||||
169951e5 test/3pdata/pngsuite/s38n3p04.png
|
||||
17a92eb2 test/3pdata/pngsuite/s39i3p04.png
|
||||
17a92eb2 test/3pdata/pngsuite/s39n3p04.png
|
||||
8cc6b93d test/3pdata/pngsuite/s40i3p04.png
|
||||
8cc6b93d test/3pdata/pngsuite/s40n3p04.png
|
||||
4e406947 test/3pdata/pngsuite/tbbn0g04.png
|
||||
c6e83019 test/3pdata/pngsuite/tbbn2c16.png
|
||||
46deef3b test/3pdata/pngsuite/tbbn3p08.png
|
||||
c6e83019 test/3pdata/pngsuite/tbgn2c16.png
|
||||
46deef3b test/3pdata/pngsuite/tbgn3p08.png
|
||||
c6e83019 test/3pdata/pngsuite/tbrn2c08.png
|
||||
2289ed1e test/3pdata/pngsuite/tbwn0g16.png
|
||||
46deef3b test/3pdata/pngsuite/tbwn3p08.png
|
||||
46deef3b test/3pdata/pngsuite/tbyn3p08.png
|
||||
59b23555 test/3pdata/pngsuite/tm3n3p02.png
|
||||
f2457b64 test/3pdata/pngsuite/tp0n0g08.png
|
||||
05846c5f test/3pdata/pngsuite/tp0n2c08.png
|
||||
3d7708a8 test/3pdata/pngsuite/tp0n3p08.png
|
||||
46deef3b test/3pdata/pngsuite/tp1n3p08.png
|
||||
926d3aa2 test/3pdata/pngsuite/xcsn0g01.png
|
||||
9098c4d8 test/3pdata/pngsuite/z00n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z03n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z06n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z09n2c08.png
|
||||
OK. aac44167 test/3pdata/pngsuite/PngSuite.png
|
||||
OK. 926d3aa2 test/3pdata/pngsuite/basi0g01.png
|
||||
OK. 8f50bdc6 test/3pdata/pngsuite/basi0g02.png
|
||||
OK. 6d612626 test/3pdata/pngsuite/basi0g04.png
|
||||
OK. 024cf410 test/3pdata/pngsuite/basi0g08.png
|
||||
OK. bb956205 test/3pdata/pngsuite/basi0g16.png
|
||||
OK. d1ae61d3 test/3pdata/pngsuite/basi2c08.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/basi2c16.png
|
||||
OK. 49bc6b98 test/3pdata/pngsuite/basi3p01.png
|
||||
OK. ad12897b test/3pdata/pngsuite/basi3p02.png
|
||||
OK. 81c22b59 test/3pdata/pngsuite/basi3p04.png
|
||||
OK. e59ecea5 test/3pdata/pngsuite/basi3p08.png
|
||||
OK. 1b468494 test/3pdata/pngsuite/basi4a08.png
|
||||
OK. 8a6dd244 test/3pdata/pngsuite/basi4a16.png
|
||||
OK. 2b1044ce test/3pdata/pngsuite/basi6a08.png
|
||||
OK. b039babf test/3pdata/pngsuite/basi6a16.png
|
||||
OK. 926d3aa2 test/3pdata/pngsuite/basn0g01.png
|
||||
OK. 8f50bdc6 test/3pdata/pngsuite/basn0g02.png
|
||||
OK. 6d612626 test/3pdata/pngsuite/basn0g04.png
|
||||
OK. 024cf410 test/3pdata/pngsuite/basn0g08.png
|
||||
OK. bb956205 test/3pdata/pngsuite/basn0g16.png
|
||||
OK. d1ae61d3 test/3pdata/pngsuite/basn2c08.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/basn2c16.png
|
||||
OK. 49bc6b98 test/3pdata/pngsuite/basn3p01.png
|
||||
OK. ad12897b test/3pdata/pngsuite/basn3p02.png
|
||||
OK. 81c22b59 test/3pdata/pngsuite/basn3p04.png
|
||||
OK. e59ecea5 test/3pdata/pngsuite/basn3p08.png
|
||||
OK. 1b468494 test/3pdata/pngsuite/basn4a08.png
|
||||
OK. 8a6dd244 test/3pdata/pngsuite/basn4a16.png
|
||||
OK. 2b1044ce test/3pdata/pngsuite/basn6a08.png
|
||||
OK. b039babf test/3pdata/pngsuite/basn6a16.png
|
||||
OK. 1b468494 test/3pdata/pngsuite/bgai4a08.png
|
||||
OK. 8a6dd244 test/3pdata/pngsuite/bgai4a16.png
|
||||
OK. 2b1044ce test/3pdata/pngsuite/bgan6a08.png
|
||||
OK. b039babf test/3pdata/pngsuite/bgan6a16.png
|
||||
OK. 1b468494 test/3pdata/pngsuite/bgbn4a08.png
|
||||
OK. 8a6dd244 test/3pdata/pngsuite/bggn4a16.png
|
||||
OK. 2b1044ce test/3pdata/pngsuite/bgwn6a08.png
|
||||
OK. b039babf test/3pdata/pngsuite/bgyn6a16.png
|
||||
OK. b58985e2 test/3pdata/pngsuite/ccwn2c08.png
|
||||
OK. b7f7127d test/3pdata/pngsuite/ccwn3p08.png
|
||||
OK. c7b4c0fa test/3pdata/pngsuite/cdfn2c08.png
|
||||
OK. dabf7a40 test/3pdata/pngsuite/cdhn2c08.png
|
||||
OK. 8491ddf5 test/3pdata/pngsuite/cdsn2c08.png
|
||||
OK. d9282a90 test/3pdata/pngsuite/cdun2c08.png
|
||||
OK. 81c22b59 test/3pdata/pngsuite/ch1n3p04.png
|
||||
OK. e59ecea5 test/3pdata/pngsuite/ch2n3p08.png
|
||||
OK. b3334ede test/3pdata/pngsuite/cm0n0g04.png
|
||||
OK. b3334ede test/3pdata/pngsuite/cm7n0g04.png
|
||||
OK. b3334ede test/3pdata/pngsuite/cm9n0g04.png
|
||||
OK. 8ce6e28c test/3pdata/pngsuite/cs3n2c16.png
|
||||
OK. d565507c test/3pdata/pngsuite/cs3n3p08.png
|
||||
OK. 2f5a21b9 test/3pdata/pngsuite/cs5n2c08.png
|
||||
OK. 2f5a21b9 test/3pdata/pngsuite/cs5n3p08.png
|
||||
OK. 8ce6e28c test/3pdata/pngsuite/cs8n2c08.png
|
||||
OK. 8ce6e28c test/3pdata/pngsuite/cs8n3p08.png
|
||||
OK. b3334ede test/3pdata/pngsuite/ct0n0g04.png
|
||||
OK. b3334ede test/3pdata/pngsuite/ct1n0g04.png
|
||||
OK. 1bfcb6e6 test/3pdata/pngsuite/cten0g04.png
|
||||
OK. 8e493daf test/3pdata/pngsuite/ctfn0g04.png
|
||||
OK. 417a539e test/3pdata/pngsuite/ctgn0g04.png
|
||||
OK. 28033324 test/3pdata/pngsuite/cthn0g04.png
|
||||
OK. 71a82501 test/3pdata/pngsuite/ctjn0g04.png
|
||||
OK. b3334ede test/3pdata/pngsuite/ctzn0g04.png
|
||||
OK. aa5328d3 test/3pdata/pngsuite/exif2c08.png
|
||||
OK. b81f03cc test/3pdata/pngsuite/f00n0g08.png
|
||||
OK. 4a12368c test/3pdata/pngsuite/f00n2c08.png
|
||||
OK. 7fe4a9d8 test/3pdata/pngsuite/f01n0g08.png
|
||||
OK. 36758edc test/3pdata/pngsuite/f01n2c08.png
|
||||
OK. e0ab5774 test/3pdata/pngsuite/f02n0g08.png
|
||||
OK. 5e613513 test/3pdata/pngsuite/f02n2c08.png
|
||||
OK. 0719e3fa test/3pdata/pngsuite/f03n0g08.png
|
||||
OK. c4709cc1 test/3pdata/pngsuite/f03n2c08.png
|
||||
OK. 457f1dab test/3pdata/pngsuite/f04n0g08.png
|
||||
OK. 7ec3c986 test/3pdata/pngsuite/f04n2c08.png
|
||||
OK. 1f319e46 test/3pdata/pngsuite/f99n0g04.png
|
||||
OK. 6000bb5b test/3pdata/pngsuite/g03n0g16.png
|
||||
OK. aa019a24 test/3pdata/pngsuite/g03n2c08.png
|
||||
OK. 8f0a3383 test/3pdata/pngsuite/g03n3p04.png
|
||||
OK. f3a44153 test/3pdata/pngsuite/g04n0g16.png
|
||||
OK. 3e852c56 test/3pdata/pngsuite/g04n2c08.png
|
||||
OK. edb3555b test/3pdata/pngsuite/g04n3p04.png
|
||||
OK. 6b105de1 test/3pdata/pngsuite/g05n0g16.png
|
||||
OK. 938803a0 test/3pdata/pngsuite/g05n2c08.png
|
||||
OK. 9f7ad612 test/3pdata/pngsuite/g05n3p04.png
|
||||
OK. 28816978 test/3pdata/pngsuite/g07n0g16.png
|
||||
OK. fedb8920 test/3pdata/pngsuite/g07n2c08.png
|
||||
OK. 9373010e test/3pdata/pngsuite/g07n3p04.png
|
||||
OK. 58eb5aca test/3pdata/pngsuite/g10n0g16.png
|
||||
OK. 8c5550d0 test/3pdata/pngsuite/g10n2c08.png
|
||||
OK. a6120550 test/3pdata/pngsuite/g10n3p04.png
|
||||
OK. 14cc7e1c test/3pdata/pngsuite/g25n0g16.png
|
||||
OK. fd0f349f test/3pdata/pngsuite/g25n2c08.png
|
||||
OK. eb13812a test/3pdata/pngsuite/g25n3p04.png
|
||||
OK. bb956205 test/3pdata/pngsuite/oi1n0g16.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/oi1n2c16.png
|
||||
OK. bb956205 test/3pdata/pngsuite/oi2n0g16.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/oi2n2c16.png
|
||||
OK. bb956205 test/3pdata/pngsuite/oi4n0g16.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/oi4n2c16.png
|
||||
OK. bb956205 test/3pdata/pngsuite/oi9n0g16.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/oi9n2c16.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/pp0n2c16.png
|
||||
OK. 8ed1f246 test/3pdata/pngsuite/pp0n6a08.png
|
||||
OK. 024cf410 test/3pdata/pngsuite/ps1n0g08.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/ps1n2c16.png
|
||||
OK. 024cf410 test/3pdata/pngsuite/ps2n0g08.png
|
||||
OK. 84bc9be8 test/3pdata/pngsuite/ps2n2c16.png
|
||||
OK. 7cf2b7b2 test/3pdata/pngsuite/s01i3p01.png
|
||||
OK. 7cf2b7b2 test/3pdata/pngsuite/s01n3p01.png
|
||||
OK. ffa30c78 test/3pdata/pngsuite/s02i3p01.png
|
||||
OK. ffa30c78 test/3pdata/pngsuite/s02n3p01.png
|
||||
OK. ad298c62 test/3pdata/pngsuite/s03i3p01.png
|
||||
OK. ad298c62 test/3pdata/pngsuite/s03n3p01.png
|
||||
OK. 2c30132c test/3pdata/pngsuite/s04i3p01.png
|
||||
OK. 2c30132c test/3pdata/pngsuite/s04n3p01.png
|
||||
OK. 5fb20358 test/3pdata/pngsuite/s05i3p02.png
|
||||
OK. 5fb20358 test/3pdata/pngsuite/s05n3p02.png
|
||||
OK. 764e90bd test/3pdata/pngsuite/s06i3p02.png
|
||||
OK. 764e90bd test/3pdata/pngsuite/s06n3p02.png
|
||||
OK. 9eebca92 test/3pdata/pngsuite/s07i3p02.png
|
||||
OK. 9eebca92 test/3pdata/pngsuite/s07n3p02.png
|
||||
OK. d57f2e84 test/3pdata/pngsuite/s08i3p02.png
|
||||
OK. d57f2e84 test/3pdata/pngsuite/s08n3p02.png
|
||||
OK. 7585127f test/3pdata/pngsuite/s09i3p02.png
|
||||
OK. 7585127f test/3pdata/pngsuite/s09n3p02.png
|
||||
OK. 034051a8 test/3pdata/pngsuite/s32i3p04.png
|
||||
OK. 034051a8 test/3pdata/pngsuite/s32n3p04.png
|
||||
OK. a377dcdd test/3pdata/pngsuite/s33i3p04.png
|
||||
OK. a377dcdd test/3pdata/pngsuite/s33n3p04.png
|
||||
OK. 5bcd998d test/3pdata/pngsuite/s34i3p04.png
|
||||
OK. 5bcd998d test/3pdata/pngsuite/s34n3p04.png
|
||||
OK. 1cefbbe2 test/3pdata/pngsuite/s35i3p04.png
|
||||
OK. 1cefbbe2 test/3pdata/pngsuite/s35n3p04.png
|
||||
OK. 97c763a3 test/3pdata/pngsuite/s36i3p04.png
|
||||
OK. 97c763a3 test/3pdata/pngsuite/s36n3p04.png
|
||||
OK. 2d6bd687 test/3pdata/pngsuite/s37i3p04.png
|
||||
OK. 2d6bd687 test/3pdata/pngsuite/s37n3p04.png
|
||||
OK. 169951e5 test/3pdata/pngsuite/s38i3p04.png
|
||||
OK. 169951e5 test/3pdata/pngsuite/s38n3p04.png
|
||||
OK. 17a92eb2 test/3pdata/pngsuite/s39i3p04.png
|
||||
OK. 17a92eb2 test/3pdata/pngsuite/s39n3p04.png
|
||||
OK. 8cc6b93d test/3pdata/pngsuite/s40i3p04.png
|
||||
OK. 8cc6b93d test/3pdata/pngsuite/s40n3p04.png
|
||||
OK. 4e406947 test/3pdata/pngsuite/tbbn0g04.png
|
||||
OK. c6e83019 test/3pdata/pngsuite/tbbn2c16.png
|
||||
OK. 46deef3b test/3pdata/pngsuite/tbbn3p08.png
|
||||
OK. c6e83019 test/3pdata/pngsuite/tbgn2c16.png
|
||||
OK. 46deef3b test/3pdata/pngsuite/tbgn3p08.png
|
||||
OK. c6e83019 test/3pdata/pngsuite/tbrn2c08.png
|
||||
OK. 2289ed1e test/3pdata/pngsuite/tbwn0g16.png
|
||||
OK. 46deef3b test/3pdata/pngsuite/tbwn3p08.png
|
||||
OK. 46deef3b test/3pdata/pngsuite/tbyn3p08.png
|
||||
OK. 59b23555 test/3pdata/pngsuite/tm3n3p02.png
|
||||
OK. f2457b64 test/3pdata/pngsuite/tp0n0g08.png
|
||||
OK. 05846c5f test/3pdata/pngsuite/tp0n2c08.png
|
||||
OK. 3d7708a8 test/3pdata/pngsuite/tp0n3p08.png
|
||||
OK. 46deef3b test/3pdata/pngsuite/tp1n3p08.png
|
||||
BAD 926d3aa2 test/3pdata/pngsuite/xcsn0g01.png
|
||||
OK. 9098c4d8 test/3pdata/pngsuite/z00n2c08.png
|
||||
OK. 9098c4d8 test/3pdata/pngsuite/z03n2c08.png
|
||||
OK. 9098c4d8 test/3pdata/pngsuite/z06n2c08.png
|
||||
OK. 9098c4d8 test/3pdata/pngsuite/z09n2c08.png
|
||||
@@ -1,9 +1,9 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
9fbe866a test/3pdata/tgasuite/cbw8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ccm8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ctc24.tga
|
||||
9fbe866a test/3pdata/tgasuite/ubw8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ucm8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/utc16.tga
|
||||
5d75ef41 test/3pdata/tgasuite/utc24.tga
|
||||
79781cfb test/3pdata/tgasuite/utc32.tga
|
||||
OK. 9fbe866a test/3pdata/tgasuite/cbw8.tga
|
||||
OK. 5d75ef41 test/3pdata/tgasuite/ccm8.tga
|
||||
OK. 5d75ef41 test/3pdata/tgasuite/ctc24.tga
|
||||
OK. 9fbe866a test/3pdata/tgasuite/ubw8.tga
|
||||
OK. 5d75ef41 test/3pdata/tgasuite/ucm8.tga
|
||||
OK. 5d75ef41 test/3pdata/tgasuite/utc16.tga
|
||||
OK. 5d75ef41 test/3pdata/tgasuite/utc24.tga
|
||||
OK. 79781cfb test/3pdata/tgasuite/utc32.tga
|
||||
@@ -0,0 +1,55 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
OK. ca4c0038 test/3pdata/webpsuite/bad_palette_index.webp
|
||||
OK. 6fbda804 test/3pdata/webpsuite/color_cache_bits_11.webp
|
||||
BAD d338aed8 test/3pdata/webpsuite/dual_transform.webp
|
||||
OK. 1ef61f19 test/3pdata/webpsuite/grid.bmp
|
||||
OK. 33b7a1f3 test/3pdata/webpsuite/grid.pgm
|
||||
OK. f79224e7 test/3pdata/webpsuite/grid.png
|
||||
OK. 06b07a30 test/3pdata/webpsuite/grid.ppm
|
||||
OK. fce8fc76 test/3pdata/webpsuite/lossless1.webp
|
||||
OK. fce8fc76 test/3pdata/webpsuite/lossless2.webp
|
||||
OK. fce8fc76 test/3pdata/webpsuite/lossless3.webp
|
||||
OK. 4cbe795c test/3pdata/webpsuite/lossless4.webp
|
||||
OK. f8e3adf4 test/3pdata/webpsuite/lossless_big_random_alpha.webp
|
||||
OK. 289af407 test/3pdata/webpsuite/lossless_color_transform.bmp
|
||||
OK. 7b7c1ae6 test/3pdata/webpsuite/lossless_color_transform.pgm
|
||||
OK. 289af407 test/3pdata/webpsuite/lossless_color_transform.ppm
|
||||
OK. 289af407 test/3pdata/webpsuite/lossless_color_transform.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_0.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_1.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_10.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_11.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_12.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_13.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_14.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_15.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_2.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_3.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_4.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_5.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_6.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_7.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_8.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_9.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_0.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_1.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_10.webp
|
||||
BAD 62adeb37 test/3pdata/webpsuite/lossless_vec_2_11.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_12.webp
|
||||
BAD 62adeb37 test/3pdata/webpsuite/lossless_vec_2_13.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_14.webp
|
||||
BAD 62adeb37 test/3pdata/webpsuite/lossless_vec_2_15.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_2.webp
|
||||
BAD 62adeb37 test/3pdata/webpsuite/lossless_vec_2_3.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_4.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_5.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_6.webp
|
||||
BAD 62adeb37 test/3pdata/webpsuite/lossless_vec_2_7.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_8.webp
|
||||
BAD 62adeb37 test/3pdata/webpsuite/lossless_vec_2_9.webp
|
||||
OK. 6957defa test/3pdata/webpsuite/near_lossless_75.webp
|
||||
OK. 7c80a001 test/3pdata/webpsuite/one_color_no_palette.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/peak.bmp
|
||||
OK. 315bbd77 test/3pdata/webpsuite/peak.pgm
|
||||
OK. 6706e719 test/3pdata/webpsuite/peak.png
|
||||
OK. 6706e719 test/3pdata/webpsuite/peak.ppm
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include "lzma.h"
|
||||
|
||||
const char* //
|
||||
mimic_lzma_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)) {
|
||||
// It's simpler if we only assume one-shot decompression.
|
||||
return "unsupported I/O limit";
|
||||
}
|
||||
lzma_stream z = LZMA_STREAM_INIT;
|
||||
|
||||
lzma_ret ret = lzma_auto_decoder(&z, UINT64_MAX, 0);
|
||||
if (ret != LZMA_OK) {
|
||||
return "liblzma: lzma_auto_decoder failed";
|
||||
}
|
||||
z.next_out = wuffs_base__io_buffer__writer_pointer(dst);
|
||||
z.avail_out = wuffs_base__io_buffer__writer_length(dst);
|
||||
z.next_in = wuffs_base__io_buffer__reader_pointer(src);
|
||||
z.avail_in = wuffs_base__io_buffer__reader_length(src);
|
||||
|
||||
ret = lzma_code(&z, LZMA_RUN);
|
||||
dst->meta.wi += (size_t)z.total_out;
|
||||
src->meta.ri += (size_t)z.total_in;
|
||||
lzma_end(&z);
|
||||
if (ret != LZMA_STREAM_END) {
|
||||
return "liblzma: lzma_code failed";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include "openssl/evp.h"
|
||||
|
||||
const char* //
|
||||
mimic_bench_sha256(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
EVP_MD_CTX* ctx = EVP_MD_CTX_new();
|
||||
if (!ctx) {
|
||||
return "EVP_MD_CTX_new failed";
|
||||
} else if (!EVP_DigestInit_ex(ctx, EVP_sha256(), NULL)) {
|
||||
return "EVP_DigestInit_ex failed";
|
||||
}
|
||||
|
||||
while (src->meta.ri < src->meta.wi) {
|
||||
uint8_t* ptr = src->data.ptr + src->meta.ri;
|
||||
size_t len = src->meta.wi - src->meta.ri;
|
||||
if (len > 0x7FFFFFFF) {
|
||||
return "src length is too large";
|
||||
} else if (len > rlimit) {
|
||||
len = rlimit;
|
||||
}
|
||||
if (!EVP_DigestUpdate(ctx, ptr, len)) {
|
||||
return "EVP_DigestUpdate failed";
|
||||
}
|
||||
src->meta.ri += len;
|
||||
}
|
||||
|
||||
uint8_t results[EVP_MAX_MD_SIZE] = {0};
|
||||
if (!EVP_DigestFinal_ex(ctx, results, NULL)) {
|
||||
return "EVP_DigestFinal_ex failed";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wuffs_base__bitvec256 //
|
||||
mimic_sha256_one_shot_checksum_bitvec256(wuffs_base__slice_u8 data) {
|
||||
uint8_t results[EVP_MAX_MD_SIZE] = {0};
|
||||
EVP_MD_CTX* ctx = EVP_MD_CTX_new();
|
||||
if (ctx) {
|
||||
if (EVP_DigestInit_ex(ctx, EVP_sha256(), NULL) && //
|
||||
EVP_DigestUpdate(ctx, data.ptr, data.len) && //
|
||||
EVP_DigestFinal_ex(ctx, results, NULL)) {
|
||||
// No-op.
|
||||
}
|
||||
EVP_MD_CTX_free(ctx);
|
||||
}
|
||||
|
||||
return wuffs_base__make_bitvec256(
|
||||
wuffs_base__peek_u64be__no_bounds_check(results + 0x18),
|
||||
wuffs_base__peek_u64be__no_bounds_check(results + 0x10),
|
||||
wuffs_base__peek_u64be__no_bounds_check(results + 0x08),
|
||||
wuffs_base__peek_u64be__no_bounds_check(results + 0x00));
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
#include "webp/decode.h"
|
||||
|
||||
static void //
|
||||
mimiclib_convert_to_y_from_bgra_nonpremul(uint8_t* dst,
|
||||
const uint8_t* src,
|
||||
uint32_t n) {
|
||||
while (n--) {
|
||||
uint32_t s0_nonpremul = wuffs_base__peek_u32le__no_bounds_check(src);
|
||||
uint32_t s0_premul =
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
s0_nonpremul);
|
||||
dst[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0_premul);
|
||||
dst += 1;
|
||||
src += 4;
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_webp_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_base__io_buffer dst_fallback =
|
||||
wuffs_base__slice_u8__writer(g_mimiclib_scratch_slice_u8);
|
||||
if (!dst) {
|
||||
dst = &dst_fallback;
|
||||
}
|
||||
|
||||
WebPDecoderConfig config;
|
||||
if (!WebPInitDecoderConfig(&config)) {
|
||||
return "mimic_webp_decode: WebPInitDecoderConfig failed";
|
||||
} else if (WebPGetFeatures(wuffs_base__io_buffer__reader_pointer(src),
|
||||
wuffs_base__io_buffer__reader_length(src),
|
||||
&config.input) != VP8_STATUS_OK) {
|
||||
return "mimic_webp_decode: WebPGetFeatures failed";
|
||||
}
|
||||
|
||||
const uint32_t w = config.input.width;
|
||||
const uint32_t h = config.input.height;
|
||||
if ((w > 0x4000) || (h > 0x4000)) {
|
||||
return "mimic_webp_decode: impossible WebP dimensions";
|
||||
}
|
||||
|
||||
switch (pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
if (((1 * w * h) > wuffs_base__io_buffer__writer_length(dst)) ||
|
||||
((4 * w * h) > g_mimiclib_scratch_slice_u8.len)) {
|
||||
return "mimic_webp_decode: image is too large";
|
||||
}
|
||||
config.output.u.RGBA.rgba = g_mimiclib_scratch_slice_u8.ptr;
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
if ((4 * w * h) > wuffs_base__io_buffer__writer_length(dst)) {
|
||||
return "mimic_webp_decode: image is too large";
|
||||
}
|
||||
config.output.u.RGBA.rgba = wuffs_base__io_buffer__writer_pointer(dst);
|
||||
break;
|
||||
|
||||
default:
|
||||
return "mimic_webp_decode: unsupported pixfmt";
|
||||
}
|
||||
|
||||
config.output.colorspace = MODE_BGRA;
|
||||
config.output.width = w;
|
||||
config.output.height = h;
|
||||
config.output.is_external_memory = 1;
|
||||
config.output.u.RGBA.stride = 4 * w;
|
||||
config.output.u.RGBA.size = 4 * w * h;
|
||||
|
||||
VP8StatusCode status =
|
||||
WebPDecode(wuffs_base__io_buffer__reader_pointer(src),
|
||||
wuffs_base__io_buffer__reader_length(src), &config);
|
||||
WebPFreeDecBuffer(&config.output);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
return "mimic_webp_decode: WebPDecode failed";
|
||||
}
|
||||
|
||||
size_t n = 0;
|
||||
switch (pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
mimiclib_convert_to_y_from_bgra_nonpremul(
|
||||
wuffs_base__io_buffer__writer_pointer(dst),
|
||||
g_mimiclib_scratch_slice_u8.ptr, 1 * w * h);
|
||||
n = 1 * w * h;
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
n = 4 * w * h;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
dst->meta.wi += n;
|
||||
if (n_bytes_out) {
|
||||
*n_bytes_out += n;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
+41
-5
@@ -172,15 +172,18 @@ do_test_xxxxx_crc32_ieee_pi(bool mimic) {
|
||||
const char* digits =
|
||||
"3."
|
||||
"141592653589793238462643383279502884197169399375105820974944592307816406"
|
||||
"2862089986280348253421170";
|
||||
if (strlen(digits) != 99) {
|
||||
"286208998628034825342117067982148086513282306647093844609550582231725359"
|
||||
"408128481117450284102701938521105559644622948954930381964428810975665933"
|
||||
"446128475648233786783165271201909145648566923460348610454326648213393607"
|
||||
"260249141";
|
||||
if (strlen(digits) != 299) {
|
||||
RETURN_FAIL("strlen(digits): have %d, want 99", (int)(strlen(digits)));
|
||||
}
|
||||
|
||||
// The want values are determined by script/checksum.go.
|
||||
//
|
||||
// wants[i] is the checksum of the first i bytes of the digits string.
|
||||
uint32_t wants[100] = {
|
||||
uint32_t wants[300] = {
|
||||
0x00000000, 0x6DD28E9B, 0x69647A00, 0x83B58BCD, 0x16E010BE, 0xAF13912C,
|
||||
0xB6C654DC, 0x02D43F2E, 0xC60167FD, 0xDE72F5D2, 0xECB2EAA3, 0x22E1CE23,
|
||||
0x26F4BB12, 0x099FD2E0, 0x2D041A2F, 0xC14373C1, 0x61A5D6D0, 0xEB60F999,
|
||||
@@ -197,10 +200,43 @@ do_test_xxxxx_crc32_ieee_pi(bool mimic) {
|
||||
0xACF0D063, 0x20CC1F13, 0x7E9EDAD2, 0xE5A44AA7, 0xC550F584, 0x101040DF,
|
||||
0x0BC4A511, 0x706E5A5A, 0x71CE81A3, 0xBB75E3F2, 0x3EDA6848, 0x8B8F08F2,
|
||||
0xA9384B2B, 0xB6C07F06, 0x6D644EE4, 0xCAD8CCB4, 0x3F70B461, 0x205F9F77,
|
||||
0x4D9D54B7, 0xD69454CC, 0xF8BB504D, 0xFC4E595C,
|
||||
0x4D9D54B7, 0xD69454CC, 0xF8BB504D, 0xFC4E595C, 0x7F992992, 0x74C121C3,
|
||||
0x8F1E35AE, 0xCBE1C7C9, 0xF8A625DE, 0xE24FB641, 0xF28F2588, 0x1991D324,
|
||||
0xC8C1AA23, 0x58AFE7CB, 0x1156CECB, 0x88166658, 0xE6E42017, 0xEEE7EF7C,
|
||||
0x438864F5, 0x3794D9E4, 0xBD850CB5, 0xD6644C94, 0x036FEC30, 0x3B622554,
|
||||
0x71858DDC, 0x7CA2004A, 0xFCCA400C, 0xFD91594A, 0x1BF35E52, 0xE8AC4D1D,
|
||||
0x99EE9787, 0x80F3E32C, 0xC1EE8438, 0x357B2C0E, 0x1356890A, 0x6DC1D812,
|
||||
0x77659B3E, 0x45A7539E, 0xE329C631, 0xD58C0252, 0x7FB0EBC9, 0xF81274F2,
|
||||
0x499E3F49, 0x629BE990, 0x73B1E71A, 0x97AE021F, 0x974A1DFA, 0xD94E7AB1,
|
||||
0xD16D43FB, 0xAE0F6D79, 0xA470A170, 0xA3171AA5, 0x52C49F5C, 0x988F8E53,
|
||||
0x71266077, 0xD4C57CF2, 0xA967015F, 0x08CB305C, 0x98D581FC, 0x374F8401,
|
||||
0xF4EC90A5, 0x25945440, 0x1C469F46, 0x6C15B902, 0x6AD35F3B, 0x45BAE55A,
|
||||
0x912EBC02, 0x149F1883, 0x871356BA, 0xA8EFA673, 0x3D7F1001, 0x6DEFF18B,
|
||||
0x10B8FFDB, 0xE5CA6C82, 0x808FC7D7, 0x9530AF35, 0x3BF47A17, 0x79E826AE,
|
||||
0xB5A64D67, 0xC9B6ECBB, 0xDFA6335F, 0x78D705E1, 0x23AEDACA, 0xFF23AEDA,
|
||||
0xE24833CA, 0xFFE24833, 0x3228E4DB, 0x0C8B59AC, 0x2CDA7FA2, 0xCB420383,
|
||||
0x69C2EA8D, 0x89B5837A, 0xAA8C93AC, 0x52CD04D5, 0x055DF067, 0x29D3FE18,
|
||||
0x9E422C2D, 0xC1F035F7, 0xD0AE8CB2, 0xA8B81BA9, 0xC2702DCC, 0x66CB2197,
|
||||
0x03DF435D, 0xEFD9A519, 0xE7589ED2, 0xE53D8CE3, 0x245EF45A, 0x782CFD26,
|
||||
0x21C3B238, 0x32F6C521, 0xB65BB188, 0x19D507B0, 0x48A4893C, 0xDBFC072F,
|
||||
0x260DA6DB, 0x7B984C78, 0xDA144AEC, 0xB4DEC00D, 0x63BDD869, 0xB0BC4F8A,
|
||||
0x80DAB1F4, 0xD782622F, 0xC6D431A0, 0x25A66CE1, 0x249E6FBA, 0x3628BEE9,
|
||||
0x5A3C9DD5, 0xEC36A4CB, 0xF65A7A8F, 0x8E47DFF3, 0x4E85AEFB, 0xAE908594,
|
||||
0xEA74BDCC, 0x618EE11E, 0x006EE491, 0x9DDD733B, 0xDC44BACC, 0xFFDC44BA,
|
||||
0x41F4CC54, 0x96473632, 0xD5F96CA2, 0x52B2712A, 0x21E92CB4, 0xA1FF1022,
|
||||
0x561D5143, 0xF23B776F, 0x594E6C10, 0x073BE005, 0x1AD285ED, 0x5D7DA3F7,
|
||||
0x3951A411, 0x9E52AE77, 0x4D235986, 0x899162C9, 0x16EA3457, 0x781E49E6,
|
||||
0xCACDB6B3, 0xA11434B8, 0x41AA0424, 0x21FA34C1, 0x1FF4132A, 0x21A46AD6,
|
||||
0xEB20F825, 0x56578EAB, 0x5CEA57FA, 0xD03396D0, 0x9CD65F4F, 0x8B2D04C5,
|
||||
0x18330003, 0x84A918AE, 0xC531F8D6, 0x02A7C882, 0xF0025EFC, 0x4EFBEB7A,
|
||||
0xAD2619DD, 0x7B1367C7, 0xF1A09B55, 0xE8461ED8, 0x0C513756, 0x71B2BECE,
|
||||
0x117FD392, 0x04C533B6, 0x3FBEA99E, 0x0A307AFE, 0xA9B9F459, 0xE81E07B7,
|
||||
0x4F388625, 0xC8970376, 0xD47CCD91, 0xEA0E5184, 0x67382EED, 0xB30E2870,
|
||||
0x4D0E0500, 0xF496D124, 0x56483882, 0x19351439, 0x42A4C708, 0xFA42F3D4,
|
||||
0x9B91EA33, 0x4CFDEBC4, 0x11429CC7, 0x86CDFA38, 0xDB326E5C, 0xE1DAC006,
|
||||
};
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
for (int i = 0; i < 300; i++) {
|
||||
uint32_t have;
|
||||
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
|
||||
.ptr = (uint8_t*)(digits),
|
||||
|
||||
@@ -0,0 +1,435 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 crc64.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__CRC64
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
// No mimic library.
|
||||
#endif
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_crc64_midsummer_gt = {
|
||||
.src_filename = "test/data/midsummer.txt",
|
||||
};
|
||||
|
||||
golden_test g_crc64_pi_gt = {
|
||||
.src_filename = "test/data/pi.txt",
|
||||
};
|
||||
|
||||
// ---------------- CRC64 Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_crc64_ecma_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_crc64__ecma_hasher h;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
&h, sizeof h, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__hasher_u64(
|
||||
wuffs_crc64__ecma_hasher__upcast_as__wuffs_base__hasher_u64(&h),
|
||||
"test/data/hat.lossy.webp", 0, SIZE_MAX, 0xE52B1F3FF3D3389E);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_crc64_ecma_golden() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
struct {
|
||||
const char* filename;
|
||||
// The want values are determined by script/checksum.go.
|
||||
uint64_t want;
|
||||
} test_cases[] = {
|
||||
{
|
||||
.filename = "test/data/hat.bmp",
|
||||
.want = 0xEADD85183B8DD1B5,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.gif",
|
||||
.want = 0x04365C489DBC96CD,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.jpeg",
|
||||
.want = 0xA4C0DB421278B786,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.lossless.webp",
|
||||
.want = 0x090AF44557A4E13D,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.lossy.webp",
|
||||
.want = 0xE52B1F3FF3D3389E,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.png",
|
||||
.want = 0x92E9F67A8948B654,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.tiff",
|
||||
.want = 0xB640F37638B639B9,
|
||||
},
|
||||
};
|
||||
|
||||
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, test_cases[tc].filename));
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
wuffs_crc64__ecma_hasher checksum;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
|
||||
uint64_t have = 0;
|
||||
size_t num_fragments = 0;
|
||||
size_t num_bytes = 0;
|
||||
do {
|
||||
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
|
||||
.ptr = src.data.ptr + num_bytes,
|
||||
.len = src.meta.wi - num_bytes,
|
||||
});
|
||||
size_t limit = 101 + 103 * num_fragments;
|
||||
if ((j > 0) && (data.len > limit)) {
|
||||
data.len = limit;
|
||||
}
|
||||
have = wuffs_crc64__ecma_hasher__update_u64(&checksum, data);
|
||||
num_fragments++;
|
||||
num_bytes += data.len;
|
||||
} while (num_bytes < src.meta.wi);
|
||||
|
||||
if (have != test_cases[tc].want) {
|
||||
RETURN_FAIL("tc=%zu, j=%d, filename=\"%s\": have 0x%016" PRIX64
|
||||
", want 0x%016" PRIX64 "\n",
|
||||
tc, j, test_cases[tc].filename, have, test_cases[tc].want);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
do_test_xxxxx_crc64_ecma_pi(bool mimic) {
|
||||
const char* digits =
|
||||
"3."
|
||||
"141592653589793238462643383279502884197169399375105820974944592307816406"
|
||||
"286208998628034825342117067982148086513282306647093844609550582231725359"
|
||||
"408128481117450284102701938521105559644622948954930381964428810975665933"
|
||||
"446128475648233786783165271201909145648566923460348610454326648213393607"
|
||||
"260249141";
|
||||
if (strlen(digits) != 299) {
|
||||
RETURN_FAIL("strlen(digits): have %d, want 99", (int)(strlen(digits)));
|
||||
}
|
||||
|
||||
// The want values are determined by script/checksum.go.
|
||||
//
|
||||
// wants[i] is the checksum of the first i bytes of the digits string.
|
||||
uint64_t wants[300] = {
|
||||
0x0000000000000000, 0xDEAB38D23CD56AB6, 0x5C257BEFCFF13F5E,
|
||||
0x4BABD3D6697B9834, 0x1FE60AA0B20E44C1, 0x34C4D86E0BC41325,
|
||||
0x6202C4935B5F9D03, 0x9A46F1A15337D622, 0x62AC46BA94076EC6,
|
||||
0x34B9922211E21A0F, 0x9A104AF7E27D6BA5, 0x2494B24742FED551,
|
||||
0xFBD89FFF950FD48C, 0x2B460EB540AFCB27, 0x1AE8349F28C5B4D5,
|
||||
0xBDDE413FCD2D1EC7, 0x4C9392FF3C6A7271, 0x8FD32F7CD8D872D1,
|
||||
0x0E65369A2D7A5C6E, 0x39D14684478C19D7, 0x82A2707ED574EA50,
|
||||
0xFB7EA93DAC985EB3, 0x1EC407757264A919, 0x548FDAE4E78AD430,
|
||||
0x90ADDB7AD74F4BE5, 0x7C529D717060C1D7, 0x32EC0E4574BA45DA,
|
||||
0x0DFDB8E543882264, 0x8AFC92B43B45B4C6, 0xFCAF4DCCE3655989,
|
||||
0xE09A4703D8AFBCCB, 0xB84AE0AEA83F5088, 0xE3FB13F0EDBAFAFF,
|
||||
0xB1B19761FF90117D, 0x44F5331DED6D95D3, 0xFA2A26D1E40F49D2,
|
||||
0x4A9F04247CFF685C, 0xFBB69449F631D531, 0xD7A898DDD1B90FD0,
|
||||
0xFAB97B7A24339D48, 0x4E639C3405727ED1, 0xC65A0913998FF73E,
|
||||
0xD4B0C51EDC88ADCF, 0x70804516491376C5, 0xB8DAFAACBDAEEC42,
|
||||
0x4E21FFB5D3EBE3A0, 0xEF9BBD96ABB95EB8, 0x650021E526ECD62A,
|
||||
0x26DCCBDD2CCB56CF, 0xC35C65A689446A51, 0xFB3F572874C46E33,
|
||||
0xEBD2A873E4535B6C, 0x8A1ABDA4ADE26FBF, 0xD56E5D054013CE49,
|
||||
0x4E4C4B127A165E82, 0x502359E552CF8C9E, 0x5553E5155C05710B,
|
||||
0x6DD027892A2E30A8, 0x60ECB99DC08F6503, 0xA51B17EF5E9ABBE0,
|
||||
0x8BC6ACB41AF7A841, 0x35C2206734C3E4D7, 0x0EDF2795369647F8,
|
||||
0x8D260A38CE239CC7, 0x4CA36AB43B697CF3, 0x011532F8EFBF81A9,
|
||||
0xA87EF3B24D62F5EE, 0xB7B1703D138CF108, 0x526DCD2F01570412,
|
||||
0xE7ED3F90BE5EB8F2, 0xF53A4AFA637A1636, 0x1F589B399E04454F,
|
||||
0x4DA3CC8A11965534, 0x6430C13B11F9F73F, 0x5B465A05A3CF25A7,
|
||||
0x63FF9EBE1B58982B, 0x25FF853C20A8FEBC, 0xD5C1B83DD89E84D8,
|
||||
0x4AB0EFBA90C3F991, 0x9E9248C7A8B1601F, 0xD87EC82655C1E3AC,
|
||||
0x637CA62C38AE96ED, 0xB45FC336DAA72156, 0xF86DE5D0B3C99145,
|
||||
0xBAE57EFD07A52486, 0x2B073354423D61D7, 0x82B0A60B05715B28,
|
||||
0x951537E4C14F942D, 0x1A5667A67944548A, 0x288231134E1D9C9A,
|
||||
0xD95A00F0AA88414E, 0x711F777C8CCA7837, 0xEB588853B0AB557A,
|
||||
0x3F7F198620ADF0A4, 0xAB6528C764F3FBA2, 0xABF132F625B7A5A9,
|
||||
0x5C5021E5EBE85D91, 0x2DAAE4B7F46D14D4, 0x0EC74F51E656E908,
|
||||
0x6EAE027D39CA7F0D, 0x296411D9BEF21CAF, 0x5CD2B4C6C4731828,
|
||||
0xD1449E41F0377567, 0xCD8A517B3411F4A5, 0x97ED64E2CD8FE6A1,
|
||||
0xABCDBABA001ED9B4, 0xD66A3B5C09E02EC2, 0x3728E501A021E172,
|
||||
0x8FA8940B26443942, 0xFE1D703B20894A27, 0xD1E651850DD38F35,
|
||||
0x1F7C4722E16AECD6, 0x75255A768CCCB0C3, 0x34AE1B3EDDFAD1D1,
|
||||
0x0EDE4BAE6F7F7ECD, 0xFC2B6F15F9316343, 0x4E650E206AAF7C2F,
|
||||
0xEE0921C815AF1439, 0x5BCC63E550CB7344, 0x096893C531E1790B,
|
||||
0xA657229B5135C9C1, 0xFC83E67CCC0F29F4, 0xF52124238F0847A7,
|
||||
0x97D5CF979534FF12, 0x5406CB2C056D8466, 0xCE2AA2700EBAB269,
|
||||
0xB5604D9DAD3E3B6C, 0xF194CCC5BC245CEC, 0x38BC6FD133B249C9,
|
||||
0xFF38BC6FD133B249, 0xB9C79AFAEF99C298, 0x9E613FB2E8CE3A24,
|
||||
0xD1862DCA841BC845, 0xFD66EFDCB67509EB, 0x7F1AE71B815FE7A8,
|
||||
0x947A450AFA64B48F, 0x6C83D6861E275F73, 0xC85945D10A1DC0C8,
|
||||
0x3736D67F2D221C9C, 0xE61ABC24C5DDC3F4, 0x7A6F48AA80CE6B25,
|
||||
0x96C8595437943720, 0x9624FE45C9236D7C, 0x3F0265F036D4789C,
|
||||
0xE61288974AC63590, 0xE5EE29247AE43BE0, 0x8B86598AD1D3D6C1,
|
||||
0xFCAE3707DD8FCFEB, 0x7F1B2FC35A341D6E, 0x89ABC57D4A0214C4,
|
||||
0xFCAC1A9B2A141E29, 0xD2C151B1FA870E5C, 0xFB2ECA1C63B7AD57,
|
||||
0xC77D9CEA9A463CF3, 0x02BB5D50E640B2D4, 0x81BCAB3B568B3AC6,
|
||||
0x08203BA2C448375C, 0xBF7BE0C18C308167, 0x063F50611F1BEE30,
|
||||
0x647B5DA7FAF77A84, 0xE327224DE4E832D5, 0x815D37444B899246,
|
||||
0x86E6F742C735C582, 0x53CE4207552CB338, 0x938F2BBC63A3F1BF,
|
||||
0xAEA70B17A752D1E4, 0xB492189BE138DD11, 0xA3840BF2F6073422,
|
||||
0xAA6B0B7A3B8A5F78, 0x8C1066BB0A818EC1, 0x34572E02107C9CEF,
|
||||
0x408CDEE95CCF5307, 0xE2910D6181E104E2, 0xCC2B5C473FCF2CCA,
|
||||
0xFFCC2B5C473FCF2C, 0x1A3CBEBAC1C224D1, 0x495AA3E24084B90C,
|
||||
0xA61710AB7644AC01, 0x2A8919953FE38E41, 0x864D236C1641AF9E,
|
||||
0x9D7B04552969FE74, 0xC8A8BD03D92A8E69, 0x0648833CDD4EF43F,
|
||||
0x5B242247A40392A4, 0xAB0173FCA57755C0, 0x4FA0FC93A85C3407,
|
||||
0x2A60AE79073D96D9, 0xF9610212D7BB05EC, 0xB7E06FCCB31628F8,
|
||||
0x01EE71FD9737FEFD, 0xF6F9F8EA590D634D, 0x35BF1F336A801E1C,
|
||||
0x2C51D32609437289, 0xDC3000F0662D3BE7, 0x889A36FD529103FC,
|
||||
0x7A01C820595927E5, 0x40C2880F7E8676BC, 0x5AF070E3BC0F5438,
|
||||
0xAFFCACE3D322735F, 0xBCF98D089A79F71E, 0x2FFD24EA65ED975D,
|
||||
0xFBD3F6693828C7CE, 0xC3816A9B3D5089C0, 0x4FC87C8ACFC413DB,
|
||||
0x82D46944DBFCA25A, 0x770F9BA9960734AE, 0x2479AD961C8AAF0E,
|
||||
0x1671CE4556E1E145, 0x8671DBBBC628ADF1, 0x01DFE049E042C078,
|
||||
0xC83419E7C5E3A557, 0x80E4FCD0CA0797CF, 0x377E6BC62CE206CB,
|
||||
0x0BB3483C6E6C425D, 0x302C866145555B7A, 0xB0F0985B4597F0C2,
|
||||
0x8460331CA4CAC9C3, 0x345F5E57B7D2D7A8, 0x1B65F560E19DC7D7,
|
||||
0x0EF18040314319DB, 0x829550B811022550, 0x0FFAA84AC21C8827,
|
||||
0xED6D0F302859BBF0, 0x461E8674C04B4E5A, 0x74EEE018F1429F7F,
|
||||
0xCB6499B9C3ACB935, 0xEBE2F3BD75E433BB, 0xAEDF66CFA6449626,
|
||||
0x6298DF2DFAF21D86, 0xA48BBB26C50FC886, 0x283CECCFCEA1D706,
|
||||
0xE2F9BD53A7736A66, 0xCE9C5D067118AC87, 0x2B734A77B94BDC5F,
|
||||
0x77A63C8AA56583D0, 0xBE96BE698FFEA2CD, 0x846E553A9600A091,
|
||||
0xA2262F107CDF0241, 0xB99A846990342E28, 0xD284672F083D2E6C,
|
||||
0x390DA7D5F2A95EA5, 0xECC920909CC60038, 0x201E6060F7CD4463,
|
||||
0xB58E795FBDC74C9A, 0x121C32DC4D0D86FF, 0xCA90B3C42CBFF832,
|
||||
0x1F6731C0A04B80A1, 0x186B7C5121D442BD, 0x5AA8D917E250060C,
|
||||
0x51A565D87CF8C4D8, 0xBEB0BD30DD273F8A, 0x1779DFFADB8F42CB,
|
||||
0x37E9F6E506F38E1E, 0xE788BBAB74591C78, 0x44A30A3127E65CDE,
|
||||
0xBEA5BB5F347C2112, 0x6B70B36BCEFA7182, 0x5323D4437C257C8C,
|
||||
0x14B1FDCDFF705CB5, 0x917F3DF2D5F8BF73, 0xB3747ABE8159411B,
|
||||
0x10ADA12ED0C00AD1, 0x0EFA48147F724416, 0x2C6A96712E5680D3,
|
||||
0x75164CA7DF038CAF, 0xEFA08A25B9B5B6D7, 0x75D586BB8B946F99,
|
||||
0x2EA6D04EFD5374DB, 0x82B507E81FCE353D, 0xD7D19B4E7050F030,
|
||||
0x902E853B7DD891C1, 0x344B10E1900BC5F0, 0xB243963CB9B3BC7F,
|
||||
0xCBA234CFE7E44816, 0xA3FB3BDEA201E8B7, 0x91C87734C6A5CEC7,
|
||||
0x4F9A3597603FE69C, 0x554C5C792E378161, 0x3AAFDEB0F3D14837,
|
||||
0xACB94213D733B17E, 0x789282A5CB2D9774, 0xF7125CB62AFE773A,
|
||||
0xE8FB34262D537D48, 0xB9D05972A665A257, 0xFB45DB14A0EB4FFB,
|
||||
0x452D1FFEB39DE093, 0x2E9628D7B86B7D54, 0xBC78E78CAE12BE10,
|
||||
0x6B726E371D601F1D, 0xDBAE995EF22A2EEE, 0x8BB8193AAB5B18D4,
|
||||
0xC69FD2969721DE58, 0xF81F25C1138417BA, 0xD51C589D25ADA831,
|
||||
0x58D2C7C252A56DC5, 0x87ADA01D6A83E763, 0x0522377F94A3416B,
|
||||
0x05A0B8E8F65D61CD, 0x7051556BBF39A309, 0x6ED0946703931047,
|
||||
};
|
||||
|
||||
for (int i = 0; i < 300; i++) {
|
||||
uint64_t have = 0;
|
||||
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
|
||||
.ptr = (uint8_t*)(digits),
|
||||
.len = (size_t)(i),
|
||||
});
|
||||
|
||||
if (mimic) {
|
||||
// A simple, slow CRC-64 ECMA implementation, 1 bit at a time.
|
||||
have = 0xFFFFFFFFFFFFFFFF;
|
||||
while (data.len--) {
|
||||
uint8_t byte = *data.ptr++;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((have ^ byte) & 1) {
|
||||
have = (have >> 1) ^ 0xC96C5795D7870F42;
|
||||
} else {
|
||||
have = (have >> 1);
|
||||
}
|
||||
byte >>= 1;
|
||||
}
|
||||
}
|
||||
have ^= 0xFFFFFFFFFFFFFFFF;
|
||||
|
||||
} else {
|
||||
wuffs_crc64__ecma_hasher checksum;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
have = wuffs_crc64__ecma_hasher__update_u64(&checksum, data);
|
||||
}
|
||||
|
||||
if (have != wants[i]) {
|
||||
RETURN_FAIL("i=%d: have 0x%016" PRIX64 ", want 0x%016" PRIX64, i, have,
|
||||
wants[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_crc64_ecma_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_xxxxx_crc64_ecma_pi(false);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
test_mimic_crc64_ecma_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_xxxxx_crc64_ecma_pi(true);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- CRC64 Benches
|
||||
|
||||
uint64_t g_wuffs_crc64_unused_u64;
|
||||
|
||||
const char* //
|
||||
wuffs_bench_crc64_ecma(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
uint64_t len = src->meta.wi - src->meta.ri;
|
||||
if (rlimit) {
|
||||
len = wuffs_base__u64__min(len, rlimit);
|
||||
}
|
||||
wuffs_crc64__ecma_hasher checksum = {0};
|
||||
CHECK_STATUS("initialize", wuffs_crc64__ecma_hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
g_wuffs_crc64_unused_u64 = wuffs_crc64__ecma_hasher__update_u64(
|
||||
&checksum, ((wuffs_base__slice_u8){
|
||||
.ptr = src->data.ptr + src->meta.ri,
|
||||
.len = len,
|
||||
}));
|
||||
src->meta.ri += len;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_crc64_ecma_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bench_crc64_ecma,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_crc64_midsummer_gt, UINT64_MAX, UINT64_MAX, 2000);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_crc64_ecma_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bench_crc64_ecma,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_crc64_pi_gt, UINT64_MAX, UINT64_MAX, 200);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_crc64_ecma_golden,
|
||||
test_wuffs_crc64_ecma_interface,
|
||||
test_wuffs_crc64_ecma_pi,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_crc64_ecma_pi,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_crc64_ecma_10k,
|
||||
bench_wuffs_crc64_ecma_100k,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/crc64";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
+47
-3
@@ -95,6 +95,48 @@ test_wuffs_jpeg_decode_interface() {
|
||||
"test/data/bricks-color.jpeg", 0, SIZE_MAX, 160, 120, 0xFF012466);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_jpeg_decode_lower_quality() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_jpeg__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_jpeg__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
wuffs_jpeg__decoder__set_quirk(
|
||||
&dec, WUFFS_BASE__QUIRK_QUALITY,
|
||||
WUFFS_BASE__QUIRK_QUALITY__VALUE__LOWER_QUALITY);
|
||||
CHECK_STRING(do_test__wuffs_base__image_decoder(
|
||||
wuffs_jpeg__decoder__upcast_as__wuffs_base__image_decoder(&dec),
|
||||
"test/data/bricks-color.jpeg", 0, SIZE_MAX, 160, 120, 0xFF012466));
|
||||
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/bricks-color.jpeg"));
|
||||
CHECK_STATUS("initialize", wuffs_jpeg__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
|
||||
CHECK_STATUS("decode_image_config",
|
||||
wuffs_jpeg__decoder__decode_image_config(&dec, NULL, &src));
|
||||
|
||||
for (int q = 0; q < 2; q++) {
|
||||
if (q) {
|
||||
wuffs_jpeg__decoder__set_quirk(
|
||||
&dec, WUFFS_BASE__QUIRK_QUALITY,
|
||||
WUFFS_BASE__QUIRK_QUALITY__VALUE__LOWER_QUALITY);
|
||||
}
|
||||
uint64_t m = wuffs_jpeg__decoder__workbuf_len(&dec).min_incl;
|
||||
if ((q == 0) && (m == 0)) {
|
||||
RETURN_FAIL("q=%d: have %" PRIu64 ", want non-zero", q, m);
|
||||
} else if ((q != 0) && (m != 0)) {
|
||||
RETURN_FAIL("q=%d: have %" PRIu64 ", want zero", q, m);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_jpeg_decode_truncated_input() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -590,7 +632,7 @@ test_wuffs_jpeg_decode_idct() {
|
||||
if (f == 0) {
|
||||
func_name = "choosy_default";
|
||||
func = &wuffs_jpeg__decoder__decode_idct__choosy_default;
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V3)
|
||||
} else if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
func_name = "x86_avx2";
|
||||
func = &wuffs_jpeg__decoder__decode_idct_x86_avx2;
|
||||
@@ -739,8 +781,9 @@ test_wuffs_jpeg_decode_mcu() {
|
||||
for (int b = 0; b < 6; b++) {
|
||||
const uint32_t mx = 0;
|
||||
const uint32_t my = 0;
|
||||
if (wuffs_jpeg__decoder__decode_mcu(&dec, wuffs_base__empty_slice_u8(), mx,
|
||||
my)) {
|
||||
wuffs_base__pixel_buffer dst = {0};
|
||||
if (wuffs_jpeg__decoder__decode_mcu(&dec, &dst,
|
||||
wuffs_base__empty_slice_u8(), mx, my)) {
|
||||
RETURN_FAIL("decode_mcu failed");
|
||||
}
|
||||
|
||||
@@ -988,6 +1031,7 @@ proc g_tests[] = {
|
||||
test_wuffs_jpeg_decode_idct,
|
||||
test_wuffs_jpeg_decode_mcu,
|
||||
test_wuffs_jpeg_decode_interface,
|
||||
test_wuffs_jpeg_decode_lower_quality,
|
||||
test_wuffs_jpeg_decode_truncated_input,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
+21
-28
@@ -134,11 +134,11 @@ test_wuffs_core_multiply_u64() {
|
||||
|
||||
// ---------------- String Conversions Tests
|
||||
|
||||
// wuffs_base__private_implementation__high_prec_dec__to_debug_string converts
|
||||
// hpd into a human-readable NUL-terminated C string.
|
||||
// wuffs_private_impl__high_prec_dec__to_debug_string converts hpd into a
|
||||
// human-readable NUL-terminated C string.
|
||||
const char* //
|
||||
wuffs_base__private_implementation__high_prec_dec__to_debug_string(
|
||||
wuffs_base__private_implementation__high_prec_dec* hpd,
|
||||
wuffs_private_impl__high_prec_dec__to_debug_string(
|
||||
wuffs_private_impl__high_prec_dec* hpd,
|
||||
wuffs_base__slice_u8 dst) {
|
||||
if (!hpd) {
|
||||
return "high_prec_dec__to_debug_string: invalid hpd";
|
||||
@@ -153,8 +153,7 @@ wuffs_base__private_implementation__high_prec_dec__to_debug_string(
|
||||
*p++ = hpd->negative ? '-' : '+';
|
||||
|
||||
// Digits and decimal point.
|
||||
if (hpd->decimal_point >
|
||||
+WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {
|
||||
if (hpd->decimal_point > +WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) {
|
||||
// We have "infinity".
|
||||
if ((q - p) < 3) {
|
||||
goto too_short;
|
||||
@@ -165,7 +164,7 @@ wuffs_base__private_implementation__high_prec_dec__to_debug_string(
|
||||
goto nul_terminator;
|
||||
|
||||
} else if (hpd->decimal_point <
|
||||
-WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {
|
||||
-WUFFS_PRIVATE_IMPL__HPD__DECIMAL_POINT__RANGE) {
|
||||
// We have "epsilon": a very small number, equivalent to zero.
|
||||
if ((q - p) < 3) {
|
||||
goto too_short;
|
||||
@@ -184,8 +183,8 @@ wuffs_base__private_implementation__high_prec_dec__to_debug_string(
|
||||
goto nul_terminator;
|
||||
|
||||
} else if (hpd->decimal_point < 0) {
|
||||
// Referring to the wuffs_base__private_implementation__high_prec_dec
|
||||
// typedef's comment, we have something like ".00789".
|
||||
// Referring to the wuffs_private_impl__high_prec_dec typedef's comment, we
|
||||
// have something like ".00789".
|
||||
if ((q - p) < (hpd->num_digits + ((uint32_t)(-hpd->decimal_point)) + 1)) {
|
||||
goto too_short;
|
||||
}
|
||||
@@ -208,8 +207,8 @@ wuffs_base__private_implementation__high_prec_dec__to_debug_string(
|
||||
}
|
||||
|
||||
} else if (((uint32_t)(hpd->decimal_point)) <= hpd->num_digits) {
|
||||
// Referring to the wuffs_base__private_implementation__high_prec_dec
|
||||
// typedef's comment, we have something like "78.9".
|
||||
// Referring to the wuffs_private_impl__high_prec_dec typedef's comment, we
|
||||
// have something like "78.9".
|
||||
if ((q - p) < (hpd->num_digits + 1)) {
|
||||
goto too_short;
|
||||
}
|
||||
@@ -231,8 +230,8 @@ wuffs_base__private_implementation__high_prec_dec__to_debug_string(
|
||||
}
|
||||
|
||||
} else {
|
||||
// Referring to the wuffs_base__private_implementation__high_prec_dec
|
||||
// typedef's comment, we have something like "78900.".
|
||||
// Referring to the wuffs_private_impl__high_prec_dec typedef's comment, we
|
||||
// have something like "78900.".
|
||||
if ((q - p) < (((uint32_t)(hpd->decimal_point)) + 1)) {
|
||||
goto too_short;
|
||||
}
|
||||
@@ -338,17 +337,15 @@ test_wuffs_strconv_hpd_rounded_integer() {
|
||||
};
|
||||
|
||||
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__private_implementation__high_prec_dec hpd;
|
||||
wuffs_private_impl__high_prec_dec hpd;
|
||||
CHECK_STATUS(
|
||||
"hpd__parse",
|
||||
wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
wuffs_private_impl__high_prec_dec__parse(
|
||||
&hpd,
|
||||
wuffs_base__make_slice_u8((uint8_t*)(void*)test_cases[tc].str,
|
||||
strlen(test_cases[tc].str)),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
|
||||
uint64_t have =
|
||||
wuffs_base__private_implementation__high_prec_dec__rounded_integer(
|
||||
&hpd);
|
||||
uint64_t have = wuffs_private_impl__high_prec_dec__rounded_integer(&hpd);
|
||||
if (have != test_cases[tc].want) {
|
||||
RETURN_FAIL("\"%s\": have %" PRIu64 ", want %" PRIu64, test_cases[tc].str,
|
||||
have, test_cases[tc].want);
|
||||
@@ -384,28 +381,24 @@ test_wuffs_strconv_hpd_shift() {
|
||||
};
|
||||
|
||||
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__private_implementation__high_prec_dec hpd;
|
||||
wuffs_private_impl__high_prec_dec hpd;
|
||||
CHECK_STATUS(
|
||||
"hpd__parse",
|
||||
wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
wuffs_private_impl__high_prec_dec__parse(
|
||||
&hpd,
|
||||
wuffs_base__make_slice_u8((uint8_t*)(void*)test_cases[tc].str,
|
||||
strlen(test_cases[tc].str)),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
|
||||
int32_t shift = test_cases[tc].shift;
|
||||
if (shift > 0) {
|
||||
wuffs_base__private_implementation__high_prec_dec__small_rshift(
|
||||
&hpd, (uint32_t)(+shift));
|
||||
wuffs_private_impl__high_prec_dec__small_rshift(&hpd, (uint32_t)(+shift));
|
||||
} else if (shift < 0) {
|
||||
wuffs_base__private_implementation__high_prec_dec__small_lshift(
|
||||
&hpd, (uint32_t)(-shift));
|
||||
wuffs_private_impl__high_prec_dec__small_lshift(&hpd, (uint32_t)(-shift));
|
||||
}
|
||||
|
||||
uint8_t have[1024];
|
||||
CHECK_STRING(
|
||||
wuffs_base__private_implementation__high_prec_dec__to_debug_string(
|
||||
&hpd,
|
||||
wuffs_base__make_slice_u8(have, WUFFS_TESTLIB_ARRAY_SIZE(have))));
|
||||
CHECK_STRING(wuffs_private_impl__high_prec_dec__to_debug_string(
|
||||
&hpd, wuffs_base__make_slice_u8(have, WUFFS_TESTLIB_ARRAY_SIZE(have))));
|
||||
if (strcmp(((const char*)(void*)(have)), test_cases[tc].want)) {
|
||||
RETURN_FAIL("\"%s\" %s %" PRId32 ":\n have: \"%s\"\n want: \"%s\"",
|
||||
test_cases[tc].str, ((shift > 0) ? ">>" : "<<"),
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 lzip.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__CRC32
|
||||
#define WUFFS_CONFIG__MODULE__LZIP
|
||||
#define WUFFS_CONFIG__MODULE__LZMA
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
// No mimic library.
|
||||
#endif
|
||||
|
||||
// ---------------- Lzip Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_lzip_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_lzip__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_lzip__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__io_transformer(
|
||||
wuffs_lzip__decoder__upcast_as__wuffs_base__io_transformer(&dec),
|
||||
"test/data/romeo.txt.lz", 0, SIZE_MAX, 942, 0x0A);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Lzip Benches
|
||||
|
||||
// No Lzip benches.
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_lzip_decode_interface,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
// No Lzip benches.
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/lzip";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 lzma.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 -llzma
|
||||
|
||||
// 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__LZMA
|
||||
|
||||
// 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/lzma.c"
|
||||
#endif
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_lzma_enwik5_gt = {
|
||||
.want_filename = "test/data/enwik5",
|
||||
.src_filename = "test/data/enwik5.lzma",
|
||||
};
|
||||
|
||||
golden_test g_lzma_romeo_gt = {
|
||||
.want_filename = "test/data/romeo.txt",
|
||||
.src_filename = "test/data/romeo.txt.lzma",
|
||||
};
|
||||
|
||||
// ---------------- LZMA Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_lzma_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_lzma__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_lzma__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__io_transformer(
|
||||
wuffs_lzma__decoder__upcast_as__wuffs_base__io_transformer(&dec),
|
||||
"test/data/romeo.txt.litonlylzma", 0, SIZE_MAX, 942, 0x0A);
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_lzma_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
wuffs_lzma__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_lzma__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_lzma__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_lzma_decode_enwik5() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_lzma_decode, &g_lzma_enwik5_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_lzma_decode_romeo_lzma1() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_lzma_decode, &g_lzma_romeo_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_lzma_decode_romeo_lzma2() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
|
||||
CHECK_STRING(read_file(&src, "test/data/romeo.txt.xz"));
|
||||
if (src.meta.wi < 0x263) {
|
||||
RETURN_FAIL("source file was too short");
|
||||
}
|
||||
src.meta.ri = 0x018;
|
||||
src.meta.wi = 0x263;
|
||||
|
||||
wuffs_lzma__decoder dec;
|
||||
CHECK_STATUS("initialize", wuffs_lzma__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
|
||||
wuffs_lzma__decoder__set_quirk(&dec, WUFFS_LZMA__QUIRK_FORMAT_EXTENSION, 2);
|
||||
CHECK_STATUS("transform_io", wuffs_lzma__decoder__transform_io(
|
||||
&dec, &have, &src, g_work_slice_u8));
|
||||
|
||||
CHECK_STRING(read_file(&want, "test/data/romeo.txt"));
|
||||
CHECK_STRING(check_io_buffers_equal("", &have, &want));
|
||||
if (src.meta.ri != src.meta.wi) {
|
||||
RETURN_FAIL("ri=0x%zX is not equal to wi=0x%zX", src.meta.ri, src.meta.wi);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
test_mimic_lzma_decode_enwik5() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_lzma_decode, &g_lzma_enwik5_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_lzma_decode_romeo_lzma1() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_lzma_decode, &g_lzma_romeo_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- LZMA Benches
|
||||
|
||||
const char* //
|
||||
bench_wuffs_lzma_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_lzma_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
tcounter_dst, &g_lzma_enwik5_gt, UINT64_MAX, UINT64_MAX, 5);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
bench_mimic_lzma_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
mimic_lzma_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
tcounter_dst, &g_lzma_enwik5_gt, UINT64_MAX, UINT64_MAX, 5);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_lzma_decode_enwik5,
|
||||
test_wuffs_lzma_decode_interface,
|
||||
test_wuffs_lzma_decode_romeo_lzma1,
|
||||
test_wuffs_lzma_decode_romeo_lzma2,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_lzma_decode_enwik5,
|
||||
test_mimic_lzma_decode_romeo_lzma1,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_lzma_decode_100k,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
bench_mimic_lzma_decode_100k,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/lzma";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 qoi.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__QOI
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
// No mimic library.
|
||||
#endif
|
||||
|
||||
// ---------------- QOI Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_qoi_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_qoi__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_qoi__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__image_decoder(
|
||||
wuffs_qoi__decoder__upcast_as__wuffs_base__image_decoder(&dec),
|
||||
"test/data/bricks-color.qoi", 0, SIZE_MAX, 160, 120, 0xFF022460);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_qoi_decode_truncated_input() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
wuffs_base__io_buffer src =
|
||||
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
|
||||
wuffs_qoi__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_qoi__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
|
||||
wuffs_base__status status =
|
||||
wuffs_qoi__decoder__decode_image_config(&dec, NULL, &src);
|
||||
if (status.repr != wuffs_base__suspension__short_read) {
|
||||
RETURN_FAIL("closed=false: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__suspension__short_read);
|
||||
}
|
||||
|
||||
src.meta.closed = true;
|
||||
status = wuffs_qoi__decoder__decode_image_config(&dec, NULL, &src);
|
||||
if (status.repr != wuffs_qoi__error__truncated_input) {
|
||||
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_qoi__error__truncated_input);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_qoi_decode_frame_config() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_qoi__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_qoi__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
|
||||
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/bricks-color.qoi"));
|
||||
CHECK_STATUS("decode_frame_config #0",
|
||||
wuffs_qoi__decoder__decode_frame_config(&dec, &fc, &src));
|
||||
|
||||
wuffs_base__status status =
|
||||
wuffs_qoi__decoder__decode_frame_config(&dec, &fc, &src);
|
||||
if (status.repr != wuffs_base__note__end_of_data) {
|
||||
RETURN_FAIL("decode_frame_config #1: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__note__end_of_data);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- QOI Benches
|
||||
|
||||
// No QOI benches.
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_qoi_decode_frame_config,
|
||||
test_wuffs_qoi_decode_interface,
|
||||
test_wuffs_qoi_decode_truncated_input,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
// No QOI benches.
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/qoi";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 sha256.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 -lcrypto -lssl
|
||||
|
||||
// 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__SHA256
|
||||
|
||||
// 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/openssl.c"
|
||||
#endif
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_sha256_midsummer_gt = {
|
||||
.src_filename = "test/data/midsummer.txt",
|
||||
};
|
||||
|
||||
golden_test g_sha256_pi_gt = {
|
||||
.src_filename = "test/data/pi.txt",
|
||||
};
|
||||
|
||||
// ---------------- SHA256 Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_sha256_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_sha256__hasher h;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_sha256__hasher__initialize(
|
||||
&h, sizeof h, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__hasher_bitvec256(
|
||||
wuffs_sha256__hasher__upcast_as__wuffs_base__hasher_bitvec256(&h),
|
||||
"test/data/hat.lossy.webp", 0, SIZE_MAX,
|
||||
wuffs_base__make_bitvec256(0x5CC50E1942D6F258, 0x6AB8300CEABA7095,
|
||||
0x204081787511F1A3, 0xC3E4E8E405B501CB));
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_sha256_golden() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
struct {
|
||||
const char* filename;
|
||||
// The want values are determined by script/checksum.go.
|
||||
wuffs_base__bitvec256 want;
|
||||
} test_cases[] = {
|
||||
{
|
||||
.filename = "test/data/hat.bmp",
|
||||
.want = wuffs_base__make_bitvec256(
|
||||
0x2FC725BA7661C777, 0x5D80DB0568DB9741, 0x14CE2B683B211925,
|
||||
0x0EE3A9C0B94EBD3E),
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.gif",
|
||||
.want = wuffs_base__make_bitvec256(
|
||||
0x64E368566B47BA08, 0xF37522D2D09BF24A, 0x483A2E527CC031B0,
|
||||
0xDA46A35274A6B3DB),
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.jpeg",
|
||||
.want = wuffs_base__make_bitvec256(
|
||||
0x2C6B9551F7574AB3, 0x7486DECA160CA57C, 0x50F1B82175229C03,
|
||||
0x6085C5A688495233),
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.lossless.webp",
|
||||
.want = wuffs_base__make_bitvec256(
|
||||
0x7AC2F1DC78F9AC80, 0xCC1142375132C3C2, 0x311B3C16A251A65E,
|
||||
0xD91429191B532107),
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.lossy.webp",
|
||||
.want = wuffs_base__make_bitvec256(
|
||||
0x5CC50E1942D6F258, 0x6AB8300CEABA7095, 0x204081787511F1A3,
|
||||
0xC3E4E8E405B501CB),
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.png",
|
||||
.want = wuffs_base__make_bitvec256(
|
||||
0x23958198999B6D59, 0x2DF493278110663A, 0x7A1BDBCAE77A1D75,
|
||||
0xD3F360AF629B5780),
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.tiff",
|
||||
.want = wuffs_base__make_bitvec256(
|
||||
0xFAC8637F04EC2392, 0x373D5F707D803B99, 0x852E5F5F54D5BBD0,
|
||||
0xF44307C419C5F9BB),
|
||||
},
|
||||
};
|
||||
|
||||
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, test_cases[tc].filename));
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
wuffs_sha256__hasher checksum;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_sha256__hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
|
||||
wuffs_base__bitvec256 have = wuffs_base__make_bitvec256(0u, 0u, 0u, 0u);
|
||||
size_t num_fragments = 0;
|
||||
size_t num_bytes = 0;
|
||||
do {
|
||||
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
|
||||
.ptr = src.data.ptr + num_bytes,
|
||||
.len = src.meta.wi - num_bytes,
|
||||
});
|
||||
size_t limit = 101 + 103 * num_fragments;
|
||||
if ((j > 0) && (data.len > limit)) {
|
||||
data.len = limit;
|
||||
}
|
||||
have = wuffs_sha256__hasher__update_bitvec256(&checksum, data);
|
||||
num_fragments++;
|
||||
num_bytes += data.len;
|
||||
} while (num_bytes < src.meta.wi);
|
||||
|
||||
if ((have.elements_u64[0] != test_cases[tc].want.elements_u64[0]) ||
|
||||
(have.elements_u64[1] != test_cases[tc].want.elements_u64[1]) ||
|
||||
(have.elements_u64[2] != test_cases[tc].want.elements_u64[2]) ||
|
||||
(have.elements_u64[3] != test_cases[tc].want.elements_u64[3])) {
|
||||
RETURN_FAIL(
|
||||
"tc=%zu, j=%d, filename=\"%s\": " //
|
||||
"have 0x%016" PRIX64 "_%016" PRIX64 //
|
||||
"_%016" PRIX64 "_%016" PRIX64 //
|
||||
", want 0x%016" PRIX64 "_%016" PRIX64 //
|
||||
"_%016" PRIX64 "_%016" PRIX64, //
|
||||
tc, j, test_cases[tc].filename, //
|
||||
have.elements_u64[3], have.elements_u64[2], //
|
||||
have.elements_u64[1], have.elements_u64[0], //
|
||||
test_cases[tc].want.elements_u64[3], //
|
||||
test_cases[tc].want.elements_u64[2], //
|
||||
test_cases[tc].want.elements_u64[1], //
|
||||
test_cases[tc].want.elements_u64[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
do_test_xxxxx_sha256_pi(bool mimic) {
|
||||
const char* digits =
|
||||
"3."
|
||||
"141592653589793238462643383279502884197169399375105820974944592307816406"
|
||||
"2862089986280348253421170";
|
||||
if (strlen(digits) != 99) {
|
||||
RETURN_FAIL("strlen(digits): have %d, want 99", (int)(strlen(digits)));
|
||||
}
|
||||
|
||||
// The want values are determined by script/checksum.go.
|
||||
//
|
||||
// wants[(4*i) .. ((4*i)+4)] is the checksum of the first i bytes of the
|
||||
// digits string.
|
||||
uint64_t wants[400] = {
|
||||
0xA495991B7852B855, 0x27AE41E4649B934C, 0x9AFBF4C8996FB924,
|
||||
0xE3B0C44298FC1C14, 0x640B7E4729B49FCE, 0x16B72230967DE01F,
|
||||
0x60CE05C1DECFE3AD, 0x4E07408562BEDB8B, 0x614E6AB3B84FA55C,
|
||||
0xD208FA9C2FAFD974, 0x9BD88B9F5D1962D3, 0x267C23695B6E8FC2,
|
||||
0xF9E34E60E3AE4F44, 0xF59FCAAF3A56B538, 0xA8D86E4F33294BE0,
|
||||
0x35EFC6DED4E13F29, 0x7EE6614143500215, 0x7107CA98B0A6C242,
|
||||
0xD6698EA1047F5C0A, 0x2EFFF1261C25D94D, 0x00EC68941F27440C,
|
||||
0x038F6515DC7AD2A2, 0x02A4C5061F8AD16C, 0xA4F7BA76DB1A09F4,
|
||||
0x3A3A1DD8934D1958, 0xCE872F8C370A08DC, 0xF91001FCB6DAB28B,
|
||||
0x4E25F49BC91285E1, 0x527E79D0A3035852, 0xCC0BF86F2A60ED7E,
|
||||
0x9C8D5AB452E8B69B, 0xC0740DD25C9DE39B, 0x5D827521BB8D54DF,
|
||||
0x0C44B4C673812078, 0x0A05F1DE66EE555F, 0x8C954CD9B6C8F818,
|
||||
0x2FC3A26B33A91CD8, 0x2AF07CC393025875, 0xFF121FED87539C49,
|
||||
0x8721D1333B764926, 0xA4CD30C8355943FD, 0x4481071EAFEDEB1E,
|
||||
0x19B8C4ECE54CA63D, 0xCAAC67952F8CD5C1, 0xD21560096807F0CB,
|
||||
0xD2D991AF41C5EF75, 0x7FB2FADEB54168EC, 0x3DEC3E77C7B4AE98,
|
||||
0xFEEF53EFE3CBEE09, 0x7C1533C0CB71A163, 0x612F6D5C2BA2B291,
|
||||
0x330548C742A7C77A, 0xAA3566FE98696357, 0x5C595BAB01FDBDFB,
|
||||
0xB3150FCE2878C94A, 0x32FA47541DA9C49E, 0x8A2BAD94F28B1D20,
|
||||
0x423A5FB1BBFF501E, 0xE9F3784E332A1CCA, 0x1F0960C3EF5338A9,
|
||||
0x0CCCEEC918ED7221, 0xF989C8334DAABE36, 0xA6983AEDD3CAD63F,
|
||||
0x1564E00B0413DB17, 0xFAE59D87E444EA39, 0x76DDEB33198A342C,
|
||||
0x07E4D2A1F7B2225A, 0xB9A283FF2DBC461A, 0x71263158DFFB4E87,
|
||||
0x1DA33E2623A69F0A, 0x0D28F3CC44E9A624, 0xF0A1B7875844C3AE,
|
||||
0x21FBDC5793903EB6, 0x1192B6E4BDEC029C, 0x280ABB25EE957ACB,
|
||||
0xF983F1F5CF4BD0F5, 0x8F8DA51908599678, 0x8BF1794930B31D48,
|
||||
0xE035C38FE2581543, 0x99B340ACCCD6137D, 0x76610E7F8041E29D,
|
||||
0x79C81D3CF596E134, 0xB5E234BF4F2E2F2F, 0xA630621B389E0269,
|
||||
0xA32BEE851AA8195F, 0x1916D3919A37F28B, 0x52BD93F5CF2BB1C9,
|
||||
0x203A83F7BC429000, 0xB941961D7FD0DC88, 0x52AE42D747CC9B7F,
|
||||
0x779C702B13086F27, 0x2C40420C10F6C5C9, 0x89E082DA67E7A2BA,
|
||||
0xD62C06AE3B1262D5, 0x4E0846AEFE097B34, 0x5E6DED4E901BE009,
|
||||
0x9A74E9A524DEF058, 0x13FA1A8D6184DE71, 0x1BEDE46B96346B8E,
|
||||
0x8BFE4F313A316226, 0x0D2B653DA3F00458, 0x676C5640EC523D07,
|
||||
0xDA7B1A41CCAE7D4E, 0x641FB4D8D2D13726, 0xCEE611F144692B66,
|
||||
0x987643879977A1BD, 0xFB1904FC6EE0D915, 0x70FE652365FEDCF9,
|
||||
0x124A7D6202DE83FC, 0x137C66C93DD8A735, 0x4A43DA05BCD32DBA,
|
||||
0x6E172C87859B68E3, 0xD909261806A23376, 0x71DCC0C5DB9810FE,
|
||||
0x1743C2DA282BE204, 0xE574568E07C2F447, 0x47004C6705CF1330,
|
||||
0x189F8C3D310C9189, 0xFFBB604311CBA061, 0x57C45B1D54E9293D,
|
||||
0x407FD98EA2EC9790, 0xA3A1BA2CAD658AEF, 0xE177F3D9A301E214,
|
||||
0xEBF75EB10D6B8225, 0x9449C881047FEF89, 0x345EAEF124098DFF,
|
||||
0x76293F79FA5D6837, 0xBA81CC1276BFF143, 0x8194DA38905F2A76,
|
||||
0x57496BFA62C36212, 0x5CC7F80FCA76488B, 0x27F6EF06C05A6667,
|
||||
0x859A911428426908, 0xAC839788AD1E3AFE, 0xBBCF0E62C9C98465,
|
||||
0x16C99E22FE8F336D, 0x7944DCB715D2B48E, 0x6D500BA806F21FED,
|
||||
0xE2C0783E3EA9F6BE, 0xAD95772328B63AA4, 0x9F2DAA9DD934B738,
|
||||
0x19B67552963DBA24, 0x4AA889C916C78EEC, 0xE183CB786F7D0225,
|
||||
0x8204624FB1DF4072, 0x1C52B79198588F75, 0x5215491F588E9061,
|
||||
0xC0ECB4BF497B3D24, 0xA3DDCF951C863B90, 0x3DC34E03715D1E86,
|
||||
0x93C7003309B2B16D, 0xDB8DC55940E6D405, 0x22A674F0A5C51BEE,
|
||||
0xB9CC42BE352273A4, 0x5288081DC7BE6307, 0x3ABFFE72285284CB,
|
||||
0xB03A58DF3811A955, 0x4D937AB0E3F28BC7, 0xFF1260C7907EBD92,
|
||||
0xEA012389BB29FCFA, 0xA6F634F7B0A91D90, 0xA1C732F0466BA190,
|
||||
0x1694A93FA04F924F, 0x7A68A298FBBE78F8, 0x688784515705B894,
|
||||
0x7BF3B2235A9BFCCF, 0x3A8D7B10D3E16143, 0xBEA09BF0EBEC453C,
|
||||
0x7A964C634DF35A00, 0xA578BC3FB1805216, 0x22511DCBA44BE006,
|
||||
0x473CF801B7E7DC82, 0x2E61B3D57F5A6400, 0xECFA2730978ECD31,
|
||||
0x4D76B0F79873109D, 0xA5E570AA856BEFC9, 0x85D50A9055BCC917,
|
||||
0x09B71ACFE36EC46A, 0xB7219D64858B1D1B, 0x6322E0AEA4762644,
|
||||
0x6110A33948746949, 0xA3834380FA84B98C, 0x416827D9BD10517B,
|
||||
0x205191477BA5E2D4, 0x8583927ED0D61E42, 0xF23C26620985246C,
|
||||
0x463FA0BD48E2D9CD, 0x5BE1E31786234856, 0x076B608F1F16EC54,
|
||||
0xFCF291E7DE66100D, 0x027B9593BE686708, 0xF7ECCC236C2F031F,
|
||||
0x101C24CB8038FFA2, 0x36FBD8565EE584ED, 0x981E43EE73218C77,
|
||||
0xE99B6E19BF8CE8DA, 0x5A45E8D434AD96C8, 0x949668B5F689B688,
|
||||
0x2596516D1350B71E, 0x6739DB9427BB8C02, 0x8031B2D3C446DD6E,
|
||||
0x4C2224CC1742F920, 0x59093F03EDBA8CD1, 0x7CB4BB75F9E08F1A,
|
||||
0x6B64AEB9CD1CDFF5, 0x2CA127A0C57C6D6C, 0xE1D9E0F0471EB1AC,
|
||||
0x3A335F3D7180856D, 0xD87D65A08487BF82, 0x07864D342C10C819,
|
||||
0x511BF7E38AF42BAE, 0x8B5D843EC502DA3B, 0x80125447E4888B8F,
|
||||
0xA1CC69B692DEA1B2, 0xDDD2B9DB35EEFC4E, 0x49F11DA1947B362E,
|
||||
0x34E40280999D3EA6, 0xA491F7A67A19442E, 0x38CD84D6A14D87F1,
|
||||
0xD3A19502C9450B5F, 0xDF47D72860C62910, 0xB29D464603F6E8F0,
|
||||
0x82F22502D37F5561, 0x4B4450DC4DC1583D, 0x85BADFAFE321525E,
|
||||
0x8296939672321D16, 0x36E12D7A4AB1B08A, 0x860650B802184FD4,
|
||||
0xE94462C6B55C3FF6, 0xE83FED74E65B3EDD, 0x3EE9B1254D10432D,
|
||||
0x78E5956D6BC70090, 0xF6F0EB6D1E334F56, 0xD7452F3FB84E4A36,
|
||||
0x6B6356F7826A9DD1, 0xF8B38562F8AF7F5A, 0x83442AE9FE5BE79B,
|
||||
0x9B6E82F6BCF031AB, 0xF36FDF177673476D, 0x112E1F92164E0E52,
|
||||
0x0BFA74605FB8A9B8, 0x48E45F150E86DEC8, 0xC4BA24790041D453,
|
||||
0x9AA2B91B81053FC2, 0x2A7A944B1AF44A23, 0x4A471FF96E24FDB7,
|
||||
0x9A2C561F8A2401C2, 0xA7AF4303D32EF538, 0xF6D40B18E4846693,
|
||||
0xF73C7D03097E2A85, 0x5963AAAC8B2E391A, 0x2326CF3AD8A24949,
|
||||
0x2955AA4CFD0955B0, 0xEFB503670B6B1CDA, 0x8F36DD3C25A09004,
|
||||
0x72C73ED09101189B, 0xE48C7DBF4C345FFA, 0xF465188486D12732,
|
||||
0x8F7191F537DC3023, 0xD76FBBE816AB8193, 0x78971FF1C5759434,
|
||||
0x9EBB4D1E515EE18A, 0x9F34BC53A2BEACEF, 0xA0DA75B06F9F8EA6,
|
||||
0x38E11C269938E34C, 0x47ADCCF552546D6D, 0x4728ED1535C94B4A,
|
||||
0xEC794468363C2E0E, 0x2938E9D38B388722, 0x2DC07DBB29AF4947,
|
||||
0x1E3B4531213FFBA2, 0x957E8DCC3E00727C, 0xD6C75341415F04D6,
|
||||
0xE336F0579666B64F, 0x1BA3345394F98EB3, 0x375B0F6C5B15DD3D,
|
||||
0xE04DB04888B4380D, 0xF83213CF696EE88C, 0x9B31BCE678AD6B18,
|
||||
0xF8EFC9964ADE38E4, 0xBC2004109A0E3AFA, 0xFAF1EA27888B1A3C,
|
||||
0x5E98EAF21609A0A7, 0x118C1DB41DA78E81, 0x86C4619A31B85BFC,
|
||||
0x5F8C9067ACAA4269, 0xF0B267621ACC79EA, 0x9C6050C66D54D3BC,
|
||||
0x24818E3F7A769CBD, 0x2250FA7C3FCB1CBB, 0xB61B7A8E81ED778D,
|
||||
0x4538060EB1141D17, 0xA221626CF97D97CB, 0x8A7723D63091967E,
|
||||
0x080F04C095C14517, 0x323E944917F9EB93, 0xA3EF852EDF53A001,
|
||||
0xA4353F820201EE29, 0x4F73E39FEE8BDBFE, 0xF0ACAAA72D2B62F7,
|
||||
0x1BE147496E7750CA, 0x91189876D80EDE4C, 0x3389F591EE806FBB,
|
||||
0x7C74F4B2303DAD0D, 0x5FBECE9186741846, 0xB04B9AE381183FAE,
|
||||
0xEE6D1C39B794CE62, 0x9016FB0579FA9402, 0x97EC8D2C65EA43B8,
|
||||
0xF2D37ED8E008422A, 0xA88DFD8B0F3AAB89, 0xD7CF6CDF34BFD209,
|
||||
0xE3628B3721931FDB, 0x0C451B3E3B436D15, 0x239BB072E5B34E41,
|
||||
0x3DC51A97B5A940C1, 0xAC0161A0DA84D53B, 0x345394823D66FC62,
|
||||
0x1B7F7E176A836AEE, 0x6612B6D3AFB30CA8, 0x01C47C26E7B2CC00,
|
||||
0x043B730599D20260, 0x3F9E463CB7C946B2, 0x4A8DAAEBFB336D43,
|
||||
0xF9B617983070ED60, 0x9AF2AF0BA91EA0D7, 0x0AC44EF9103AE372,
|
||||
0x8B66DBF1D2C5E991, 0xC3B16BB058908557, 0xBD8240471D86C144,
|
||||
0x3E2C14E27BC64098, 0xDDCD99498E58F066, 0xE388E41366082790,
|
||||
0xA63D08B8AF4977D9, 0x0BCF499AFA092637, 0xDBB0A064FFA9E303,
|
||||
0xBD45DDD5BA1477EE, 0xB8F750B4D84076E9, 0x3A535BB3BDE3D3D9,
|
||||
0x9525F2A6EE6F38D3, 0x6CDF53C189D3E726, 0x538AB825624B96DD,
|
||||
0x730DE4A6B79DD8B1, 0x51B74D121690D957, 0x8E3E7626617E0B24,
|
||||
0xC44263402923D601, 0xD0530C69581EF7EF, 0xBA6C3F80FCF5DB55,
|
||||
0x4B7E7C204C8ACD97, 0xB0E7053FD43FACD4, 0xED5F518F302EFD69,
|
||||
0x1624AE47324832FC, 0x7F17547B953914AD, 0x525C47949C18BCEA,
|
||||
0x313955A415351A58, 0x307E18AD60ED4B54, 0xB03344E911DF01D6,
|
||||
0x20C38803D44CF9CD, 0xDDB3956944628B64, 0x11A5DEA12D3DB3EC,
|
||||
0x593659D66BC87815, 0xE5AF653BAE6F1869, 0xF47815E9DE6A716E,
|
||||
0x2508DCD62F17EAD9, 0x64A61858259ED57B, 0xFDAAE31E9178B455,
|
||||
0x266008D2BEBD6ECC, 0x01A7BC2FBD4F1FF1, 0x75D074C7FE629A1D,
|
||||
0x726F46CB272A92A1, 0x217F12238920FE7A, 0x99A0B1A4A8EB311C,
|
||||
0x48E5BD99F0A5CDDE, 0x0CC73F9EFFEA61E2, 0x142BADB1DCD76ED6,
|
||||
0x6B6696D8D16E993E, 0xF73977B29D3332B2, 0x3532EC396A463E8D,
|
||||
0x08485AF320F6EF4A, 0x3BE313B7F5F5462D, 0xC7EDDABFD3A52DEC,
|
||||
0xE3C0AE2EE970AB95, 0x59DACF3BB3C53E2B, 0x3E135135F158E39C,
|
||||
0x4B25757F5EF36523, 0xDCE58EEC3A4E8B12, 0x27A7532E62B6147F,
|
||||
0xAA5D819242B97295, 0x815E4E99C89F0115, 0x90AD0232C1A6A145,
|
||||
0xE6FC5968AC8C1AFE, 0xB24A3CF866116B23, 0x3134AEF31EA120B2,
|
||||
0xFBD01F222353BCFA, 0xC5C85E7FE228C34A, 0x385ABA08C78A08FB,
|
||||
0x28EEFFB4F741E27D, 0x10F7CA989D8373CE, 0x99E053B9784F8535,
|
||||
0x350A957CEEA5AA93,
|
||||
};
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
wuffs_base__bitvec256 have = wuffs_base__make_bitvec256(0u, 0u, 0u, 0u);
|
||||
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
|
||||
.ptr = (uint8_t*)(digits),
|
||||
.len = (size_t)(i),
|
||||
});
|
||||
|
||||
if (mimic) {
|
||||
#ifdef WUFFS_MIMIC
|
||||
have = mimic_sha256_one_shot_checksum_bitvec256(data);
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
} else {
|
||||
wuffs_sha256__hasher checksum;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_sha256__hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
have = wuffs_sha256__hasher__update_bitvec256(&checksum, data);
|
||||
}
|
||||
|
||||
if ((have.elements_u64[0] != wants[(4 * i) + 0]) ||
|
||||
(have.elements_u64[1] != wants[(4 * i) + 1]) ||
|
||||
(have.elements_u64[2] != wants[(4 * i) + 2]) ||
|
||||
(have.elements_u64[3] != wants[(4 * i) + 3])) {
|
||||
RETURN_FAIL(
|
||||
"i=%d: " //
|
||||
"have 0x%016" PRIX64 "_%016" PRIX64 //
|
||||
"_%016" PRIX64 "_%016" PRIX64 //
|
||||
", want 0x%016" PRIX64 "_%016" PRIX64 //
|
||||
"_%016" PRIX64 "_%016" PRIX64, //
|
||||
i, //
|
||||
have.elements_u64[3], have.elements_u64[2], //
|
||||
have.elements_u64[1], have.elements_u64[0], //
|
||||
wants[(4 * i) + 3], wants[(4 * i) + 2], //
|
||||
wants[(4 * i) + 1], wants[(4 * i) + 0]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_sha256_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_xxxxx_sha256_pi(false);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
test_mimic_sha256_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_xxxxx_sha256_pi(true);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- SHA256 Benches
|
||||
|
||||
wuffs_base__bitvec256 g_wuffs_sha256_unused_bitvec256;
|
||||
|
||||
const char* //
|
||||
wuffs_bench_sha256(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
uint64_t len = src->meta.wi - src->meta.ri;
|
||||
if (rlimit) {
|
||||
len = wuffs_base__u64__min(len, rlimit);
|
||||
}
|
||||
wuffs_sha256__hasher checksum = {0};
|
||||
CHECK_STATUS("initialize", wuffs_sha256__hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
g_wuffs_sha256_unused_bitvec256 = wuffs_sha256__hasher__update_bitvec256(
|
||||
&checksum, ((wuffs_base__slice_u8){
|
||||
.ptr = src->data.ptr + src->meta.ri,
|
||||
.len = len,
|
||||
}));
|
||||
src->meta.ri += len;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_sha256_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bench_sha256,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_sha256_midsummer_gt, UINT64_MAX, UINT64_MAX, 100);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_sha256_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bench_sha256,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_sha256_pi_gt, UINT64_MAX, UINT64_MAX, 10);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
bench_mimic_sha256_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
mimic_bench_sha256,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_sha256_midsummer_gt, UINT64_MAX, UINT64_MAX, 100);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_mimic_sha256_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
mimic_bench_sha256,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_sha256_pi_gt, UINT64_MAX, UINT64_MAX, 10);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_sha256_golden,
|
||||
test_wuffs_sha256_interface,
|
||||
test_wuffs_sha256_pi,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_sha256_pi,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_sha256_10k,
|
||||
bench_wuffs_sha256_100k,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
bench_mimic_sha256_10k,
|
||||
bench_mimic_sha256_100k,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/sha256";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 vp8.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__VP8
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
// No mimic library.
|
||||
#endif
|
||||
|
||||
// ---------------- VP8 Tests
|
||||
|
||||
// No VP8 tests.
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- VP8 Benches
|
||||
|
||||
// No VP8 benches.
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
// No VP8 tests.
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
// No VP8 benches.
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/vp8";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
+36
-4
@@ -317,6 +317,10 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
.color = 0xFF444444,
|
||||
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__Y_16BE,
|
||||
},
|
||||
{
|
||||
.color = 0x55444444,
|
||||
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL,
|
||||
},
|
||||
{
|
||||
.color = 0x55443300,
|
||||
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL,
|
||||
@@ -370,6 +374,10 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
// When updating this list, also consider updating the pixel formats that
|
||||
// fuzz/c/std/pixel_swizzler_fuzzer.c exercises and those that
|
||||
// wuffs_aux::DecodeImageCallbacks::SelectPixfmt accepts.
|
||||
//
|
||||
// SelectPixfmt excludes WUFFS_BASE__PIXEL_FORMAT__Y, even though we test
|
||||
// it here, since it doesn't support every source pixel format in the
|
||||
// srcs array. See "dst WUFFS_BASE__PIXEL_FORMAT__Y allow-list" below.
|
||||
{
|
||||
.color = 0xFF000010,
|
||||
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__BGR_565,
|
||||
@@ -402,6 +410,10 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
.color = 0x33002233,
|
||||
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL,
|
||||
},
|
||||
{
|
||||
.color = 0xFF999999,
|
||||
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__Y,
|
||||
},
|
||||
};
|
||||
|
||||
const wuffs_base__pixel_blend blends[] = {
|
||||
@@ -439,6 +451,19 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
}
|
||||
|
||||
for (size_t d = 0; d < WUFFS_TESTLIB_ARRAY_SIZE(dsts); d++) {
|
||||
// See "dst WUFFS_BASE__PIXEL_FORMAT__Y allow-list" above.
|
||||
if (dsts[d].pixfmt_repr == WUFFS_BASE__PIXEL_FORMAT__Y) {
|
||||
switch (srcs[s].pixfmt_repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate the dst_pixbuf.
|
||||
wuffs_base__pixel_config dst_pixcfg = ((wuffs_base__pixel_config){});
|
||||
wuffs_base__pixel_config__set(&dst_pixcfg, dsts[d].pixfmt_repr,
|
||||
@@ -476,10 +501,10 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
wuffs_base__pixel_buffer__palette(&src_pixbuf), blends[b]));
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(
|
||||
&swizzler,
|
||||
wuffs_base__table_u8__row_u32(
|
||||
wuffs_private_impl__table_u8__row_u32(
|
||||
wuffs_base__pixel_buffer__plane(&dst_pixbuf, 0), height / 2),
|
||||
dst_palette,
|
||||
wuffs_base__table_u8__row_u32(
|
||||
wuffs_private_impl__table_u8__row_u32(
|
||||
wuffs_base__pixel_buffer__plane(&src_pixbuf, 0), height / 2));
|
||||
|
||||
// Check the middle dst pixel.
|
||||
@@ -490,7 +515,7 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
want_dst_pixel = srcs[s].color;
|
||||
} else if (blends[b] == WUFFS_BASE__PIXEL_BLEND__SRC_OVER) {
|
||||
tolerance += 1;
|
||||
want_dst_pixel = wuffs_base__composite_premul_premul_u32_axxx(
|
||||
want_dst_pixel = wuffs_private_impl__composite_premul_premul_u32_axxx(
|
||||
dsts[d].color, srcs[s].color);
|
||||
} else {
|
||||
return "unsupported blend";
|
||||
@@ -498,6 +523,13 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
if (dst_transparency == WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE) {
|
||||
want_dst_pixel |= 0xFF000000;
|
||||
}
|
||||
if (dsts[d].pixfmt_repr == WUFFS_BASE__PIXEL_FORMAT__Y) {
|
||||
want_dst_pixel =
|
||||
0xFF000000 |
|
||||
(0x00010101 *
|
||||
wuffs_base__color_u32_argb_premul__as__color_u8_gray(
|
||||
want_dst_pixel));
|
||||
}
|
||||
wuffs_base__color_u32_argb_premul have_dst_pixel =
|
||||
wuffs_base__pixel_buffer__color_u32_at(&dst_pixbuf, width / 2,
|
||||
height / 2);
|
||||
@@ -536,7 +568,7 @@ test_wuffs_upsample_inv_h2v1() {
|
||||
};
|
||||
|
||||
const uint8_t* have_ptr =
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v1_triangle(
|
||||
wuffs_private_impl__swizzle_ycc__upsample_inv_h2v1_triangle(
|
||||
g_have_array_u8, src_array0, src_array0, 16, 0, true, true);
|
||||
|
||||
const bool closed = true;
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 webp.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 -lwebp
|
||||
|
||||
// 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__VP8
|
||||
#define WUFFS_CONFIG__MODULE__WEBP
|
||||
|
||||
// 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/webp.c"
|
||||
#endif
|
||||
|
||||
static wuffs_webp__decoder g_webp_decoder;
|
||||
|
||||
// ---------------- WebP Tests
|
||||
|
||||
const char* //
|
||||
wuffs_webp_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_webp__decoder* dec = &g_webp_decoder;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_webp__decoder__initialize(dec, sizeof *dec, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
return do_run__wuffs_base__image_decoder(
|
||||
wuffs_webp__decoder__upcast_as__wuffs_base__image_decoder(dec),
|
||||
n_bytes_out, dst, pixfmt, quirks_ptr, quirks_len, src);
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
const char* //
|
||||
test_wuffs_webp_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_webp__decoder* dec = &g_webp_decoder;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_webp__decoder__initialize(
|
||||
dec, sizeof *dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__image_decoder(
|
||||
wuffs_webp__decoder__upcast_as__wuffs_base__image_decoder(dec),
|
||||
"test/data/bricks-color.lossless.webp", 0, SIZE_MAX, 160, 120,
|
||||
0xFF022460);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
do_test_mimic_webp_decode(const char* filename) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, filename));
|
||||
|
||||
src.meta.ri = 0;
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
CHECK_STRING(wuffs_webp_decode(
|
||||
NULL, &have, WUFFS_INITIALIZE__DEFAULT_OPTIONS,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, &src));
|
||||
|
||||
src.meta.ri = 0;
|
||||
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
CHECK_STRING(mimic_webp_decode(
|
||||
NULL, &want, WUFFS_INITIALIZE__DEFAULT_OPTIONS,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, &src));
|
||||
|
||||
return check_io_buffers_equal("", &have, &want);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_webp_lossless_decode_image_19k_8bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_mimic_webp_decode("test/data/bricks-gray.lossless.webp");
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_webp_lossless_decode_image_40k_24bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_mimic_webp_decode("test/data/hat.lossless.webp");
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_webp_lossless_decode_image_77k_8bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_mimic_webp_decode("test/data/bricks-dither.lossless.webp");
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_webp_lossless_decode_image_552k_32bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_mimic_webp_decode(
|
||||
"test/data/hibiscus.primitive.lossless.webp");
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_webp_lossless_decode_image_4002k_24bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_mimic_webp_decode("test/data/harvesters.lossless.webp");
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- WebP Benches
|
||||
|
||||
const char* //
|
||||
bench_wuffs_webp_lossless_decode_image_19k_8bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&wuffs_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__Y), NULL, 0,
|
||||
"test/data/bricks-gray.lossless.webp", 0, SIZE_MAX, 50);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_webp_lossless_decode_image_40k_24bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&wuffs_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/hat.lossless.webp", 0, SIZE_MAX, 30);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_webp_lossless_decode_image_77k_8bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&wuffs_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/bricks-dither.lossless.webp", 0, SIZE_MAX, 50);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_webp_lossless_decode_image_552k_32bpp() {
|
||||
uint32_t q = WUFFS_BASE__QUIRK_IGNORE_CHECKSUM;
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&wuffs_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
&q, 1, "test/data/hibiscus.primitive.lossless.webp", 0, SIZE_MAX, 4);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_webp_lossless_decode_image_4002k_24bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&wuffs_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/harvesters.lossless.webp", 0, SIZE_MAX, 1);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
bench_mimic_webp_lossless_decode_image_19k_8bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&mimic_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__Y), NULL, 0,
|
||||
"test/data/bricks-gray.lossless.webp", 0, SIZE_MAX, 50);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_mimic_webp_lossless_decode_image_40k_24bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&mimic_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/hat.lossless.webp", 0, SIZE_MAX, 30);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_mimic_webp_lossless_decode_image_77k_8bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&mimic_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/bricks-dither.lossless.webp", 0, SIZE_MAX, 50);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_mimic_webp_lossless_decode_image_552k_32bpp() {
|
||||
uint32_t q = WUFFS_BASE__QUIRK_IGNORE_CHECKSUM;
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&mimic_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
&q, 1, "test/data/hibiscus.primitive.lossless.webp", 0, SIZE_MAX, 4);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_mimic_webp_lossless_decode_image_4002k_24bpp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_image_decode(
|
||||
&mimic_webp_decode,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
NULL, 0, "test/data/harvesters.lossless.webp", 0, SIZE_MAX, 1);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_webp_decode_interface,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_webp_lossless_decode_image_19k_8bpp,
|
||||
test_mimic_webp_lossless_decode_image_40k_24bpp,
|
||||
test_mimic_webp_lossless_decode_image_77k_8bpp,
|
||||
test_mimic_webp_lossless_decode_image_552k_32bpp,
|
||||
test_mimic_webp_lossless_decode_image_4002k_24bpp,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_webp_lossless_decode_image_19k_8bpp,
|
||||
bench_wuffs_webp_lossless_decode_image_40k_24bpp,
|
||||
bench_wuffs_webp_lossless_decode_image_77k_8bpp,
|
||||
bench_wuffs_webp_lossless_decode_image_552k_32bpp,
|
||||
bench_wuffs_webp_lossless_decode_image_4002k_24bpp,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
bench_mimic_webp_lossless_decode_image_19k_8bpp,
|
||||
bench_mimic_webp_lossless_decode_image_40k_24bpp,
|
||||
bench_mimic_webp_lossless_decode_image_77k_8bpp,
|
||||
bench_mimic_webp_lossless_decode_image_552k_32bpp,
|
||||
bench_mimic_webp_lossless_decode_image_4002k_24bpp,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/webp";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
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 xz.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 -llzma
|
||||
|
||||
// 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__CRC32
|
||||
#define WUFFS_CONFIG__MODULE__CRC64
|
||||
#define WUFFS_CONFIG__MODULE__LZMA
|
||||
#define WUFFS_CONFIG__MODULE__SHA256
|
||||
#define WUFFS_CONFIG__MODULE__XZ
|
||||
|
||||
// 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/lzma.c"
|
||||
#endif
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_xz_enwik5_gt = {
|
||||
.want_filename = "test/data/enwik5",
|
||||
.src_filename = "test/data/enwik5.xz",
|
||||
};
|
||||
|
||||
golden_test g_xz_romeo_delta1_gt = {
|
||||
.want_filename = "test/data/romeo.txt",
|
||||
.src_filename = "test/data/romeo.txt.delta1.xz",
|
||||
};
|
||||
|
||||
golden_test g_xz_romeo_gt = {
|
||||
.want_filename = "test/data/romeo.txt",
|
||||
.src_filename = "test/data/romeo.txt.xz",
|
||||
};
|
||||
|
||||
// ---------------- LZMA Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_xz_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_xz__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_xz__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__io_transformer(
|
||||
wuffs_xz__decoder__upcast_as__wuffs_base__io_transformer(&dec),
|
||||
"test/data/romeo.txt.delta1.xz", 0, SIZE_MAX, 942, 0x0A);
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_xz_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
wuffs_xz__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_xz__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_xz__decoder__transform_io(
|
||||
&dec, &limited_dst, &limited_src, g_work_slice_u8);
|
||||
|
||||
dst->meta.wi += limited_dst.meta.wi;
|
||||
src->meta.ri += limited_src.meta.ri;
|
||||
|
||||
if (((wlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_write)) ||
|
||||
((rlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_read))) {
|
||||
continue;
|
||||
}
|
||||
return status.repr;
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_xz_decode_with_history(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
if (wlimit != UINT64_MAX) {
|
||||
return "wuffs_xz_decode_with_history assumes wlimit == UINT64_MAX";
|
||||
}
|
||||
|
||||
wuffs_xz__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_xz__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
|
||||
while (true) {
|
||||
wuffs_base__io_buffer limited_src = make_limited_reader(*src, rlimit);
|
||||
|
||||
// Compared to wuffs_xz_decode, wuffs_xz_decode_with_history passes dst
|
||||
// directly, not limited_dst (which has no history).
|
||||
wuffs_base__status status = wuffs_xz__decoder__transform_io(
|
||||
&dec, dst, &limited_src, g_work_slice_u8);
|
||||
|
||||
src->meta.ri += limited_src.meta.ri;
|
||||
|
||||
if (((rlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_read))) {
|
||||
continue;
|
||||
}
|
||||
return status.repr;
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_xz_decode_enwik5() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_xz_decode, &g_xz_enwik5_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_xz_decode_one_byte_reads_sans_history() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_xz_decode, &g_xz_romeo_delta1_gt, UINT64_MAX,
|
||||
1);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_xz_decode_one_byte_reads_with_history() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_xz_decode_with_history, &g_xz_romeo_delta1_gt,
|
||||
UINT64_MAX, 1);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_xz_decode_romeo() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_xz_decode, &g_xz_romeo_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
test_mimic_xz_decode_enwik5() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_lzma_decode, &g_xz_enwik5_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_xz_decode_romeo() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_lzma_decode, &g_xz_romeo_gt, UINT64_MAX,
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- LZMA Benches
|
||||
|
||||
const char* //
|
||||
bench_wuffs_xz_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_xz_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
tcounter_dst, &g_xz_enwik5_gt, UINT64_MAX, UINT64_MAX, 5);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
bench_mimic_xz_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
mimic_lzma_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
|
||||
tcounter_dst, &g_xz_enwik5_gt, UINT64_MAX, UINT64_MAX, 5);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_xz_decode_enwik5,
|
||||
test_wuffs_xz_decode_interface,
|
||||
test_wuffs_xz_decode_one_byte_reads_sans_history,
|
||||
test_wuffs_xz_decode_one_byte_reads_with_history,
|
||||
test_wuffs_xz_decode_romeo,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_xz_decode_enwik5,
|
||||
test_mimic_xz_decode_romeo,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_xz_decode_100k,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
bench_mimic_xz_decode_100k,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/xz";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -559,7 +559,7 @@ copy_to_io_buffer_from_pixel_buffer(wuffs_base__io_buffer* dst,
|
||||
for (uint32_t p = 0; p < 1; p++) {
|
||||
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(src, p);
|
||||
for (uint32_t y = r.min_incl_y; y < r.max_excl_y; y++) {
|
||||
wuffs_base__slice_u8 row = wuffs_base__table_u8__row_u32(tab, y);
|
||||
wuffs_base__slice_u8 row = wuffs_private_impl__table_u8__row_u32(tab, y);
|
||||
if ((r.min_incl_x >= r.max_excl_x) ||
|
||||
(r.max_excl_x > (row.len / bytes_per_pixel))) {
|
||||
break;
|
||||
@@ -1184,6 +1184,37 @@ do_test__wuffs_base__hasher_u64(wuffs_base__hasher_u64* b,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
do_test__wuffs_base__hasher_bitvec256(wuffs_base__hasher_bitvec256* b,
|
||||
const char* src_filename,
|
||||
size_t src_ri,
|
||||
size_t src_wi,
|
||||
wuffs_base__bitvec256 want) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file_fragment(&src, src_filename, src_ri, src_wi));
|
||||
wuffs_base__bitvec256 have = wuffs_base__hasher_bitvec256__update_bitvec256(
|
||||
b, ((wuffs_base__slice_u8){
|
||||
.ptr = (uint8_t*)(src.data.ptr + src.meta.ri),
|
||||
.len = (size_t)(src.meta.wi - src.meta.ri),
|
||||
}));
|
||||
if ((have.elements_u64[0] != want.elements_u64[0]) ||
|
||||
(have.elements_u64[1] != want.elements_u64[1]) ||
|
||||
(have.elements_u64[2] != want.elements_u64[2]) ||
|
||||
(have.elements_u64[3] != want.elements_u64[3])) {
|
||||
RETURN_FAIL("have 0x%016" PRIX64 "_%016" PRIX64 //
|
||||
"_%016" PRIX64 "_%016" PRIX64 //
|
||||
", want 0x%016" PRIX64 "_%016" PRIX64 //
|
||||
"_%016" PRIX64 "_%016" PRIX64, //
|
||||
have.elements_u64[3], have.elements_u64[2], //
|
||||
have.elements_u64[1], have.elements_u64[0], //
|
||||
want.elements_u64[3], want.elements_u64[2], //
|
||||
want.elements_u64[1], want.elements_u64[0]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
do_test__wuffs_base__image_decoder(
|
||||
wuffs_base__image_decoder* b,
|
||||
|
||||
Binary file not shown.
@@ -62,6 +62,10 @@ were then generated by `example/convert-to-nia` and
|
||||
`crude-flag.*` is an original animation by Nigel Tao
|
||||
<nigeltao@golang.org>. See the `lib/nie` documentation.
|
||||
|
||||
`enwik5` is the first 1e5 bytes of the [enwik8 or
|
||||
enwik9](https://mattmahoney.net/dc/textdata.html) data, derived from the
|
||||
English Wikipedia as of 2006.
|
||||
|
||||
`file-sizes.json` was created by running `script/print-file-sizes-json.go` in
|
||||
this repository's root directory.
|
||||
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
// Copyright 2024 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// Usage: go run make.go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
recipes := []struct {
|
||||
filterID string
|
||||
filterName string
|
||||
generator func() []byte
|
||||
}{
|
||||
// No test case generated for 04/x86, as the x86 CPU bytecode format is
|
||||
// complicated (variable length instructions). Test coverage is instead
|
||||
// provided by xz-tests-files's good-1-x86-lzma2.xz file.
|
||||
//
|
||||
// Similarly, no test case here for 0b/riscv. It's covered by the
|
||||
// good-1-riscv-lzma2-*.xz files.
|
||||
{"05", "powerpc", genPowerpc},
|
||||
{"06", "ia64", genIa64},
|
||||
{"07", "arm", genArm},
|
||||
{"07", "arm=start=1000", genArm},
|
||||
{"08", "armthumb", genArmthumb},
|
||||
{"09", "sparc", genSparc},
|
||||
{"0a", "arm64", genArm64},
|
||||
}
|
||||
|
||||
for _, recipe := range recipes {
|
||||
contents := recipe.generator()
|
||||
filename := fmt.Sprintf("xz-filter-%s-%08x-%s.dat",
|
||||
recipe.filterID,
|
||||
crc32.ChecksumIEEE(contents),
|
||||
strings.Replace(recipe.filterName, "=", "_", -1))
|
||||
if err := os.WriteFile(filename, contents, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Wrote %s\n", filename)
|
||||
|
||||
cmd := exec.Command("xz", "--keep", "--force", "--"+recipe.filterName, "--lzma2", filename)
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Wrote %s.xz\n", filename)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// pi's digits are a source of random-looking numbers. len(pi) is 128.
|
||||
const pi = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844"
|
||||
|
||||
// The artificial data generated below is designed to tickle XZ's BCJ (Branch,
|
||||
// Call, Jump) filters. See xz-embedded's linux/lib/xz/xz_dec_bcj.c for C code
|
||||
// implementations.
|
||||
|
||||
func genPowerpc() []byte {
|
||||
b := make256Bytes()
|
||||
for i := 0; (i + 4) <= len(b); i += 4 {
|
||||
x := peekU32BE(b[i:])
|
||||
switch pi[i>>2] & 1 {
|
||||
case 0:
|
||||
x = (x & 0x03FF_FFFC) | 0x4800_0001
|
||||
default:
|
||||
continue
|
||||
}
|
||||
pokeU32BE(b[i:], x)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func genIa64() []byte {
|
||||
var bitMasks = [8]uint64{0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F}
|
||||
interveneIndex := 0
|
||||
|
||||
b := make256Bytes()
|
||||
for i := 0; (i + 16) <= len(b); i += 16 {
|
||||
mask := 0
|
||||
switch pi[i>>2] & 3 {
|
||||
case 0:
|
||||
continue
|
||||
case 1:
|
||||
b[i], mask = 0x10, 4
|
||||
case 2:
|
||||
b[i], mask = 0x12, 6
|
||||
case 3:
|
||||
b[i], mask = 0x16, 7
|
||||
}
|
||||
|
||||
loopUntilIntervention:
|
||||
for true {
|
||||
for slot, bitPos := 0, 5; slot < 3; slot, bitPos = slot+1, bitPos+41 {
|
||||
if ((mask >> slot) & 1) == 0 {
|
||||
continue
|
||||
}
|
||||
bytePos := bitPos >> 3
|
||||
bitRes := bitPos & 7
|
||||
instr := uint64(0)
|
||||
for j := 0; j < 6; j++ {
|
||||
instr |= uint64(b[i+j+bytePos]) << (8 * j)
|
||||
}
|
||||
|
||||
intervene := (pi[interveneIndex%len(pi)] & 3) == 0
|
||||
interveneIndex++
|
||||
if !intervene {
|
||||
continue
|
||||
}
|
||||
norm := instr >> bitRes
|
||||
norm = (norm &^ 0x01E0_0000_0000) | 0x00A0_0000_0000
|
||||
norm = (norm &^ 0x0E00) | 0x0000
|
||||
newInstr := (instr & bitMasks[bitRes]) | (norm << bitRes)
|
||||
for j := 0; j < 6; j++ {
|
||||
b[i+j+bytePos] = uint8(newInstr >> (8 * j))
|
||||
}
|
||||
|
||||
instr = uint64(0)
|
||||
for j := 0; j < 6; j++ {
|
||||
instr |= uint64(b[i+j+bytePos]) << (8 * j)
|
||||
}
|
||||
norm = instr >> bitRes
|
||||
if ((norm>>37)&0x0F) == 0x05 && ((norm>>9)&0x07) == 0x00 {
|
||||
break loopUntilIntervention
|
||||
}
|
||||
panic("intervention failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func genArm() []byte {
|
||||
b := make256Bytes()
|
||||
for i := range b {
|
||||
if ((i & 3) == 3) &&
|
||||
((pi[i>>2] & 1) != 0) {
|
||||
b[i] = 0xEB
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func genArmthumb() []byte {
|
||||
b := make256Bytes()
|
||||
for i := 0; (i + 4) <= len(b); {
|
||||
x := peekU32LE(b[i:])
|
||||
switch pi[i>>2] & 1 {
|
||||
case 0:
|
||||
i += 2
|
||||
case 1:
|
||||
x = (x & 0x07FF_07FF) | 0xF800_F000
|
||||
pokeU32LE(b[i:], x)
|
||||
i += 4
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func genSparc() []byte {
|
||||
b := make256Bytes()
|
||||
for i := 0; (i + 4) <= len(b); i += 4 {
|
||||
x := peekU32BE(b[i:])
|
||||
switch pi[i>>2] & 3 {
|
||||
case 0:
|
||||
x = (x & 0x003F_FFFF) | 0x4000_0000
|
||||
case 1:
|
||||
x = (x & 0x003F_FFFF) | 0x7FC0_0000
|
||||
default:
|
||||
continue
|
||||
}
|
||||
pokeU32BE(b[i:], x)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func genArm64() []byte {
|
||||
b := make256Bytes()
|
||||
for i := 0; (i + 4) <= len(b); i += 4 {
|
||||
x := peekU32LE(b[i:])
|
||||
switch pi[i>>2] & 3 {
|
||||
case 0:
|
||||
x = (x & 0x03FF_FFFF) | 0x9400_0000
|
||||
case 1:
|
||||
x = (x & 0x60FF_FFFF) | 0x90C0_0000
|
||||
default:
|
||||
continue
|
||||
}
|
||||
pokeU32LE(b[i:], x)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func make256Bytes() []byte {
|
||||
b := make([]byte, 256)
|
||||
for i := range b {
|
||||
b[i] = byte(i)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func peekU32BE(b []byte) uint32 {
|
||||
return (uint32(b[0]) << 0x18) |
|
||||
(uint32(b[1]) << 0x10) |
|
||||
(uint32(b[2]) << 0x08) |
|
||||
(uint32(b[3]) << 0x00)
|
||||
}
|
||||
|
||||
func peekU32LE(b []byte) uint32 {
|
||||
return (uint32(b[0]) << 0x00) |
|
||||
(uint32(b[1]) << 0x08) |
|
||||
(uint32(b[2]) << 0x10) |
|
||||
(uint32(b[3]) << 0x18)
|
||||
}
|
||||
|
||||
func pokeU32BE(b []byte, x uint32) {
|
||||
b[0] = uint8(x >> 0x18)
|
||||
b[1] = uint8(x >> 0x10)
|
||||
b[2] = uint8(x >> 0x08)
|
||||
b[3] = uint8(x >> 0x00)
|
||||
}
|
||||
|
||||
func pokeU32LE(b []byte, x uint32) {
|
||||
b[0] = uint8(x >> 0x00)
|
||||
b[1] = uint8(x >> 0x08)
|
||||
b[2] = uint8(x >> 0x10)
|
||||
b[3] = uint8(x >> 0x18)
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
|
||||
_!"#$%&$()*+,-./0123456789:;<=>?BCDUFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno1rstUvwxyz{|}~≠ヤ�㊧炎笈克_髄駐舶沫�圀悃棔。「」、・ヲァィゥェォィュョ_アイウエオ6エクケェサシスセソツテトユニヌネノハヒフヘホマムメモヤユヨラリルレロリン゙_矮聿褂鉅鳰�濵_�����涇���
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,812 @@
|
||||
<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
|
||||
<siteinfo>
|
||||
<sitename>Wikipedia</sitename>
|
||||
<base>http://en.wikipedia.org/wiki/Main_Page</base>
|
||||
<generator>MediaWiki 1.6alpha</generator>
|
||||
<case>first-letter</case>
|
||||
<namespaces>
|
||||
<namespace key="-2">Media</namespace>
|
||||
<namespace key="-1">Special</namespace>
|
||||
<namespace key="0" />
|
||||
<namespace key="1">Talk</namespace>
|
||||
<namespace key="2">User</namespace>
|
||||
<namespace key="3">User talk</namespace>
|
||||
<namespace key="4">Wikipedia</namespace>
|
||||
<namespace key="5">Wikipedia talk</namespace>
|
||||
<namespace key="6">Image</namespace>
|
||||
<namespace key="7">Image talk</namespace>
|
||||
<namespace key="8">MediaWiki</namespace>
|
||||
<namespace key="9">MediaWiki talk</namespace>
|
||||
<namespace key="10">Template</namespace>
|
||||
<namespace key="11">Template talk</namespace>
|
||||
<namespace key="12">Help</namespace>
|
||||
<namespace key="13">Help talk</namespace>
|
||||
<namespace key="14">Category</namespace>
|
||||
<namespace key="15">Category talk</namespace>
|
||||
<namespace key="100">Portal</namespace>
|
||||
<namespace key="101">Portal talk</namespace>
|
||||
</namespaces>
|
||||
</siteinfo>
|
||||
<page>
|
||||
<title>AaA</title>
|
||||
<id>1</id>
|
||||
<revision>
|
||||
<id>32899315</id>
|
||||
<timestamp>2005-12-27T18:46:47Z</timestamp>
|
||||
<contributor>
|
||||
<username>Jsmethers</username>
|
||||
<id>614213</id>
|
||||
</contributor>
|
||||
<text xml:space="preserve">#REDIRECT [[AAA]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AlgeriA</title>
|
||||
<id>5</id>
|
||||
<revision>
|
||||
<id>18063769</id>
|
||||
<timestamp>2005-07-03T11:13:13Z</timestamp>
|
||||
<contributor>
|
||||
<username>Docu</username>
|
||||
<id>8029</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>adding cur_id=5: {{R from CamelCase}}</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Algeria]]{{R from CamelCase}}</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AmericanSamoa</title>
|
||||
<id>6</id>
|
||||
<revision>
|
||||
<id>18063795</id>
|
||||
<timestamp>2005-07-03T11:14:17Z</timestamp>
|
||||
<contributor>
|
||||
<username>Docu</username>
|
||||
<id>8029</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>adding to cur_id=6 {{R from CamelCase}}</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[American Samoa]]{{R from CamelCase}}</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AppliedEthics</title>
|
||||
<id>8</id>
|
||||
<revision>
|
||||
<id>15898943</id>
|
||||
<timestamp>2002-02-25T15:43:11Z</timestamp>
|
||||
<contributor>
|
||||
<ip>Conversion script</ip>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>Automated conversion</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Applied ethics]]
|
||||
</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AccessibleComputing</title>
|
||||
<id>10</id>
|
||||
<revision>
|
||||
<id>15898945</id>
|
||||
<timestamp>2003-04-25T22:18:38Z</timestamp>
|
||||
<contributor>
|
||||
<username>Ams80</username>
|
||||
<id>7543</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>Fixing redirect</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Accessible_computing]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AdA</title>
|
||||
<id>11</id>
|
||||
<revision>
|
||||
<id>15898946</id>
|
||||
<timestamp>2002-09-22T16:02:58Z</timestamp>
|
||||
<contributor>
|
||||
<username>Andre Engels</username>
|
||||
<id>300</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<text xml:space="preserve">#REDIRECT [[Ada programming language]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>Anarchism</title>
|
||||
<id>12</id>
|
||||
<revision>
|
||||
<id>42136831</id>
|
||||
<timestamp>2006-03-04T01:41:25Z</timestamp>
|
||||
<contributor>
|
||||
<username>CJames745</username>
|
||||
<id>832382</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>/* Anarchist Communism */ too many brackets</comment>
|
||||
<text xml:space="preserve">{{Anarchism}}
|
||||
'''Anarchism''' originated as a term of abuse first used against early [[working class]] [[radical]]s including the [[Diggers]] of the [[English Revolution]] and the [[sans-culotte|''sans-culottes'']] of the [[French Revolution]].[http://uk.encarta.msn.com/encyclopedia_761568770/Anarchism.html] Whilst the term is still used in a pejorative way to describe ''"any act that used violent means to destroy the organization of society"''<ref>[http://www.cas.sc.edu/socy/faculty/deflem/zhistorintpolency.html History of International Police Cooperation], from the final protocols of the "International Conference of Rome for the Social Defense Against Anarchists", 1898</ref>, it has also been taken up as a positive label by self-defined anarchists.
|
||||
|
||||
The word '''anarchism''' is [[etymology|derived from]] the [[Greek language|Greek]] ''[[Wiktionary:&#945;&#957;&#945;&#961;&#967;&#943;&#945;|&#945;&#957;&#945;&#961;&#967;&#943;&#945;]]'' ("without [[archon]]s (ruler, chief, king)"). Anarchism as a [[political philosophy]], is the belief that ''rulers'' are unnecessary and should be abolished, although there are differing interpretations of what this means. Anarchism also refers to related [[social movement]]s) that advocate the elimination of authoritarian institutions, particularly the [[state]].<ref>[http://en.wikiquote.org/wiki/Definitions_of_anarchism Definitions of anarchism] on Wikiquote, accessed 2006</ref> The word "[[anarchy]]," as most anarchists use it, does not imply [[chaos]], [[nihilism]], or [[anomie]], but rather a harmonious [[anti-authoritarian]] society. In place of what are regarded as authoritarian political structures and coercive economic institutions, anarchists advocate social relations based upon [[voluntary association]] of autonomous individuals, [[mutual aid]], and [[self-governance]].
|
||||
|
||||
While anarchism is most easily defined by what it is against, anarchists also offer positive visions of what they believe to be a truly free society. However, ideas about how an anarchist society might work vary considerably, especially with respect to economics; there is also disagreement about how a free society might be brought about.
|
||||
|
||||
== Origins and predecessors ==
|
||||
|
||||
[[Peter Kropotkin|Kropotkin]], and others, argue that before recorded [[history]], human society was organized on anarchist principles.<ref>[[Peter Kropotkin|Kropotkin]], Peter. ''"[[Mutual Aid: A Factor of Evolution]]"'', 1902.</ref> Most anthropologists follow Kropotkin and Engels in believing that hunter-gatherer bands were egalitarian and lacked division of labour, accumulated wealth, or decreed law, and had equal access to resources.<ref>[[Friedrich Engels|Engels]], Freidrich. ''"[http://www.marxists.org/archive/marx/works/1884/origin-family/index.htm Origins of the Family, Private Property, and the State]"'', 1884.</ref>
|
||||
[[Image:WilliamGodwin.jpg|thumb|right|150px|William Godwin]]
|
||||
|
||||
Anarchists including the [[The Anarchy Organisation]] and [[Murray Rothbard|Rothbard]] find anarchist attitudes in [[Taoism]] from [[History of China|Ancient China]].<ref>The Anarchy Organization (Toronto). ''Taoism and Anarchy.'' [[April 14]] [[2002]] [http://www.toxicpop.co.uk/library/taoism.htm Toxicpop mirror] [http://www.geocities.com/SoHo/5705/taoan.html Vanity site mirror]</ref><ref>[[Murray Rothbard|Rothbard]], Murray. ''"[http://www.lewrockwell.com/rothbard/ancient-chinese.html The Ancient Chinese Libertarian Tradition]"'', an extract from ''"[http://www.mises.org/journals/jls/9_2/9_2_3.pdf Concepts of the Role of Intellectuals in Social Change Toward Laissez Faire]"'', The Journal of Libertarian Studies, 9 (2) Fall 1990.</ref> [[Peter Kropotkin|Kropotkin]] found similar ideas in [[stoicism|stoic]] [[Zeno of Citium]]. According to Kropotkin, Zeno "repudiated the omnipotence of the state, its intervention and regimentation, and proclaimed the sovereignty of the moral law of the individual". <ref>[http://www.blackcrayon.com/page.jsp/library/britt1910.html Anarchism], written by Peter Kropotkin, from Encyclopaedia Britannica, 1910]</ref>
|
||||
|
||||
The [[Anabaptist]]s of 16th century Europe are sometimes considered to be religious forerunners of modern anarchism. [[Bertrand Russell]], in his ''History of Western Philosophy'', writes that the Anabaptists "repudiated all law, since they held that the good man will be guided at every moment by [[the Holy Spirit]]...[f]rom this premise they arrive at [[communism]]...."<ref>[[Bertrand Russell|Russell]], Bertrand. ''"Ancient philosophy"'' in ''A History of Western Philosophy, and its connection with political and social circumstances from the earliest times to the present day'', 1945.</ref> [[Diggers (True Levellers)|The Diggers]] or "True Levellers" were an early communistic movement during the time of the [[English Civil War]], and are considered by some as forerunners of modern anarchism.<ref>[http://www.zpub.com/notes/aan-hist.html An Anarchist Timeline], from Encyclopaedia Britannica, 1994.</ref>
|
||||
|
||||
In the [[modern era]], the first to use the term to mean something other than chaos was [[Louis-Armand de Lom d'Arce de Lahontan, Baron de Lahontan|Louis-Armand, Baron de Lahontan]] in his ''Nouveaux voyages dans l'Amérique septentrionale'', (1703), where he described the [[Native Americans in the United States|indigenous American]] society, which had no state, laws, prisons, priests, or private property, as being in anarchy<ref>[http://etext.lib.virginia.edu/cgi-local/DHI/dhi.cgi?id=dv1-12 Dictionary of the History of Ideas - ANARCHISM]</ref>. [[Russell Means]], a [[libertarian]] and leader in the [[American Indian Movement]], has repeatedly stated that he is "an anarchist, and so are all [his] ancestors."
|
||||
|
||||
In 1793, in the thick of the [[French Revolution]], [[William Godwin]] published ''An Enquiry Concerning Political Justice'' [http://web.bilkent.edu.tr/Online/www.english.upenn.edu/jlynch/Frank/Godwin/pjtp.html]. Although Godwin did not use the word ''anarchism'', many later anarchists have regarded this book as the first major anarchist text, and Godwin as the "founder of philosophical anarchism." But at this point no anarchist movement yet existed, and the term ''anarchiste'' was known mainly as an insult hurled by the [[bourgeois]] [[Girondins]] at more radical elements in the [[French revolution]].
|
||||
|
||||
==The first self-labelled anarchist==
|
||||
[[Image:Pierre_Joseph_Proudhon.jpg|110px|thumb|left|Pierre Joseph Proudhon]]
|
||||
{{main articles|[[Pierre-Joseph Proudhon]] and [[Mutualism (economic theory)]]}}
|
||||
|
||||
It is commonly held that it wasn't until [[Pierre-Joseph Proudhon]] published ''[[What is Property?]]'' in 1840 that the term "anarchist" was adopted as a self-description. It is for this reason that some claim Proudhon as the founder of modern anarchist theory. In [[What is Property?]] Proudhon answers with the famous accusation "[[Property is theft]]." In this work he opposed the institution of decreed "property" (propriété), where owners have complete rights to "use and abuse" their property as they wish, such as exploiting workers for profit.<ref name="proudhon-prop">[[Pierre-Joseph Proudhon|Proudhon]], Pierre-Joseph. ''"[http://www.marxists.org/reference/subject/economics/proudhon/property/ch03.htm Chapter 3. Labour as the efficient cause of the domain of property]"'' from ''"[[What is Property?]]"'', 1840</ref> In its place Proudhon supported what he called 'possession' - individuals can have limited rights to use resources, capital and goods in accordance with principles of equality and justice.
|
||||
|
||||
Proudhon's vision of anarchy, which he called [[mutualism]] (mutuellisme), involved an exchange economy where individuals and groups could trade the products of their labor using ''labor notes'' which represented the amount of working time involved in production. This would ensure that no one would profit from the labor of others. Workers could freely join together in co-operative workshops. An interest-free bank would be set up to provide everyone with access to the means of production. Proudhon's ideas were influential within French working class movements, and his followers were active in the [[Revolution of 1848]] in France.
|
||||
|
||||
Proudhon's philosophy of property is complex: it was developed in a number of works over his lifetime, and there are differing interpretations of some of his ideas. ''For more detailed discussion see [[Pierre-Joseph Proudhon|here]].''
|
||||
|
||||
==Max Stirner's Egoism==
|
||||
{{main articles|[[Max Stirner]] and [[Egoism]]}}
|
||||
|
||||
In his ''The Ego and Its Own'' Stirner argued that most commonly accepted social institutions - including the notion of State, property as a right, natural rights in general, and the very notion of society - were mere illusions or ''ghosts'' in the mind, saying of society that "the individuals are its reality." He advocated egoism and a form of amoralism, in which individuals would unite in 'associations of egoists' only when it was in their self interest to do so. For him, property simply comes about through might: "Whoever knows how to take, to defend, the thing, to him belongs property." And, "What I have in my power, that is my own. So long as I assert myself as holder, I am the proprietor of the thing."
|
||||
|
||||
Stirner never called himself an anarchist - he accepted only the label 'egoist'. Nevertheless, his ideas were influential on many individualistically-inclined anarchists, although interpretations of his thought are diverse.
|
||||
|
||||
==American individualist anarchism==
|
||||
[[Image:BenjaminTucker.jpg|thumb|150px|left|[[Benjamin Tucker]]]]
|
||||
{{main articles|[[Individualist anarchism]] and [[American individualist anarchism]]}}
|
||||
|
||||
In 1825 [[Josiah Warren]] had participated in a [[communitarian]] experiment headed by [[Robert Owen]] called [[New Harmony]], which failed in a few years amidst much internal conflict. Warren blamed the community's failure on a lack of [[individual sovereignty]] and a lack of private property. Warren proceeded to organise experimenal anarchist communities which respected what he called "the sovereignty of the individual" at [[Utopia (anarchist community)|Utopia]] and [[Modern Times]]. In 1833 Warren wrote and published ''The Peaceful Revolutionist'', which some have noted to be the first anarchist periodical ever published. Benjamin Tucker says that Warren "was the first man to expound and formulate the doctrine now known as Anarchism." (''Liberty'' XIV (December, 1900):1)
|
||||
|
||||
[[Benjamin Tucker]] became interested in anarchism through meeting Josiah Warren and [[William B. Greene]]. He edited and published ''Liberty'' from August 1881 to April 1908; it is widely considered to be the finest individualist-anarchist periodical ever issued in the English language. Tucker's conception of individualist anarchism incorporated the ideas of a variety of theorists: Greene's ideas on [[mutualism|mutual banking]]; Warren's ideas on [[cost the limit of price|cost as the limit of price]] (a [[heterodox economics|heterodox]] variety of [[labour theory of value]]); [[Proudhon]]'s market anarchism; [[Max Stirner]]'s [[egoism]]; and, [[Herbert Spencer]]'s "law of equal freedom". Tucker strongly supported the individual's right to own the product of his or her labour as "[[private property]]", and believed in a <ref name="tucker-pay">[[Benjamin Tucker|Tucker]], Benjamin. ''"[http://www.blackcrayon.com/page.jsp/library/tucker/tucker37.htm Labor and Its Pay]"'' Individual Liberty: Selections From the Writings of Benjamin R. Tucker, Vanguard Press, New York, 1926, Kraus Reprint Co., Millwood, NY, 1973.</ref>[[market economy]] for trading this property. He argued that in a truly free market system without the state, the abundance of competition would eliminate profits and ensure that all workers received the full value of their labor.
|
||||
|
||||
Other 19th century individualists included [[Lysander Spooner]], [[Stephen Pearl Andrews]], and [[Victor Yarros]].
|
||||
|
||||
==The First International==
|
||||
[[Image:Bakuninfull.jpg|thumb|150px|right|[[Bakunin|Mikhail Bakunin 1814-1876]]]]
|
||||
{{main articles|[[International Workingmen's Association]], [[Anarchism and Marxism]]}}
|
||||
|
||||
In Europe, harsh reaction followed the revolutions of 1848. Twenty years later in 1864 the [[International Workingmen's Association]], sometimes called the 'First International', united some diverse European revolutionary currents including anarchism. Due to its genuine links to active workers movements the International became signficiant.
|
||||
|
||||
From the start [[Karl Marx]] was a leading figure in the International: he was elected to every succeeding General Council of the association. The first objections to Marx came from the [[Mutualism|Mutualists]] who opposed communism and statism. Shortly after [[Mikhail Bakunin]] and his followers joined in 1868, the First International became polarised into two camps, with Marx and Bakunin as their respective figureheads. The clearest difference between the camps was over strategy. The anarchists around Bakunin favoured (in Kropotkin's words) "direct economical struggle against capitalism, without interfering in the political parliamentary agitation." At that time Marx and his followers focused on parliamentary activity.
|
||||
|
||||
Bakunin characterised Marx's ideas as [[authoritarian]], and predicted that if a Marxist party gained to power its leaders would end up as bad as the [[ruling class]] they had fought against.<ref>[[Mikhail Bakunin|Bakunin]], Mikhail. ''"[http://www.litencyc.com/php/adpage.php?id=1969 Statism and Anarchy]"''</ref> In 1872 the conflict climaxed with a final split between the two groups at the [[Hague Congress (1872)|Hague Congress]]. This is often cited as the origin of the [[Anarchist_objections_to_marxism|conflict between anarchists and Marxists]]. From this moment the ''[[Social democracy|social democratic]]'' and ''[[Libertarian socialism|libertarian]]'' currents of socialism had distinct organisations including rival [[List of left-wing internationals|'internationals'.]]
|
||||
|
||||
==Anarchist Communism==
|
||||
{{main|Anarchist communism}}
|
||||
[[Image:PeterKropotkin.jpg|thumb|150px|right|Peter Kropotkin]]
|
||||
|
||||
Proudhon and Bakunin both opposed [[communism]], associating it with statism. However, in the 1870s many anarchists moved away from Bakunin's economic thinking (called "collectivism") and embraced communist concepts. Communists believed the means of production should be owned collectively, and that goods be distributed by need, not labor. [http://nefac.net/node/157]
|
||||
|
||||
An early anarchist communist was Joseph Déjacque, the first person to describe himself as "[[libertarian socialism|libertarian]]".[http://recollectionbooks.com/bleed/Encyclopedia/DejacqueJoseph.htm]<ref>[http://joseph.dejacque.free.fr/ecrits/lettreapjp.htm De l'être-humain mâle et femelle - Lettre à P.J. Proudhon par Joseph Déjacque] (in [[French language|French]])</ref> Unlike Proudhon, he argued that "it is not the product of his or her labor that the worker has a right to, but to the satisfaction of his or her needs, whatever may be their nature." He announced his ideas in his US published journal Le Libertaire (1858-1861).
|
||||
|
||||
Peter Kropotkin, often seen as the most important theorist, outlined his economic ideas in The Conquest of Bread and Fields, Factories and Workshops. He felt co-operation is more beneficial than competition, illustrated in nature in Mutual Aid: A Factor of Evolution (1897). Subsequent anarchist communists include Emma Goldman and Alexander Berkman. Many in the anarcho-syndicalist movements (see below) saw anarchist communism as their objective. Isaac Puente's 1932 Comunismo Libertario was adopted by the Spanish CNT as its manifesto for a post-revolutionary society.
|
||||
|
||||
Some anarchists disliked merging communism with anarchism. Several individualist anarchists maintained that abolition of private property was not consistent with liberty. For example, Benjamin Tucker, whilst professing respect for Kropotkin and publishing his work[http://www.zetetics.com/mac/libdebates/apx1pubs.html], described communist anarchism as "pseudo-anarchism".<ref name="tucker-pay"/>
|
||||
|
||||
==Propaganda of the deed==
|
||||
[[Image:JohannMost.jpg|left|150px|thumb|[[Johann Most]] was an outspoken advocate of violence]]
|
||||
{{main|Propaganda of the deed}}
|
||||
|
||||
Anarchists have often been portrayed as dangerous and violent, due mainly to a number of high-profile violent acts, including [[riot]]s, [[assassination]]s, [[insurrection]]s, and [[terrorism]] by some anarchists. Some [[revolution]]aries of the late 19th century encouraged acts of political violence, such as [[bomb]]ings and the [[assassination]]s of [[head of state|heads of state]] to further anarchism. Such actions have sometimes been called '[[propaganda by the deed]]'.
|
||||
|
||||
One of the more outspoken advocates of this strategy was [[Johann Most]], who said "the existing system will be quickest and most radically overthrown by the annihilation of its exponents. Therefore, massacres of the enemies of the people must be set in motion."{{fact}} Most's preferred method of terrorism, dynamite, earned him the moniker "Dynamost."
|
||||
|
||||
However, there is no [[consensus]] on the legitimacy or utility of violence in general. [[Mikhail Bakunin]] and [[Errico Malatesta]], for example, wrote of violence as a necessary and sometimes desirable force in revolutionary settings. But at the same time, they denounced acts of individual terrorism. (Malatesta in "On Violence" and Bakunin when he refuted Nechaev).
|
||||
|
||||
Other anarchists, sometimes identified as [[anarcho-pacifists|pacifist anarchists]], advocated complete [[nonviolence]]. [[Leo Tolstoy]], whose philosophy is often viewed as a form of [[Christian anarchism|Christian anarchism]] ''(see below)'', was a notable exponent of [[nonviolent resistance]].
|
||||
|
||||
==Anarchism in the labour movement==
|
||||
{{seealso|Anarcho-syndicalism}}
|
||||
|
||||
[[Image:Flag of Anarcho syndicalism.svg|thumb|175px|The red-and-black flag, coming from the experience of anarchists in the labour movement, is particularly associated with anarcho-syndicalism.]]
|
||||
|
||||
[[Anarcho-syndicalism]] was an early 20th century working class movement seeking to overthrow capitalism and the state to institute a worker controlled society. The movement pursued [[industrial action]]s, such as [[general strike]], as a primary strategy. Many anarcho-syndicalists believed in [[anarchist communism]], though not all communists believed in syndicalism.
|
||||
|
||||
After the [[Paris Commune|1871 repression]] French anarchism reemerged, influencing the ''Bourses de Travails'' of autonomous workers groups and trade unions. From this movement the [[Confédération Générale du Travail]] (General Confederation of Work, CGT) was formed in 1895 as the first major anarcho-syndicalist movement. [[Emile Pataud]] and [[Emile Pouget]]'s writing for the CGT saw [[libertarian communism]] developing from a [[general strike]]. After 1914 the CGT moved away from anarcho-syndicalism due to the appeal of [[Bolshevism]]. French-style syndicalism was a significant movement in Europe prior to 1921, and remained a significant movement in Spain until the mid 1940s.
|
||||
|
||||
The [[Industrial Workers of the World]] (IWW), founded in 1905 in the US, espoused [[industrial unionism|unionism]] and sought a [[general strike]] to usher in a stateless society. In 1923 100,000 members existed, with the support of up to 300,000. Though not explicitly anarchist, they organized by rank and file democracy, embodying a spirit of resistance that has inspired many Anglophone syndicalists.
|
||||
|
||||
[[Image:CNT_tu_votar_y_ellos_deciden.jpg|thumb|175px|CNT propaganda from April 2004. Reads: Don't let the politicians rule our lives/ You vote and they decide/ Don't allow it/ Unity, Action, Self-management.]]
|
||||
|
||||
Spanish anarchist trade union federations were formed in the 1870's, 1900 and 1910. The most successful was the [[Confederación Nacional del Trabajo]] (National Confederation of Labour: CNT), founded in 1910. Prior to the 1940s the CNT was the major force in Spanish working class politics. With a membership of 1.58 million in 1934, the CNT played a major role in the [[Spanish Civil War]]. ''See also:'' [[Anarchism in Spain]].
|
||||
|
||||
Syndicalists like [[Ricardo Flores Magón]] were key figures in the [[Mexican Revolution]]. [[Latin America|Latin American]] anarchism was strongly influenced, extending to the [[Zapatista Army of National Liberation|Zapatista]] rebellion and the [[factory occupation movements]] in Argentina. In Berlin in 1922 the CNT was joined with the [[International Workers Association]], an anarcho-syndicalist successor to the [[First International]].
|
||||
|
||||
Contemporary anarcho-syndicalism continues as a minor force in many socities; much smaller than in the 1910s, 20s and 30s.
|
||||
|
||||
The largest organised anarchist movement today is in Spain, in the form of the [[Confederación General del Trabajo]] and the [[CNT]]. The CGT claims a paid-up membership of 60,000, and received over a million votes in Spanish [[syndical]] elections. Other active syndicalist movements include the US [[Workers Solidarity Alliance]], and the UK [[Solidarity Federation]]. The revolutionary industrial unionist [[Industrial Workers of the World]] also exists, claiming 2,000 paid members. Contemporary critics of anarcho-syndicalism and revolutionary industrial unionism claim that they are [[workerist]] and fail to deal with economic life outside work. Post-leftist critics such as [[Bob Black]] claim anarcho-syndicalism advocates oppressive social structures, such as [[Manual labour|work]] and the [[workplace]].
|
||||
|
||||
Anarcho-syndicalists in general uphold principles of workers solidarity, [[direct action]], and self-management.
|
||||
|
||||
==The Russian Revolution==
|
||||
{{main|Russian Revolution of 1917}}
|
||||
|
||||
The [[Russian Revolution of 1917]] was a seismic event in the development of anarchism as a movement and as a philosophy.
|
||||
|
||||
Anarchists participated alongside the [[Bolsheviks]] in both February and October revolutions, many anarchists initially supporting the Bolshevik coup. However the Bolsheviks soon turned against the anarchists and other left-wing opposition, a conflict which culminated in the 1918 [[Kronstadt rebellion]]. Anarchists in central Russia were imprisoned or driven underground, or joined the victorious Bolsheviks. In [[Ukraine]] anarchists fought in the [[Russian Civil War|civil war]] against both Whites and Bolsheviks within the Makhnovshchina peasant army led by [[Nestor Makhno]]).
|
||||
|
||||
Expelled American anarchists [[Emma Goldman]] and [[Alexander Berkman]] before leaving Russia were amongst those agitating in response to Bolshevik policy and the suppression of the Kronstadt uprising. Both wrote classic accounts of their experiences in Russia, aiming to expose the reality of Bolshevik control. For them, [[Bakunin]]'s predictions about the consequences of Marxist rule had proved all too true.
|
||||
|
||||
The victory of the Bolsheviks in the October Revolution and the resulting Russian Civil War did serious damage to anarchist movements internationally. Many workers and activists saw Bolshevik success as setting an example; Communist parties grew at the expense of anarchism and other socialist movements. In France and the US for example, the major syndicalist movements of the [[CGT]] and [[IWW]] began to realign themselves away from anarchism and towards the [[Comintern|Communist International]].
|
||||
|
||||
In Paris, the [[Dielo Truda]] group of Russian anarchist exiles which included [[Nestor Makhno]] concluded that anarchists needed to develop new forms of organisation in response to the structures of Bolshevism. Their 1926 manifesto, known as the [[Platformism|Organisational Platform of the Libertarian Communists]], was supported by some communist anarchists, though opposed by many others.
|
||||
|
||||
The ''Platform'' continues to inspire some contemporary anarchist groups who believe in an anarchist movement organised around its principles of 'theoretical unity', 'tactical unity', 'collective responsibility' and 'federalism'. Platformist groups today include the [[Workers Solidarity Movement]] in Ireland, the UK's [[Anarchist Federation]], and the late [[North Eastern Federation of Anarchist Communists]] in the northeastern United States and bordering Canada.
|
||||
|
||||
==The fight against fascism==
|
||||
{{main articles|[[Anti-fascism]] and [[Anarchism in Spain]]}}
|
||||
[[Image:CNT-armoured-car-factory.jpg|right|thumb|270px|[[Spain]], [[1936]]. Members of the [[CNT]] construct [[armoured car]]s to fight against the [[fascist]]s in one of the [[collectivisation|collectivised]] factories.]]
|
||||
In the 1920s and 1930s the familiar dynamics of anarchism's conflict with the state were transformed by the rise of [[fascism]] in Europe. In many cases, European anarchists faced difficult choices - should they join in [[popular front]]s with reformist democrats and Soviet-led [[Communists]] against a common fascist enemy? Luigi Fabbri, an exile from Italian fascism, was amongst those arguing that fascism was something different:
|
||||
|
||||
:"Fascism is not just another form of government which, like all others, uses violence. It is the most authoritarian and the most violent form of government imaginable. It represents the utmost glorification of the theory and practice of the principle of authority." {{fact}}
|
||||
|
||||
In France, where the fascists came close to insurrection in the February 1934 riots, anarchists divided over a 'united front' policy. [http://melior.univ-montp3.fr/ra_forum/en/people/berry_david/fascism_or_revolution.html] In Spain, the [[CNT]] initially refused to join a popular front electoral alliance, and abstention by CNT supporters led to a right wing election victory. But in 1936, the CNT changed its policy and anarchist votes helped bring the popular front back to power. Months later, the ruling class responded with an attempted coup, and the [[Spanish Civil War]] (1936-39) was underway.
|
||||
|
||||
In reponse to the army rebellion [[Anarchism in Spain|an anarchist-inspired]] movement of peasants and workers, supported by armed militias, took control of the major [[city]] of [[Barcelona]] and of large areas of rural Spain where they [[collectivization|collectivized]] the land. But even before the eventual fascist victory in 1939, the anarchists were losing ground in a bitter struggle with the [[Stalinists]]. The CNT leadership often appeared confused and divided, with some members controversially entering the government. Stalinist-led troops suppressed the collectives, and persecuted both [[POUM|dissident marxists]] and anarchists.
|
||||
|
||||
Since the late 1970s anarchists have been involved in fighting the rise of [[neo-fascism|neo-fascist]] groups. In Germany and the United Kingdom some anarchists worked within [[militant]] [[anti-fascism|anti-fascist]] groups alongside members of the [[Marxist]] left. They advocated directly combating fascists with physical force rather than relying on the state. Since the late 1990s, a similar tendency has developed within US anarchism. ''See also: [[Anti-Racist Action]] (US), [[Anti-Fascist Action]] (UK), [[Antifa]]''
|
||||
|
||||
==Religious anarchism==
|
||||
[[Image:LeoTolstoy.jpg|thumb|150px|[[Leo Tolstoy|Leo Tolstoy]] 1828-1910]]
|
||||
{{main articles|[[Christian anarchism]] and [[Anarchism and religion]]}}
|
||||
|
||||
Most anarchist culture tends to be [[secular]] if not outright [[militant athiesm|anti-religious]]. However, the combination of religious social conscience, historical religiousity amongst oppressed social classes, and the compatibility of some interpretations of religious traditions with anarchism has resulted in religious anarchism.
|
||||
|
||||
[[Christian anarchism|Christian anarchists]] believe that there is no higher authority than [[God]], and oppose earthly authority such as [[government]] and established churches. They believe that Jesus' teachings were clearly anarchistic, but were corrupted when "Christianity" was declared the official religion of Rome. Christian anarchists, who follow Jesus' directive to "turn the other cheek", are strict [[pacifism|pacifists]]. The most famous advocate of Christian anarchism was [[Leo Tolstoy]], author of ''[[The Kingdom of God is Within You]]'', who called for a society based on compassion, nonviolent principles and freedom. Christian anarchists tend to form [[experimental communities]]. They also occasionally [[tax resistance|resist taxation]]. Many Christian anarchists are [[vegetarianism|vegetarian]] or [[veganism|vegan]]{{fact}}.
|
||||
|
||||
Christian anarchy can be said to have roots as old as the religion's birth, as the [[early church]] exhibits many anarchistic tendencies, such as communal goods and wealth. By aiming to obey utterly certain of the Bible's teachings certain [[anabaptism|anabaptist]] groups of sixteenth century Europe attempted to emulate the early church's social-economic organisation and philosophy by regarding it as the only social structure capable of true obediance to Jesus' teachings, and utterly rejected (in theory) all earthly hierarchies and authority (and indeed non-anabaptists in general) and violence as ungodly. Such groups, for example the [[Hutterites]], typically went from initially anarchistic beginnings to, as their movements stabalised, more authoritarian social models.
|
||||
|
||||
[[Chinese Anarchism]] was most influential in the 1920s. Strands of Chinese anarchism included [[Tai-Xu]]'s [[Buddhist Anarchism]] which was influenced by Tolstoy and the [[well-field system]].
|
||||
|
||||
[[Neopaganism]], with its focus on the environment and equality, along with its often decentralized nature, has lead to a number of neopagan anarchists. One of the most prominent is [[Starhawk]], who writes extensively about both [[spirituality]] and [[activism]].
|
||||
|
||||
==Anarchism and feminism==
|
||||
[[Image:Goldman-4.jpg|thumb|left|150px|[[Emma Goldman]]]]
|
||||
{{main|Anarcha-Feminism}}
|
||||
|
||||
Early [[French feminism|French feminists]] such as [[Jenny d'Héricourt]] and [[Juliette Adam]] criticised the [[mysogyny]] in the anarchism of [[Proudhon]] during the 1850s.
|
||||
|
||||
Anarcha-feminism is a kind of [[radical feminism]] that espouses the belief that [[patriarchy]] is a fundamental problem in society. While anarchist feminism has existed for more than a hundred years, its explicit formulation as ''anarcha-feminism'' dates back to the early 70s<ref>[http://www.anarcha.org/sallydarity/Anarcho-FeminismTwoStatements.htm Anarcho-Feminism - Two Statements - Who we are: An Anarcho-Feminist Manifesto]</ref>, during the [[second-wave feminism|second-wave]] feminist movement. Anarcha-feminism, views [[patriarchy]] as the first manifestation of hierarchy in human history; thus, the first form of oppression occurred in the dominance of male over female. Anarcha-feminists then conclude that if feminists are against patriarchy, they must also be against all forms of [[hierarchy]], and therefore must reject the authoritarian nature of the state and capitalism. {{fact}}
|
||||
|
||||
Anarcho-primitivists see the creation of gender roles and patriarchy a creation of the start of [[civilization]], and therefore consider primitivism to also be an anarchist school of thought that addresses feminist concerns. [[Eco-feminism]] is often considered a feminist variant of green anarchist feminist thought.
|
||||
|
||||
Anarcha-feminism is most often associated with early 20th-century authors and theorists such as [[Emma Goldman]] and [[Voltairine de Cleyre]], although even early first-wave feminist [[Mary Wollstonecraft]] held proto-anarchist views, and William Godwin is often considered a feminist anarchist precursor. It should be noted that Goldman and de Cleyre, though they both opposed the state, had opposing philosophies, as de Cleyre explains: "Miss Goldman is a communist; I am an individualist. She wishes to destroy the right of property, I wish to assert it. I make my war upon privilege and authority, whereby the right of property, the true right in that which is proper to the individual, is annihilated. She believes that co-operation would entirely supplant competition; I hold that competition in one form or another will always exist, and that it is highly desirable it should." In the [[Spanish Civil War]], an anarcha-feminist group, "Free Women", organized to defend both anarchist and feminist ideas.
|
||||
|
||||
In the modern day anarchist movement, many anarchists, male or female, consider themselves feminists, and anarcha-feminist ideas are growing. The publishing of Quiet Rumors, an anarcha-feminist reader, has helped to spread various kinds of anti-authoritarian and anarchist feminist ideas to the broader movement. Wendy McElroy has popularized an individualist-anarchism take on feminism in her books, articles, and individualist feminist website.<ref>[http://www.ifeminists.net I-feminists.net]</ref>
|
||||
|
||||
==Anarcho-capitalism==
|
||||
[[Image:Murray Rothbard Smile.JPG|thumb|left|150px|[[Murray Rothbard]] (1926-1995)]]
|
||||
{{main|Anarcho-capitalism}}
|
||||
Anarcho-capitalism is a predominantly United States-based theoretical tradition that desires a stateless society with the economic system of [[free market]] [[capitalism]]. Unlike other branches of anarchism, it does not oppose [[profit]] or capitalism. Consequently, most anarchists do not recognise anarcho-capitalism as a form of anarchism.
|
||||
|
||||
[[Murray Rothbard]]'s synthesis of [[classical liberalism]] and [[Austrian economics]] was germinal for the development of contemporary anarcho-capitalist theory. He defines anarcho-capitalism in terms of the [[non-aggression principle]], based on the concept of [[Natural Law]]. Competiting theorists use egoism, [[utilitarianism]] (used by [[David Friedman]]), or [[contractarianism]] (used by [[Jan Narveson]]). Some [[minarchism|minarchists]], such as [[Ayn Rand]], [[Robert Nozick]], and [[Robert A. Heinlein]], have influenced anarcho-capitalism.
|
||||
|
||||
Some anarcho-capitalists, along with some right-wing libertarian historians such as David Hart and [[Ralph Raico]], considered similar philosophies existing prior to Rothbard to be anarcho-capitalist, such as those of [[Gustave de Molinari]] and [[Auberon Herbert]] <ref>[[Gustave de Molinari|Molinari]], Gustave de. ''[http://praxeology.net/MR-GM-PS.htm Preface to "The Production of Security"]'', translated by J. Huston McCulloch, Occasional Papers Series #2 (Richard M. Ebeling, Editor), New York: The Center for Libertarian Studies, May 1977.</ref><ref name="david-hart"/><ref>[[Ralph Raico|Raico]], Ralph [http://www.mises.org/story/1787 ''Authentic German Liberalism of the 19th Century''] Ecole Polytechnique, Centre de Recherce en Epistemologie Appliquee, Unité associée au CNRS (2004).</ref> Opponents of anarcho-capitalists dispute these claims.<ref>McKay, Iain; Elkin, Gary; Neal, Dave ''et al'' [http://www.infoshop.org/faq/append11.html Replies to Some Errors and Distortions in Bryan Caplan's "Anarchist Theory FAQ" version 5.2] ''An Anarchist FAQ Version 11.2'' Accessed February 20, 2006.</ref>
|
||||
|
||||
The place of anarcho-capitalism within anarchism, and indeed whether it is a form of anarchism at all, is highly controversial. For more on this debate see ''[[Anarchism and anarcho-capitalism]]''.
|
||||
|
||||
==Anarchism and the environment==
|
||||
{{seealso|Anarcho-primitivism|Green anarchism|Eco-anarchism|Ecofeminism}}
|
||||
|
||||
Since the late 1970s anarchists in Anglophone and European countries have been taking action for the natural environment. [[Eco-anarchism|Eco-anarchists]] or [[Green anarchism|Green anarchists]] believe in [[deep ecology]]. This is a worldview that embraces [[biodiversity]] and [[sustainability]]. Eco-anarchists often use [[direct action]] against what they see as earth-destroying institutions. Of particular importance is the [[Earth First!]] movement, that takes action such as [[tree sitting]]. Another important component is [[ecofeminism]], which sees the domination of nature as a metaphor for the domination of women. Green anarchism also involves a critique of industrial capitalism, and, for some green anarchists, civilization itself.{{fact}}
|
||||
|
||||
Primitivism is a predominantly Western philosophy that advocates a return to a pre-industrial and usually pre-agricultural society. It develops a critique of industrial civilization. In this critique [[technology]] and [[development]] have [[alienation|alienated]] people from the natural world. This philosophy develops themes present in the political action of the [[Luddites]] and the writings of [[Jean-Jacques Rousseau]]. Primitivism developed in the context of the [[Reclaim the Streets]], Earth First! and the [[Earth Liberation Front]] movements. [[John Zerzan]] wrote that [[civilization]] &mdash; not just the state &mdash; would need to fall for anarchy to be achieved.{{fact}} Anarcho-primitivists point to the anti-authoritarian nature of many 'primitive' or hunter-gatherer societies throughout the world's history, as examples of anarchist societies.
|
||||
|
||||
==Other branches and offshoots==
|
||||
Anarchism generates many eclectic and syncretic philosophies and movements. Since the Western social formet in the 1960s and 1970s a number new of movements and schools have appeared. Most of these stances are limited to even smaller numbers than the schools and movements listed above.
|
||||
|
||||
[[Image:Hakim Bey.jpeg|thumb|right|[[Hakim Bey]]]]
|
||||
*'''Post-left anarchy''' - Post-left anarchy (also called egoist-anarchism) seeks to distance itself from the traditional "left" - communists, liberals, social democrats, etc. - and to escape the confines of [[ideology]] in general. Post-leftists argue that anarchism has been weakened by its long attachment to contrary "leftist" movements and single issue causes ([[anti-war]], [[anti-nuclear]], etc.). It calls for a synthesis of anarchist thought and a specifically anti-authoritarian revolutionary movement outside of the leftist milieu. It often focuses on the individual rather than speaking in terms of class or other broad generalizations and shuns organizational tendencies in favor of the complete absence of explicit hierarchy. Important groups and individuals associated with Post-left anarchy include: [[CrimethInc]], the magazine [[Anarchy: A Journal of Desire Armed]] and its editor [[Jason McQuinn]], [[Bob Black]], [[Hakim Bey]] and others. For more information, see [[Infoshop.org]]'s ''Anarchy After Leftism''<ref>[http://www.infoshop.org/afterleftism.html Infoshop.org - Anarchy After Leftism]</ref> section, and the [http://anarchism.ws/postleft.html Post-left section] on [http://anarchism.ws/ anarchism.ws.] ''See also:'' [[Post-left anarchy]]
|
||||
|
||||
*'''Post-structuralism''' - The term postanarchism was originated by [[Saul Newman]], first receiving popular attention in his book ''[[From Bakunin to Lacan]]'' to refer to a theoretical move towards a synthesis of classical anarchist theory and [[poststructuralist]] thought. Subsequent to Newman's use of the term, however, it has taken on a life of its own and a wide range of ideas including [[autonomism]], [[post-left anarchy]], [[situationism]], [[post-colonialism]] and Zapatismo. By its very nature post-anarchism rejects the idea that it should be a coherent set of doctrines and beliefs. As such it is difficult, if not impossible, to state with any degree of certainty who should or shouldn't be grouped under the rubric. Nonetheless key thinkers associated with post-anarchism include [[Saul Newman]], [[Todd May]], [[Gilles Deleuze]] and [[Félix Guattari]]. ''External reference: Postanarchism Clearinghouse''<ref>[http://www.postanarchism.org/ Post anarchist clearing house]</ref> ''See also'' [[Post-anarchism]]
|
||||
|
||||
*'''Insurrectionary anarchism''' - Insurrectionary anarchism is a form of revolutionary anarchism critical of formal anarchist labor unions and federations. Insurrectionary anarchists advocate informal organization, including small affinity groups, carrying out acts of resistance in various struggles, and mass organizations called base structures, which can include exploited individuals who are not anarchists. Proponents include [[Wolfi Landstreicher]] and [[Alfredo M. Bonanno]], author of works including "Armed Joy" and "The Anarchist Tension". This tendency is represented in the US in magazines such as [[Willful Disobedience]] and [[Killing King Abacus]]. ''See also:'' [[Insurrectionary anarchism]]
|
||||
|
||||
*'''Small 'a' anarchism''' - '''Small 'a' anarchism''' is a term used in two different, but not unconnected contexts. Dave Neal posited the term in opposition to big 'A' Anarchism in the article [http://www.spunk.org/library/intro/practice/sp001689.html Anarchism: Ideology or Methodology?]. While big 'A' Anarchism referred to ideological Anarchists, small 'a' anarchism was applied to their methodological counterparts; those who viewed anarchism as "a way of acting, or a historical tendency against illegitimate authority." As an anti-ideological position, small 'a' anarchism shares some similarities with [[post-left anarchy]]. [[David Graeber]] and [[Andrej Grubacic]] offer an alternative use of the term, applying it to groups and movements organising according to or acting in a manner consistent with anarchist principles of decentralisation, voluntary association, mutual aid, the network model, and crucially, "the rejection of any idea that the end justifies the means, let alone that the business of a revolutionary is to seize state power and then begin imposing one's vision at the point of a gun."[http://www.zmag.org/content/showarticle.cfm?SectionID=41&ItemID=4796]
|
||||
|
||||
==Other issues==
|
||||
*'''Conceptions of an anarchist society''' - Many political philosophers justify support of the state as a means of regulating violence, so that the destruction caused by human conflict is minimized and fair relationships are established. Anarchists argue that pursuit of these ends does not justify the establishment of a state; many argue that the state is incompatible with those goals and the ''cause'' of chaos, violence, and war. Anarchists argue that the state helps to create a [[Monopoly on the legitimate use of physical force|monopoly on violence]], and uses violence to advance elite interests. Much effort has been dedicated to explaining how anarchist societies would handle criminality.''See also:'' [[Anarchism and Society]]
|
||||
|
||||
*'''Civil rights and cultural sovereignty''' - [[Black anarchism]] opposes the existence of a state, capitalism, and subjugation and domination of people of color, and favors a non-hierarchical organization of society. Theorists include [[Ashanti Alston]], [[Lorenzo Komboa Ervin]], and [[Sam Mbah]]. [[Anarchist People of Color]] was created as a forum for non-caucasian anarchists to express their thoughts about racial issues within the anarchist movement, particularly within the United States. [[National anarchism]] is a political view which seeks to unite cultural or ethnic preservation with anarchist views. Its adherents propose that those preventing ethnic groups (or [[races]]) from living in separate autonomous groupings should be resisted. [[Anti-Racist Action]] is not an anarchist group, but many anarchists are involved. It focuses on publicly confronting racist agitators. The [[Zapatista]] movement of Chiapas, Mexico is a cultural sovereignty group with some anarchist proclivities.
|
||||
|
||||
*'''Neocolonialism and Globalization''' - Nearly all anarchists oppose [[neocolonialism]] as an attempt to use economic coercion on a global scale, carried out through state institutions such as the [[World Bank]], [[World Trade Organization]], [[G8|Group of Eight]], and the [[World Economic Forum]]. [[Globalization]] is an ambiguous term that has different meanings to different anarchist factions. Most anarchists use the term to mean neocolonialism and/or [[cultural imperialism]] (which they may see as related). Many are active in the [[anti-globalization]] movement. Others, particularly anarcho-capitalists, use "globalization" to mean the worldwide expansion of the division of labor and trade, which they see as beneficial so long as governments do not intervene.
|
||||
|
||||
*'''Parallel structures''' - Many anarchists try to set up alternatives to state-supported institutions and "outposts," such as [[Food Not Bombs]], [[infoshop]]s, educational systems such as home-schooling, neighborhood mediation/arbitration groups, and so on. The idea is to create the structures for a new anti-authoritarian society in the shell of the old, authoritarian one.
|
||||
|
||||
*'''Technology''' - Recent technological developments have made the anarchist cause both easier to advance and more conceivable to people. Many people use the Internet to form on-line communities. [[Intellectual property]] is undermined and a gift-culture supported by [[file sharing|sharing music files]], [[open source]] programming, and the [[free software movement]]. These cyber-communities include the [[GNU]], [[Linux]], [[Indymedia]], and [[Wiki]]. <!-- ***NEEDS SOURCE THAT E-GOLD IS USED BY ANARCHISTS*** [[Public key cryptography]] has made anonymous digital currencies such as [[e-gold]] and [[Local Exchange Trading Systems]] an alternative to statist [[fiat money]]. --> Some anarchists see [[information technology]] as the best weapon to defeat authoritarianism. Some even think the information age makes eventual anarchy inevitable.<ref>[http://www.modulaware.com/a/?m=select&id=0684832720 The Sovereign Individual -- Mastering the transition to the information age]</ref> ''See also'': [[Crypto-anarchism]] and [[Cypherpunk]].
|
||||
|
||||
*'''Pacifism''' - Some anarchists consider [[Pacifism]] (opposition to [[war]]) to be inherent in their philosophy. [[Anarcho-pacifism|anarcho-pacifists]] take it further and follow [[Leo Tolstoy]]'s belief in [[Nonviolence|non-violence]]. Anarchists see war as an activity in which the state seeks to gain and consolidate power, both domestically and in foreign lands, and subscribe to [[Randolph Bourne]]'s view that "war is the health of the state"<ref>[http://struggle.ws/hist_texts/warhealthstate1918.html War is the Health of the State]</ref>. A lot of anarchist activity has been [[anti-war]] based.
|
||||
|
||||
*'''Parliamentarianism''' - In general terms, the anarchist ethos opposes voting in elections, because voting amounts to condoning the state.<ref>[http://members.aol.com/vlntryst/hitler.html The Voluntaryist - Why I would not vote against Hitler]</ref>. [[Voluntaryism]] is an anarchist school of thought which emphasizes "tending your own garden" and "neither ballots nor bullets." The anarchist case against voting is explained in ''The Ethics of Voting''<ref>[http://www.voluntaryist.com/nonvoting/ethics_of_voting.php Voluntaryist - The ethics of voting]</ref> by [[George H. Smith]]. (Also see "Voting Anarchists: An Oxymoron or What?" by [[Joe Peacott]], and writings by [[Fred Woodworth]]).
|
||||
|
||||
*'''Sectarianism''' - Most anarchist schools of thought are, to some degree, [[sectarian]]. There is often a difference of opinion ''within'' each school about how to react to, or interact with, other schools. Some, such as [[panarchy|panarchists]], believe that it is possible for a variety of modes of social life to coexist and compete. Some anarchists view opposing schools as a social impossibility and resist interaction; others see opportunities for coalition-building, or at least temporary alliances for specific purposes. ''See [[anarchism without adjectives]].''
|
||||
|
||||
==Criticisms of anarchism==
|
||||
:''Main article:'' [[Criticisms of anarchism]]
|
||||
|
||||
'''Violence.''' Since anarchism has often been associated with violence and destruction, some people have seen it as being too violent. On the other hand hand, [[Frederick Engels]] criticsed anarchists for not being violent enough:
|
||||
:''"A revolution is certainly the most authoritarian thing there is; it is the act whereby one part of the population imposes its will upon the other part by means of rifles, bayonets and cannon — authoritarian means, if such there be at all; and if the victorious party does not want to have fought in vain, it must maintain this rule by means of the terror which its arms inspire in the reactionists. Would the Paris Commune have lasted a single day if it had not made use of this authority of the armed people against the bourgeois?"<ref>[http://www.marxists.org/archive/marx/works/1872/10/authority.htm ''On Authority'']</ref>
|
||||
|
||||
'''Utopianism.''' Anarchism is often criticised as unfeasible, or plain [[utopian]], even by many who agree that it's a nice idea in principle. For example, Carl Landauer in his book ''European Socialism'' criticizes anarchism as being unrealistically utopian, and holds that government is a "lesser evil" than a society without "repressive force." He holds that the belief that "ill intentions will cease if repressive force disappears" is an "absurdity."<ref>[[Carl Landauer|Landauer]], Carl. ''European Socialism: A History of Ideas and Movements'' (1959) (retrieved from "Anarchist Theory FAQ" by [[Bryan Caplan]] on [[January 27]] [[2006]]</ref> However, it must be noted that not all anarchists have such a utopian view of anarchism. For example, some, such as Benjamin Tucker, advocate privately-funded institutions that defend individual liberty and property. However, other anarchists, such as Sir [[Herbert Read]], proudly accept the characterization "utopian."
|
||||
|
||||
'''[[Social class|Class]] character.''' [[Marxists]] have characterised anarchism as an expression of the class interests of the [[petite bourgeoisie]] or perhaps the [[lumpenproletariat]]. See e.g. Plekhanov<ref>[[G. V. Plekhanov]] ''"[http://www.marxists.org/archive/plekhanov/1895/anarch/index.htm Anarchism and Socialism]"''</ref> for a Marxist critique of 1895. Anarchists have also been characterised as spoilt [[middle-class]] [[dilettante]]s, most recently in relation to [[anti-capitalism|anti-capitalist]] protesters.
|
||||
|
||||
'''Tacit authoritarianism.''' In recent decades anarchism has been criticised by 'situationists', 'post-anarchists' and others of preserving 'tacitly statist', authoritarian or bureaucratic tendencies behind a dogmatic facade.<ref>[http://library.nothingness.org/articles/SI/en/display/20 ''Society of the Spectacle] Paragraph 91</ref>
|
||||
|
||||
'''Hypocrisy.''' Some critics point to the [[sexist]]<ref>[[Jenny P. d'Hericourt]], ''"[http://www.pinn.net/~sunshine/whm2003/hericourt2.html Contemporary feminist critic of Proudhon]"''</ref> and [[racist]] views of some prominent anarchists, notably [[Pierre-Joseph Proudhon|Proudhon]] and [[Mikhail Bakunin|Bakunin]], as examples of [[hypocrisy]] inherent within anarchism. While many anarchists, however, dismiss that the personal prejudices of 19th century theorists influence the beliefs of present-day anarchists, others criticise modern anarchism for continuing to be [[eurocentric]] and reference the impact of anarchist thinkers like Proudhon on [[fascism]] through groups like [[Cercle Proudhon]].<ref>[http://www.stewarthomesociety.org/ai.htm ''Anarchist Integralism]</ref> Anarcho-capitalist [[Bryan Caplan]] argues that the treatment of fascists and suspected fascist sympathizers by Spanish Anarchists in the Spanish Civil War was a form of illegitimate coercion, making the proffessed anarchists "ultimately just a third faction of totalitarians," alongside the communists and fascists. He also criticizes the willingness of the CNT to join the (statist) Republican government during the civil war, and references [[Stanley G. Payne]]'s book on the Franco regime which claims that the CNT entered negotiations with the fascist government six years after the war.<ref>[[Bryan Caplan|Caplan]], Bryan. ''"[http://www.gmu.edu/departments/economics/bcaplan/spain.htm The Anarcho-Statists of Spain]"''</ref>
|
||||
|
||||
==Cultural phenomena==
|
||||
[[Image:Noam_chomsky.jpg|thumb|150px|right| [[Noam Chomsky]] (1928–)]]
|
||||
The kind of anarchism that is most easily encountered in popular culture is represented by celebrities who publicly identify themselves as anarchists. Although some anarchists reject any focus on such famous living individuals as inherently élitist, the following figures are examples of prominent publicly self-avowed anarchists:
|
||||
|
||||
* the [[MIT]] professor of [[Linguistics]] [[Noam Chomsky]]
|
||||
* the [[science fiction]] author [[Ursula K. Le Guin]]
|
||||
* the social historian [[Howard Zinn]]
|
||||
* entertainer and author [[Hans Alfredsson]]
|
||||
* the [[Avant-garde]] artist [[Nicolás Rosselló]]
|
||||
|
||||
In [[Denmark]], the [[Freetown Christiania]] was created in downtown [[Copenhagen]]. The housing and employment crisis in most of [[Western Europe]] led to the formation of [[commune (intentional community)|communes]] and squatter movements like the one still thriving in [[Barcelona]], in [[Catalonia]]. Militant [[antifa|resistance to neo-Nazi groups]] in places like Germany, and the uprisings of [[autonomous Marxism]], [[situationist]], and [[Autonomist]] groups in France and Italy also helped to give popularity to anti-authoritarian, non-capitalist ideas.
|
||||
|
||||
In various musical styles, anarchism rose in popularity. Most famous for the linking of anarchist ideas and music has been punk rock, although in the modern age, hip hop, and folk music are also becoming important mediums for the spreading of the anarchist message. In the [[United Kingdom|UK]] this was associated with the [[punk rock]] movement; the band [[Crass]] is celebrated for its anarchist and [[pacifism|pacifist]] ideas. The [[Dutch people|Dutch]] punk band [[The Ex]] further exemplifies this expression.
|
||||
''For further details, see [[anarcho-punk]]''
|
||||
|
||||
==See also==
|
||||
<!-- (Please take care in adding to this list that it not grow excessively large, consider adding to the list of anarchist concepts page) -->
|
||||
There are many concepts relevant to the topic of anarchism, this is a brief summary. There is also a more extensive [[list of anarchist concepts]].
|
||||
|
||||
* [[individualist anarchism]], [[anarcho-communism]], [[anarcho-syndicalism]], [[anarcho-capitalism]], [[mutualism]], [[Christian anarchism]], [[anarcha-feminism]], [[green anarchism]], [[nihilist anarchism]], [[anarcho-nationalism]], [[black anarchism]], [[national anarchism]]. [[post-anarchism]], [[post-left anarchism]]
|
||||
* [[Libertarian Socialism]]
|
||||
* [[Anarchist symbolism]]
|
||||
* [[Anarchism/Links|List of anarchism links]]
|
||||
* [[List of anarchists]]
|
||||
* [[List of anarchist organizations]]
|
||||
* [[Major conflicts within anarchist thought]]
|
||||
* [[Past and present anarchist communities]]
|
||||
|
||||
===Historical events===
|
||||
*[[Paris Commune]] (1871)
|
||||
*[[Haymarket Riot]] (1886)
|
||||
*[[The Makhnovschina]] (1917 &mdash; 1921)
|
||||
*[[Kronstadt rebellion]] (1921)
|
||||
*[[Spanish Revolution]] (1936) (see [[Anarchism in Spain]] and [[Spanish Revolution]])
|
||||
*May 1968, France (1968)
|
||||
*[[WTO Ministerial Conference of 1999|WTO Meeting in Seattle]] (1999)
|
||||
|
||||
===Books===
|
||||
{{main|List of anarchist books}}
|
||||
|
||||
The following is a sample of books that have been referenced in this page, a more complete list can be found at the [[list of anarchist books]].
|
||||
|
||||
*[[Mikhail Bakunin]], ''[[God and the State]]'' [http://dwardmac.pitzer.edu/Anarchist_Archives/bakunin/godandstate/godandstate_ch1.html]
|
||||
*[[Emma Goldman]], ''[[Anarchism & Other Essays]]'' [http://dwardmac.pitzer.edu/Anarchist_Archives/goldman/GoldmanCW.html]
|
||||
*[[Peter Kropotkin]], ''[[Mutual Aid: A Factor of Evolution|Mutual Aid]]'' [http://www.gutenberg.org/etext/4341]
|
||||
*[[Pierre-Joseph Proudhon]], ''[[What is Property?]]'' [http://www.gutenberg.org/etext/360]
|
||||
*[[Rudolf Rocker]], ''[[Anarcho-Syndicalism (book)|Anarcho-Syndicalism]]''
|
||||
*[[Murray Rothbard]] ''[[The Ethics of Liberty]]'' [http://www.mises.org/rothbard/ethics/ethics.asp]
|
||||
*[[Max Stirner]], ''[[The Ego And Its Own]]'' [http://www.df.lth.se/~triad/stirner/]
|
||||
*[[Leo Tolstoy]], ''[[The Kingdom of God is Within You]]'' [http://www.kingdomnow.org/withinyou.html]
|
||||
|
||||
===Anarchism by region/culture===
|
||||
* [[African Anarchism]]
|
||||
* [[Anarchism in Spain]]
|
||||
* [[Anarchism in the English tradition]]
|
||||
* [[Chinese anarchism]]
|
||||
|
||||
==References==
|
||||
<div style="font-size: 85%">
|
||||
<references/>
|
||||
</div>
|
||||
|
||||
'''These notes have no corresponding reference in the article. They might be re-used.'''
|
||||
# {{note|bill}} [http://ns52.super-hosts.com/~vaz1net/bill/anarchism/library/thelaw.html]
|
||||
# {{note|praxeology}} [http://praxeology.net/GM-PS.htm]
|
||||
# {{note|platform}} [http://flag.blackened.net/revolt/platform/plat_preface.html]
|
||||
# {{note|appleton}} [http://www.againstpolitics.com/market_anarchism/appleton_boston.htm Against Politics - Appleton - Boston Anarchists]
|
||||
# {{note|Yarros-NotUtopian}} [[Victor Yarros|Yarros, Victor]] ''Liberty'' VII, [[January 2]] [[1892]].
|
||||
# {{note|totse}} [http://www.totse.com/en/politics/anarchism/161594.html Noam Chomsky on Anarchism by Noam Chomsky]
|
||||
|
||||
==External links==
|
||||
The overwhelming diversity and number of links relating to anarchism is extensively covered on the [[List of anarchism web resources|links subpage]].
|
||||
{{wikiquote|Definitions of anarchism}}
|
||||
*[http://anarchoblogs.protest.net/ Anarchoblogs] Blogs by Anarchists.
|
||||
*[http://dwardmac.pitzer.edu/Anarchist_Archives/ Anarchy Archives] extensively archives information relating to famous anarchists. This includes many of their books and other publications.
|
||||
*Hundreds of anarchists are listed, with short bios, links & dedicated pages [http://recollectionbooks.com/bleed/gallery/galleryindex.htm at the Daily Bleed's Anarchist Encyclopedia]
|
||||
*[http://www.infoshop.org/ Infoshop.org] ([[Infoshop.org|wikipedia page]])
|
||||
*[http://www.iww.org/ Industrial Workers of the World]
|
||||
|
||||
<!-- Attention! The external link portion of this article regularly grows far beyond manageable size. Please only list an outside link if it applies to anarchism in general and is somewhat noteworthy. Links to lesser known sites or submovements will be routinely moved to the list page to keep this article free of clutter -->
|
||||
|
||||
|
||||
[[Category:Anarchism|*]]
|
||||
[[Category:Forms of government|Anarchism]]
|
||||
[[Category:Political ideology entry points|Anarchism]]
|
||||
[[Category:Political theories|Anarchism]]
|
||||
[[Category:Social philosophy|Anarchism]]
|
||||
|
||||
[[ar:لاسلطوية]]
|
||||
[[ast:Anarquismu]]
|
||||
[[bg:Анархизъм]]
|
||||
[[bs:Anarhizam]]
|
||||
[[ca:Anarquisme]]
|
||||
[[cs:Anarchismus]]
|
||||
[[da:Anarkisme]]
|
||||
[[de:Anarchismus]]
|
||||
[[eo:Anarkiismo]]
|
||||
[[es:Anarquismo]]
|
||||
[[et:Anarhism]]
|
||||
[[eu:Anarkismo]]
|
||||
[[fa:دولتزدائی]]
|
||||
[[fi:Anarkismi]]
|
||||
[[fr:Anarchisme]]
|
||||
[[gl:Anarquismo]]
|
||||
[[he:אנרכיזם]]
|
||||
[[hu:Anarchizmus]]
|
||||
[[id:Anarkisme]]
|
||||
[[is:Stjórnleysisstefna]]
|
||||
[[it:Anarchismo]]
|
||||
[[ja:アナキズム]]
|
||||
[[ko:아나키즘]]
|
||||
[[lt:Anarchizmas]]
|
||||
[[nl:Anarchisme]]
|
||||
[[nn:Anarkisme]]
|
||||
[[no:Anarkisme]]
|
||||
[[pl:Anarchizm]]
|
||||
[[pt:Anarquismo]]
|
||||
[[ro:Anarhism]]
|
||||
[[ru:Анархизм]]
|
||||
[[sco:Anarchism]]
|
||||
[[simple:Anarchism]]
|
||||
[[sk:Anarchizmus]]
|
||||
[[sl:Anarhizem]]
|
||||
[[sr:Анархизам]]
|
||||
[[sv:Anarkism]]
|
||||
[[th:ลัทธิอนาธิปไตย]]
|
||||
[[tr:Anarşizm]]
|
||||
[[zh:无政府主义]]
|
||||
[[zh-min-nan:Hui-thóng-tī-chú-gī]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanHistory</title>
|
||||
<id>13</id>
|
||||
<revision>
|
||||
<id>15898948</id>
|
||||
<timestamp>2002-08-27T03:07:44Z</timestamp>
|
||||
<contributor>
|
||||
<username>Magnus Manske</username>
|
||||
<id>4</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>whoops</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[History of Afghanistan]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanGeography</title>
|
||||
<id>14</id>
|
||||
<revision>
|
||||
<id>15898949</id>
|
||||
<timestamp>2002-02-25T15:43:11Z</timestamp>
|
||||
<contributor>
|
||||
<ip>Conversion script</ip>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>Automated conversion</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Geography of Afghanistan]]
|
||||
</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanPeople</title>
|
||||
<id>15</id>
|
||||
<revision>
|
||||
<id>15898950</id>
|
||||
<timestamp>2002-08-21T10:42:35Z</timestamp>
|
||||
<contributor>
|
||||
<username>-- April</username>
|
||||
<id>166</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>fix link</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Demographics of Afghanistan]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanEconomy</title>
|
||||
<id>17</id>
|
||||
<revision>
|
||||
<id>15898951</id>
|
||||
<timestamp>2002-05-17T15:30:05Z</timestamp>
|
||||
<contributor>
|
||||
<username>AxelBoldt</username>
|
||||
<id>2</id>
|
||||
</contributor>
|
||||
<comment>fix redirect</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Economy of Afghanistan]]
|
||||
</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanCommunications</title>
|
||||
<id>18</id>
|
||||
<revision>
|
||||
<id>15898952</id>
|
||||
<timestamp>2002-09-13T13:39:26Z</timestamp>
|
||||
<contributor>
|
||||
<username>Andre Engels</username>
|
||||
<id>300</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>indirect redirect</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Communications in Afghanistan]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanTransportations</title>
|
||||
<id>19</id>
|
||||
<revision>
|
||||
<id>15898953</id>
|
||||
<timestamp>2002-10-09T13:36:44Z</timestamp>
|
||||
<contributor>
|
||||
<username>Magnus Manske</username>
|
||||
<id>4</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>#REDIRECT [[Transportation in Afghanistan]]</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Transportation in Afghanistan]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanMilitary</title>
|
||||
<id>20</id>
|
||||
<revision>
|
||||
<id>15898954</id>
|
||||
<timestamp>2002-09-03T01:14:20Z</timestamp>
|
||||
<contributor>
|
||||
<username>Andre Engels</username>
|
||||
<id>300</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>short-circuiting two-step redirect</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Military of Afghanistan]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AfghanistanTransnationalIssues</title>
|
||||
<id>21</id>
|
||||
<revision>
|
||||
<id>15898955</id>
|
||||
<timestamp>2002-10-09T13:37:01Z</timestamp>
|
||||
<contributor>
|
||||
<username>Magnus Manske</username>
|
||||
<id>4</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>#REDIRECT [[Foreign relations of Afghanistan]]</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Foreign relations of Afghanistan]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AlTruism</title>
|
||||
<id>22</id>
|
||||
<revision>
|
||||
<id>15898956</id>
|
||||
<timestamp>2002-02-25T15:43:11Z</timestamp>
|
||||
<contributor>
|
||||
<ip>Conversion script</ip>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>Automated conversion</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Altruism]]
|
||||
</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AssistiveTechnology</title>
|
||||
<id>23</id>
|
||||
<revision>
|
||||
<id>15898957</id>
|
||||
<timestamp>2003-04-25T22:20:03Z</timestamp>
|
||||
<contributor>
|
||||
<username>Ams80</username>
|
||||
<id>7543</id>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>Fixing redirect</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Assistive_technology]]</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>AmoeboidTaxa</title>
|
||||
<id>24</id>
|
||||
<revision>
|
||||
<id>15898958</id>
|
||||
<timestamp>2002-02-25T15:43:11Z</timestamp>
|
||||
<contributor>
|
||||
<ip>Conversion script</ip>
|
||||
</contributor>
|
||||
<minor />
|
||||
<comment>Automated conversion</comment>
|
||||
<text xml:space="preserve">#REDIRECT [[Amoeboid]]
|
||||
</text>
|
||||
</revision>
|
||||
</page>
|
||||
<page>
|
||||
<title>Autism</title>
|
||||
<id>25</id>
|
||||
<revision>
|
||||
<id>42019020</id>
|
||||
<timestamp>2006-03-03T06:39:21Z</timestamp>
|
||||
<contributor>
|
||||
<username>Ohnoitsjamie</username>
|
||||
<id>507787</id>
|
||||
</contributor>
|
||||
<comment>rv difficult-to-follow paragraph</comment>
|
||||
<text xml:space="preserve"><!-- NOTES:
|
||||
|
||||
1) Please do not convert the bullets to subheadings here as the table of contents would be too large in that case (for example, see the FAC).
|
||||
2) Use ref/note combos for all links and explicitly cited references
|
||||
3) Reference anything you put here with notable references, as this subject tends to attract a lot of controversy.
|
||||
|
||||
-->{{DiseaseDisorder infobox |
|
||||
Name = Childhood autism |
|
||||
ICD10 = F84.0 |
|
||||
ICD9 = {{ICD9|299.0}} |
|
||||
}}
|
||||
'''Autism''' is classified as a neurodevelopmental disorder that manifests itself in markedly abnormal social interaction, communication ability, patterns of interests, and patterns of behavior.
|
||||
|
||||
Although the specific [[etiology]] of autism is unknown, many researchers suspect that autism results from genetically mediated vulnerabilities to environmental triggers. And while there is disagreement about the magnitude, nature, and mechanisms for such environmental factors, researchers have found at least seven major genes prevalent among individuals diagnosed as autistic. Some estimate that autism occurs in as many as one [[United States]] child in 166, however the [[National Institute of Mental Health]] gives a more conservative estimate of one in 1000{{ref|NihAutismov2005}}. For families that already have one autistic child, the odds of a second autistic child may be as high as one in twenty. Diagnosis is based on a list of [[Psychiatry|psychiatric]] criteria, and a series of standardized clinical tests may also be used.
|
||||
|
||||
Autism may not be [[Physiology|physiologically]] obvious. A complete physical and [[neurological]] evaluation will typically be part of diagnosing autism. Some now speculate that autism is not a single condition but a group of several distinct conditions that manifest in similar ways.
|
||||
|
||||
By definition, autism must manifest delays in "social interaction, language as used in social communication, or symbolic or imaginative play," with "onset prior to age 3 years", according to the [[Diagnostic and Statistical Manual of Mental Disorders]]. The [[ICD-10]] also says that symptoms must "manifest before the age of three years." There have been large increases in the reported [[Autism epidemic|incidence of autism]], for reasons that are heavily debated by [[research]]ers in [[psychology]] and related fields within the [[scientific community]].
|
||||
|
||||
Some children with autism have improved their social and other skills to the point where they can fully participate in mainstream education and social events, but there are lingering concerns that an absolute cure from autism is impossible with current technology. However, many autistic children and adults who are able to communicate (at least in writing) are opposed to attempts to cure their conditions, and see such conditions as part of who they are.
|
||||
|
||||
==History==
|
||||
[[image:Asperger_kl2.jpg|frame|right|Dr. [[Hans Asperger]] described a form of autism in the 1940s that later became known as [[Asperger's syndrome]].]]
|
||||
|
||||
The word ''autism'' was first used in the [[English language]] by Swiss psychiatrist [[Eugene Bleuler]] in a 1912 number of the ''American Journal of Insanity''. It comes from the Greek word for "self".
|
||||
|
||||
However, the [[Medical classification|classification]] of autism did not occur until the middle of the [[twentieth century]], when in 1943 psychiatrist Dr. [[Leo Kanner]] of the [[Johns Hopkins Hospital]] in Baltimore reported on 11 child patients with striking behavioral similarities, and introduced the label ''early infantile autism''. He suggested "autism" from the [[Greek language|Greek]] &alpha;&upsilon;&tau;&omicron;&sigmaf; (''autos''), meaning "self", to describe the fact that the children seemed to lack interest in other people. Although Kanner's first paper on the subject was published in a (now defunct) journal, ''The Nervous Child'', almost every characteristic he originally described is still regarded as typical of the autistic spectrum of disorders.
|
||||
|
||||
At the same time an [[Austria|Austrian]] scientist, Dr. [[Hans Asperger]], described a different form of autism that became known as [[Asperger's syndrome]]&mdash;but the widespread recognition of Asperger's work was delayed by [[World War II]] in [[Germany]], and by the fact that his seminal paper wasn't translated into English for almost 50 years. The majority of his work wasn't widely read until 1997.
|
||||
|
||||
Thus these two conditions were described and are today listed in the [[Diagnostic and Statistical Manual of Mental Disorders]] DSM-IV-TR (fourth edition, text revision 1) as two of the five [[Pervasive developmental disorder|pervasive developmental disorders]] (PDD), more often referred to today as [[Autistic spectrum|autism spectrum disorders]] (ASD). All of these conditions are characterized by varying degrees of difference in [[communication skill]]s, social interactions, and restricted, repetitive and stereotyped patterns of [[Human behavior|behavior]].
|
||||
|
||||
Few clinicians today solely use the DSM-IV criteria for determining a diagnosis of autism, which are based on the absence or delay of certain developmental milestones. Many clinicians instead use an alternate means (or a combination thereof) to more accurately determine a [[diagnosis]].
|
||||
|
||||
==Terminology==
|
||||
{{wiktionarypar2|autism|autistic}}
|
||||
When referring to someone diagnosed with autism, the term ''autistic'' is often used. However, the term ''person with autism'' can be used instead. This is referred to as ''[[person-first terminology]]''. The [[autistic community]] generally prefers the term ''autistic'' for reasons that are fairly controversial. This article uses the term ''autistic'' (see [[Talk:Autism|talk page]]).
|
||||
|
||||
==Characteristics==
|
||||
[[Image:kanner_kl2.jpg|frame|right|Dr. [[Leo Kanner]] introduced the label ''early infantile autism'' in 1943.]]
|
||||
There is a great diversity in the skills and behaviors of individuals diagnosed as autistic, and physicians will often arrive at different conclusions about the appropriate diagnosis. Much of this is due to the [[sensory system]] of an autistic which is quite different from the sensory system of other people, since certain [[stimulus|stimulations]] can affect an autistic differently than a non-autistic, and the degree to which the sensory system is affected varies wildly from one autistic person to another.
|
||||
|
||||
Nevertheless, professionals within [[pediatric]] care and development often look for early indicators of autism in order to initiate treatment as early as possible. However, some people do not believe in treatment for autism, either because they do not believe autism is a disorder or because they believe treatment can do more harm than good.
|
||||
|
||||
===Social development===
|
||||
Typically, developing infants are social beings&mdash;early in life they do such things as gaze at people, turn toward voices, grasp a finger, and even smile. In contrast, most autistic children prefer objects to faces and seem to have tremendous difficulty learning to engage in the give-and-take of everyday human interaction. Even in the first few months of life, many seem indifferent to other people because they avoid eye contact and do not interact with them as often as non-autistic children.
|
||||
|
||||
Children with autism often appear to prefer being alone to the company of others and may passively accept such things as hugs and cuddling without reciprocating, or resist attention altogether. Later, they seldom seek comfort from others or respond to parents' displays of [[anger]] or [[affection]] in a typical way. Research has suggested that although autistic children are attached to their [[parent]]s, their expression of this attachment is unusual and difficult to interpret. Parents who looked forward to the joys of cuddling, [[teaching]], and playing with their child may feel crushed by this lack of expected [[attachment theory|attachment]] behavior.
|
||||
|
||||
Children with autism appear to lack "[[Theory of mind|theory of mind]]", the ability to see things from another person's perspective, a behavior cited as exclusive to human beings above the age of five and, possibly, other higher [[primate]]s such as adult [[gorilla]]s, [[Common chimpanzee|chimpanzee]]s and [[bonobos]]. Typical 5-year-olds can develop insights into other people's different knowledge, feelings, and intentions, interpretations based upon social cues (e.g., gestures, facial expressions). An individual with autism seems to lack these interpretation skills, an inability that leaves them unable to predict or understand other people's actions. The [[social alienation]] of autistic and Asperger's people is so intense from childhood that many of them have [[imaginary friend]]s as companionship. However, having an imaginary friend is not necessarily a sign of autism and also occurs in non-autistic children.
|
||||
|
||||
Although not universal, it is common for autistic people to not regulate their behavior. This can take the form of crying or verbal outbursts that may seem out of proportion to the situation. Individuals with autism generally prefer consistent routines and environments; they may react negatively to changes in them. It is not uncommon for these individuals to exhibit aggression, increased levels of self-stimulatory behavior, self-injury or extensive withdrawal in overwhelming situations.
|
||||
|
||||
===Sensory system===
|
||||
A key indicator to clinicians making a proper assessment for autism would include looking for symptoms much like those found in [[Sensory Integration Dysfunction|sensory integration dysfunction]]. Children will exhibit problems coping with the normal sensory input. Indicators of this disorder include oversensitivity or underreactivity to touch, movement, sights, or sounds; physical clumsiness or carelessness; poor body awareness; a tendency to be easily distracted; impulsive physical or verbal behavior; an activity level that is unusually high or low; not unwinding or calming oneself; difficulty learning new movements; difficulty in making transitions from one situation to another; social and/or emotional problems; delays in [[Speech delay|speech]], [[Language delay|language]] or [[motor skills]]; specific learning difficulties/delays in academic achievement.
|
||||
|
||||
One common example is an individual with autism [[Hearing (sense)|hearing]]. A person with Autism may have trouble hearing certain people while other people are louder than usual. Or the person with autism may be unable to filter out sounds in certain situations, such as in a large crowd of people (see [[cocktail party effect]]). However, this is perhaps the part of the autism that tends to vary the most from person to person, so these examples may not apply to every autistic.
|
||||
|
||||
It should be noted that sensory difficulties, although reportedly common in autistics, are not part of the [[DSM-IV]] diagnostic criteria for ''autistic disorder''.
|
||||
|
||||
===Communication difficulties===
|
||||
By age 3, typical children have passed predictable language learning milestones; one of the earliest is babbling. By the first birthday, a typical toddler says words, turns when he or she hears his or her name, points when he or she wants a toy, and when offered something distasteful, makes it clear that the answer is "no." Speech development in people with autism takes different paths. Some remain [[mute]] throughout their lives while being fully [[literacy|literate]] and able to communicate in other ways&mdash;images, [[sign language]], and [[typing]] are far more natural to them. Some infants who later show signs of autism coo and babble during the first few months of life, but stop soon afterwards. Others may be delayed, developing language as late as the [[adolescence|teenage]] years. Still, inability to speak does not mean that people with autism are unintelligent or unaware. Once given appropriate accommodations, many will happily converse for hours, and can often be found in online [[chat room]]s, discussion boards or [[website]]s and even using communication devices at autism-community social events such as [[Autreat]].
|
||||
|
||||
Those who do speak often use [[language]] in unusual ways, retaining features of earlier stages of language development for long periods or throughout their lives. Some speak only single words, while others repeat the same phrase over and over. Some repeat what they hear, a condition called [[echolalia]]. Sing-song repetitions in particular are a calming, joyous activity that many autistic adults engage in. Many people with autism have a strong [[tonality|tonal]] sense, and can often understand spoken language.
|
||||
Some children may exhibit only slight delays in language, or even seem to have precocious language and unusually large [[vocabulary|vocabularies]], but have great difficulty in sustaining typical [[conversation]]s. The "give and take" of non-autistic conversation is hard for them, although they often carry on a [[monologue]] on a favorite subject, giving no one else an opportunity to comment. When given the chance to converse with other autistics, they comfortably do so in "parallel monologue"&mdash;taking turns expressing views and information. Just as "[[neurotypical]]s" (people without autism) have trouble understanding autistic [[body language]]s, vocal tones, or phraseology, people with autism similarly have trouble with such things in people without autism. In particular, autistic language abilities tend to be highly literal; people without autism often inappropriately attribute hidden meaning to what people with autism say or expect the person with autism to sense such unstated meaning in their own words.
|
||||
|
||||
The body language of people with autism can be difficult for other people to understand. Facial expressions, movements, and gestures may be easily understood by some other people with autism, but do not match those used by other people. Also, their tone of voice has a much more subtle inflection in reflecting their feelings, and the [[auditory system]] of a person without autism often cannot sense the fluctuations. What seems to non-autistic people like a high-pitched, sing-song, or flat, [[robot]]-like voice is common in autistic children. Some autistic children with relatively good language skills speak like little adults, rather than communicating at their current age level, which is one of the things that can lead to problems.
|
||||
|
||||
Since non-autistic people are often unfamiliar with the autistic [[body language]], and since autistic natural language may not tend towards speech, autistic people often struggle to let other people know what they need. As anybody might do in such a situation, they may scream in frustration or resort to grabbing what they want. While waiting for non-autistic people to learn to communicate with them, people with autism do whatever they can to get through to them. Communication difficulties may contribute to autistic people becoming socially anxious or depressed.
|
||||
|
||||
===Repetitive behaviors===
|
||||
Although people with autism usually appear physically normal and have good muscle control, unusual repetitive motions, known as self-stimulation or "stimming," may set them apart. These behaviors might be extreme and highly apparent or more subtle. Some children and older individuals spend a lot of time repeatedly flapping their arms or wiggling their toes, others suddenly freeze in position. As [[child]]ren, they might spend hours lining up their cars and trains in a certain way, not using them for pretend play. If someone accidentally moves one of these toys, the child may be tremendously upset. Autistic children often need, and demand, absolute consistency in their environment. A slight change in any routine&mdash;in mealtimes, dressing, taking a bath, or going to school at a certain time and by the same route&mdash;can be extremely disturbing. People with autism sometimes have a persistent, intense preoccupation. For example, the child might be obsessed with learning all about [[vacuum cleaners]], [[train]] schedules or [[lighthouses]]. Often they show great interest in different languages, numbers, symbols or [[science]] topics. Repetitive behaviors can also extend into the spoken word as well. Perseveration of a single word or phrase, even for a specific number of times can also become a part of the child's daily routine.
|
||||
|
||||
===Effects in education===
|
||||
Children with autism are affected with these symptoms every day. These unusual characteristics set them apart from the everyday normal student. Because they have trouble understanding people’s thoughts and feelings, they have trouble understanding what their teacher may be telling them. They do not understand that facial expressions and vocal variations hold meanings and may misinterpret what emotion their instructor is displaying. This inability to fully decipher the world around them makes education stressful. Teachers need to be aware of a student's disorder so that they are able to help the student get the best out of the lessons being taught.
|
||||
|
||||
Some students learn better with visual aids as they are better able to understand material presented this way. Because of this, many teachers create “visual schedules” for their autistic students. This allows the student to know what is going on throughout the day, so they know what to prepare for and what activity they will be doing next. Some autistic children have trouble going from one activity to the next, so this visual schedule can help to reduce stress.
|
||||
|
||||
Research has shown that working in pairs may be beneficial to autistic children. <!-- cite a source here, please! --> Autistic students have problems in schools not only with language and communication, but with socialization as well. They feel self-conscious about themselves and many feel that they will always be outcasts. By allowing them to work with peers they can make friends, which in turn can help them cope with the problems that arise. By doing so they can become more integrated into the mainstream environment of the classroom.
|
||||
|
||||
A teacher's aide can also be useful to the student. The aide is able to give more elaborate directions that the teacher may not have time to explain to the autistic child. The aide can also facilitate the autistic child in such a way as to allow them to stay at a similar level to the rest of the class. This allows a partially one-on-one lesson structure so that the child is still able to stay in a normal classroom but be given the extra help that they need.
|
||||
|
||||
There are many different techniques that teachers can use to assist their students. A teacher needs to become familiar with the child’s disorder to know what will work best with that particular child. Every child is going to be different and teachers have to be able to adjust with every one of them.
|
||||
|
||||
Students with Autism Spectrum Disorders typically have high levels of anxiety and stress, particularly in social environments like school. If a student exhibits aggressive or explosive behavior, it is important for educational teams to recognize the impact of stress and anxiety. Preparing students for new situations by writing Social Stories can lower anxiety. Teaching social and emotional concepts using systematic teaching approaches such as The Incredible 5-Point Scale or other Cognitive Behavioral strategies can increase a student's ability to control excessive behavioral reactions.
|
||||
|
||||
== DSM definition ==
|
||||
Autism is defined in section 299.00 of the [[Diagnostic and Statistical Manual of Mental Disorders]] (DSM-IV) as:
|
||||
#A total of six (or more) items from (1), (2) and (3), with at least two from (1), and one each from (2) and (3):
|
||||
##qualitative impairment in social interaction, as manifested by at least two of the following:
|
||||
###marked impairment in the use of multiple nonverbal behaviors such as eye-to-eye gaze, facial expression, body postures, and gestures to regulate social interaction
|
||||
###failure to develop peer relationships appropriate to developmental level
|
||||
###a lack of spontaneous seeking to share enjoyment, interests, or achievements with other people (e.g., by a lack of showing, bringing, or pointing out objects of interest)
|
||||
###lack of social or emotional reciprocity
|
||||
##qualitative impairments in communication as manifested by at least one of the following:
|
||||
###delay in, or total lack of, the development of spoken language (not accompanied by an attempt to compensate through alternative modes of communication such as gesture or mime)
|
||||
###in individuals with adequate speech, marked impairment in the ability to initiate or sustain a conversation with others
|
||||
###stereotyped and repetitive use of language or idiosyncratic language
|
||||
###lack of varied, spontaneous make-believe play or social imitative play appropriate to developmental level
|
||||
##restricted repetitive and stereotyped patterns of behavior, interests, and activities, as manifested by at least one of the following:
|
||||
###encompassing preoccupation with one or more stereotyped and restricted patterns of interest that is abnormal either in intensity or focus
|
||||
###apparently inflexible adherence to specific, nonfunctional routines or rituals
|
||||
###stereotyped and repetitive motor mannerisms (e.g., hand or finger flapping or twisting, or complex whole-body movements)
|
||||
###persistent preoccupation with parts of objects
|
||||
#Delays or abnormal functioning in at least one of the following areas, with onset prior to age 3 years: (1) social interaction, (2) language as used in social communication, or (3) symbolic or imaginative play.
|
||||
#The disturbance is not better accounted for by [[Rett syndrome|Rett's Disorder]] or [[Childhood disintegrative disorder|Childhood Disintegrative Disorder]].
|
||||
|
||||
The ''Diagnostic and Statistical Manual''<!-- -->'s diagnostic criteria in general is controversial for being vague and subjective. (See the [[DSM cautionary statement]].) The criteria for autism is much more controversial and some clinicians today may ignore it completely, instead solely relying on other methods for determining the diagnosis.
|
||||
|
||||
== Types of autism ==
|
||||
Autism presents in a wide degree, from those who are nearly [[dysfunctional]] and apparently [[Developmental Disability|mentally handicapped]] to those whose symptoms are mild or remedied enough to appear unexceptional ("normal") to the general public. In terms of both classification and therapy, autistic individuals are often divided into those with an [[Intelligence Quotient|IQ]]&lt;80 referred to as having "low-functioning autism" (LFA), while those with IQ&gt;80 are referred to as having "high-functioning autism" (HFA). Low and high functioning are more generally applied to how well an individual can accomplish activities of daily living, rather than to [[IQ]]. The terms low and high functioning are controversial and not all autistics accept these labels. Further, these two labels are not currently used or accepted in autism literature.
|
||||
|
||||
This discrepancy can lead to confusion among service providers who equate IQ with functioning and may refuse to serve high-IQ autistic people who are severely compromised in their ability to perform daily living tasks, or may fail to recognize the intellectual potential of many autistic people who are considered LFA. For example, some professionals refuse to recognize autistics who can speak or write as being autistic at all, because they still think of autism as a communication disorder so severe that no speech or writing is possible.
|
||||
|
||||
As a consequence, many "high-functioning" autistic persons, and autistic people with a relatively high [[IQ]], are underdiagnosed, thus making the claim that "autism implies retardation" self-fulfilling. The number of people diagnosed with LFA is not rising quite as sharply as HFA, indicating that at least part of the explanation for the apparent rise is probably better diagnostics.
|
||||
|
||||
=== Asperger's and Kanner's syndrome ===
|
||||
[[Image:Hans Asperger.jpg|thumb|right|160px|Asperger described his patients as "little professors".]]
|
||||
In the current [[Diagnostic and Statistical Manual of Mental Disorders]] (DSM-IV-TR), the most significant difference between Autistic Disorder (Kanner's) and Asperger's syndrome is that a diagnosis of the former includes the observation of "[d]elays or abnormal functioning in at least one of the following areas, with onset prior to age 3 years: (1) social interaction, (2) language as used in social communication, or (3) symbolic or imaginative play[,]" {{ref|bnat}} while a diagnosis of Asperger's syndrome observes "no clinically significant delay" in these areas. {{ref|bnas}}
|
||||
|
||||
The DSM makes no mention of level of intellectual functioning, but the fact that Asperger's autistics as a group tend to perform better than those with Kanner's autism has produced a popular conception that ''[[Asperger's syndrome]]'' is synonymous with "higher-functioning autism," or that it is a lesser [[disorder]] than ''autism''. There is also a popular but not necessarily true conception that all autistic individuals with a high level of intellectual functioning have Asperger's autism or that both types are merely [[geek]]s with a medical label attached. Also, autism has evolved in the public understanding, but the popular identification of autism with relatively severe cases as accurately depicted in ''[[Rain Man]]'' has encouraged relatives of family members diagnosed in the autistic spectrum to speak of their loved ones as having Asperger's syndrome rather than autism.
|
||||
|
||||
===Autism as a spectrum disorder===
|
||||
{{details|Autistic spectrum}}
|
||||
|
||||
Another view of these disorders is that they are on a continuum known as [[autistic spectrum]] disorders. A related continuum is [[Sensory Integration Dysfunction]], which is about how well we integrate the information we receive from our senses. Autism, Asperger's syndrome, and Sensory Integration Dysfunction are all closely related and overlap.
|
||||
|
||||
There are two main manifestations of classical autism, [[regressive autism]] and [[early infantile autism]]. Early infantile autism is present at birth while regressive autism begins before the age of 3 and often around 18 months. Although this causes some controversy over when the neurological differences involved in autism truly begin, some believe that it is only a matter of when an environmental toxin triggers the disorder. This triggering could occur during gestation due to a toxin that enters the mother's body and is transfered to the fetus. The triggering could also occur after birth during the crucial early nervous system development of the child due to a toxin directly entering the child's body.
|
||||
|
||||
== Increase in diagnoses of autism ==
|
||||
{{details|Autism epidemic}}
|
||||
|
||||
[[Image:autismnocgraph.png|right|thumb|400px|The number of reported cases of autism has increased dramatically over the past decade. Statistics in graph from the [[National Center for Health Statistics]].]]
|
||||
There has been an explosion worldwide in reported cases of autism over the last ten years, which is largely reminiscent of increases in the diagnosis of [[schizophrenia]] and [[multiple personality disorder]] in the twentieth century. This has brought rise to a number of different theories as to the nature of the sudden increase.
|
||||
|
||||
Epidemiologists argue that the rise in diagnoses in the United States is partly or entirely attributable to changes in diagnostic criteria, reclassifications, public awareness, and the incentive to receive federally mandated services. A widely cited study from the [[M.I.N.D. Institute]] in California ([[17 October]] [[2002]]), claimed that the increase in autism is real, even after those complicating factors are accounted for (see reference in this section below).
|
||||
|
||||
Other researchers remain unconvinced (see references below), including Dr. Chris Johnson, a professor of pediatrics at the University of Texas Health Sciences Center at [[San Antonio]] and cochair of the [[American Academy of Pediatrics]] Autism Expert Panel, who says, "There is a chance we're seeing a true rise, but right now I don't think anybody can answer that question for sure." ([[Newsweek]] reference below).
|
||||
|
||||
The answer to this question has significant ramifications on the direction of research, since a ''real increase'' would focus more attention (and research funding) on the search for environmental factors, while ''little or no real increase'' would focus more attention to genetics. On the other hand, it is conceivable that certain environmental factors (vaccination, diet, societal changes) may have a particular impact on people with a specific genetic constitution. There is little public research on the effects of [[in vitro fertilization]] on the number of incidences of autism.
|
||||
|
||||
One of the more popular theories is that there is a connection between "geekdom" and autism. This is hinted, for instance, by a ''Wired Magazine'' article in 2001 entitled "The [[Geek]] Syndrome", which is a point argued by many in the autism rights movement{{ref|Wired}}. This article, many professionals assert, is just one example of the media's application of mental disease labels to what is actually variant normal behavior&mdash;they argue that shyness, lack of athletic ability or social skills, and intellectual interests, even when they seem unusual to others, are not in themselves signs of autism or Asperger's syndrome. Others assert that it is actually the medical profession which is applying mental disease labels to children who in the past would have simply been accepted as a little different or even labeled 'gifted'. See [[clinomorphism]] for further discussion of this issue.
|
||||
|
||||
Due to the recent publicity surrounding autism and autistic spectrum disorders, an increasing number of adults are choosing to seek diagnoses of high-functioning autism or Asperger's syndrome in light of symptoms they currently experience or experienced during childhood. Since the cause of autism is thought to be at least partly genetic, a proportion of these adults seek their own diagnosis specifically as follow-up to their children's diagnoses. Because autism falls into the [[pervasive developmental disorder]] category, strictly speaking, symptoms must have been present in a given patient before age seven in order to make a [[differential diagnosis]].
|
||||
|
||||
== Therapies ==
|
||||
{{details|Autism therapies}}
|
||||
|
||||
==Sociology==
|
||||
Due to the complexity of autism, there are many facets of [[sociology]] that need to be considered when discussing it, such as the culture which has evolved from autistic persons connecting and communicating with one another. In addition, there are several subgroups forming within the autistic community, sometimes in strong opposition to one another.
|
||||
|
||||
===Community and politics===
|
||||
{{details|Autistic community}}
|
||||
{{details|Autism rights movement}}
|
||||
|
||||
Much like many other controversies in the world, the autistic community itself has splintered off into several groups. Essentially, these groups are those who seek a cure for autism, dubbed ''
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,35 @@
|
||||
# Generated by script/print-mzcat-checksums.sh
|
||||
OK. 29058c73 test/data/256.bytes.bz2
|
||||
OK. 29058c73 test/data/256.bytes.gz
|
||||
OK. 29058c73 test/data/256.bytes.two-concatenated-streams.xz
|
||||
OK. 2b581525 test/data/DCI-P3-D65.icc.zlib
|
||||
OK. 6ddef9db test/data/abraca.txt.bz2
|
||||
OK. b19df306 test/data/archive.tar.bz2
|
||||
OK. b19df306 test/data/archive.tar.gz
|
||||
OK. 6ddef9db test/data/artificial-bzip2/abraca.txt.bz2
|
||||
OK. 6ddef9db test/data/artificial-bzip2/huffman-258.bz2
|
||||
OK. fa3907fb test/data/artificial-xz-filter/xz-filter-05-fa3907fb-powerpc.dat.xz
|
||||
OK. e147593e test/data/artificial-xz-filter/xz-filter-06-e147593e-ia64.dat.xz
|
||||
OK. 9a3fb8ae test/data/artificial-xz-filter/xz-filter-07-9a3fb8ae-arm.dat.xz
|
||||
OK. 9a3fb8ae test/data/artificial-xz-filter/xz-filter-07-9a3fb8ae-arm_start_1000.dat.xz
|
||||
OK. 84e8999d test/data/artificial-xz-filter/xz-filter-08-84e8999d-armthumb.dat.xz
|
||||
OK. 0353bd24 test/data/artificial-xz-filter/xz-filter-09-0353bd24-sparc.dat.xz
|
||||
OK. dfdb871b test/data/artificial-xz-filter/xz-filter-0a-dfdb871b-arm64.dat.xz
|
||||
OK. acef87f1 test/data/enwik5.block-size-32k.xz
|
||||
OK. acef87f1 test/data/enwik5.lzma
|
||||
OK. acef87f1 test/data/enwik5.lzma2-chunk-max-1-13.xz
|
||||
OK. acef87f1 test/data/enwik5.xz
|
||||
OK. 3db2cdc6 test/data/midsummer.txt.bz2
|
||||
OK. 3db2cdc6 test/data/midsummer.txt.gz
|
||||
OK. 3db2cdc6 test/data/midsummer.txt.zlib
|
||||
OK. 519e8b87 test/data/pi.txt.bz2
|
||||
OK. 519e8b87 test/data/pi.txt.gz
|
||||
OK. 519e8b87 test/data/pi.txt.zlib
|
||||
OK. abe507ef test/data/romeo.txt.bz2
|
||||
OK. abe507ef test/data/romeo.txt.delta1.xz
|
||||
OK. abe507ef test/data/romeo.txt.gz
|
||||
OK. abe507ef test/data/romeo.txt.litonlylzma
|
||||
OK. abe507ef test/data/romeo.txt.lz
|
||||
OK. abe507ef test/data/romeo.txt.lzma
|
||||
OK. abe507ef test/data/romeo.txt.xz
|
||||
OK. abe507ef test/data/romeo.txt.zlib
|
||||
+134
-123
@@ -1,124 +1,135 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
d3bb0beb test/data/DCI-P3-D65.icc
|
||||
646e081a test/data/animated-red-blue.000000.nie
|
||||
181c6916 test/data/animated-red-blue.000001.nie
|
||||
e651a889 test/data/animated-red-blue.000002.nie
|
||||
14a5b4b0 test/data/animated-red-blue.000003.nie
|
||||
76e40058 test/data/animated-red-blue.apng
|
||||
76e40058 test/data/animated-red-blue.gif
|
||||
f9a10dac test/data/artificial-gif/background-color.gif
|
||||
36e7d9c7 test/data/artificial-gif/empty-palette.gif
|
||||
db4c30eb test/data/artificial-gif/frame-out-of-bounds.gif
|
||||
f2dc2c43 test/data/artificial-gif/metadata-empty.gif
|
||||
f2dc2c43 test/data/artificial-gif/metadata-full.gif
|
||||
a1a9b56d test/data/artificial-gif/multiple-graphic-controls.gif
|
||||
046a2d07 test/data/artificial-gif/multiple-loop-counts.gif
|
||||
ba6e48f8 test/data/artificial-gif/no-frames.gif
|
||||
f33b9bc1 test/data/artificial-gif/pixel-data-none.gif
|
||||
ac9d76d8 test/data/artificial-gif/pixel-data-not-enough.gif
|
||||
2342e3fc test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif
|
||||
2342e3fc test/data/artificial-gif/pixel-data-too-much-good-lzw.gif
|
||||
39a71dce test/data/artificial-gif/small-frame-interlaced.gif
|
||||
beaec397 test/data/artificial-gif/transparent-index.gif
|
||||
f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
|
||||
0564b364 test/data/artificial-png/apng-skip-idat.png
|
||||
e08a7cc8 test/data/artificial-png/exif.png
|
||||
e08a7cc8 test/data/artificial-png/key-value-pairs.png
|
||||
076cb375 test/data/bricks-color.bmp
|
||||
72a1f9cc test/data/bricks-color.jpeg
|
||||
076cb375 test/data/bricks-color.png
|
||||
076cb375 test/data/bricks-color.tga
|
||||
f36c2e80 test/data/bricks-dither.bmp
|
||||
f36c2e80 test/data/bricks-dither.gif
|
||||
f36c2e80 test/data/bricks-dither.no-ancillary.png
|
||||
f36c2e80 test/data/bricks-dither.png
|
||||
c2bce675 test/data/bricks-gray.bmp
|
||||
c2bce675 test/data/bricks-gray.gif
|
||||
3a2478ad test/data/bricks-gray.jpeg
|
||||
c2bce675 test/data/bricks-gray.no-ancillary.png
|
||||
c2bce675 test/data/bricks-gray.png
|
||||
c2bce675 test/data/bricks-gray.tga
|
||||
7aebfe6c test/data/bricks-nodither.bmp
|
||||
7aebfe6c test/data/bricks-nodither.gif
|
||||
7aebfe6c test/data/bricks-nodither.png
|
||||
7aebfe6c test/data/bricks-nodither.tga
|
||||
ae2e547d test/data/bricks-nodither.wbmp
|
||||
b47730a2 test/data/checkerboard.gamma1dot0.png
|
||||
b47730a2 test/data/checkerboard.gamma2dot2.png
|
||||
aa3e6c7c test/data/crude-flag.nie
|
||||
3014b4c0 test/data/gifplayer-muybridge.gif
|
||||
030f5a48 test/data/harvesters.bmp
|
||||
c18b3d5a test/data/harvesters.gif
|
||||
f217df74 test/data/harvesters.jpeg
|
||||
030f5a48 test/data/harvesters.png
|
||||
e776c90f test/data/hat.bmp
|
||||
6dcba6a4 test/data/hat.gif
|
||||
2298f3ca test/data/hat.jpeg
|
||||
e776c90f test/data/hat.png
|
||||
d30bfe5d test/data/hat.wbmp
|
||||
33a44f22 test/data/hibiscus.primitive.bmp
|
||||
25e212b3 test/data/hibiscus.primitive.gif
|
||||
9624fa44 test/data/hibiscus.primitive.jpeg
|
||||
33a44f22 test/data/hibiscus.primitive.png
|
||||
60040742 test/data/hibiscus.regular.bmp
|
||||
b727da8b test/data/hibiscus.regular.gif
|
||||
41e39405 test/data/hibiscus.regular.jpeg
|
||||
60040742 test/data/hibiscus.regular.png
|
||||
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
|
||||
96bdbbb3 test/data/hippopotamus.jpeg
|
||||
d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
|
||||
dcbb225a test/data/hippopotamus.nie
|
||||
57d9a4dd test/data/hippopotamus.pgm
|
||||
dcbb225a test/data/hippopotamus.ppm
|
||||
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
|
||||
d42a13cd test/data/peacock.default.jpeg
|
||||
c8a50351 test/data/peacock.default.truncated.decoded-by-djpeg.png
|
||||
91b6bebb test/data/peacock.default.truncated.decoded-by-wuffs.png
|
||||
91b6bebb test/data/peacock.default.truncated.jpeg
|
||||
d49bab2d test/data/peacock.grayscale.jpeg
|
||||
d42a13cd test/data/peacock.optimize.jpeg
|
||||
bdf8cc70 test/data/peacock.png
|
||||
bdf8cc70 test/data/peacock.ppm
|
||||
d42a13cd test/data/peacock.progressive.jpeg
|
||||
52e723b6 test/data/peacock.progressive.scan000.jpeg
|
||||
79c58501 test/data/peacock.progressive.scan001.jpeg
|
||||
c0b6c555 test/data/peacock.progressive.scan002.jpeg
|
||||
ec5a371f test/data/peacock.progressive.scan003.jpeg
|
||||
487afc66 test/data/peacock.progressive.scan004.jpeg
|
||||
b12a7c4f test/data/peacock.progressive.scan005.jpeg
|
||||
610eb71e test/data/peacock.progressive.scan006.jpeg
|
||||
0adacc97 test/data/peacock.progressive.scan007.jpeg
|
||||
bc00fee5 test/data/peacock.progressive.scan008.jpeg
|
||||
d42a13cd test/data/peacock.progressive.scan009.jpeg
|
||||
2ba9d5b9 test/data/peacock.progressive.truncated.decoded-by-djpeg.png
|
||||
245d37de test/data/peacock.progressive.truncated.decoded-by-wuffs.png
|
||||
245d37de test/data/peacock.progressive.truncated.jpeg
|
||||
951676cc test/data/peacock.q30.jpeg
|
||||
56835223 test/data/peacock.q99.jpeg
|
||||
7fa9064e test/data/peacock.s-very-weird.jpeg
|
||||
1543f677 test/data/peacock.s-weird.jpeg
|
||||
5437be55 test/data/peacock.s1x1-444.jpeg
|
||||
a9d83d57 test/data/peacock.s1x3.jpeg
|
||||
6862951e test/data/peacock.s2x1-422.jpeg
|
||||
d42a13cd test/data/peacock.s2x2-420.jpeg
|
||||
bf7e8c96 test/data/pjw-thumbnail.bmp
|
||||
bf7e8c96 test/data/pjw-thumbnail.gif
|
||||
7c67a37f test/data/pjw-thumbnail.jpeg
|
||||
bf7e8c96 test/data/pjw-thumbnail.png
|
||||
38cb4cbf test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png
|
||||
38cb4cbf test/data/red-blue-gradient.gamma1dot0.png
|
||||
38cb4cbf test/data/red-blue-gradient.gamma1dot8.png
|
||||
38cb4cbf test/data/red-blue-gradient.gamma2dot2.png
|
||||
38cb4cbf test/data/red-blue-gradient.vanilla.png
|
||||
75060601 test/data/rgb24png.bmp
|
||||
79ab18b6 test/data/ridiculously-fast.png
|
||||
OK. d3bb0beb test/data/DCI-P3-D65.icc
|
||||
OK. 646e081a test/data/animated-red-blue.000000.nie
|
||||
OK. 181c6916 test/data/animated-red-blue.000001.nie
|
||||
OK. e651a889 test/data/animated-red-blue.000002.nie
|
||||
OK. 14a5b4b0 test/data/animated-red-blue.000003.nie
|
||||
OK. 76e40058 test/data/animated-red-blue.apng
|
||||
OK. 76e40058 test/data/animated-red-blue.gif
|
||||
OK. f9a10dac test/data/artificial-gif/background-color.gif
|
||||
OK. 36e7d9c7 test/data/artificial-gif/empty-palette.gif
|
||||
OK. db4c30eb test/data/artificial-gif/frame-out-of-bounds.gif
|
||||
OK. f2dc2c43 test/data/artificial-gif/metadata-empty.gif
|
||||
OK. f2dc2c43 test/data/artificial-gif/metadata-full.gif
|
||||
OK. a1a9b56d test/data/artificial-gif/multiple-graphic-controls.gif
|
||||
OK. 046a2d07 test/data/artificial-gif/multiple-loop-counts.gif
|
||||
OK. ba6e48f8 test/data/artificial-gif/no-frames.gif
|
||||
BAD f33b9bc1 test/data/artificial-gif/pixel-data-none.gif
|
||||
BAD ac9d76d8 test/data/artificial-gif/pixel-data-not-enough.gif
|
||||
BAD 2342e3fc test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif
|
||||
BAD 2342e3fc test/data/artificial-gif/pixel-data-too-much-good-lzw.gif
|
||||
OK. 39a71dce test/data/artificial-gif/small-frame-interlaced.gif
|
||||
OK. beaec397 test/data/artificial-gif/transparent-index.gif
|
||||
BAD f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
|
||||
OK. 0564b364 test/data/artificial-png/apng-skip-idat.png
|
||||
OK. e08a7cc8 test/data/artificial-png/exif.png
|
||||
OK. e08a7cc8 test/data/artificial-png/key-value-pairs.png
|
||||
OK. 076cb375 test/data/bricks-color.bmp
|
||||
OK. 72a1f9cc test/data/bricks-color.jpeg
|
||||
OK. 076cb375 test/data/bricks-color.lossless.webp
|
||||
OK. 076cb375 test/data/bricks-color.png
|
||||
OK. 076cb375 test/data/bricks-color.qoi
|
||||
OK. 076cb375 test/data/bricks-color.tga
|
||||
OK. f36c2e80 test/data/bricks-dither.bmp
|
||||
OK. f36c2e80 test/data/bricks-dither.gif
|
||||
OK. f36c2e80 test/data/bricks-dither.lossless.webp
|
||||
OK. f36c2e80 test/data/bricks-dither.no-ancillary.png
|
||||
OK. f36c2e80 test/data/bricks-dither.png
|
||||
OK. c2bce675 test/data/bricks-gray.bmp
|
||||
OK. c2bce675 test/data/bricks-gray.gif
|
||||
OK. 3a2478ad test/data/bricks-gray.jpeg
|
||||
OK. c2bce675 test/data/bricks-gray.lossless.webp
|
||||
OK. c2bce675 test/data/bricks-gray.no-ancillary.png
|
||||
OK. c2bce675 test/data/bricks-gray.png
|
||||
OK. c2bce675 test/data/bricks-gray.tga
|
||||
OK. 7aebfe6c test/data/bricks-nodither.bmp
|
||||
OK. 7aebfe6c test/data/bricks-nodither.gif
|
||||
OK. 7aebfe6c test/data/bricks-nodither.lossless.webp
|
||||
OK. 7aebfe6c test/data/bricks-nodither.png
|
||||
OK. 7aebfe6c test/data/bricks-nodither.tga
|
||||
OK. ae2e547d test/data/bricks-nodither.wbmp
|
||||
OK. b47730a2 test/data/checkerboard.gamma1dot0.png
|
||||
OK. b47730a2 test/data/checkerboard.gamma2dot2.png
|
||||
OK. aa3e6c7c test/data/crude-flag.nie
|
||||
OK. 3014b4c0 test/data/gifplayer-muybridge.gif
|
||||
OK. 030f5a48 test/data/harvesters.bmp
|
||||
OK. c18b3d5a test/data/harvesters.gif
|
||||
OK. f217df74 test/data/harvesters.jpeg
|
||||
OK. 030f5a48 test/data/harvesters.lossless.webp
|
||||
OK. 030f5a48 test/data/harvesters.png
|
||||
OK. e776c90f test/data/hat.bmp
|
||||
OK. 6dcba6a4 test/data/hat.gif
|
||||
OK. 2298f3ca test/data/hat.jpeg
|
||||
OK. e776c90f test/data/hat.lossless.webp
|
||||
OK. e776c90f test/data/hat.png
|
||||
OK. d30bfe5d test/data/hat.wbmp
|
||||
OK. 33a44f22 test/data/hibiscus.primitive.bmp
|
||||
OK. 25e212b3 test/data/hibiscus.primitive.gif
|
||||
OK. 9624fa44 test/data/hibiscus.primitive.jpeg
|
||||
OK. 33a44f22 test/data/hibiscus.primitive.lossless.webp
|
||||
OK. 33a44f22 test/data/hibiscus.primitive.png
|
||||
OK. 60040742 test/data/hibiscus.regular.bmp
|
||||
OK. b727da8b test/data/hibiscus.regular.gif
|
||||
OK. 41e39405 test/data/hibiscus.regular.jpeg
|
||||
OK. 60040742 test/data/hibiscus.regular.lossless.webp
|
||||
OK. 60040742 test/data/hibiscus.regular.png
|
||||
OK. dcbb225a test/data/hippopotamus.bmp
|
||||
OK. ed4b78fc test/data/hippopotamus.interlaced.gif
|
||||
OK. dcbb225a test/data/hippopotamus.interlaced.png
|
||||
BAD c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
|
||||
BAD 7c6a771b test/data/hippopotamus.interlaced.truncated.png
|
||||
OK. 96bdbbb3 test/data/hippopotamus.jpeg
|
||||
OK. dcbb225a test/data/hippopotamus.lossless.webp
|
||||
OK. d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
OK. 7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
|
||||
OK. dcbb225a test/data/hippopotamus.nie
|
||||
OK. 57d9a4dd test/data/hippopotamus.pgm
|
||||
OK. dcbb225a test/data/hippopotamus.ppm
|
||||
OK. ed4b78fc test/data/hippopotamus.regular.gif
|
||||
OK. dcbb225a test/data/hippopotamus.regular.png
|
||||
BAD 888b1c04 test/data/hippopotamus.regular.truncated.png
|
||||
OK. 2dccfe56 test/data/muybridge-frame-000.wbmp
|
||||
OK. db2733f5 test/data/muybridge.apng
|
||||
OK. db2733f5 test/data/muybridge.gif
|
||||
OK. d42a13cd test/data/peacock.default.jpeg
|
||||
OK. c8a50351 test/data/peacock.default.truncated.decoded-by-djpeg.png
|
||||
OK. 91b6bebb test/data/peacock.default.truncated.decoded-by-wuffs.png
|
||||
BAD 91b6bebb test/data/peacock.default.truncated.jpeg
|
||||
OK. d49bab2d test/data/peacock.grayscale.jpeg
|
||||
OK. d42a13cd test/data/peacock.optimize.jpeg
|
||||
OK. bdf8cc70 test/data/peacock.png
|
||||
OK. bdf8cc70 test/data/peacock.ppm
|
||||
OK. d42a13cd test/data/peacock.progressive.jpeg
|
||||
OK. 52e723b6 test/data/peacock.progressive.scan000.jpeg
|
||||
OK. 79c58501 test/data/peacock.progressive.scan001.jpeg
|
||||
OK. c0b6c555 test/data/peacock.progressive.scan002.jpeg
|
||||
OK. ec5a371f test/data/peacock.progressive.scan003.jpeg
|
||||
OK. 487afc66 test/data/peacock.progressive.scan004.jpeg
|
||||
OK. b12a7c4f test/data/peacock.progressive.scan005.jpeg
|
||||
OK. 610eb71e test/data/peacock.progressive.scan006.jpeg
|
||||
OK. 0adacc97 test/data/peacock.progressive.scan007.jpeg
|
||||
OK. bc00fee5 test/data/peacock.progressive.scan008.jpeg
|
||||
OK. d42a13cd test/data/peacock.progressive.scan009.jpeg
|
||||
OK. 2ba9d5b9 test/data/peacock.progressive.truncated.decoded-by-djpeg.png
|
||||
OK. 245d37de test/data/peacock.progressive.truncated.decoded-by-wuffs.png
|
||||
BAD 245d37de test/data/peacock.progressive.truncated.jpeg
|
||||
OK. 951676cc test/data/peacock.q30.jpeg
|
||||
OK. 56835223 test/data/peacock.q99.jpeg
|
||||
OK. 7fa9064e test/data/peacock.s-very-weird.jpeg
|
||||
OK. 1543f677 test/data/peacock.s-weird.jpeg
|
||||
OK. 5437be55 test/data/peacock.s1x1-444.jpeg
|
||||
OK. a9d83d57 test/data/peacock.s1x3.jpeg
|
||||
OK. 6862951e test/data/peacock.s2x1-422.jpeg
|
||||
OK. d42a13cd test/data/peacock.s2x2-420.jpeg
|
||||
OK. bf7e8c96 test/data/pjw-thumbnail.bmp
|
||||
OK. bf7e8c96 test/data/pjw-thumbnail.gif
|
||||
OK. 7c67a37f test/data/pjw-thumbnail.jpeg
|
||||
OK. bf7e8c96 test/data/pjw-thumbnail.lossless.webp
|
||||
OK. bf7e8c96 test/data/pjw-thumbnail.png
|
||||
OK. 38cb4cbf test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png
|
||||
OK. 38cb4cbf test/data/red-blue-gradient.gamma1dot0.png
|
||||
OK. 38cb4cbf test/data/red-blue-gradient.gamma1dot8.png
|
||||
OK. 38cb4cbf test/data/red-blue-gradient.gamma2dot2.png
|
||||
OK. 38cb4cbf test/data/red-blue-gradient.vanilla.png
|
||||
OK. 75060601 test/data/rgb24png.bmp
|
||||
OK. 79ab18b6 test/data/ridiculously-fast.png
|
||||
Reference in new issue
Block a user