Compare commits

...
198 Commits
Author SHA1 Message Date
Nigel Tao 6381a325eb release: wuffs gen -version=0.4.0-alpha.1 2023-10-06 16:16:22 +11:00
Nigel Tao 5336b511e0 std/xxhash32: add SIMD comment 2023-10-06 14:19:48 +11:00
Nigel Tao be2eb64a51 Roll back 'std/xxhash32: add hasher.up_x86_sse42'
See the previous commit for the rationale.
2023-10-06 14:04:56 +11:00
Nigel Tao b9b28dbe8b std/xxhash32: add hasher.up_x86_sse42
This commit will soon be followed by a rollback, but it is committed
anyway so that we can refer to these numbers in the git log.

name                         old speed      new speed      delta

wuffs_xxhash32_10k/clang11   7.81GB/s ± 0%  4.46GB/s ± 1%  -42.86%  (p=0.008 n=5+5)
wuffs_xxhash32_100k/clang11  7.96GB/s ± 0%  4.67GB/s ± 1%  -41.34%  (p=0.008 n=5+5)

wuffs_xxhash32_10k/gcc10     7.83GB/s ± 0%  4.48GB/s ± 2%  -42.81%  (p=0.008 n=5+5)
wuffs_xxhash32_100k/gcc10    7.95GB/s ± 0%  4.69GB/s ± 2%  -41.04%  (p=0.008 n=5+5)

mimic_xxhash32_10k           7.70GB/s ± 1%  7.73GB/s ± 1%     ~     (p=0.421 n=5+5)
mimic_xxhash32_100k          7.79GB/s ± 0%  7.84GB/s ± 1%     ~     (p=0.730 n=4+5)
2023-10-06 13:59:31 +11:00
Nigel Tao 1304ee6265 std/xxhash64: add new package 2023-10-06 13:10:47 +11:00
Nigel Tao e766e9ecde check: ensure interface methods are public 2023-10-06 10:48:07 +11:00
Nigel Tao 88efa8360f base: add hasher_u64 2023-10-06 10:33:53 +11:00
Nigel Tao 74a6ea2fcd all: relicense from Apache2 to dual Apache2/MIT
The LICENSE has changed from a single license (Apache2) to a dual
license (Apache2 or MIT, at your option).

If you've previously used Wuffs under the Apache2 license, you are able
to keep doing so. No further action required by you.

The two files listed below (previous releases) are exceptions, as they
are older snapshots, frozen in time. Their license has not changed:
release/c/wuffs-v0.2.c
release/c/wuffs-v0.3.c

Every name in the AUTHORS file, other than Google Inc., has signed
Google's CLA (Contributor License Agreement).
2023-10-06 10:00:59 +11:00
Nigel Tao 80b1988237 std: add hasher_u32 update!, checksum_u32 methods 2023-10-05 19:27:02 +11:00
Nigel Tao b5eee6ac4f doc/std: update lists of base interface methods 2023-10-05 19:08:34 +11:00
Nigel Tao bec02d7c31 std/xxhash32: add new package 2023-10-05 19:08:22 +11:00
Nigel Tao 5fb82e7d0a std: add compact_retaining, history_retain_length 2023-10-05 13:24:44 +11:00
Nigel Tao 0f91f23bb6 std/jpeg: prefer decode_frame errors over swizzle
"g++ script/manual-test-truncated-input.cc && ./a.out test/data/*" is
now happy.
2023-10-04 22:27:41 +11:00
Nigel Tao 68b94fc206 std/gif: remove obsolete use "std/lzw" line 2023-10-04 20:28:05 +11:00
Nigel Tao 59aa09a7ee script: fix wuffs_foo__bar::unique_ptr decls 2023-10-04 20:25:24 +11:00
Nigel Tao 8e42e01d3c std/gif: remove the std/lzw dependency
name                                         old speed      new speed      delta

wuffs_gif_decode_1k_bw/clang11                683MB/s ± 0%   682MB/s ± 0%     ~     (p=0.690 n=5+5)
wuffs_gif_decode_1k_color_full_init/clang11   168MB/s ± 0%   184MB/s ± 0%  +10.01%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/clang11   204MB/s ± 0%   230MB/s ± 0%  +12.77%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/clang11             746MB/s ± 0%   819MB/s ± 0%   +9.90%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/clang11          200MB/s ± 0%   218MB/s ± 0%   +8.97%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/clang11                  246MB/s ± 0%   257MB/s ± 0%   +4.33%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/clang11      543MB/s ± 0%   562MB/s ± 0%   +3.44%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/clang11       210MB/s ± 0%   220MB/s ± 0%   +4.90%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_full_init/clang11      214MB/s ± 0%   224MB/s ± 0%   +4.96%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/clang11      214MB/s ± 0%   224MB/s ± 0%   +4.98%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/clang11      1.24GB/s ± 0%  1.29GB/s ± 0%   +3.85%  (p=0.008 n=5+5)

wuffs_gif_decode_1k_bw/gcc10                  649MB/s ± 0%   588MB/s ± 0%   -9.42%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/gcc10     167MB/s ± 0%   198MB/s ± 0%  +18.57%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/gcc10     195MB/s ± 0%   251MB/s ± 0%  +28.64%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/gcc10               753MB/s ± 0%   871MB/s ± 0%  +15.64%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/gcc10            199MB/s ± 0%   233MB/s ± 0%  +16.86%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/gcc10                    258MB/s ± 0%   265MB/s ± 0%   +2.93%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/gcc10        560MB/s ± 0%   561MB/s ± 0%   +0.19%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/gcc10         221MB/s ± 0%   227MB/s ± 0%   +2.65%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_full_init/gcc10        227MB/s ± 0%   232MB/s ± 0%   +2.29%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/gcc10        227MB/s ± 0%   232MB/s ± 0%   +2.28%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/gcc10        1.29GB/s ± 0%  1.28GB/s ± 0%   -0.22%  (p=0.008 n=5+5)
2023-10-04 20:19:25 +11:00
Nigel Tao 6f79c182ea lang/ast: add TypeExpr.IsXxx methods 2023-10-04 17:09:59 +11:00
Nigel Tao 2f5108978d base: add magic numbers for LZMA, XZ 2023-10-04 10:12:04 +11:00
Nigel Tao 6184059c05 test/3pdata: tweak blinksuite JPEG commentary 2023-09-27 22:31:37 +10:00
Nigel Tao ca50faaa92 test/3pdata: add more commentary about djpeg diffs 2023-09-26 22:09:25 +10:00
Nigel Tao bffbad69a4 cgen: halve the sizeof wuffs_foo__bar::unique_ptr 2023-09-24 21:22:22 +10:00
Nigel Tao bdba035779 cgen: ignore -Wcast-qual when making a roslice 2023-09-24 12:18:52 +10:00
Nigel Tao 70c1a78cd8 test/3pdata: add etc-blinksuite.commentary.md 2023-09-24 11:50:55 +10:00
Nigel Tao d6dceacf5e root: add Mascot section to the README.md 2023-09-23 12:11:32 +10:00
Nigel Tao 186bdc5fe2 Roll back 'decode truncated... on MCU boundaries'
See the previous commit for the rationale.
2023-09-16 20:53:15 +10:00
Nigel Tao a3cecef69a std/jpeg: decode truncated JPEGs on MCU boundaries
This only affects truncated (malformed) JPEGs. It moves Wuffs' std/jpeg
decoder closer to libjpeg-turbo, as seen by the "hash of the decoded
output" for test/data/peacock.default.truncated.jpeg now matching
test/data/peacock.default.truncated.decoded-by-djpeg.png instead of
test/data/peacock.default.truncated.decoded-by-wuffs.png

The decoding of test/data/peacock.progressive.truncated.jpeg is not yet
affected, requiring further investigation, but a future commit could
similarly make that match djpeg.

The two libraries don't use exactly the same algorithm because, for
performance, Wuffs' decoder reads from the bitstream 8 bytes at a time
where libjpeg-turbo reads only 1 byte at a time.

While this change moves Wuffs' output closer to libjpeg-turbo (to
repeat, only for truncated JPEGs; well-formed JPEGs are unaffected), the
benchmarks below show a negative performance impact, and visual
inspection of test/data/peacock.*.truncated.decoded-by-*.png shows that
matching libjpeg-turbo *exactly* on truncated JPEGs doesn't actually
always look better.

On balance, it doesn't seem worth it to keep this change (and spend more
time on that further investigation).

This commit will soon be followed by a rollback, but it is committed
anyway so that we can refer to these numbers in the git log.

name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                378MB/s ± 0%   364MB/s ± 0%  -3.53%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   325MB/s ± 0%   340MB/s ± 0%  +4.62%  (p=0.016 n=5+4)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.02GB/s ± 0%  0.99GB/s ± 0%  -2.64%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               842MB/s ± 0%   815MB/s ± 0%  -3.16%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          916MB/s ± 0%   887MB/s ± 0%  -3.08%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.10GB/s ± 0%  1.07GB/s ± 2%  -3.39%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             919MB/s ± 0%   892MB/s ± 0%  -2.95%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  360MB/s ± 0%   348MB/s ± 0%  -3.34%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     290MB/s ± 0%   283MB/s ± 0%  -2.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      925MB/s ± 0%   909MB/s ± 0%  -1.70%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 758MB/s ± 0%   732MB/s ± 0%  -3.43%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            829MB/s ± 0%   799MB/s ± 0%  -3.54%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10            981MB/s ± 0%   964MB/s ± 0%  -1.72%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               835MB/s ± 0%   811MB/s ± 0%  -2.89%  (p=0.008 n=5+5)
2023-09-16 20:49:46 +10:00
Nigel Tao 721463be95 test/data: add PNGs of truncated-JPEG decodings
"Decoded by wuffs" means as of commit 268b9594.

"Decoded by djpeg" means as of libjpeg-turbo version 3.0.1.
2023-09-16 14:43:19 +10:00
Nigel Tao 268b959462 script: add print-jpeg-markers.go
Also make truncate-progressive-jpeg.go work with reset markers.
2023-09-10 18:12:55 +10:00
Nigel Tao d89ec2d40b std/jpeg: drain bitstream for truncated input
name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                367MB/s ± 0%   378MB/s ± 0%  +2.91%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   333MB/s ± 0%   325MB/s ± 0%  -2.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.00GB/s ± 0%  1.02GB/s ± 0%  +1.37%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               822MB/s ± 0%   842MB/s ± 0%  +2.39%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          898MB/s ± 0%   916MB/s ± 0%  +1.98%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.09GB/s ± 0%  1.10GB/s ± 0%  +1.21%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             898MB/s ± 0%   919MB/s ± 0%  +2.29%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  362MB/s ± 0%   360MB/s ± 0%  -0.55%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     292MB/s ± 0%   290MB/s ± 0%  -0.57%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      934MB/s ± 0%   925MB/s ± 0%  -1.03%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 759MB/s ± 0%   758MB/s ± 0%  -0.25%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            828MB/s ± 0%   829MB/s ± 0%    ~     (p=0.222 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           1.00GB/s ± 0%  0.98GB/s ± 0%  -1.44%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               837MB/s ± 0%   835MB/s ± 0%  -0.29%  (p=0.008 n=5+5)
2023-08-28 19:35:08 +10:00
Nigel Tao 813c054c18 example: add ALLOW_GIGABYTES_OF_PIXEL_BUFFERS 2023-08-27 22:15:09 +10:00
Nigel Tao 4f67db8842 script: confirm-matches-djpeg note truncated input 2023-08-27 21:17:57 +10:00
Nigel Tao 00d180ae74 std/jpeg: make decode_mcu* num-bits ask consistent
name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                367MB/s ± 0%   367MB/s ± 0%  -0.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   332MB/s ± 0%   333MB/s ± 0%  +0.41%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.00GB/s ± 0%  1.00GB/s ± 0%  +0.44%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               821MB/s ± 0%   822MB/s ± 0%  +0.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          896MB/s ± 0%   898MB/s ± 0%  +0.17%  (p=0.032 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.09GB/s ± 0%  1.09GB/s ± 0%    ~     (p=0.095 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             898MB/s ± 0%   898MB/s ± 0%    ~     (p=0.786 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  364MB/s ± 0%   362MB/s ± 0%  -0.45%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     293MB/s ± 0%   292MB/s ± 0%  -0.31%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      932MB/s ± 0%   934MB/s ± 0%  +0.20%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 762MB/s ± 0%   759MB/s ± 0%  -0.35%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            833MB/s ± 0%   828MB/s ± 0%  -0.54%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           1.00GB/s ± 0%  1.00GB/s ± 0%  -0.25%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               841MB/s ± 0%   837MB/s ± 0%  -0.49%  (p=0.016 n=4+5)
2023-08-27 10:35:05 +10:00
Nigel Tao dfe5bcd36e std/jpeg: decode something for truncated input 2023-08-27 10:15:40 +10:00
Nigel Tao 45350db8ca test/data: add peacock.*.truncated.jpeg 2023-08-26 10:41:46 +10:00
Nigel Tao 80e847dceb std/jpeg: stash mcu_blocks during progressive IDCT 2023-08-25 23:03:06 +10:00
Nigel Tao 4417dcea4e std/jpeg: use default Huffman tables if missing 2023-08-24 16:18:11 +10:00
Nigel Tao eca57ef5b3 base: add status.is_truncated_input_error
This just adds a C/C++ function/method. We may or may not add the
corresponding Wuffs method in a future commit.
2023-08-24 16:11:15 +10:00
Nigel Tao 7d4ef9c122 fuzz: let pixel_swizzler_fuzzer do 4 components 2023-08-22 16:31:38 +10:00
Nigel Tao 7cdeeadbf4 fuzz: fix pixel_swizzler_fuzzer build 2023-08-21 22:22:31 +10:00
Nigel Tao 6489915ed3 std/jpeg: decode CMYK and YCbCrK JPEGs
Once again, the benchmarks don't exercise the CMYK / YCbCrK code paths
per se, but here are the numbers:

name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                376MB/s ± 0%   376MB/s ± 0%    ~     (p=0.310 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   341MB/s ± 0%   340MB/s ± 0%  -0.42%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.01GB/s ± 0%  1.01GB/s ± 0%  +0.27%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               836MB/s ± 1%   839MB/s ± 0%  +0.37%  (p=0.016 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          912MB/s ± 0%   914MB/s ± 0%  +0.28%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.10GB/s ± 0%  1.11GB/s ± 0%  +0.82%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             916MB/s ± 0%   916MB/s ± 0%    ~     (p=0.841 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  368MB/s ± 0%   361MB/s ± 0%  -1.87%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     279MB/s ± 0%   292MB/s ± 0%  +4.68%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      947MB/s ± 1%   930MB/s ± 0%  -1.74%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 770MB/s ± 0%   760MB/s ± 0%  -1.32%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            838MB/s ± 0%   826MB/s ± 0%  -1.36%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           1.00GB/s ± 0%  1.01GB/s ± 0%  +1.04%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               847MB/s ± 0%   833MB/s ± 0%  -1.67%  (p=0.008 n=5+5)
2023-08-21 22:13:39 +10:00
Nigel Tao f569699221 pixconv: rename private etc__convert_func type 2023-08-21 19:34:47 +10:00
Nigel Tao 72b9c23120 std/jpeg: decode RGB (not just YCbCr) JPEGs
The benchmarks don't exercise the RGB code paths per se, but it does
affect the numbers. Especially for gcc, this essentially undoes the
performance impact of the previous (trivial) commit. This is all
presumably another code alignment coincidence per
https://news.ycombinator.com/item?id=23633583

name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                376MB/s ± 0%   376MB/s ± 0%     ~     (p=1.000 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   338MB/s ± 0%   341MB/s ± 0%   +0.98%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.01GB/s ± 0%  1.01GB/s ± 0%   +0.35%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               841MB/s ± 0%   836MB/s ± 1%   -0.65%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          913MB/s ± 0%   912MB/s ± 0%   -0.18%  (p=0.016 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.11GB/s ± 0%  1.10GB/s ± 0%   -0.34%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             920MB/s ± 0%   916MB/s ± 0%   -0.42%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  349MB/s ± 0%   368MB/s ± 0%   +5.60%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     328MB/s ± 0%   279MB/s ± 0%  -14.82%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      925MB/s ± 0%   947MB/s ± 1%   +2.33%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 732MB/s ± 0%   770MB/s ± 0%   +5.23%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            798MB/s ± 0%   838MB/s ± 0%   +4.99%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10            962MB/s ± 0%   996MB/s ± 0%   +3.54%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               806MB/s ± 0%   847MB/s ± 0%   +5.19%  (p=0.008 n=5+5)
2023-08-21 16:12:21 +10:00
Nigel Tao 748e44fe71 base: skip bulk load/save on short slice length
This is about semantics (being easier to reason about if transforming
between u32 and u8 and the u8 slice length is short and not a multiple
of 4). It's not an optimization per se, but for the record, it does have
significant performance impact:

name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                369MB/s ± 0%   376MB/s ± 0%   +1.97%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   309MB/s ± 0%   338MB/s ± 0%   +9.29%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.00GB/s ± 0%  1.01GB/s ± 0%   +1.31%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               827MB/s ± 0%   841MB/s ± 0%   +1.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          897MB/s ± 0%   913MB/s ± 0%   +1.86%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.10GB/s ± 0%  1.11GB/s ± 0%   +0.11%  (p=0.024 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             900MB/s ± 0%   920MB/s ± 0%   +2.20%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  369MB/s ± 0%   349MB/s ± 0%   -5.45%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     283MB/s ± 0%   328MB/s ± 0%  +15.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      945MB/s ± 0%   925MB/s ± 0%   -2.12%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 769MB/s ± 0%   732MB/s ± 0%   -4.88%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            842MB/s ± 0%   798MB/s ± 0%   -5.25%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           1.01GB/s ± 0%  0.96GB/s ± 0%   -4.77%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               848MB/s ± 0%   806MB/s ± 0%   -4.96%  (p=0.008 n=5+5)
2023-08-19 21:18:53 +10:00
Nigel Tao 14a8bd0feb std/jpeg: allow fewer-components sequential scans
name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                366MB/s ± 0%   369MB/s ± 0%  +0.81%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   302MB/s ± 0%   309MB/s ± 0%  +2.28%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.00GB/s ± 0%  1.00GB/s ± 0%  -0.58%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               820MB/s ± 0%   827MB/s ± 0%  +0.80%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          895MB/s ± 0%   897MB/s ± 0%  +0.24%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.11GB/s ± 0%  1.10GB/s ± 0%  -0.30%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             897MB/s ± 0%   900MB/s ± 0%  +0.30%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  370MB/s ± 0%   369MB/s ± 0%  -0.26%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     309MB/s ± 0%   283MB/s ± 0%  -8.35%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      948MB/s ± 0%   945MB/s ± 0%  -0.27%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 769MB/s ± 0%   769MB/s ± 0%    ~     (p=0.310 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            841MB/s ± 0%   842MB/s ± 0%  +0.13%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           1.00GB/s ± 0%  1.01GB/s ± 0%  +0.75%  (p=0.016 n=4+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               846MB/s ± 0%   848MB/s ± 0%  +0.22%  (p=0.008 n=5+5)
2023-08-19 17:22:47 +10:00
Nigel Tao 2f5f203d1b test/3pdata: regenerate nia-checksums-of-*.txt 2023-08-19 17:18:11 +10:00
Nigel Tao 41d0c095c8 std/jpeg: implement block smoothing
"script/confirm-matches-djpeg.sh test/data/*.jpeg" is now all matches.

name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                369MB/s ± 0%   366MB/s ± 0%   -0.79%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   335MB/s ± 0%   302MB/s ± 0%   -9.93%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.01GB/s ± 0%  1.00GB/s ± 0%   -1.07%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               829MB/s ± 0%   820MB/s ± 0%   -1.03%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          903MB/s ± 0%   895MB/s ± 0%   -0.93%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         1.12GB/s ± 0%  1.11GB/s ± 0%   -1.28%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             906MB/s ± 0%   897MB/s ± 0%   -0.93%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  350MB/s ± 0%   370MB/s ± 0%   +5.54%  (p=0.016 n=4+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     334MB/s ± 0%   309MB/s ± 0%   -7.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      924MB/s ± 0%   948MB/s ± 0%   +2.61%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 745MB/s ± 0%   769MB/s ± 0%   +3.25%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            813MB/s ± 0%   841MB/s ± 0%   +3.41%  (p=0.029 n=4+4)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           1.00GB/s ± 0%  1.00GB/s ± 0%   +0.25%  (p=0.029 n=4+4)
wuffs_jpeg_decode_4002k_24bpp/gcc10               821MB/s ± 0%   846MB/s ± 0%   +3.00%  (p=0.008 n=5+5)
2023-08-19 17:16:51 +10:00
Nigel Tao d60bfb05e8 check: ban bulk methods on slices of refined types 2023-08-06 15:30:42 +10:00
Nigel Tao be9d3fcf0f example/convert-to-nia: add -output-netpbm flag 2023-08-06 10:49:53 +10:00
Nigel Tao 9c3275658a doc: add note about shipping in Google Chrome M93 2023-08-03 17:38:43 +10:00
Nigel Tao fd5ab5f7b3 pixconv: tweak "if (triangle_filter_for_2to1)" 2023-07-31 16:05:10 +10:00
Nigel Tao 836a878861 pixconv: remove unused total_src_len? variables 2023-07-31 09:38:00 +10:00
Nigel Tao 5afaa8911c pixconv: guard swizzle_ycc__etc__avx2 with #ifdef 2023-07-30 18:52:16 +10:00
Nigel Tao e60966aa45 pixconv: remove some obsolete swizzle_ycc code 2023-07-30 17:49:19 +10:00
Nigel Tao b3d0d7b855 pixconv: apply YCC->RGB SIMD code to 444 JPEGs
name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                368MB/s ± 0%   368MB/s ± 0%     ~     (p=0.421 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   333MB/s ± 0%   335MB/s ± 0%   +0.54%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.01GB/s ± 0%  1.01GB/s ± 0%   +0.38%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               829MB/s ± 0%   828MB/s ± 0%   -0.16%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          902MB/s ± 0%   902MB/s ± 0%     ~     (p=0.690 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11          649MB/s ± 0%  1121MB/s ± 0%  +72.72%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             905MB/s ± 0%   906MB/s ± 0%     ~     (p=0.222 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  362MB/s ± 0%   351MB/s ± 0%   -3.06%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     328MB/s ± 0%   330MB/s ± 0%   +0.53%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      926MB/s ± 0%   921MB/s ± 0%   -0.54%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 757MB/s ± 0%   743MB/s ± 0%   -1.83%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            835MB/s ± 0%   814MB/s ± 0%   -2.55%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10            655MB/s ± 0%  1001MB/s ± 0%  +52.74%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               843MB/s ± 0%   820MB/s ± 0%   -2.70%  (p=0.016 n=4+5)
2023-07-30 15:56:59 +10:00
Nigel Tao 3dbfb00c42 pixconv: add godbolt comment for upsample code 2023-07-29 11:49:08 +10:00
Nigel Tao 2687d1daaf pixconv: fix -Werror=pedantic/overflow errors 2023-07-23 22:11:19 +10:00
Nigel Tao bfc7fc2f45 std/jpeg: add upsample_inv_h2v2 GCC AVX2 comment 2023-07-23 22:04:02 +10:00
Nigel Tao 51bc60ef92 std/jpeg: avoid AVX2 upsample_inv_h2v2 for GCC
name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                369MB/s ± 0%   368MB/s ± 0%     ~     (p=1.000 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   332MB/s ± 0%   333MB/s ± 0%   +0.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.01GB/s ± 0%  1.01GB/s ± 0%     ~     (p=1.000 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               829MB/s ± 0%   829MB/s ± 0%     ~     (p=0.905 n=4+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11          902MB/s ± 0%   902MB/s ± 0%     ~     (p=0.548 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11          649MB/s ± 0%   649MB/s ± 0%     ~     (p=0.841 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             904MB/s ± 0%   905MB/s ± 0%   +0.14%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  322MB/s ± 0%   362MB/s ± 0%  +12.60%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     284MB/s ± 0%   328MB/s ± 0%  +15.63%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      908MB/s ± 0%   926MB/s ± 0%   +2.04%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 730MB/s ± 0%   757MB/s ± 0%   +3.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            785MB/s ± 0%   835MB/s ± 0%   +6.40%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10            625MB/s ± 0%   655MB/s ± 0%   +4.76%  (p=0.016 n=4+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10               783MB/s ± 0%   843MB/s ± 0%   +7.57%  (p=0.016 n=5+4)
2023-07-23 21:59:52 +10:00
Nigel Tao 5dfc913cb0 base: let cpu_arch__have_x86_etc return true 2023-07-23 21:48:33 +10:00
Nigel Tao e2b9566fc5 base: restrict x86_avx2 to 64-bit (not 32-bit) x86
32-bit C/C++ compilers don't always compile the AVX intrinsics. Per the
60773 bug below,
> clang++ -m32 etc etc fuzz/c/std/jpeg_fuzzer.c
> undefined reference to `_mm_cvtsi128_si64'
> undefined reference to `_mm256_extract_epi64'

See also the "#ifdef __x86_64__" guards in
https://github.com/gcc-mirror/gcc/blob/4a3895903c29ed85da6fcb886f31ff23d4c6e935/gcc/config/i386/emmintrin.h#L228-L231
https://github.com/llvm/llvm-project/blob/08fab9ebecf72a682279d75489dc2460121cbeed/clang/lib/Headers/emmintrin.h#L3502-L3515

Note that -m32 is not the same as -mx32
> $ touch empty.c
> $ gcc       -dM -E empty.c | grep -E '__i386__|__x86_64__'
> #define __x86_64__ 1
> $ gcc -m32  -dM -E empty.c | grep -E '__i386__|__x86_64__'
> #define __i386__ 1
> $ gcc -mx32 -dM -E empty.c | grep -E '__i386__|__x86_64__'
> #define __x86_64__ 1

Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60773
2023-07-23 21:20:35 +10:00
Nigel Tao 605b10a492 pixconv: fix cpu_arch__have_x86_avx2 copy/pasto
Not sure why the benchmark numbers change, but they do.

name                                             old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                376MB/s ± 0%   369MB/s ± 0%  -2.06%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11   311MB/s ± 0%   332MB/s ± 0%  +6.69%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   1.02GB/s ± 0%  1.01GB/s ± 0%  -1.35%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11               842MB/s ± 0%   829MB/s ± 0%  -1.54%  (p=0.016 n=5+4)
wuffs_jpeg_decode_552k_24bpp_420/clang11          917MB/s ± 0%   902MB/s ± 0%  -1.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11          649MB/s ± 0%   649MB/s ± 0%    ~     (p=0.548 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11             921MB/s ± 0%   904MB/s ± 0%  -1.82%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                  326MB/s ± 0%   322MB/s ± 0%  -1.26%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10     292MB/s ± 0%   284MB/s ± 0%  -2.69%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10      920MB/s ± 0%   908MB/s ± 0%  -1.31%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                 742MB/s ± 0%   730MB/s ± 0%  -1.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10            792MB/s ± 0%   785MB/s ± 0%  -0.94%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10            627MB/s ± 0%   625MB/s ± 0%  -0.23%  (p=0.029 n=4+4)
wuffs_jpeg_decode_4002k_24bpp/gcc10               792MB/s ± 0%   783MB/s ± 0%  -1.13%  (p=0.008 n=5+5)
2023-07-23 21:13:43 +10:00
Nigel Tao cd769a0cdf pixconv: add upsample_inv_h2v2_triangle_x86_avx2
name                                             old speed     new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11               370MB/s ± 0%   376MB/s ± 0%   +1.84%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  295MB/s ± 0%   311MB/s ± 0%   +5.56%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   726MB/s ± 0%  1021MB/s ± 0%  +40.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              622MB/s ± 0%   842MB/s ± 0%  +35.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         659MB/s ± 0%   917MB/s ± 0%  +39.15%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         649MB/s ± 0%   649MB/s ± 0%   -0.09%  (p=0.016 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            675MB/s ± 0%   921MB/s ± 0%  +36.49%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 351MB/s ± 0%   326MB/s ± 0%   -7.21%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    334MB/s ± 0%   292MB/s ± 0%  -12.67%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     924MB/s ± 0%   920MB/s ± 0%   -0.41%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                740MB/s ± 0%   742MB/s ± 0%   +0.27%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           812MB/s ± 0%   792MB/s ± 0%   -2.38%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           647MB/s ± 0%   627MB/s ± 0%   -3.16%  (p=0.016 n=5+4)
wuffs_jpeg_decode_4002k_24bpp/gcc10              817MB/s ± 0%   792MB/s ± 0%   -3.01%  (p=0.016 n=4+5)
2023-07-23 12:03:07 +10:00
Nigel Tao fed3da528c pixconv: add pixel swizzler x86_sse42 prototypes 2023-07-22 13:23:37 +10:00
Nigel Tao 35c1f76f86 pixconv: add swizzle_ycc__convert_rgbx_x86_avx2
Some of the benchmark numbers move around even though they don't use the
new etc__convert_rgbx_x86_avx2 code paths. It's possibly just a code
alignment coincidence per https://news.ycombinator.com/item?id=23633583

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               372MB/s ± 0%  370MB/s ± 0%  -0.64%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  278MB/s ± 0%  295MB/s ± 0%  +5.89%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   710MB/s ± 0%  726MB/s ± 0%  +2.30%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              603MB/s ± 0%  622MB/s ± 0%  +3.12%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         635MB/s ± 0%  659MB/s ± 0%  +3.82%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         650MB/s ± 0%  649MB/s ± 0%  -0.17%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            629MB/s ± 0%  675MB/s ± 0%  +7.20%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 364MB/s ± 0%  351MB/s ± 0%  -3.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    334MB/s ± 0%  334MB/s ± 0%  -0.06%  (p=0.032 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     944MB/s ± 0%  924MB/s ± 0%  -2.19%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                769MB/s ± 0%  740MB/s ± 0%  -3.75%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           842MB/s ± 0%  812MB/s ± 0%  -3.60%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           661MB/s ± 0%  647MB/s ± 0%  -2.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              849MB/s ± 0%  817MB/s ± 0%  -3.77%  (p=0.016 n=5+4)
2023-07-22 13:11:12 +10:00
Nigel Tao 4facef4e01 pixconv: add swizzle_ycc__convert_bgrx_x86_avx2
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               365MB/s ± 1%  372MB/s ± 0%   +1.77%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  241MB/s ± 0%  278MB/s ± 0%  +15.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   477MB/s ± 0%  710MB/s ± 0%  +48.91%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              429MB/s ± 0%  603MB/s ± 0%  +40.56%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         446MB/s ± 0%  635MB/s ± 0%  +42.18%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         644MB/s ± 0%  650MB/s ± 0%   +1.06%  (p=0.016 n=4+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            458MB/s ± 0%  629MB/s ± 0%  +37.46%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 352MB/s ± 0%  364MB/s ± 0%   +3.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    295MB/s ± 0%  334MB/s ± 0%  +13.19%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     669MB/s ± 0%  944MB/s ± 0%  +41.07%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                567MB/s ± 0%  769MB/s ± 0%  +35.59%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           605MB/s ± 0%  842MB/s ± 0%  +39.07%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           647MB/s ± 0%  661MB/s ± 0%   +2.19%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              613MB/s ± 0%  849MB/s ± 0%  +38.61%  (p=0.008 n=5+5)
2023-07-22 12:51:51 +10:00
Nigel Tao 10d4ff7532 pixconv: factor out swizzle_ycc__convert_func
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               368MB/s ± 0%  365MB/s ± 1%  -0.75%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  231MB/s ± 0%  241MB/s ± 0%  +4.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   470MB/s ± 0%  477MB/s ± 0%  +1.35%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              416MB/s ± 0%  429MB/s ± 0%  +3.14%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         433MB/s ± 0%  446MB/s ± 0%  +3.02%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         646MB/s ± 0%  644MB/s ± 0%  -0.39%  (p=0.016 n=5+4)
wuffs_jpeg_decode_4002k_24bpp/clang11            439MB/s ± 0%  458MB/s ± 0%  +4.35%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 364MB/s ± 0%  352MB/s ± 0%  -3.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    294MB/s ± 0%  295MB/s ± 0%  +0.38%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     680MB/s ± 0%  669MB/s ± 0%  -1.58%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                578MB/s ± 0%  567MB/s ± 0%  -1.92%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           622MB/s ± 0%  605MB/s ± 0%  -2.67%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           659MB/s ± 0%  647MB/s ± 0%  -1.72%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              630MB/s ± 0%  613MB/s ± 0%  -2.74%  (p=0.008 n=5+5)
2023-07-20 11:22:06 +10:00
Nigel Tao 6f510552be cgen: add type casts for some avx2 methods 2023-07-18 13:26:39 +10:00
Nigel Tao 44d89c8838 base: add some more x86_m256i methods 2023-07-18 12:48:52 +10:00
Nigel Tao ecaf25ebf0 std/jpeg: "AC all zero" fast path for x86_avx2
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               370MB/s ± 0%  368MB/s ± 0%  -0.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  231MB/s ± 0%  231MB/s ± 0%  -0.26%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   470MB/s ± 0%  470MB/s ± 0%    ~     (p=0.841 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              418MB/s ± 0%  416MB/s ± 0%  -0.42%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         435MB/s ± 0%  433MB/s ± 0%  -0.33%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         620MB/s ± 0%  646MB/s ± 0%  +4.20%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            441MB/s ± 0%  439MB/s ± 0%  -0.51%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 352MB/s ± 0%  364MB/s ± 0%  +3.41%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    296MB/s ± 0%  294MB/s ± 0%  -0.69%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     666MB/s ± 0%  680MB/s ± 0%  +2.10%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                565MB/s ± 0%  578MB/s ± 0%  +2.34%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           608MB/s ± 0%  622MB/s ± 0%  +2.26%  (p=0.016 n=5+4)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           624MB/s ± 0%  659MB/s ± 0%  +5.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              616MB/s ± 0%  630MB/s ± 0%  +2.29%  (p=0.008 n=5+5)
2023-07-18 12:04:19 +10:00
Nigel Tao 2bff962cf1 std/jpeg: add decoder.decode_idct_x86_avx2
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               237MB/s ± 0%  370MB/s ± 0%  +55.94%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  205MB/s ± 0%  231MB/s ± 0%  +12.80%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   379MB/s ± 0%  470MB/s ± 0%  +23.92%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              332MB/s ± 0%  418MB/s ± 0%  +25.95%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         345MB/s ± 0%  435MB/s ± 0%  +25.99%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         483MB/s ± 0%  620MB/s ± 0%  +28.53%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            349MB/s ± 0%  441MB/s ± 0%  +26.47%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 231MB/s ± 0%  352MB/s ± 0%  +52.78%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    227MB/s ± 0%  296MB/s ± 0%  +30.44%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     500MB/s ± 0%  666MB/s ± 0%  +33.21%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                417MB/s ± 0%  565MB/s ± 0%  +35.32%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           440MB/s ± 0%  608MB/s ± 0%  +38.37%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           478MB/s ± 0%  624MB/s ± 0%  +30.70%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              445MB/s ± 0%  616MB/s ± 0%  +38.42%  (p=0.008 n=5+5)
2023-07-18 09:17:08 +10:00
Nigel Tao 0af626b850 std/jpeg: grow quant_tables' elements, s/u8/u16/ 2023-07-17 10:27:49 +10:00
Nigel Tao e5b6f2563e std/jpeg: prepare decode_idct_x86_avx2.wuffs 2023-07-16 19:54:36 +10:00
Nigel Tao 4dfd70928b std: add "get_quirk(key: u32) u64" 2023-07-16 12:04:09 +10:00
Nigel Tao 84d1aa0d79 cmd/wuffs: show cmdArgs when "wuffs gen" fails 2023-07-16 11:44:08 +10:00
Nigel Tao 8954281a4e pixconv: allow decoding to PIXEL_FORMAT__RGB
"wuffs genlib" binary size changes:
 77936 clang-static/wuffs-base-pixconv.o  # Before = 1.00x
 79792 clang-static/wuffs-base-pixconv.o  # After  = 1.02x
173784 gcc-static/wuffs-base-pixconv.o    # Before = 1.00x
177112 gcc-static/wuffs-base-pixconv.o    # After  = 1.02x

Some of the benchmark numbers move around even though they don't use the
new WUFFS_BASE__PIXEL_FORMAT__RGB code paths. It's possibly just a code
alignment coincidence per https://news.ycombinator.com/item?id=23633583

name                                                       old speed      new speed      delta

wuffs_jpeg_decode_19k_8bpp/clang11                          249MB/s ± 0%   251MB/s ± 0%   +0.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11             222MB/s ± 0%   225MB/s ± 0%   +1.16%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11              405MB/s ± 0%   406MB/s ± 0%     ~     (p=1.000 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11                         357MB/s ± 0%   356MB/s ± 0%   -0.24%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11                    370MB/s ± 0%   372MB/s ± 0%   +0.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11                    504MB/s ± 0%   508MB/s ± 0%   +0.83%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11                       375MB/s ± 0%   374MB/s ± 0%     ~     (p=0.095 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                            258MB/s ± 0%   254MB/s ± 0%   -1.68%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10               267MB/s ± 0%   240MB/s ± 0%   -9.95%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10                537MB/s ± 0%   537MB/s ± 0%     ~     (p=0.556 n=4+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                           458MB/s ± 0%   453MB/s ± 0%   -1.18%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10                      482MB/s ± 0%   478MB/s ± 0%   -0.78%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10                      508MB/s ± 0%   511MB/s ± 0%   +0.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10                         489MB/s ± 0%   484MB/s ± 0%   -1.11%  (p=0.016 n=4+5)

wuffs_png_decode_image_19k_8bpp/clang11                     269MB/s ± 0%   275MB/s ± 0%   +2.25%  (p=0.008 n=5+5)
wuffs_png_decode_image_40k_24bpp/clang11                    328MB/s ± 0%   328MB/s ± 0%     ~     (p=0.841 n=5+5)
wuffs_png_decode_image_77k_8bpp/clang11                     949MB/s ± 0%   962MB/s ± 0%   +1.29%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang11   854MB/s ± 0%   859MB/s ± 0%   +0.54%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_verify_checksum/clang11   822MB/s ± 0%   826MB/s ± 0%   +0.52%  (p=0.008 n=5+5)
wuffs_png_decode_image_4002k_24bpp/clang11                  331MB/s ± 0%   332MB/s ± 0%   +0.15%  (p=0.008 n=5+5)

wuffs_png_decode_image_19k_8bpp/gcc10                       287MB/s ± 0%   277MB/s ± 0%   -3.46%  (p=0.008 n=5+5)
wuffs_png_decode_image_40k_24bpp/gcc10                      341MB/s ± 0%   346MB/s ± 0%   +1.34%  (p=0.008 n=5+5)
wuffs_png_decode_image_77k_8bpp/gcc10                      1.02GB/s ± 0%  1.01GB/s ± 0%   -0.41%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10     939MB/s ± 0%   916MB/s ± 0%   -2.50%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10     895MB/s ± 0%   874MB/s ± 0%   -2.41%  (p=0.008 n=5+5)
wuffs_png_decode_image_4002k_24bpp/gcc10                    352MB/s ± 0%   350MB/s ± 0%   -0.44%  (p=0.008 n=5+5)

Updates #131
2023-07-16 11:17:45 +10:00
Nigel Tao 129d8008a2 doc: add more "decode an image" docs/comments 2023-07-15 13:26:45 +10:00
Nigel Tao 2644620770 check: allow p[i] if p has type "ptr array[N] T" 2023-06-29 18:15:08 +10:00
Nigel Tao b97560b292 cgen: emit "do { etc } while (0);" for some loops 2023-06-28 22:58:07 +10:00
Nigel Tao 99cc599f92 example/toy-aux-image: comment on config macros 2023-06-28 14:11:38 +10:00
Nigel Tao dd29401137 std/jpeg: re-format generated IDCT code 2023-06-28 13:49:55 +10:00
Nigel Tao 97c4e85e0e std/jpeg: add more-SIMD-like IDCT algorithm
This adds commented-out code that is equivalent to the existing IDCT
algorithm. It's slower as is (and hence commented out) but it is closer
to a follow-up commit's SIMD-optimized algorithm.
2023-06-28 13:45:25 +10:00
Nigel Tao 49f50cca91 std/jpeg: cap the implicit-zero bitstream padding
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59966

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               241MB/s ± 0%  237MB/s ± 0%  -1.57%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  213MB/s ± 0%  212MB/s ± 0%  -0.43%  (p=0.016 n=5+4)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   387MB/s ± 0%  386MB/s ± 0%  -0.08%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              341MB/s ± 0%  340MB/s ± 0%  -0.50%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         356MB/s ± 0%  353MB/s ± 0%  -0.89%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         484MB/s ± 0%  480MB/s ± 0%  -0.96%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            364MB/s ± 0%  360MB/s ± 0%  -1.12%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 244MB/s ± 0%  247MB/s ± 0%  +0.88%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    254MB/s ± 0%  254MB/s ± 0%  -0.20%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     508MB/s ± 0%  512MB/s ± 0%  +0.61%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                434MB/s ± 0%  436MB/s ± 0%  +0.39%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           456MB/s ± 0%  458MB/s ± 0%  +0.41%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           481MB/s ± 0%  483MB/s ± 0%  +0.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              463MB/s ± 0%  466MB/s ± 0%  +0.57%  (p=0.016 n=4+5)
2023-06-23 21:38:01 +10:00
Nigel Tao 66ef485efa cgen: emit "break/continue" not "goto", part 3
A selection of benchmarks below. Some are up, some are down.

name                                                                old speed      new speed      delta

wuffs_bzip2_decode_10k/clang11                                      59.5MB/s ± 0%  59.1MB/s ± 0%   -0.72%  (p=0.008 n=5+5)
wuffs_bzip2_decode_100k/clang11                                     49.6MB/s ± 1%  47.4MB/s ± 0%   -4.48%  (p=0.008 n=5+5)

wuffs_bzip2_decode_10k/gcc10                                        59.0MB/s ± 0%  59.8MB/s ± 0%   +1.40%  (p=0.008 n=5+5)
wuffs_bzip2_decode_100k/gcc10                                       49.8MB/s ± 2%  53.0MB/s ± 0%   +6.51%  (p=0.008 n=5+5)

wuffs_deflate_decode_1k_full_init/clang11                            184MB/s ± 0%   182MB/s ± 0%   -1.06%  (p=0.008 n=5+5)
wuffs_deflate_decode_1k_part_init/clang11                            213MB/s ± 0%   211MB/s ± 0%   -0.65%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_full_init/clang11                           399MB/s ± 0%   409MB/s ± 0%   +2.68%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_part_init/clang11                           409MB/s ± 0%   421MB/s ± 0%   +2.96%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_just_one_read/clang11                      518MB/s ± 0%   517MB/s ± 0%     ~     (p=0.095 n=5+5)
wuffs_deflate_decode_100k_many_big_reads/clang11                     322MB/s ± 0%   319MB/s ± 0%   -0.93%  (p=0.008 n=5+5)

wuffs_deflate_decode_1k_full_init/gcc10                              173MB/s ± 0%   175MB/s ± 0%   +1.07%  (p=0.008 n=5+5)
wuffs_deflate_decode_1k_part_init/gcc10                              205MB/s ± 0%   208MB/s ± 0%   +1.26%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_full_init/gcc10                             408MB/s ± 0%   396MB/s ± 0%   -2.94%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_part_init/gcc10                             421MB/s ± 0%   408MB/s ± 0%   -2.88%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_just_one_read/gcc10                        542MB/s ± 0%   519MB/s ± 0%   -4.13%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_many_big_reads/gcc10                       340MB/s ± 0%   327MB/s ± 0%   -3.77%  (p=0.008 n=5+5)

wuffs_json_decode_1k/clang11                                        1.26GB/s ± 0%  1.34GB/s ± 0%   +6.90%  (p=0.008 n=5+5)
wuffs_json_decode_21k_formatted/clang11                              681MB/s ± 0%   684MB/s ± 0%   +0.47%  (p=0.008 n=5+5)
wuffs_json_decode_26k_compact/clang11                               1.00GB/s ± 0%  1.14GB/s ± 0%  +14.26%  (p=0.008 n=5+5)
wuffs_json_decode_217k_stringy/clang11                               786MB/s ± 0%   907MB/s ± 0%  +15.40%  (p=0.008 n=5+5)

wuffs_json_decode_1k/gcc10                                          1.20GB/s ± 0%  1.22GB/s ± 0%   +1.41%  (p=0.008 n=5+5)
wuffs_json_decode_21k_formatted/gcc10                                681MB/s ± 0%   719MB/s ± 0%   +5.59%  (p=0.008 n=5+5)
wuffs_json_decode_26k_compact/gcc10                                  957MB/s ± 0%   976MB/s ± 0%   +1.94%  (p=0.008 n=5+5)
wuffs_json_decode_217k_stringy/gcc10                                 773MB/s ± 0%   781MB/s ± 0%   +1.01%  (p=0.008 n=5+5)

wuffs_png_decode_image_19k_8bpp/clang11                              256MB/s ± 0%   256MB/s ± 0%     ~     (p=0.421 n=5+5)
wuffs_png_decode_image_40k_24bpp/clang11                             311MB/s ± 0%   313MB/s ± 0%   +0.57%  (p=0.008 n=5+5)
wuffs_png_decode_image_77k_8bpp/clang11                              907MB/s ± 0%   904MB/s ± 0%   -0.28%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang11            821MB/s ± 0%   812MB/s ± 0%   -1.08%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_verify_checksum/clang11            790MB/s ± 0%   782MB/s ± 0%   -0.94%  (p=0.008 n=5+5)
wuffs_png_decode_image_4002k_24bpp/clang11                           315MB/s ± 0%   315MB/s ± 0%   -0.09%  (p=0.008 n=5+5)

wuffs_png_decode_image_19k_8bpp/gcc10                                266MB/s ± 0%   273MB/s ± 0%   +2.94%  (p=0.008 n=5+5)
wuffs_png_decode_image_40k_24bpp/gcc10                               329MB/s ± 0%   324MB/s ± 2%   -1.65%  (p=0.008 n=5+5)
wuffs_png_decode_image_77k_8bpp/gcc10                                952MB/s ± 2%   967MB/s ± 0%   +1.57%  (p=0.016 n=5+4)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10              871MB/s ± 0%   894MB/s ± 0%   +2.59%  (p=0.029 n=4+4)
wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10              831MB/s ± 0%   851MB/s ± 0%   +2.45%  (p=0.008 n=5+5)
wuffs_png_decode_image_4002k_24bpp/gcc10                             336MB/s ± 0%   335MB/s ± 0%   -0.53%  (p=0.008 n=5+5)
2023-06-23 21:04:24 +10:00
Nigel Tao de55ff7746 cgen: emit "break/continue" not "goto", part 2
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               241MB/s ± 0%  241MB/s ± 0%    ~     (p=0.690 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  213MB/s ± 0%  213MB/s ± 0%    ~     (p=0.690 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   386MB/s ± 0%  387MB/s ± 0%    ~     (p=0.270 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              341MB/s ± 0%  341MB/s ± 0%    ~     (p=0.556 n=5+4)
wuffs_jpeg_decode_552k_24bpp_420/clang11         356MB/s ± 0%  356MB/s ± 0%    ~     (p=0.310 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         484MB/s ± 0%  484MB/s ± 0%    ~     (p=0.095 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            362MB/s ± 0%  364MB/s ± 0%    ~     (p=0.095 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 245MB/s ± 0%  244MB/s ± 0%  -0.19%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    252MB/s ± 0%  254MB/s ± 0%  +0.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     513MB/s ± 0%  508MB/s ± 0%  -0.88%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                433MB/s ± 0%  434MB/s ± 0%  +0.38%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           458MB/s ± 0%  456MB/s ± 0%  -0.41%  (p=0.029 n=4+4)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           486MB/s ± 0%  481MB/s ± 0%  -1.00%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              465MB/s ± 0%  463MB/s ± 0%  -0.39%  (p=0.029 n=4+4)
2023-06-23 18:29:20 +10:00
Nigel Tao f155db4d5c cgen: emit "break/continue" not "goto", part 1
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               229MB/s ± 0%  241MB/s ± 0%  +5.29%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  205MB/s ± 0%  213MB/s ± 0%  +3.89%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   375MB/s ± 0%  386MB/s ± 0%  +3.01%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              326MB/s ± 0%  341MB/s ± 0%  +4.80%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         339MB/s ± 0%  356MB/s ± 0%  +5.14%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         475MB/s ± 0%  484MB/s ± 0%  +2.04%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            343MB/s ± 0%  362MB/s ± 0%  +5.77%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 245MB/s ± 0%  245MB/s ± 0%  -0.07%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    254MB/s ± 0%  252MB/s ± 0%  -0.52%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     514MB/s ± 0%  513MB/s ± 0%    ~     (p=0.151 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                434MB/s ± 0%  433MB/s ± 0%  -0.35%  (p=0.016 n=5+4)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           459MB/s ± 0%  458MB/s ± 0%  -0.12%  (p=0.016 n=5+4)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           486MB/s ± 0%  486MB/s ± 0%  -0.03%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              467MB/s ± 0%  465MB/s ± 0%  -0.26%  (p=0.016 n=5+4)
2023-06-23 17:46:40 +10:00
Nigel Tao 8d9d6c1292 Performance mystery: load-bearing "no-op continue"
There is no semantic difference in this commit. There's no further code
after the if-else chain in the loop body. Nonetheless, adding a "no-op
continue" impacts performance: bad for clang and good for gcc.

Profiling suggests we spend less than 5% overall in
wuffs_jpeg__decoder__fill_bitstream.

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               241MB/s ± 0%  229MB/s ± 0%  -5.02%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  213MB/s ± 0%  205MB/s ± 0%  -4.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   386MB/s ± 0%  375MB/s ± 0%  -2.88%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              341MB/s ± 0%  326MB/s ± 0%  -4.58%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         356MB/s ± 0%  339MB/s ± 0%  -4.90%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         484MB/s ± 0%  475MB/s ± 0%  -1.96%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            364MB/s ± 0%  343MB/s ± 0%  -5.83%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 234MB/s ± 0%  245MB/s ± 0%  +4.68%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    245MB/s ± 0%  254MB/s ± 0%  +3.35%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     500MB/s ± 0%  514MB/s ± 0%  +2.81%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                417MB/s ± 0%  434MB/s ± 0%  +4.18%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           442MB/s ± 0%  459MB/s ± 0%  +3.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           477MB/s ± 0%  486MB/s ± 0%  +1.99%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              450MB/s ± 0%  467MB/s ± 0%  +3.70%  (p=0.008 n=5+5)

It is a mystery why this happens. Note though that the "continue" in the
Wuffs code becomes a "goto" in the generated C code, because (in the
general case) Wuffs has "labeled continue/break", which can jump out of
a not-inner-most loop, and C99 does not. Wuffs' "generate C code" thus
uses a C "goto". A follow-up commit may try a C "continue" instead.

To reproduce:

----
$ git clone https://github.com/google/wuffs.git
$ cd wuffs
$ gcc --version | head -n 1
gcc (Debian 10.2.1-6) 10.2.1 20210110

$ # Check out this commit.
$ git checkout --quiet THE_HASH_OF_THIS_COMMIT
$ gcc -O3 -Wall -std=c99 test/c/std/jpeg.c -DWUFFS_MIMIC -ljpeg
$ ./a.out -bench -focus=wuffs_jpeg_decode_77k_24bpp | grep MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  176988 ns/op	     433.927 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  176849 ns/op	     434.268 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  176800 ns/op	     434.389 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  176844 ns/op	     434.279 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  176869 ns/op	     434.218 MB/s

$ # Check out the parent commit.
$ git checkout --quiet THE_HASH_OF_THIS_COMMIT^
$ gcc -O3 -Wall -std=c99 test/c/std/jpeg.c -DWUFFS_MIMIC -ljpeg
$ ./a.out -bench -focus=wuffs_jpeg_decode_77k_24bpp | grep MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  183848 ns/op	     417.734 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  183870 ns/op	     417.684 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  183833 ns/op	     417.770 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  183873 ns/op	     417.679 MB/s
Benchmarkwuffs_jpeg_decode_77k_24bpp/gcc10	    3000	  183843 ns/op	     417.746 MB/s
----
2023-06-23 17:02:14 +10:00
Nigel Tao 40fca0f03d std/jpeg: roll back fill_bitstream inner loop
Commit 723c604a "std/jpeg: tweak decoder.fill_bitstream inner loop"
inadvertently changed "increment wi" behavior in the rare code paths.

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               237MB/s ± 0%  241MB/s ± 0%  +1.79%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  213MB/s ± 0%  213MB/s ± 0%  +0.36%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   384MB/s ± 0%  386MB/s ± 0%  +0.50%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              338MB/s ± 0%  341MB/s ± 0%  +0.95%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         353MB/s ± 0%  356MB/s ± 0%  +0.99%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         481MB/s ± 0%  484MB/s ± 0%  +0.61%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            359MB/s ± 0%  364MB/s ± 0%  +1.40%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 245MB/s ± 0%  234MB/s ± 0%  -4.45%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    247MB/s ± 0%  245MB/s ± 0%  -0.59%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     510MB/s ± 0%  500MB/s ± 0%  -1.94%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                432MB/s ± 0%  417MB/s ± 0%  -3.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           456MB/s ± 0%  442MB/s ± 0%  -3.14%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           484MB/s ± 0%  477MB/s ± 0%  -1.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              465MB/s ± 0%  450MB/s ± 0%  -3.28%  (p=0.008 n=5+5)
2023-06-23 16:29:16 +10:00
Nigel Tao a00150f62f std/jpeg: tweak decode_mcu up-front r.length check
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               236MB/s ± 0%  237MB/s ± 0%  +0.11%  (p=0.032 n=4+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  210MB/s ± 0%  213MB/s ± 0%  +1.20%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   385MB/s ± 0%  384MB/s ± 0%    ~     (p=0.095 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              338MB/s ± 0%  338MB/s ± 0%    ~     (p=0.151 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         353MB/s ± 0%  353MB/s ± 0%    ~     (p=0.548 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         481MB/s ± 0%  481MB/s ± 0%    ~     (p=0.690 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            360MB/s ± 0%  359MB/s ± 0%  -0.35%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 244MB/s ± 0%  245MB/s ± 0%  +0.44%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    251MB/s ± 0%  247MB/s ± 0%  -1.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     509MB/s ± 0%  510MB/s ± 0%  +0.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                431MB/s ± 0%  432MB/s ± 0%  +0.24%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           455MB/s ± 0%  456MB/s ± 0%  +0.26%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           481MB/s ± 0%  484MB/s ± 0%  +0.56%  (p=0.016 n=4+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              463MB/s ± 0%  465MB/s ± 0%  +0.36%  (p=0.008 n=5+5)
2023-06-22 11:37:40 +10:00
Nigel Tao 255516bc21 std/jpeg: comments for "read Huffman LUT earlier"
This commit is the second of two. It just adds comments to the code
added by the previous commit.
2023-06-21 22:51:22 +10:00
Nigel Tao d9c7740ea6 std/jpeg: read Huffman look-up table earlier
This commit is the first of two. It just changes code, and is the
minimal code change that leads to these performance improvements. The
follow-up commit will add comments that will also include a reference to
this one's commit hash. Even later commits may do some more refactoring.

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               224MB/s ± 0%  236MB/s ± 0%  +5.38%  (p=0.016 n=5+4)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  211MB/s ± 0%  210MB/s ± 0%  -0.55%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   377MB/s ± 0%  385MB/s ± 0%  +1.91%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              328MB/s ± 0%  338MB/s ± 0%  +3.23%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         341MB/s ± 0%  353MB/s ± 0%  +3.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         472MB/s ± 0%  481MB/s ± 0%  +1.93%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            347MB/s ± 0%  360MB/s ± 0%  +3.70%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 225MB/s ± 0%  244MB/s ± 0%  +8.27%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    246MB/s ± 0%  251MB/s ± 0%  +1.67%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     498MB/s ± 0%  509MB/s ± 0%  +2.18%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                408MB/s ± 0%  431MB/s ± 0%  +5.86%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           428MB/s ± 0%  455MB/s ± 0%  +6.38%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           470MB/s ± 0%  481MB/s ± 0%  +2.46%  (p=0.016 n=5+4)
wuffs_jpeg_decode_4002k_24bpp/gcc10              433MB/s ± 0%  463MB/s ± 0%  +7.03%  (p=0.008 n=5+5)
2023-06-21 21:56:54 +10:00
Nigel Tao bedf2bd7c3 lang: let skip_u32_fast imply can_undo_byte 2023-06-20 23:02:01 +10:00
Nigel Tao 723c604a5b std/jpeg: tweak decoder.fill_bitstream inner loop
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               229MB/s ± 0%  225MB/s ± 0%  -1.78%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  212MB/s ± 0%  212MB/s ± 0%    ~     (p=0.421 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   380MB/s ± 0%  377MB/s ± 0%  -0.56%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              331MB/s ± 0%  328MB/s ± 0%  -1.00%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         344MB/s ± 0%  341MB/s ± 0%  -0.97%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         476MB/s ± 0%  473MB/s ± 0%  -0.66%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            350MB/s ± 0%  348MB/s ± 0%  -0.64%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 215MB/s ± 0%  225MB/s ± 0%  +4.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    246MB/s ± 0%  247MB/s ± 0%  +0.35%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     485MB/s ± 0%  499MB/s ± 0%  +2.84%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                394MB/s ± 0%  408MB/s ± 0%  +3.63%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           414MB/s ± 0%  428MB/s ± 0%  +3.30%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           462MB/s ± 0%  470MB/s ± 0%  +1.81%  (p=0.016 n=4+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              420MB/s ± 0%  433MB/s ± 0%  +3.13%  (p=0.008 n=5+5)
2023-06-20 22:21:10 +10:00
Nigel Tao 8916f1b6ea lang: add if.likely and if.unlikely 2023-06-20 18:00:48 +10:00
Nigel Tao 1acd74482a std/jpeg: add more EXTEND comments 2023-06-20 17:33:08 +10:00
Nigel Tao 38205517d4 test: fix some errors in "compile C as C++" 2023-06-20 17:25:56 +10:00
Nigel Tao e7df7cafac cgen: add WUFFS_BASE__GENERATED_C_CODE macro
This disables UBSan's "unsigned-integer-overflow" runtime checks.

Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59966
2023-06-20 17:04:35 +10:00
Nigel Tao 6eb92544bd std/jpeg: tweak decode_mcu z variable assignment
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               227MB/s ± 0%  229MB/s ± 0%  +0.93%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  213MB/s ± 0%  212MB/s ± 0%  -0.50%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   380MB/s ± 0%  380MB/s ± 0%    ~     (p=1.000 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              329MB/s ± 0%  331MB/s ± 0%  +0.73%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         342MB/s ± 0%  344MB/s ± 0%  +0.72%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         469MB/s ± 0%  476MB/s ± 0%  +1.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            348MB/s ± 0%  350MB/s ± 0%  +0.51%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 213MB/s ± 0%  215MB/s ± 0%  +0.70%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    246MB/s ± 0%  246MB/s ± 0%    ~     (p=0.095 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     482MB/s ± 0%  485MB/s ± 0%  +0.61%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                392MB/s ± 0%  394MB/s ± 0%  +0.53%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           412MB/s ± 0%  414MB/s ± 0%  +0.45%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           460MB/s ± 0%  462MB/s ± 0%  +0.43%  (p=0.016 n=5+4)
wuffs_jpeg_decode_4002k_24bpp/gcc10              419MB/s ± 0%  420MB/s ± 0%  +0.32%  (p=0.008 n=5+5)
2023-06-19 20:13:01 +10:00
Nigel Tao 48fa7182f4 std/jpeg: tweak UNZIG comments 2023-06-19 13:19:24 +10:00
Nigel Tao 36323abf87 std/jpeg: tighten EXTEND element type s/u32/u16/
I'm not sure of the underlying reason for the gcc benchmark anomaly (the
clang numbers don't change).

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               227MB/s ± 0%  227MB/s ± 0%     ~     (p=0.151 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  209MB/s ± 0%  213MB/s ± 0%   +1.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   379MB/s ± 0%  380MB/s ± 0%   +0.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              329MB/s ± 0%  329MB/s ± 0%   +0.06%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         342MB/s ± 0%  342MB/s ± 0%     ~     (p=0.690 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         468MB/s ± 0%  469MB/s ± 0%   +0.10%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            348MB/s ± 0%  348MB/s ± 0%   +0.08%  (p=0.016 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 213MB/s ± 0%  213MB/s ± 0%     ~     (p=0.151 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    221MB/s ± 0%  246MB/s ± 0%  +11.51%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     487MB/s ± 0%  482MB/s ± 0%   -0.98%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                392MB/s ± 0%  392MB/s ± 0%     ~     (p=1.000 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           413MB/s ± 0%  412MB/s ± 0%     ~     (p=0.190 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           459MB/s ± 0%  460MB/s ± 0%   +0.09%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              419MB/s ± 0%  419MB/s ± 0%   +0.04%  (p=0.008 n=5+5)
2023-06-18 21:35:49 +10:00
Nigel Tao e4902dbd45 std/jpeg: tweak "this.mcu_zig_index" vs "var z" 2023-06-18 21:18:41 +10:00
Nigel Tao 9b97c27ec6 std/jpeg: tweak UNZIG array
We'll hopefully claw back the performance in a follow-up commit.

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               222MB/s ± 0%  224MB/s ± 0%   +1.11%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  213MB/s ± 0%  210MB/s ± 0%   -1.53%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   376MB/s ± 0%  378MB/s ± 0%   +0.37%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              325MB/s ± 0%  328MB/s ± 0%   +0.66%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         339MB/s ± 0%  340MB/s ± 0%   +0.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         468MB/s ± 0%  469MB/s ± 0%   +0.27%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            344MB/s ± 0%  346MB/s ± 0%   +0.37%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 212MB/s ± 0%  213MB/s ± 0%   +0.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    246MB/s ± 0%  221MB/s ± 0%   -9.98%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     484MB/s ± 0%  484MB/s ± 0%     ~     (p=0.056 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                390MB/s ± 0%  392MB/s ± 0%   +0.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           415MB/s ± 0%  414MB/s ± 0%   -0.17%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           463MB/s ± 0%  459MB/s ± 0%   -0.78%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              420MB/s ± 0%  419MB/s ± 0%   -0.19%  (p=0.008 n=5+5)
2023-06-18 20:57:50 +10:00
Nigel Tao 19e5cccee3 std/jpeg: add an EXTEND look-up table
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               223MB/s ± 0%  222MB/s ± 0%  -0.81%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  208MB/s ± 0%  213MB/s ± 0%  +2.32%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   375MB/s ± 0%  376MB/s ± 0%  +0.34%  (p=0.016 n=4+5)
wuffs_jpeg_decode_77k_24bpp/clang11              319MB/s ± 0%  325MB/s ± 0%  +1.92%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         329MB/s ± 0%  339MB/s ± 0%  +3.00%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         465MB/s ± 0%  468MB/s ± 0%  +0.65%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            331MB/s ± 0%  344MB/s ± 0%  +4.02%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 208MB/s ± 0%  212MB/s ± 0%  +1.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    243MB/s ± 0%  246MB/s ± 0%  +1.09%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     479MB/s ± 0%  484MB/s ± 0%  +1.17%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                385MB/s ± 0%  390MB/s ± 0%  +1.40%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           407MB/s ± 0%  415MB/s ± 0%  +1.98%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           457MB/s ± 0%  463MB/s ± 0%  +1.29%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              411MB/s ± 0%  420MB/s ± 0%  +2.06%  (p=0.008 n=5+5)
2023-06-18 18:44:41 +10:00
Nigel Tao 44e745dd0e std/jpeg: optimize EXTEND'ing MCU bits
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               224MB/s ± 1%  223MB/s ± 0%     ~     (p=0.190 n=4+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  206MB/s ± 0%  208MB/s ± 0%   +0.86%  (p=0.016 n=4+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   374MB/s ± 0%  375MB/s ± 0%   +0.26%  (p=0.016 n=5+4)
wuffs_jpeg_decode_77k_24bpp/clang11              319MB/s ± 0%  319MB/s ± 0%   +0.16%  (p=0.029 n=4+4)
wuffs_jpeg_decode_552k_24bpp_420/clang11         329MB/s ± 0%  329MB/s ± 0%   -0.06%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         465MB/s ± 0%  465MB/s ± 0%   -0.12%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            332MB/s ± 0%  331MB/s ± 0%   -0.15%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 176MB/s ± 0%  208MB/s ± 0%  +18.26%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    246MB/s ± 0%  243MB/s ± 0%   -1.03%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     472MB/s ± 0%  479MB/s ± 0%   +1.33%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                334MB/s ± 0%  385MB/s ± 0%  +15.33%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           351MB/s ± 0%  407MB/s ± 0%  +15.74%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           425MB/s ± 0%  457MB/s ± 0%   +7.38%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              349MB/s ± 0%  411MB/s ± 0%  +17.74%  (p=0.008 n=5+5)
2023-06-18 17:37:23 +10:00
Nigel Tao 143991a301 std/jpeg: check up-front for sufficient AC bits
The micro-benchmarks are mixed for now, but this sets us up to remove an
inner-loop bounds check in a future commit.

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               226MB/s ± 0%  224MB/s ± 1%  -1.03%  (p=0.029 n=4+4)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  210MB/s ± 0%  206MB/s ± 0%  -1.59%  (p=0.029 n=4+4)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   379MB/s ± 0%  374MB/s ± 0%  -1.25%  (p=0.016 n=4+5)
wuffs_jpeg_decode_77k_24bpp/clang11              326MB/s ± 0%  319MB/s ± 0%  -2.35%  (p=0.029 n=4+4)
wuffs_jpeg_decode_552k_24bpp_420/clang11         338MB/s ± 0%  329MB/s ± 0%  -2.53%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         468MB/s ± 0%  465MB/s ± 0%  -0.58%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            347MB/s ± 0%  332MB/s ± 0%  -4.41%  (p=0.016 n=4+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 174MB/s ± 0%  176MB/s ± 0%  +1.18%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    247MB/s ± 0%  246MB/s ± 0%  -0.55%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     477MB/s ± 0%  472MB/s ± 0%  -0.90%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                328MB/s ± 0%  334MB/s ± 0%  +1.69%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           346MB/s ± 0%  351MB/s ± 0%  +1.57%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           424MB/s ± 0%  425MB/s ± 0%  +0.39%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              350MB/s ± 0%  349MB/s ± 0%  -0.23%  (p=0.008 n=5+5)
2023-06-18 17:37:12 +10:00
Nigel Tao 2ca61b521f test/data: add ridiculously-fast.png 2023-06-17 19:50:47 +10:00
Nigel Tao 5b84fb54d8 script: add RUSTFLAGS to bench-rust-jpeg
Adding "RUSTFLAGS='-C target-cpu=native'" numbers to the previous
commit's numbers:

name                                             speed

// Go 1.21
go_jpeg_decode_19k_8bpp                          46.8MB/s ± 5%
go_jpeg_decode_30k_24bpp_progressive             55.8MB/s ± 5%
go_jpeg_decode_30k_24bpp_sequential              90.5MB/s ± 5%
go_jpeg_decode_77k_24bpp                         75.8MB/s ± 2%
go_jpeg_decode_552k_24bpp_420                    81.1MB/s ± 6%
go_jpeg_decode_552k_24bpp_444                    83.0MB/s ± 5%
go_jpeg_decode_4002k_24bpp                       91.3MB/s ± 4%

// Rust 1.63, default configuration
rust_jpeg_decode_image_19k_8bpp                   153MB/s ± 3%
rust_jpeg_decode_image_30k_24bpp_progressive     51.1MB/s ± 3%
rust_jpeg_decode_image_30k_24bpp_sequential       107MB/s ± 6%
rust_jpeg_decode_image_77k_24bpp                  118MB/s ± 2%
rust_jpeg_decode_image_552k_24bpp_420             183MB/s ± 3%
rust_jpeg_decode_image_552k_24bpp_444             181MB/s ± 4%
rust_jpeg_decode_image_4002k_24bpp                258MB/s ± 3%

// Rust 1.63, RUSTFLAGS='-C target-cpu=native'
rust_jpeg_decode_image_19k_8bpp                   158MB/s ± 1%
rust_jpeg_decode_image_30k_24bpp_progressive     54.4MB/s ± 3%
rust_jpeg_decode_image_30k_24bpp_sequential       137MB/s ± 6%
rust_jpeg_decode_image_77k_24bpp                  130MB/s ± 1%
rust_jpeg_decode_image_552k_24bpp_420             211MB/s ± 7%
rust_jpeg_decode_image_552k_24bpp_444             201MB/s ± 4%
rust_jpeg_decode_image_4002k_24bpp                280MB/s ± 0%

// Wuffs, clang 14.0
wuffs_jpeg_decode_19k_8bpp/clang14                177MB/s ± 0%
wuffs_jpeg_decode_30k_24bpp_progressive/clang14   191MB/s ± 0%
wuffs_jpeg_decode_30k_24bpp_sequential/clang14    339MB/s ± 0%
wuffs_jpeg_decode_77k_24bpp/clang14               286MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_420/clang14          298MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_444/clang14          369MB/s ± 0%
wuffs_jpeg_decode_4002k_24bpp/clang14             297MB/s ± 0%

// Wuffs, gcc 12.2
wuffs_jpeg_decode_19k_8bpp/gcc12                  160MB/s ± 0%
wuffs_jpeg_decode_30k_24bpp_progressive/gcc12     208MB/s ± 1%
wuffs_jpeg_decode_30k_24bpp_sequential/gcc12      400MB/s ± 1%
wuffs_jpeg_decode_77k_24bpp/gcc12                 292MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_420/gcc12            305MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_444/gcc12            363MB/s ± 1%
wuffs_jpeg_decode_4002k_24bpp/gcc12               305MB/s ± 0%
2023-06-16 09:41:16 +10:00
Nigel Tao 32961a8413 script: add bench-rust-jpeg
This commit only adds Rust code, but it's as good a moment as any to
take a snapshot of how Wuffs' work-in-progress JPEG decoder performance
(which does not use SIMD optimizations yet) compares to Go and Rust.

The numbers in this commit were measured on different hardware (and
different C compiler versions) than other recent Wuffs commits, so the
absolute numbers aren't directly comparable across commits.

name                                             speed

// Go 1.21
go_jpeg_decode_19k_8bpp                          46.8MB/s ± 5%
go_jpeg_decode_30k_24bpp_progressive             55.8MB/s ± 5%
go_jpeg_decode_30k_24bpp_sequential              90.5MB/s ± 5%
go_jpeg_decode_77k_24bpp                         75.8MB/s ± 2%
go_jpeg_decode_552k_24bpp_420                    81.1MB/s ± 6%
go_jpeg_decode_552k_24bpp_444                    83.0MB/s ± 5%
go_jpeg_decode_4002k_24bpp                       91.3MB/s ± 4%

// Rust 1.63
rust_jpeg_decode_image_19k_8bpp                   153MB/s ± 3%
rust_jpeg_decode_image_30k_24bpp_progressive     51.1MB/s ± 3%
rust_jpeg_decode_image_30k_24bpp_sequential       107MB/s ± 6%
rust_jpeg_decode_image_77k_24bpp                  118MB/s ± 2%
rust_jpeg_decode_image_552k_24bpp_420             183MB/s ± 3%
rust_jpeg_decode_image_552k_24bpp_444             181MB/s ± 4%
rust_jpeg_decode_image_4002k_24bpp                258MB/s ± 3%

// Wuffs, clang 14.0
wuffs_jpeg_decode_19k_8bpp/clang14                177MB/s ± 0%
wuffs_jpeg_decode_30k_24bpp_progressive/clang14   191MB/s ± 0%
wuffs_jpeg_decode_30k_24bpp_sequential/clang14    339MB/s ± 0%
wuffs_jpeg_decode_77k_24bpp/clang14               286MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_420/clang14          298MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_444/clang14          369MB/s ± 0%
wuffs_jpeg_decode_4002k_24bpp/clang14             297MB/s ± 0%

// Wuffs, gcc 12.2
wuffs_jpeg_decode_19k_8bpp/gcc12                  160MB/s ± 0%
wuffs_jpeg_decode_30k_24bpp_progressive/gcc12     208MB/s ± 1%
wuffs_jpeg_decode_30k_24bpp_sequential/gcc12      400MB/s ± 1%
wuffs_jpeg_decode_77k_24bpp/gcc12                 292MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_420/gcc12            305MB/s ± 0%
wuffs_jpeg_decode_552k_24bpp_444/gcc12            363MB/s ± 1%
wuffs_jpeg_decode_4002k_24bpp/gcc12               305MB/s ± 0%
2023-06-14 22:55:09 +10:00
Nigel Tao e1df1b2835 script: update print-jpeg-idct-code.go
Its output now once again matches the fragment in
std/jpeg/decode_idct_default.wuffs, which was recently hand-edited in
commit c0d7d7d0 "std/jpeg: remove decode_idct block-selector arg". This
commit's edit should have been part of that previous commit.
2023-06-14 16:12:48 +10:00
Nigel Tao 724aec33df cgen: remove unnecessary parens for ptr-to-array 2023-06-13 22:39:21 +10:00
Nigel Tao 43beae1d3d lang: make "return a slice" return a slice of this 2023-06-13 22:38:29 +10:00
Nigel Tao 66723c6706 lang: make this.foo read-only in a pure function 2023-06-13 22:38:29 +10:00
Nigel Tao dd6a5d5435 std/jpeg: memoize ac_huff_table_fast
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               215MB/s ± 0%  226MB/s ± 0%  +5.17%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  209MB/s ± 0%  210MB/s ± 0%  +0.50%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   368MB/s ± 0%  380MB/s ± 1%  +3.11%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              313MB/s ± 0%  327MB/s ± 0%  +4.27%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         326MB/s ± 0%  338MB/s ± 0%  +3.50%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         462MB/s ± 0%  468MB/s ± 0%  +1.14%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            329MB/s ± 1%  346MB/s ± 0%  +5.39%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 174MB/s ± 0%  175MB/s ± 0%  +0.55%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    228MB/s ± 0%  248MB/s ± 0%  +8.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     472MB/s ± 0%  478MB/s ± 0%  +1.20%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                327MB/s ± 0%  328MB/s ± 0%  +0.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           344MB/s ± 0%  346MB/s ± 0%  +0.46%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           422MB/s ± 0%  424MB/s ± 0%  +0.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              349MB/s ± 0%  348MB/s ± 0%  -0.24%  (p=0.008 n=5+5)
2023-06-13 22:38:29 +10:00
Nigel Tao 19f56ebfd2 lang: allow "slice_var as ptr array[etc] etc" 2023-06-13 22:38:25 +10:00
Nigel Tao 6411561deb check: add maxPointerBounds and funcBounds 2023-06-13 11:52:16 +10:00
Nigel Tao 8ac22ceab2 cgen: allow "var x : nptr array[etc] etc" 2023-06-13 10:49:37 +10:00
Nigel Tao dfab0d2b3d mimiclib: allow jpeg decoding via stb_image 2023-06-12 17:24:49 +10:00
Nigel Tao 1f0f323414 std/jpeg: memoize Huffman table selectors 2023-06-12 16:23:53 +10:00
Nigel Tao 04344db374 cgen: remove "// ¡ BEGIN set_color_u32_at" 2023-06-11 12:33:36 +10:00
Nigel Tao 7511bda9e5 cgen: refactor patch_pixconv's set_color_u32_at 2023-06-11 12:02:47 +10:00
Nigel Tao 43d9c604a2 cgen: unroll etc__swizzle_ycck for 444
name                                             old speed     new speed     delta

wuffs_jpeg_decode_552k_24bpp_444/clang11         440MB/s ± 0%  459MB/s ± 0%  +4.48%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           393MB/s ± 0%  412MB/s ± 0%  +4.82%  (p=0.008 n=5+5)
2023-06-11 11:23:29 +10:00
Nigel Tao 41fb661626 cgen: make patch_pixconv etc__bgrx__hv11 explicit 2023-06-11 11:20:49 +10:00
Nigel Tao 1b0900ac73 cgen: re-organize patch_pixconv.go generated funcs 2023-06-11 10:47:29 +10:00
Nigel Tao c0d7d7d046 std/jpeg: remove decode_idct block-selector arg
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               210MB/s ± 0%  213MB/s ± 0%  +1.54%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  200MB/s ± 0%  197MB/s ± 0%  -1.31%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   362MB/s ± 0%  373MB/s ± 0%  +3.04%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              307MB/s ± 0%  318MB/s ± 0%  +3.82%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         318MB/s ± 0%  331MB/s ± 0%  +4.09%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         434MB/s ± 0%  440MB/s ± 0%  +1.34%  (p=0.016 n=4+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            320MB/s ± 0%  340MB/s ± 0%  +6.29%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 165MB/s ± 0%  172MB/s ± 0%  +4.32%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    224MB/s ± 0%  227MB/s ± 0%  +1.30%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     454MB/s ± 0%  465MB/s ± 0%  +2.40%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                311MB/s ± 0%  324MB/s ± 0%  +4.38%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           327MB/s ± 0%  342MB/s ± 0%  +4.52%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           384MB/s ± 0%  393MB/s ± 0%  +2.34%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              324MB/s ± 0%  345MB/s ± 1%  +6.26%  (p=0.008 n=5+5)
2023-06-10 14:12:08 +10:00
Nigel Tao d248ade0e6 test/3pdata: add blinksuite, bmpsuite, golangsuite 2023-06-09 22:10:07 +10:00
Nigel Tao fe5c1f25b8 test/data: add more peacock.*.jpeg files 2023-06-09 21:29:21 +10:00
Nigel Tao 379000a711 cgen: optimize etc__swizzle_ycck for 420 bgrx/rgbx
name                                             old speed     new speed     delta

wuffs_jpeg_decode_30k_24bpp_progressive/clang11  172MB/s ± 0%  200MB/s ± 0%  +15.74%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   292MB/s ± 0%  362MB/s ± 0%  +23.88%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              256MB/s ± 0%  307MB/s ± 0%  +19.79%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         264MB/s ± 0%  318MB/s ± 0%  +20.32%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            269MB/s ± 0%  320MB/s ± 0%  +19.13%  (p=0.008 n=5+5)

wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    202MB/s ± 0%  224MB/s ± 0%  +11.01%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     350MB/s ± 0%  454MB/s ± 0%  +29.83%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                248MB/s ± 0%  311MB/s ± 0%  +24.97%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           261MB/s ± 0%  327MB/s ± 0%  +25.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              259MB/s ± 0%  324MB/s ± 0%  +25.38%  (p=0.008 n=5+5)
2023-06-09 19:21:28 +10:00
Nigel Tao aec9003ea0 cgen: refactor patch_pixconv.go 2023-06-09 17:47:55 +10:00
Nigel Tao 311ea1a1f4 cgen: more optimize etc__swizzle_ycck for 444
name                                             old speed     new speed     delta

wuffs_jpeg_decode_552k_24bpp_444/clang11         356MB/s ± 0%  443MB/s ± 0%  +24.62%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           348MB/s ± 0%  380MB/s ± 0%   +9.26%  (p=0.008 n=5+5)
2023-06-09 17:15:31 +10:00
Nigel Tao 5d5d01a189 cgen: add "¡ INSERT patch_pixconv" mechanism 2023-06-08 23:26:37 +10:00
Nigel Tao f43246e3bb std/cbor: fix BEGIN/END comment typo 2023-06-08 22:47:22 +10:00
Nigel Tao d6cc525059 std/jpeg: optimize IDCT when AC terms are zero
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               199MB/s ± 0%  211MB/s ± 0%   +5.69%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  169MB/s ± 1%  176MB/s ± 0%   +4.32%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   269MB/s ± 0%  291MB/s ± 0%   +7.89%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              250MB/s ± 0%  254MB/s ± 0%   +1.90%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         258MB/s ± 0%  262MB/s ± 0%   +1.51%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         275MB/s ± 0%  356MB/s ± 0%  +29.59%  (p=0.016 n=5+4)
wuffs_jpeg_decode_4002k_24bpp/clang11            261MB/s ± 0%  263MB/s ± 1%   +0.61%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 153MB/s ± 0%  165MB/s ± 0%   +8.09%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    180MB/s ± 0%  197MB/s ± 0%   +9.56%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     288MB/s ± 0%  337MB/s ± 0%  +16.81%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                237MB/s ± 0%  245MB/s ± 0%   +3.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           247MB/s ± 0%  256MB/s ± 0%   +3.71%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           249MB/s ± 0%  348MB/s ± 0%  +39.88%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              247MB/s ± 0%  254MB/s ± 0%   +2.81%  (p=0.008 n=5+5)
2023-06-08 22:03:46 +10:00
Nigel Tao ca2909b6d7 cgen: optimize etc__swizzle_ycck for 444 bgrx/rgbx
name                                             old speed     new speed     delta

wuffs_jpeg_decode_552k_24bpp_444/clang11         227MB/s ± 0%  275MB/s ± 0%  +20.76%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           223MB/s ± 0%  249MB/s ± 0%  +11.51%  (p=0.008 n=5+5)
2023-06-07 22:25:02 +10:00
Nigel Tao a3e8531ecb std/jpeg: add swizzle_ycck_scratch_buffer_2k 2023-06-06 22:25:30 +10:00
Nigel Tao dcb5b0e1c7 test: add 4:4:4 (not just 4:2:0) JPEG test+bench 2023-06-05 22:25:22 +10:00
Nigel Tao e930d66897 lang: reject 0-length arrays 2023-06-05 13:33:15 +10:00
Nigel Tao 4a2f570d56 cgen: simplify bulk_etc method's generated code 2023-06-05 13:28:16 +10:00
Nigel Tao 2865c5bfbd std/jpeg: call slice.bulk_{load,save}_host_endian
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59540

name                                             old speed     new speed     delta

wuffs_jpeg_decode_30k_24bpp_progressive/clang11  131MB/s ± 0%  168MB/s ± 0%  +28.44%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    167MB/s ± 0%  175MB/s ± 0%   +4.80%  (p=0.008 n=5+5)
2023-06-05 12:51:50 +10:00
Nigel Tao 4a164cda64 std/jpeg: tweak apply_progressive_idct 2023-06-05 09:29:30 +10:00
Nigel Tao 9c3ca6257d cgen: generate 123u (instead of 123) even more 2023-06-04 22:09:19 +10:00
Nigel Tao 677a1c5b8e cgen: builtin generates unsigned values more often 2023-06-04 22:01:54 +10:00
Nigel Tao 238aadd8eb std/jpeg: factor out calculate_multiple_competc 2023-06-04 21:27:23 +10:00
Nigel Tao 2f18dc61d0 std/jpeg: call slice.bulk_memset 2023-06-04 21:22:14 +10:00
Nigel Tao 5edfe45e15 std/jpeg: add "#unsupported scan count"
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59540
2023-06-04 15:46:18 +10:00
Nigel Tao 0b18d43e4f std/jpeg: avoid unnecessary IDCT applications
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59540

name                                             old speed      new speed      delta
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  84.6MB/s ± 0%  136.4MB/s ± 0%  +61.33%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    93.8MB/s ± 0%  166.5MB/s ± 0%  +77.49%  (p=0.008 n=5+5)
2023-06-04 15:30:20 +10:00
Nigel Tao 442533f08c std/jpeg: avoid unnecessary swizzles
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59540

name                                             old speed      new speed      delta
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  32.4MB/s ± 0%  84.6MB/s ± 0%  +160.78%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    38.6MB/s ± 0%  93.8MB/s ± 0%  +142.75%  (p=0.008 n=5+5)
2023-06-04 13:24:39 +10:00
Nigel Tao e5c92a0ce3 script: add bench-go-jpeg 2023-06-04 12:58:27 +10:00
Nigel Tao 4751ef4de5 test: add std/jpeg mimic tests and benches 2023-06-04 12:44:17 +10:00
Nigel Tao 0904751e2d example: add toy-aux-image 2023-06-04 10:47:22 +10:00
Nigel Tao 27a3197727 script: add truncate-progressive-jpeg.go
"script/confirm-matches-djpeg.sh test/data/*.jpeg" shows differences on
"test/data/peacock.progressive.scan00[0-8].jpeg".
2023-06-01 22:32:37 +10:00
Nigel Tao 50d765839c cgen: generate 123u (instead of 123) more often 2023-06-01 19:58:50 +10:00
Nigel Tao 805e37915f root: add BUILD.md 2023-06-01 13:20:47 +10:00
Nigel Tao da95945d65 example: remove #include <linux/prctl.h>
These don't work with musl-libc. They're also unnecessary with gnu-libc.

Updates #124
2023-06-01 12:18:30 +10:00
Nigel Tao d7ddc153ba std/jpeg: decode progressive JPEGs
"script/confirm-matches-djpeg.sh test/data/*.jpeg" is now all matches.
2023-06-01 12:16:14 +10:00
Nigel Tao 1cd3604351 std/jpeg: prepare to decode progressive JPEGs 2023-05-30 15:36:50 +10:00
Nigel Tao 0aad753137 test/data: add peacock.*
"script/confirm-matches-djpeg.sh test/data/*.jpeg" shows a difference on
"test/data/peacock.progressive.jpeg".
2023-05-22 16:11:12 +10:00
Nigel Tao 02a6a13236 cgen: drop redundant "& mask" in "(x & mask) as T" 2023-05-22 16:03:24 +10:00
Nigel Tao 145ff0ce64 std/jpeg: have fill_bitstream call copy_from_slice 2023-05-22 14:23:16 +10:00
Nigel Tao ac3bd9cdba std/jpeg: reject 2 (not 1, 3 or 4) components 2023-05-22 14:11:46 +10:00
Nigel Tao 7d73f3cfa4 pixconv: fix ycck implicit promotion to signed int
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59182
2023-05-22 14:00:17 +10:00
Nigel Tao 06ffee27a2 std/jpeg: allow DQT markers after SOF marker
Fixes #120
2023-05-21 22:28:59 +10:00
Nigel Tao a41149e73c std/jpeg: implement triangle-filter upsampling
"script/confirm-matches-djpeg.sh test/data/*.jpeg" is now all matches.
2023-05-21 22:05:38 +10:00
Nigel Tao 94df43c530 std/jpeg: prepare for triangle-filter upsampling 2023-05-21 22:04:45 +10:00
Nigel Tao 56fae16567 script: add confirm-matches-djpeg.sh 2023-05-18 10:17:08 +10:00
Nigel Tao 9ffc41d16d std/jpeg: tighten decoder workbuf_len worst case 2023-05-17 22:45:23 +10:00
Nigel Tao de5dc68b40 std/jpeg: remove components_{w,h}_in_blocks fields 2023-05-17 22:10:42 +10:00
Nigel Tao 917aeb1748 gitignore: add /usr/bin/perf output files 2023-05-17 17:12:18 +10:00
Nigel Tao 5ab65d0923 cgen: generate 123u instead of 123 (for std/jpeg)
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59018
2023-05-16 22:19:43 +10:00
Nigel Tao 85b244aa49 std/netpbm: add new package 2023-05-16 16:29:58 +10:00
Nigel Tao 382303a99d fuzz: add jpeg_fuzzer.c
Updates #42
2023-05-15 12:22:26 +10:00
Nigel Tao 7514dede23 std/jpeg: decode color images, not just gray
Updates #42
2023-05-14 23:03:33 +10:00
Nigel Tao 3bd83e3ebb std/jpeg: apply Inverse DCT
Updates #42
2023-05-11 21:29:07 +10:00
Nigel Tao 8cfe304f3c std/jpeg: implement Inverse DCT
Updates #42
2023-05-08 21:51:47 +10:00
Nigel Tao cac4df3bde std/tga: re-type a field from slice to roslice 2023-05-06 10:03:15 +10:00
Nigel Tao 65924cd44d std/lzw: have flush return a roslice 2023-05-06 10:00:02 +10:00
Nigel Tao c914f66a6c std/jpeg: decode Huffman entropy coded data
Updates #42
2023-05-06 09:47:10 +10:00
Nigel Tao 6fd9767b5d std/jpeg: calculate number of MCUs and blocks
Updates #42
2023-04-30 14:17:27 +10:00
Nigel Tao e9b537b516 std/jpeg: decode SOS (up to entropy coded data)
Updates #42
2023-04-29 14:30:34 +10:00
Nigel Tao a95f39e2d1 std/png: delete old comment re APNG is unsupported 2023-04-29 12:00:24 +10:00
Nigel Tao 57b80f8c2e example: avoid gcc -Wstringop-overread for strnlen 2023-04-29 11:59:07 +10:00
Nigel Tao d36277f0c0 std/jpeg: decode DHT (Huffman tables)
Updates #42
2023-04-29 11:14:59 +10:00
Nigel Tao 0ccceece0b std/jpeg: decode SOF, producing the image config
Updates #42
2023-04-24 11:14:54 +10:00
Nigel Tao 0bbc4c0083 std/jpeg: add new package
This is just a placeholder decoder implementation (and all of the
required plumbing) that produces a 1x1 reddish-purple image. Follow-up
commits will add flesh to the metaphorical bones.

Updates #42
2023-04-21 18:33:00 +10:00
Nigel Tao bc86394bef base: rename min/max arg to no_more/less_than 2023-04-16 12:12:27 +10:00
Nigel Tao 95630b6677 lang/check: tighten checkConstElement constraint 2023-04-16 11:50:30 +10:00
Nigel Tao 4834cb97c8 base: deprecate ETC__PIXEL_FORMAT__NUM_PLANES_MAX 2023-04-16 11:12:06 +10:00
Nigel Tao e126c998e0 std: limit supported image dimensions to 0xFF_FFFF 2023-04-16 08:57:55 +10:00
Nigel Tao d8c23a3a66 std/lzw: change set_literal_width to set_quirk 2023-04-15 09:59:40 +10:00
Nigel Tao 6e84987d33 std: change set_quirk_enabled to set_quirk 2023-04-14 21:42:15 +10:00
Nigel Tao 176cdf7527 test: fix gcc -Wmaybe-uninitialized false positive
When running "gcc -O3 -Wall test/c/std/adler32.c", gcc 12.2.0 (but not
gcc 10.2.1) would warn that adler32's "checksum.private_impl.f_started"
may be used uninitialized. There is no warning without the "-O3".

That warning is a false positive. f_started is always zero-initialized
by wuffs_adler32__hasher__initialize (unless opted in to
WUFFS_INITIALIZE__ALREADY_ZEROED, which the benchmarks do not).

Also update test/c/std/crc32.c so that all of the base.hasher_u32
wuffs_bench_etc functions are consistent, even though gcc on crc32.c
does not produce that same false positive warning.
2023-04-12 13:31:01 +10:00
Nigel Tao 35fd84bea0 lang: allow copy_from_slice arg to be read-only 2023-04-12 13:18:43 +10:00
Nigel Tao 29c4122360 lang: have hasher_u32.update_u32 take a roslice 2023-04-10 21:16:53 +10:00
Nigel Tao ea3fbc37f5 lang: change const array to const roarray 2023-04-10 16:06:10 +10:00
Nigel Tao f3caf09d77 lang: add read-only type decorators 2023-04-10 15:29:12 +10:00
Nigel Tao 6e8349129c base: remove deprecated names 2023-04-09 16:12:49 +10:00
Nigel Tao 6ede29ab3a cmd/wuffs: tweak genWuffs output to be wuffsfmt'ed 2023-04-09 15:58:04 +10:00
Nigel Tao 49fa501f0d lang/parse: struct private data now needs a "+" 2023-04-09 15:45:06 +10:00
Nigel Tao f5eb38d76e wuffsfmt: indent with 4 spaces (not a tab) 2023-04-09 15:28:07 +10:00
Nigel Tao 9c03b8c71d wuffsfmt: double-indents hanging lines 2023-04-09 15:22:25 +10:00
383 changed files with 104071 additions and 9587 deletions

No files matched your search

+2
View File
@@ -4,4 +4,6 @@
/gen
/hello-wuffs-c/parse.c
Cargo.lock
perf.data
perf.data.old
target
+115
View File
@@ -0,0 +1,115 @@
# Build Instructions
Answering "how do I build Wuffs" depends on what exactly you mean by "Wuffs":
1. The Wuffs library (e.g. image decoders) in C/C++ form.
2. Its example programs (e.g. jsonptr).
3. The Wuffs toolchain (e.g. Wuffs-to-C compiler/proof-checker).
4. The Wuffs library in Wuffs form (converting it to C/C++ code).
5. Everything.
## Quick Start
The rest of this document assumes that you've already checked out and moved
into the Wuffs repository's directory, like this:
```
git clone https://github.com/google/wuffs.git
cd wuffs
```
If you just want to kick the metaphorical tyres:
```
./build-example.sh example/jsonptr
gen/bin/example-jsonptr test/data/rfc-6901-json-pointer.json
```
## Building the Wuffs Library (in C/C++ Form)
There's no build step, in that there's no "configure and make" step needed
before moving on to building the example programs.
To elaborate, transpiling (converting Wuffs-the-library from `*.wuffs` form
into a single `*.c` file) isn't done by whoever *checks out* the Wuffs
repository. It's done by whoever *checks in* code changes.
Wuffs-the-library is provided as [single file C
library](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt). The
example programs just `#include` that file directly.
For your own projects, just copy `release/c/wuffs-$VERSION.c` to your directory
and add that file to your pre-existing build system, or compile an `*.o` object
file directly like below. Remember to define the `WUFFS_IMPLEMENTATION` macro
to compile all of the C code in that single file, not just the "header" part.
```
# Most developers won't have to do this. It just demonstrates how to produce
# wuffs-v0.3.o directly from a C/C++ compiler.
gcc -c -DWUFFS_IMPLEMENTATION -O3 release/c/wuffs-v0.3.c
```
## Building the Example Programs
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
```
Some example programs require additional libraries:
```
g++ example/imageviewer/imageviewer.cc -lxcb -lxcb-image -lxcb-render -lxcb-render-util
g++ example/sdl-imageviewer/sdl-imageviewer.cc -lSDL2 -lSDL2_image
```
The `build-example.sh` script (an alternative to running your favorite C/C++
compiler directly) takes care of having to remember those additional libraries.
```
./build-example.sh example/sdl-imageviewer
gen/bin/example-sdl-imageviewer test/data/hat.jpeg
```
Building the fuzzers are similar, using `build-fuzz.sh` instead of
`build-example.sh`.
## Building the Wuffs Toolchain
Most developers won't have to do this. See the sections above instead.
But after editing `lang/check/*.go` files, do this:
```
go install ./cmd/wuffs*
```
## Building the Wuffs library (from its Wuffs Form)
Most developers won't have to do this. See the sections above instead.
But after editing `std/jpeg/*.wuffs` files, do this:
```
wuffs gen std/...
```
## Building Everything (All of the Above, Plus Tests, Benchmarks, Etc)
Most developers won't have to do this. See the sections above instead.
But before sending a Pull Request, do this:
```
./build-all.sh
```
+34
View File
@@ -1,3 +1,37 @@
This software is distributed under the terms of both the MIT license and the
Apache License (Version 2.0).
MIT license
Copyright 2023 The Wuffs Authors
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Apache 2 license
Apache License
Version 2.0, January 2004
+177
View File
@@ -0,0 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
+25
View File
@@ -0,0 +1,25 @@
Copyright 2023 The Wuffs Authors
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+39 -8
View File
@@ -1,12 +1,15 @@
![WUFFS Logo](./doc/logo/wuffs-acronym-logo-1536x1024.png)
Wuffs is a **memory-safe programming language** (and a **standard library**
written in that language) for **Wrangling Untrusted File Formats Safely**.
Wrangling includes parsing, decoding and encoding. Example file formats include
images, audio, video, fonts and compressed archives.
It is **fast**. Per its [benchmarks](/doc/benchmarks.md) and other linked-to
blog posts:
It is [**"ridiculously
fast"**](https://twitter.com/richgel999/status/1481027198530248714).
![Screenshot of a tweet saying "ridiculously
fast"](./test/data/ridiculously-fast.png)
Per its [benchmarks](/doc/benchmarks.md) and other linked-to blog posts:
- It can decode bzip2 **[1.3x faster than `/usr/bin/bzcat`
(C)](https://nigeltao.github.io/blog/2022/wuffs-bzip2-decoder.html)**.
@@ -181,10 +184,15 @@ wuffs test: some tests failed
- `hello-wuffs-c` holds an example program for Wuffs the Language.
# Building
See the [BUILD](/BUILD.md) instructions.
# Documentation
- [Getting Started](/doc/getting-started.md). **Start here** if you want to
play but aren't sure how.
play but aren't sure how (and [BUILD](/BUILD.md) doesn't help).
- [Background](/doc/background.md).
- [Benchmarks](/doc/benchmarks.md).
- [Binary Size](/doc/binary-size.md).
@@ -199,6 +207,14 @@ wuffs test: some tests failed
The [Note](/doc/note) directory also contains various short articles.
# Non-C/C++ Languages
- [dev0x13/pywuffs](https://github.com/dev0x13/pywuffs) holds Python bindings
for Wuffs the Library.
- Bindings for Go, Rust and other languages are tracked as [issue
#38](https://github.com/google/wuffs/issues/38).
# Status
Version 0.3. The API and ABI aren't stabilized yet. The compiler undoubtedly
@@ -209,7 +225,10 @@ there.
Nonetheless, Wuffs' GIF decoder has shipped in the Google Chrome web browser
[since June
2021](https://chromium-review.googlesource.com/c/chromium/src/+/2940044).
2021](https://chromium-review.googlesource.com/c/chromium/src/+/2940044)
(milestone M93). See also the ["ridiculously
fast"](https://twitter.com/richgel999/status/1481027198530248714) tweet already
mentioned above.
# Discussion
@@ -230,7 +249,10 @@ Source code is [auto-formatted](/doc/note/auto-formatting.md).
# License
Apache 2. See the LICENSE file for details.
This software is distributed under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE for details.
# Disclaimer
@@ -239,6 +261,15 @@ This is not an official Google product, it is just code that happens to be
owned by Google.
# Mascot
Tony is an arse-kicking wombat who loves playing
[full-forward](https://en.wikipedia.org/wiki/Full-forward) and hates buffer
overflows.
![WUFFS Logo](./doc/logo/wuffs-acronym-logo-1536x1024.png)
---
Updated on January 2023.
Updated on September 2023.
+7 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2018 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
@@ -36,6 +30,8 @@
# cd wuffs
# gcc ./example/zcat/zcat.c
# ./a.out < ./test/data/romeo.txt.gz
#
# See BUILD.md for more discussion.
if [ ! -e wuffs-root-directory.txt ]; then
echo "$0 should be run from the Wuffs root directory."
+6 -12
View File
@@ -1,21 +1,15 @@
#!/bin/bash -eu
# Copyright 2018 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
# See build-all.sh for commentary.
# See BUILD.md and build-all.sh for more discussion.
if [ ! -e wuffs-root-directory.txt ]; then
echo "$0 should be run from the Wuffs root directory."
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2018 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -2,17 +2,11 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
+10 -22
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
@@ -57,17 +51,11 @@ func main1() error {
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
+8 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
@@ -205,7 +199,7 @@ func (h *genHelper) genDir(dirname string, qualFilenames []string) error {
if err := cmd.Run(); err == nil {
// No-op.
} else if _, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("%s: failed", command)
return fmt.Errorf("%s failed, args=%q", command, cmdArgs)
} else {
return err
}
@@ -294,9 +288,9 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
}
fmt.Fprintf(out, ") ")
if o := n.Out(); o != nil {
fmt.Fprintf(out, "%s", o.Str(&h.tm))
fmt.Fprintf(out, "%s ", o.Str(&h.tm))
}
fmt.Fprintf(out, " { }\n")
fmt.Fprintf(out, "{ }\n")
case a.KStatus:
n := n.AsStatus()
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+6 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
@@ -66,7 +60,7 @@ func genreleaseLang(wuffsRoot string, revision string, commitDate, gitRevListCou
if err := cmd.Run(); err == nil {
// No-op.
} else if _, ok := err.(*exec.ExitError); ok {
return "", nil, fmt.Errorf("%s: failed", command)
return "", nil, fmt.Errorf("%s failed, args=%q", command, args)
} else {
return "", nil, err
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package main
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+3
View File
@@ -9,10 +9,13 @@ new. The [top level README](/README.md) also has some general remarks. Its
sections include:
- Goals and Non-Goals
- Hermeticity
- What Does Wuffs Code Look Like?
- What Does Compile Time Checking Look Like?
- Directory Layout
- Building
- Documentation
- Non-C/C++ Languages
- Status
- Discussion
- Contributing
+36
View File
@@ -1,6 +1,42 @@
# Changelog
## Work In Progress
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 `example/toy-aux-image`.
- 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/jpeg`.
- Added `std/netpbm`.
- Added `std/xxhash32`.
- Added `std/xxhash64`.
- 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.
- 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 read-only type decorators: `roarray`, `roslice` and `rotable`.
- 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).
## 2023-04-08 version 0.3.3
The `wuffs_base__parse_number_f64` function has been further optimized.
+29 -5
View File
@@ -1,15 +1,39 @@
# Getting Started
If you just want to **decode an image**:
- [example/toy-aux-image](/example/toy-aux-image/toy-aux-image.cc) demonstrates
the high-level `wuffs_aux::DecodeImage` C++ function (for decoding still
images, not animated images) and links to more documentation.
- [example/convert-to-nia](/example/convert-to-nia/convert-to-nia.c)
demonstrates the low-level C API, which is more complicated but (1) handles
animation, (2) handles asynchronous I/O, (3) handles metadata and (4) does no
dynamic memory allocation, so it can run under a `SECCOMP_MODE_STRICT`
sandbox. Wuffs is already a memory-safe language, but this provides defense
in depth and can make the security audit trivial.
- [script/print-image-metadata.cc](/script/print-image-metadata.cc)
demonstrates extracting image metadata like ICC color profiles (in raw form).
In all of these cases, you don't need to first configure or build any Wuffs
code. You can just run a C/C++ compiler, like this (for an unoptimized build):
`g++ example/toy-aux-image/toy-aux-image.cc -o my-toy-aux-image`
If you want a fast (optimized) build, pass `-O3` or equivalent to your C/C++
compiler, or from the Wuffs root directory, run this:
`./build-example.sh example/toy-aux-image`
---
If you're looking to **use the Wuffs standard library** generally, e.g. you
want to safely decode some gzip'ed data in your C program, see the [Wuffs the
Library](/doc/wuffs-the-library.md) document and the [other examples](/example)
instead of this document.
If you're looking to **write your own Wuffs code** outside of its standard
library, e.g. you want to safely decode your own custom file format, see the
[Wuffs the Language](/doc/wuffs-the-language.md) document and the
[/hello-wuffs-c](/hello-wuffs-c) example instead of this document.
If you're looking to just **use the Wuffs standard library**, e.g. you want to
safely decode some gzip'ed data in your C program, see the [Wuffs the
Library](/doc/wuffs-the-library.md) document and the [other examples](/example)
instead of this document.
If you're looking to **modify the Wuffs language**, it's probably best to ask
the [mailing list](https://groups.google.com/forum/#!forum/wuffs).
+16 -9
View File
@@ -30,20 +30,26 @@ even for malformed input.
## Wuffs API
Each quirk is assigned a `uint32_t` value, packed using the [base38 namespace
Each quirk is assigned a `uint32_t` number, packed using the [base38 namespace
convention](/doc/note/base38-and-fourcc.md). Decoders and encoders can have a
`set_quirk_enabled!(quirk base.u32, enabled base.bool)` method whose first
argument is this `uint32_t` value.
`set_quirk!(key: base.u32, value: base.u64) base.status` method whose key
argument is this `uint32_t` number.
For example, the base38 encoding of `"gif "` and `"json"` is `0x0F8586` and
`0x124265` respectively, so that the GIF-specific quirks have a `uint32_t`
value of `((0x0F8586 << 10) | g)`, and the JSON-specific quirks have a
`uint32_t` value of `((0x124265 << 10) | j)`, for some small integers `g` and
`j`. The high bits are a namespace. The overall quirk values are different even
if `g` and `j` re-use the same 10-bit integer.
`0x124265` respectively, so that the GIF-specific quirks have a `uint32_t` key
of `((0x0F8586 << 10) | g)` and the JSON-specific quirks have a `uint32_t` key
of `((0x124265 << 10) | j)`, for some small integers `g` and `j`. The high bits
are a namespace. The overall quirk keys are different even if `g` and `j`
re-use the same 10-bit integer.
The generated `C` language file defines human-readable names for those constant
values, such as `WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK`.
numbers, such as `WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK`.
The value argument (a `uint64_t` number) is often effectively a boolean: zero
means to disable and non-zero to enable the quirk. But `set_quirk` is sometimes
also used to pass out-of-band configuration, and not necessarily due to
underspecified file formats, such as `WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE`.
For those cases, zero typically means to use the default configuration.
## Listing
@@ -61,4 +67,5 @@ Package-specific quirks:
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
- [JSON decoder quirks](/std/json/decode_quirks.wuffs)
- [LZW decoder quirks](/std/lzw/decode_quirks.wuffs)
- [ZLIB decoder quirks](/std/zlib/decode_quirks.wuffs)
+4 -1
View File
@@ -47,13 +47,16 @@ to enable.
- `ADLER32: BASE`
- `BMP: BASE`
- `BZIP2: BASE`
- `CBOR: BASE`
- `CRC32: BASE`
- `DEFLATE: BASE`
- `GIF: BASE, LZW`
- `GIF: BASE`
- `GZIP: BASE, CRC32, DEFLATE`
- `JPEG: BASE`
- `JSON: BASE`
- `LZW: BASE`
- `NETPBM: BASE`
- `NIE: BASE`
- `PNG: BASE, ADLER32, CRC32, DEFLATE, ZLIB`
- `TGA: BASE`
+3 -1
View File
@@ -25,7 +25,9 @@ APIs](https://github.com/google/wuffs/issues/73), after Wuffs v0.2 is released.
In Wuffs syntax, the `base.io_transformer` methods are:
- `set_quirk_enabled!(quirk: u32, enabled: bool)`
- `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`
+20 -5
View File
@@ -4,10 +4,10 @@ Hashers take a stream of bytes (of arbitrary length) and produce a fixed length
value - the hash. For example, the CRC-32/IEEE hashing algorithm produces a 32
bit value (a `base.u32`). The MD5 hashing algorithm produces a 128 bit value.
Wuffs' hasher implementations have only one method. For 32 bit hashes, the
method signature is `update_u32!(x: slice base.u8) base.u32`. It incrementally
updates the hasher object's state with the addition data `x`, and returns the
hash value so far, for all of the data up to and including `x`.
Wuffs' hasher implementations have one core method. For 32 bit hashes, the
method signature is `update_u32!(x: roslice base.u8) base.u32`. It
incrementally updates the hasher object's state with the addition data `x`, and
returns the hash value so far, for all of the data up to and including `x`.
This method is stateful. Calling `update_u32` twice with the same slice of
bytes can produce two different hash values. Conversely, calling `update_u32`
@@ -15,6 +15,13 @@ twice with two different slices should be equivalent to calling it once on
their concatenation. [Re-initialize](/doc/note/initialization.md) the object to
reset the state.
The `update_u32!` method is equivalent to calling `update!` and then
`checksum_u32` (which is a pure method). For the rare algorithms where
computing the checksum from internal state is relatively expensive, and when
streaming many relatively-small updates, it might be more efficient to call
`update!` N times and `checksum_u32` only once, instead of calling
`update_u32!` N times.
Wuffs' hasher implementations are not cryptographic. They make no attempt to
resist timing attacks.
@@ -23,14 +30,22 @@ resist timing attacks.
In Wuffs syntax, the `base.hasher_u32` methods are:
- `set_quirk_enabled!(quirk: u32, enabled: bool)`
- `checksum_u32() u32`
- `get_quirk(key: u32) u64`
- `set_quirk!(key: u32, value: u64) status`
- `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.
## Implementations
- [std/adler32](/std/adler32)
- [std/crc32](/std/crc32)
- [std/xxhash32](/std/xxhash32)
- [std/xxhash64](/std/xxhash64)
## Examples
+18 -5
View File
@@ -7,12 +7,19 @@ but the `gif` could be replaced by `jpeg`, `png`, etc.
Some image formats (GIF) are animated, consisting of an image header and then N
frames. The image header gives e.g. the overall image's width and height. Each
frame consists of a frame header (e.g. frame rectangle bounds, display
duration) and a payload (the pixels).
duration) and a payload (the pixels). Headers are also known as configurations.
Wuffs image decoders will reject an image dimension (width or height) that is
above `0xFF_FFFF = 16_777215` pixels, even if the underlying image file format
permits more. This limit simplifies handling potential overflow. For example,
`width * bytes_per_pixel` will not overflow an `i32` and `width * height *
bytes_per_pixel` will not overflow an `i64`. Similarly, converting a pixel
width from integers to 26.6 fixed point units will not overflow an `i32`.
In general, there is one `wuffs_base__image_config` and then N pairs of
(`wuffs_base__frame_config`, frame). Non-animated (still) image formats are
treated the same way: that their N is 1 and their single frame's bounds equals
the overall image bounds.
(`wuffs_base__frame_config`, frame payload). Non-animated (still) image formats
are treated the same way: that their N is 1 and their single frame's bounds
equals the overall image bounds.
To decode everything (without knowing N in advance) sequentially:
@@ -103,11 +110,13 @@ In Wuffs syntax, the `base.image_decoder` methods are:
- `decode_frame_config?(dst: nptr frame_config, src: io_reader)`
- `decode_image_config?(dst: nptr image_config, src: io_reader)`
- `frame_dirty_rect() rect_ie_u32`
- `get_quirk(key: u32) u64`
- `history_retain_length() u64`
- `num_animation_loops() u32`
- `num_decoded_frame_configs() u64`
- `num_decoded_frames() u64`
- `restart_frame!(index: u64, io_position: u64) status`
- `set_quirk_enabled!(quirk: u32, enabled: bool)`
- `set_quirk!(key: u32, value: u64) status`
- `set_report_metadata!(fourcc: u32, report: bool)`
- `tell_me_more?(dst: io_writer, minfo: nptr more_information, src: io_reader)`
- `workbuf_len() range_ii_u64`
@@ -117,6 +126,8 @@ In Wuffs syntax, the `base.image_decoder` methods are:
- [std/bmp](/std/bmp)
- [std/gif](/std/gif)
- [std/jpeg](/std/jpeg)
- [std/netpbm](/std/netpbm)
- [std/nie](/std/nie)
- [std/png](/std/png)
- [std/tga](/std/tga)
@@ -129,6 +140,8 @@ In Wuffs syntax, the `base.image_decoder` methods are:
- [example/gifplayer](/example/gifplayer)
- [example/imageviewer](/example/imageviewer)
- [example/sdl-imageviewer](/example/sdl-imageviewer)
- [example/toy-aux-image](/example/toy-aux-image) **start here** if you want
just want an easy example of Wuffs' C++ API.
- [script/print-average-pixel](/script/print-average-pixel.cc)
- [script/print-image-metadata](/script/print-image-metadata.cc)
+1 -1
View File
@@ -49,7 +49,7 @@ to a 100-element array of unsigned 32-bit integers. Types can also be
## Structs
Structs are a list of fields, enclosed in parentheses: `struct foo(x: base.u32,
y: base.u32)`, possibly extended with a second list of [optionally
y: base.u32)`, possibly extended (by a `+`) with a second list of [optionally
initialized](/doc/note/initialization.md#partial-zero-initialization) fields.
The struct name, `foo`, may be followed by a question mark `?`, which means
that its methods may be [coroutines](/doc/note/coroutines.md).
+2
View File
@@ -24,3 +24,5 @@ examples. To check out and build just one, such as `jsonptr`:
When re-building, you only need the last of those three lines. To run it:
gen/bin/example-jsonptr test/data/json-things.unformatted.json
See also the top-level [BUILD](/BUILD.md) instructions.
+8 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -62,7 +56,6 @@ for a C compiler $CC, such as clang or gcc.
#include "../../release/c/wuffs-unsupported-snapshot.c"
#if defined(__linux__)
#include <linux/prctl.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
@@ -213,7 +206,8 @@ main1(int argc, char** argv) {
return wuffs_base__status__message(&status);
}
wuffs_base__io_buffer__compact(&src);
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";
}
@@ -228,7 +222,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);
}
const int stderr_fd = 2;
ignore_return_value(write(stderr_fd, status_msg, n));
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+157 -34
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -29,6 +23,8 @@ https://skia-review.googlesource.com/c/skia/+/290618
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// Wuffs ships as a "single file C library" or "header file library" as per
@@ -63,7 +59,8 @@ https://skia-review.googlesource.com/c/skia/+/290618
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
@@ -78,7 +75,6 @@ https://skia-review.googlesource.com/c/skia/+/290618
// ----
#if defined(__linux__)
#include <linux/prctl.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
@@ -98,15 +94,20 @@ static const char* g_usage =
"\n"
"Flags:\n"
" -1 -first-frame-only\n"
" -p -output-netpbm\n"
" -fail-if-unsandboxed\n"
"\n"
"convert-to-nia converts an image from stdin (e.g. in the BMP, GIF, JPEG\n"
"or PNG format) to stdout (in the NIA format, or in the NIE format if\n"
"the -first-frame-only flag is given).\n"
"or PNG format) to stdout (in the NIA format, or in the NIE or PPM/PGM\n"
"format if the -1 or -p flag is given; you cannot specify both flags).\n"
"\n"
"NIA/NIE is a trivial animated/still image file format, specified at\n"
"https://github.com/google/wuffs/blob/main/doc/spec/nie-spec.md\n"
"\n"
"PPM (color) and PGM (gray) are also trivial still image file formats.\n"
"They do not support alpha or animation. Using -p means that this program\n"
"outputs the same format as /usr/bin/djpeg\n"
"\n"
"The -fail-if-unsandboxed flag causes the program to exit if it does not\n"
"self-impose a sandbox. On Linux, it self-imposes a SECCOMP_MODE_STRICT\n"
"sandbox, regardless of whether this flag was set.";
@@ -120,9 +121,10 @@ static const char* g_usage =
bool g_sandboxed = false;
wuffs_base__pixel_buffer g_pixbuf = {0};
wuffs_base__io_buffer g_src = {0};
wuffs_base__slice_u8 g_pixbuf_slice = {0};
wuffs_base__slice_u8 g_pixbuf_backup_slice = {0};
wuffs_base__io_buffer g_src = {0};
wuffs_base__slice_u8 g_workbuf_slice = {0};
wuffs_base__image_config g_image_config = {0};
@@ -130,6 +132,7 @@ wuffs_base__frame_config g_frame_config = {0};
int32_t g_fourcc = 0;
uint32_t g_width = 0;
uint32_t g_height = 0;
bool g_pixfmt_is_gray = false;
uint32_t g_num_animation_loops = 0;
uint64_t g_num_printed_frames = 0;
@@ -137,6 +140,8 @@ wuffs_base__image_decoder* g_image_decoder = NULL;
union {
wuffs_bmp__decoder bmp;
wuffs_gif__decoder gif;
wuffs_jpeg__decoder jpeg;
wuffs_netpbm__decoder netpbm;
wuffs_nie__decoder nie;
wuffs_png__decoder png;
wuffs_tga__decoder tga;
@@ -163,9 +168,21 @@ union {
#define PIXBUF_ARRAY_SIZE (256 * 1024 * 1024)
#endif
// Uncomment this #define (or use a C compiler flag) to decode very large
// images like test/3pdata/blinksuite/large-size-image-crash.jpeg which is
// 48010 * 16173 = 776_465730 pixels, roughly 2.9 GiB at 4 bytes per pixel.
//
// This requires calling malloc (before self-imposing a SECCOMP_MODE_STRICT
// sandbox). By default (without this #define), the buffers are statically
// allocated and do not require syscalls.
//
// #define ALLOW_GIGABYTES_OF_PIXEL_BUFFERS 1
uint8_t g_src_buffer_array[SRC_BUFFER_ARRAY_SIZE] = {0};
#if !defined(ALLOW_GIGABYTES_OF_PIXEL_BUFFERS)
uint8_t g_workbuf_array[WORKBUF_ARRAY_SIZE] = {0};
uint8_t g_pixbuf_array[PIXBUF_ARRAY_SIZE] = {0};
#endif
// ----
@@ -175,6 +192,7 @@ struct {
bool fail_if_unsandboxed;
bool first_frame_only;
bool output_netpbm;
} g_flags = {0};
const char* //
@@ -207,10 +225,18 @@ parse_flags(int argc, char** argv) {
g_flags.first_frame_only = true;
continue;
}
if (!strcmp(arg, "p") || !strcmp(arg, "output-netpbm")) {
g_flags.output_netpbm = true;
continue;
}
return g_usage;
}
if (g_flags.first_frame_only && g_flags.output_netpbm) {
return g_usage;
}
g_flags.remaining_argc = argc - c;
g_flags.remaining_argv = argv + c;
return NULL;
@@ -223,11 +249,11 @@ static void //
ignore_return_value(int ignored) {}
const char* //
read_more_src() {
read_more_src(uint64_t history_retain_length) {
if (g_src.meta.closed) {
return "main: unexpected end of file";
}
wuffs_base__io_buffer__compact(&g_src);
wuffs_base__io_buffer__compact_retaining(&g_src, history_retain_length);
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) {
@@ -253,7 +279,7 @@ load_image_type() {
(wuffs_base__io_buffer__reader_length(&g_src) == g_src.data.len)) {
break;
}
TRY(read_more_src());
TRY(read_more_src(0));
}
return NULL;
}
@@ -282,6 +308,16 @@ initialize_image_decoder() {
&g_potential_decoders.gif);
return NULL;
case WUFFS_BASE__FOURCC__JPEG:
status = wuffs_jpeg__decoder__initialize(
&g_potential_decoders.jpeg, sizeof g_potential_decoders.jpeg,
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_jpeg__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.jpeg);
return NULL;
case WUFFS_BASE__FOURCC__NIE:
status = wuffs_nie__decoder__initialize(
&g_potential_decoders.nie, sizeof g_potential_decoders.nie,
@@ -292,6 +328,16 @@ initialize_image_decoder() {
&g_potential_decoders.nie);
return NULL;
case WUFFS_BASE__FOURCC__NPBM:
status = wuffs_netpbm__decoder__initialize(
&g_potential_decoders.netpbm, sizeof g_potential_decoders.netpbm,
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_netpbm__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.netpbm);
return NULL;
case WUFFS_BASE__FOURCC__PNG:
status = wuffs_png__decoder__initialize(
&g_potential_decoders.png, sizeof g_potential_decoders.png,
@@ -358,7 +404,7 @@ advance_for_redirect() {
break;
}
g_src.meta.ri = g_src.meta.wi;
TRY(read_more_src());
TRY(read_more_src(0));
}
return NULL;
}
@@ -385,7 +431,8 @@ redirect:
} else if (status.repr != wuffs_base__suspension__short_read) {
return wuffs_base__status__message(&status);
}
TRY(read_more_src());
TRY(read_more_src(
wuffs_base__image_decoder__history_retain_length(g_image_decoder)));
}
// Read the dimensions.
@@ -396,6 +443,16 @@ redirect:
}
g_width = w;
g_height = h;
switch (wuffs_base__pixel_config__pixel_format(&g_image_config.pixcfg).repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
g_pixfmt_is_gray = true;
break;
default:
g_pixfmt_is_gray = false;
break;
}
// Override the image's native pixel format to be BGRA_NONPREMUL.
wuffs_base__pixel_config__set(&g_image_config.pixcfg,
@@ -405,22 +462,21 @@ redirect:
// Configure the work buffer.
uint64_t workbuf_len =
wuffs_base__image_decoder__workbuf_len(g_image_decoder).max_incl;
if (workbuf_len > WORKBUF_ARRAY_SIZE) {
if (g_workbuf_slice.len < workbuf_len) {
return "main: image is too large (to configure work buffer)";
}
g_workbuf_slice.ptr = &g_workbuf_array[0];
g_workbuf_slice.len = workbuf_len;
// Configure the pixel buffer and (if there's capacity) its backup buffer.
uint64_t num_pixels = ((uint64_t)w) * ((uint64_t)h);
if (num_pixels > (PIXBUF_ARRAY_SIZE / BYTES_PER_PIXEL)) {
if (g_pixbuf_slice.len < (num_pixels * BYTES_PER_PIXEL)) {
return "main: image is too large (to configure pixel buffer)";
}
g_pixbuf_slice.ptr = &g_pixbuf_array[0];
size_t old_pixbuf_slice_len = g_pixbuf_slice.len;
g_pixbuf_slice.len = num_pixels * BYTES_PER_PIXEL;
size_t pixbuf_array_remaining = PIXBUF_ARRAY_SIZE - g_pixbuf_slice.len;
size_t pixbuf_array_remaining = old_pixbuf_slice_len - g_pixbuf_slice.len;
if (pixbuf_array_remaining >= g_pixbuf_slice.len) {
g_pixbuf_backup_slice.ptr = &g_pixbuf_array[g_pixbuf_slice.len];
g_pixbuf_backup_slice.ptr = g_pixbuf_slice.ptr + g_pixbuf_slice.len;
g_pixbuf_backup_slice.len = g_pixbuf_slice.len;
}
@@ -471,6 +527,14 @@ print_nix_header(uint32_t magic_u32le) {
ignore_return_value(write(STDOUT_FD, &data[0], 16));
}
void //
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));
}
void //
print_nia_duration(wuffs_base__flicks duration) {
uint8_t data[8];
@@ -489,11 +553,36 @@ print_nie_frame() {
for (size_t y = 0; y < tab.height; y++) {
ignore_return_value(
write(STDOUT_FD, tab.ptr + (y * tab.stride), tab.width));
break;
}
}
}
void //
print_netpbm_frame() {
g_num_printed_frames++;
uint8_t data[4096];
size_t o = 0;
const size_t o_increment = g_pixfmt_is_gray ? 1 : 3;
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
for (size_t y = 0; y < tab.height; y++) {
const uint8_t* row = tab.ptr + (y * tab.stride);
for (size_t x = 0; x < tab.width; x += 4) {
data[o + 0] = row[x + 2];
data[o + 1] = row[x + 1];
data[o + 2] = row[x + 0];
o += o_increment;
if ((o + 3) > sizeof(data)) {
ignore_return_value(write(STDOUT_FD, &data[0], o));
o = 0;
}
}
}
if (o > 0) {
ignore_return_value(write(STDOUT_FD, &data[0], o));
o = 0;
}
}
void //
print_nia_padding() {
if (g_width & g_height & 1) {
@@ -542,7 +631,8 @@ convert_frames() {
} else if (dfc_status.repr != wuffs_base__suspension__short_read) {
return wuffs_base__status__message(&dfc_status);
}
TRY(read_more_src());
TRY(read_more_src(
wuffs_base__image_decoder__history_retain_length(g_image_decoder)));
}
wuffs_base__flicks duration =
@@ -584,7 +674,8 @@ convert_frames() {
if (df_status.repr != wuffs_base__suspension__short_read) {
break;
}
decode_frame_io_error_message = read_more_src();
decode_frame_io_error_message = read_more_src(
wuffs_base__image_decoder__history_retain_length(g_image_decoder));
if (decode_frame_io_error_message != NULL) {
// Neuter the "short read" df_status so that convert_frames returns the
// I/O error message instead.
@@ -617,6 +708,9 @@ convert_frames() {
wuffs_base__image_decoder__num_animation_loops(g_image_decoder);
// Print a complete NIE frame (and surrounding bytes, for NIA).
if (g_flags.output_netpbm) {
print_netpbm_frame();
} else {
if (!g_flags.first_frame_only) {
print_nia_duration(total_duration);
}
@@ -624,13 +718,14 @@ convert_frames() {
if (!g_flags.first_frame_only) {
print_nia_padding();
}
}
// Return early if there was an error decoding the frame.
if (df_status.repr != NULL) {
return wuffs_base__status__message(&df_status);
} else if (decode_frame_io_error_message != NULL) {
return decode_frame_io_error_message;
} else if (g_flags.first_frame_only) {
} else if (g_flags.first_frame_only || g_flags.output_netpbm) {
return NULL;
}
@@ -669,11 +764,13 @@ main1(int argc, char** argv) {
TRY(load_image_type());
TRY(load_image_config());
if (!g_flags.first_frame_only) {
if (g_flags.output_netpbm) {
print_netpbm_header();
} else if (!g_flags.first_frame_only) {
print_nix_header(0x41AFC36E); // "nïA" as a u32le.
}
const char* ret = convert_frames();
if (!g_flags.first_frame_only) {
if (!g_flags.first_frame_only && !g_flags.output_netpbm) {
print_nia_footer();
}
return ret;
@@ -691,7 +788,7 @@ compute_exit_code(const char* status_msg) {
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);
}
}
ignore_return_value(write(STDERR_FD, status_msg, n));
@@ -712,6 +809,32 @@ compute_exit_code(const char* status_msg) {
int //
main(int argc, char** argv) {
#if !defined(ALLOW_GIGABYTES_OF_PIXEL_BUFFERS)
{
g_pixbuf_slice =
wuffs_base__make_slice_u8(&g_pixbuf_array[0], sizeof(g_pixbuf_array));
g_workbuf_slice =
wuffs_base__make_slice_u8(&g_workbuf_array[0], sizeof(g_workbuf_array));
}
#elif !defined(__WORDSIZE) || (__WORDSIZE != 64)
#error "ALLOW_GIGABYTES_OF_PIXEL_BUFFERS requires a word size of 64 bits"
#else
// Call malloc before we self-impose a SECCOMP_MODE_STRICT sandbox.
{
static const size_t four_gigabytes = 0x100000000ul;
void* p = malloc(four_gigabytes);
void* w = malloc(four_gigabytes);
if (!p || !w) {
return compute_exit_code(
"could not allocate ALLOW_GIGABYTES_OF_PIXEL_BUFFERS");
}
g_pixbuf_slice = wuffs_base__make_slice_u8(p, four_gigabytes);
g_workbuf_slice = wuffs_base__make_slice_u8(w, four_gigabytes);
}
#endif // !defined(ALLOW_GIGABYTES_OF_PIXEL_BUFFERS)
// ----
#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT);
g_sandboxed = true;
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+7 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -90,7 +84,6 @@ micros_since_start(struct timespec* now) {
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__GIF
// If building this program in an environment that doesn't easily accommodate
@@ -353,8 +346,8 @@ play() {
}
if (g_flags.quirk_honor_background_color) {
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR, true);
wuffs_gif__decoder__set_quirk(&dec, WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR,
1);
}
wuffs_base__io_buffer src;
+7 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -79,7 +73,8 @@ The Escape key quits.
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+15 -22
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -141,7 +135,6 @@ for a C++ compiler $CXX, such as clang++ or g++.
#include "../../release/c/wuffs-unsupported-snapshot.c"
#if defined(__linux__)
#include <linux/prctl.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
@@ -976,21 +969,21 @@ initialize_globals(int argc, char** argv) {
.message());
if (g_flags.input_allow_comments) {
g_dec.set_quirk_enabled(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, true);
g_dec.set_quirk_enabled(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, true);
g_dec.set_quirk(WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, 1);
g_dec.set_quirk(WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, 1);
}
if (g_flags.input_allow_extra_comma) {
g_dec.set_quirk_enabled(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, true);
g_dec.set_quirk(WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, 1);
}
if (g_flags.input_allow_inf_nan_numbers) {
g_dec.set_quirk_enabled(WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS, true);
g_dec.set_quirk(WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS, 1);
}
// Consume any optional trailing whitespace and comments. This isn't part of
// the JSON spec, but it works better with line oriented Unix tools (such as
// "echo 123 | jsonptr" where it's "echo", not "echo -n") or hand-edited JSON
// files which can accidentally contain trailing whitespace.
g_dec.set_quirk_enabled(WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER, true);
g_dec.set_quirk(WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER, 1);
return nullptr;
}
@@ -1002,11 +995,11 @@ static void //
ignore_return_value(int ignored) {}
const char* //
read_src() {
read_src(uint64_t history_retain_length) {
if (g_src.meta.closed) {
return "main: internal error: read requested on a closed source";
}
g_src.compact();
g_src.compact_retaining(history_retain_length);
if (g_src.meta.wi >= g_src.data.len) {
return "main: g_src buffer is full";
}
@@ -1399,7 +1392,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());
TRY(read_src(g_dec.history_retain_length()));
}
if ((g_src.meta.ri < g_src.meta.wi) || !g_src.meta.closed) {
return "main: valid JSON followed by further (unexpected) data";
@@ -1410,7 +1403,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());
TRY(read_src(g_dec.history_retain_length()));
g_cursor_index = g_src.meta.ri;
} else if (status.repr == wuffs_base__suspension__short_write) {
g_tok.compact();
@@ -1432,7 +1425,7 @@ compute_exit_code(const char* status_msg) {
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);
}
}
const int stderr_fd = 2;
+12 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -77,8 +71,12 @@ isn't otherwise doing anything.
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__ZLIB
// If building this program in an environment that doesn't easily accommodate
@@ -189,7 +187,7 @@ class Wuffs_Load_RW_Input : public wuffs_aux::sync_io::Input {
private:
std::string //
CopyIn(wuffs_aux::IOBuffer* dst) override {
CopyIn(wuffs_aux::IOBuffer* dst, uint64_t history_retain_length) override {
if (!m_rw) {
return "Wuffs_Load_RW_Input: NULL SDL_RWops";
} else if (!dst) {
@@ -197,7 +195,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();
dst->compact_retaining(history_retain_length);
if (dst->writer_length() == 0) {
return "Wuffs_Load_RW_Input: full IOBuffer";
}
+218
View File
@@ -0,0 +1,218 @@
// 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.
// ----------------
/*
toy-aux-image demonstrates using the wuffs_aux::DecodeImage C++ function to
decode an in-memory compressed image. In this example, the compressed image is
hard-coded to a specific image: a JPEG encoding of the first frame of the
test/data/muybridge.gif animated image.
To run:
$CXX toy-aux-image.cc && ./a.out; rm -f a.out
for a C++ compiler $CXX, such as clang++ or g++.
The expected output:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@X@@@@XX@@@@@@@@@@X
XXXXX@@XXX@@@@@@@II@@@X@X@@@@@
XXXXX@@XX@@X@@@XO+XXX@XX@@@X@@
XXXXXXXX@XX@X@XI=I@@XXI+OXX@XX
XXXXXXXXXXXXXXX+=+OXO+=::OXX@X
XXXXXXXXXXXXXXXXXX=+==:::=XXXX
XXXXXXXXO+:::::+OO+===+OI=+XXX
XXXO::=++:::==+++XI+++X@XXO@XX
XXXO=X@X+::=::::+O++=I@XX@XXXX
XXXXX@XXX=:::::::::=+@XXXX@XXX
XXXXXXXX@O::IXO=::::O@@XXXXXXX
XXXXXXXXO=X+X@@XX::O@@XXXXXXXX
XXXXXXXXXOO=X@X@X+OIXXXXXXXXXX
XXXXXXXXXXX+IIXX+X@OX@XXXXXXXX
XXXXXXXXX@XXOI+IIOOOXXXXXXXXXX
XXXXXXXXXXX@XXXXX@XXXXXXXXXXXX
XXXXXXXXXXXXXXXXX@XXXXXXXXXXXX
OOOOXXXXXXXXXXOXXXXXXXXXXXXOOO
=+++IIIIIIIOOOOOOOOOOIIIIIIII+
*/
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
//
// This can help the compiler ignore or discard unused code, which can produce
// faster compiles and smaller binaries. Other motivations are discussed in the
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__AUX__BASE
#define WUFFS_CONFIG__MODULE__AUX__IMAGE
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__JPEG
// 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"
// g_src_array and g_src_len hold a grayscale JPEG image of a galloping horse.
//
// $ convert 'test/data/muybridge.gif[0]' -colorspace gray x.jpeg
// $ hd x.jpeg
// 00000000 ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 |......JFIF......|
// 00000010 00 01 00 00 ff db 00 43 00 03 02 02 02 02 02 03 |.......C........|
// 00000020 02 02 02 03 03 03 03 04 06 04 04 04 04 04 08 06 |................|
// etc
// 00000200 53 04 29 20 5a 26 25 41 d3 44 75 ee fa 37 07 d5 |S.) Z&%A.Du..7..|
// 00000210 fd 40 67 91 55 49 14 49 6c 55 53 af 14 ed e7 fd |.@g.UI.IlUS.....|
// 00000220 6e 3f ff d9 |n?..|
// 00000224
uint8_t g_src_array[] = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43,
0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x03,
0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06,
0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a,
0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d,
0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, 0x12, 0x10,
0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x14,
0x00, 0x1e, 0x01, 0x01, 0x11, 0x00, 0xff, 0xc4, 0x00, 0x18, 0x00, 0x01,
0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0x08, 0x03, 0x05, 0x06, 0xff, 0xc4, 0x00, 0x2e,
0x10, 0x00, 0x02, 0x01, 0x04, 0x00, 0x05, 0x01, 0x05, 0x09, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x11,
0x00, 0x07, 0x08, 0x12, 0x21, 0x13, 0x22, 0x31, 0x41, 0x51, 0x61, 0x14,
0x17, 0x23, 0x32, 0x42, 0x52, 0x71, 0x81, 0x91, 0xff, 0xda, 0x00, 0x08,
0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xbd, 0x63, 0xbc, 0x2a, 0x15, 0x49,
0x6a, 0x02, 0xbb, 0x0d, 0x80, 0xcc, 0x01, 0x3f, 0x5d, 0x71, 0xc7, 0x5f,
0x3a, 0x80, 0xe5, 0x85, 0x92, 0x5a, 0xeb, 0x5a, 0xf3, 0x0b, 0x18, 0x9a,
0xf7, 0x48, 0x1a, 0x35, 0xb5, 0xc9, 0x7c, 0xa5, 0x82, 0x67, 0x9f, 0x5e,
0xcc, 0x47, 0xbd, 0xc0, 0x52, 0x4e, 0x87, 0x9f, 0x77, 0x06, 0xb5, 0xbd,
0x58, 0x47, 0x80, 0xd9, 0x5a, 0xd5, 0x96, 0x50, 0x5d, 0x2f, 0x59, 0xf5,
0x45, 0x63, 0x16, 0xc7, 0x2d, 0xd0, 0x89, 0x7e, 0xcd, 0xea, 0x76, 0xb4,
0x50, 0xc7, 0x34, 0x60, 0xa4, 0x88, 0x11, 0x97, 0x4c, 0x0b, 0x31, 0x25,
0x87, 0xc3, 0x41, 0x87, 0x97, 0xfc, 0xce, 0xb3, 0xf3, 0x27, 0x16, 0xa5,
0xca, 0x6c, 0x8d, 0x50, 0x91, 0xcc, 0x5a, 0x29, 0xe9, 0xaa, 0x17, 0xb2,
0x7a, 0x49, 0xd7, 0xc4, 0x90, 0xca, 0x9f, 0xa5, 0xd4, 0xf8, 0x23, 0xf8,
0x23, 0x60, 0x83, 0xc6, 0xb2, 0xed, 0xcb, 0xbc, 0x07, 0x30, 0xba, 0xd0,
0xdf, 0xb2, 0xbc, 0x46, 0xd7, 0x78, 0xae, 0xb7, 0x43, 0x24, 0x14, 0x72,
0xd7, 0x53, 0xac, 0xe2, 0x04, 0x90, 0xa9, 0x7e, 0xd5, 0x6d, 0xa8, 0x27,
0xb4, 0x7b, 0x5a, 0xd8, 0xf3, 0xa3, 0xe4, 0xf1, 0x26, 0xd6, 0xf4, 0x6d,
0x8b, 0xfd, 0xe3, 0x65, 0x32, 0x64, 0xd9, 0xc5, 0xeb, 0x0b, 0xa3, 0xb9,
0x91, 0x57, 0x61, 0x92, 0x19, 0x51, 0xe0, 0x49, 0xe5, 0x96, 0x50, 0xca,
0xd3, 0xb0, 0x1e, 0xaa, 0x84, 0x8d, 0x1b, 0xb1, 0xbd, 0x36, 0x1e, 0xb0,
0x50, 0x58, 0xaf, 0x73, 0x24, 0x74, 0xbd, 0xca, 0xac, 0xaa, 0xd3, 0x7f,
0xb8, 0xe6, 0x7c, 0xc6, 0xca, 0xe2, 0xc8, 0xaa, 0x68, 0x63, 0x5a, 0x6c,
0x76, 0x48, 0xe3, 0x58, 0xc4, 0x74, 0x7a, 0x31, 0x24, 0x92, 0x22, 0x9f,
0xc3, 0x94, 0xc5, 0x1a, 0xea, 0x26, 0x05, 0x91, 0x5f, 0xcb, 0x16, 0xdf,
0x6d, 0x1a, 0xec, 0x4b, 0x33, 0xaa, 0x22, 0x17, 0x3d, 0xcc, 0x54, 0x6b,
0xb8, 0xe8, 0x0d, 0x9f, 0x99, 0xd0, 0x03, 0xfa, 0x1c, 0x4b, 0xb8, 0x47,
0x51, 0xdc, 0xc1, 0xbc, 0xd2, 0xa4, 0xd5, 0x90, 0xda, 0x36, 0x57, 0x7a,
0x4a, 0x66, 0x03, 0xf2, 0x83, 0xfb, 0xfe, 0xbc, 0x23, 0xd9, 0xb9, 0xab,
0x95, 0xdc, 0xed, 0xed, 0x34, 0xed, 0x48, 0xa5, 0x48, 0x20, 0x24, 0x3e,
0x3e, 0x1f, 0x32, 0x78, 0xc9, 0x72, 0xe6, 0xb6, 0x53, 0x04, 0x29, 0x20,
0x5a, 0x26, 0x25, 0x41, 0xd3, 0x44, 0x75, 0xee, 0xfa, 0x37, 0x07, 0xd5,
0xfd, 0x40, 0x67, 0x91, 0x55, 0x49, 0x14, 0x49, 0x6c, 0x55, 0x53, 0xaf,
0x14, 0xed, 0xe7, 0xfd, 0x6e, 0x3f, 0xff, 0xd9,
};
size_t g_src_len = 0x224;
static std::string //
decode() {
// Call wuffs_aux::DecodeImage, which is the entry point to Wuffs' high-level
// C++ API for decoding images. This API is easier to use than Wuffs'
// low-level C API but the low-level one (1) handles animation, (2) handles
// asynchronous I/O, (3) handles metadata and (4) does no dynamic memory
// allocation, so it can run under a `SECCOMP_MODE_STRICT` sandbox.
// Obviously, if you don't need any of those features, then these simple
// lines of code here suffices.
//
// This example program doesn't explicitly use Wuffs' low-level C API but, if
// you're curious to learn more, the wuffs_aux::DecodeImage implementation in
// internal/cgen/auxiliary/*.cc uses it, as does the example/convert-to-nia C
// program. There's also documentation at doc/std/image-decoders.md
//
// If you also want metadata like EXIF orientation and ICC color profiles,
// script/print-image-metadata.cc has some example code. It uses Wuffs'
// low-level API but it's a C++ program to use Wuffs' shorter convenience
// methods: `decoder->decode_frame_config(NULL, &src)` instead of C's
// `wuffs_base__image_decoder__decode_frame_config(decoder, NULL, &src)`.
wuffs_aux::DecodeImageCallbacks callbacks;
wuffs_aux::sync_io::MemoryInput input(&g_src_array[0], g_src_len);
wuffs_aux::DecodeImageResult result =
wuffs_aux::DecodeImage(callbacks, input);
if (!result.error_message.empty()) {
return result.error_message;
}
// If result.error_message is empty then the DecodeImage call succeeded. The
// decoded image is held in result.pixbuf, backed by memory that is released
// when result.pixbuf_mem_owner (a std::unique_ptr) is destroyed. In this
// example program, this happens at the end of this function.
// Print result.pixbuf as ASCII art.
uint32_t w = result.pixbuf.pixcfg.width();
uint32_t h = result.pixbuf.pixcfg.height();
for (uint32_t y = 0; y < h; y++) {
for (uint32_t x = 0; x < w; x++) {
// color is 32 bits (4x8 bits). The blue channel occupies the low 8 bits.
// The green channel occupies the next 8 bits. Red the next 8 and alpha
// the high 8 bits. Since our hard-coded JPEG image is grayscale, this
// example program just prints an ASCII value based on the high 3 bits of
// the blue channel value.
//
// This example program also configures wuffs_aux::DecodeImage to only
// support JPEG images (and not BMP, PNG, etc). To add support for other
// image file formats, add e.g. "#define WUFFS_CONFIG__MODULE__BMP" (and
// any dependencies) next to the "#define WUFFS_CONFIG__MODULE__JPEG"
// line above. Dependencies are listed at
// https://github.com/google/wuffs/tree/main/doc/std#modules-and-dependencies
//
// Calling the color_u32_at method is simple and easy, but like any
// one-call-per-pixel approach, it has some performance overhead. An
// alternative approach calls result.pixbuf.plane instead, to get the
// table (base pointer, width, height and stride) for the interleaved
// (not multi-planar) WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL pixel data,
// and proceeds with pointer arithmetic. See example/imageviewer code.
wuffs_base__color_u32_argb_premul color =
result.pixbuf.color_u32_at(x, y);
putchar("-:=+IOX@"[(color & 0xFF) >> 5]);
}
putchar('\n');
}
return std::string();
}
int //
main(int argc, char** argv) {
std::string status_msg = decode();
if (!status_msg.empty()) {
fprintf(stderr, "%s\n", status_msg.c_str());
return 1;
}
return 0;
}
+10 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -30,6 +24,10 @@ LD_LIBRARY_PATH=../../gen/lib/c/$CC-dynamic ./a.out
rm -f a.out
for a C compiler $CC, such as clang or gcc.
The expected output:
Hello Wuffs.
*/
#include <stdio.h>
@@ -49,7 +47,7 @@ for a C compiler $CC, such as clang or gcc.
#endif
uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE];
// src_ptr and src_len hold a gzip-encoded "Hello Wuffs."
// g_src_array and g_src_len hold a gzip-encoded "Hello Wuffs."
//
// $ echo "Hello Wuffs." | gzip --no-name | hd
// 00000000 1f 8b 08 00 00 00 00 00 00 03 f3 48 cd c9 c9 57 |...........H...W|
+8 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -64,7 +58,6 @@ for a C compiler $CC, such as clang or gcc.
#include "../../release/c/wuffs-unsupported-snapshot.c"
#if defined(__linux__)
#include <linux/prctl.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
@@ -215,7 +208,8 @@ main1(int argc, char** argv) {
return wuffs_base__status__message(&status);
}
wuffs_base__io_buffer__compact(&src);
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";
}
@@ -230,7 +224,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);
}
const int stderr_fd = 2;
ignore_return_value(write(stderr_fd, status_msg, n));
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#include <inttypes.h>
#include <stdio.h>
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#ifndef WUFFS_INCLUDE_GUARD
#error "Wuffs' .h files need to be included before this file"
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+7 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -97,8 +91,8 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
// Ignore the checksum for 99.99%-ish of all input. When fuzzers generate
// random input, the checkum is very unlikely to match. Still, it's useful to
// verify that checksumming does not lead to e.g. buffer overflows.
wuffs_bzip2__decoder__set_quirk_enabled(
&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, hash & 0xFFFE);
wuffs_bzip2__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
hash & 0xFFFE);
uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
wuffs_base__io_buffer dst =
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+6 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -64,7 +58,6 @@ It should print "PASS", amongst other information, and exit(0).
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
@@ -88,7 +81,7 @@ void set_quirks(wuffs_gif__decoder* dec, uint64_t hash) {
for (uint32_t i = 0; quirks[i]; i++) {
uint64_t bit = 1 << (i & 63);
if (hash & bit) {
wuffs_gif__decoder__set_quirk_enabled(dec, quirks[i], true);
wuffs_gif__decoder__set_quirk(dec, quirks[i], 1);
}
}
}
+82
View File
@@ -0,0 +1,82 @@
// 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.
// ----------------
// 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 jpeg_fuzzer.c
./a.out ../../../test/data/*.jpeg
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__JPEG
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../fuzzlib/fuzzlib.c"
#include "../fuzzlib/fuzzlib_image_decoder.c"
const char* //
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
wuffs_jpeg__decoder dec;
wuffs_base__status status = wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
hash = wuffs_base__u64__rotate_right(hash, 1);
if (!wuffs_base__status__is_ok(&status)) {
return wuffs_base__status__message(&status);
}
return fuzz_image_decoder(
src, hash,
wuffs_jpeg__decoder__upcast_as__wuffs_base__image_decoder(&dec));
}
+6 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -264,7 +258,7 @@ void set_quirks(wuffs_json__decoder* dec, uint64_t hash) {
for (uint32_t i = 0; g_quirks[i]; i++) {
uint64_t bit = 1 << (i & 63);
if (hash & bit) {
wuffs_json__decoder__set_quirk_enabled(dec, g_quirks[i], true);
wuffs_json__decoder__set_quirk(dec, g_quirks[i], 1);
}
}
}
+229 -27
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -94,28 +88,37 @@ const wuffs_base__pixel_blend blends[] = {
WUFFS_BASE__PIXEL_BLEND__SRC_OVER,
};
// allocate_guarded_page allocates (2 * page_size) bytes of memory. The first
// page has read|write permissions. The second page has no permissions, so that
size_t //
round_up_to_pagesize(size_t n) {
size_t ps = getpagesize();
if (ps <= 0) {
return n;
}
return ((n + (ps - 1)) / ps) * ps;
}
// allocate_guarded_pages allocates (2 * len) bytes of memory. The first half
// has read|write permissions. The second half has no permissions, so that
// attempting to read or write to it will cause a segmentation fault.
const char* //
allocate_guarded_page(uint8_t** ptr_out, int page_size) {
allocate_guarded_pages(uint8_t** ptr_out, size_t len) {
void* ptr =
mmap(NULL, 2 * page_size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
mmap(NULL, 2 * len, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (ptr == MAP_FAILED) {
return "fuzz: internal error: mmap failed";
}
if (mprotect(ptr, page_size, PROT_READ | PROT_WRITE)) {
if (mprotect(ptr, len, PROT_READ | PROT_WRITE)) {
return "fuzz: internal error: mprotect failed";
}
*ptr_out = ptr;
return NULL;
}
// fuzz tests that, regardless of the randomized inputs, calling
// wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice will not crash
// the fuzzer (e.g. due to reads or write past buffer bounds).
// fuzz_swizzle_interleaved_from_slice tests that, regardless of the randomized
// inputs, calling wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice
// will not crash the fuzzer (e.g. due to reads or write past buffer bounds).
const char* //
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
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) {
@@ -149,14 +152,14 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
return wuffs_base__status__message(&status);
}
int page_size = getpagesize();
if (page_size < 0x100) {
return "fuzz: internal error: page_size is too small";
static size_t alloc_size = 0;
if (alloc_size == 0) {
alloc_size = round_up_to_pagesize(0x100);
}
static uint8_t* dst_alloc = NULL;
if (!dst_alloc) {
const char* z = allocate_guarded_page(&dst_alloc, page_size);
const char* z = allocate_guarded_pages(&dst_alloc, alloc_size);
if (z != NULL) {
return z;
}
@@ -164,7 +167,7 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
static uint8_t* src_alloc = NULL;
if (!src_alloc) {
const char* z = allocate_guarded_page(&src_alloc, page_size);
const char* z = allocate_guarded_pages(&src_alloc, alloc_size);
if (z != NULL) {
return z;
}
@@ -176,14 +179,20 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
return "fuzz: not enough data";
}
wuffs_base__slice_u8 dst_slice =
wuffs_base__make_slice_u8(dst_alloc + page_size - dst_len, dst_len);
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 + page_size - src_len, src_len);
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;
// When manually testing this program, enabling this code should lead to a
// segmentation fault.
#if 0
src_slice.ptr[src_slice.len]++;
#endif
// Calling etc__swizzle_interleaved_from_slice should not crash, whether for
// reading/writing out of bounds or for other reasons.
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(
@@ -191,3 +200,196 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
return NULL;
}
const char* //
fuzz_swizzle_ycck(wuffs_base__io_buffer* src, uint64_t hash) {
uint8_t dst_palette_array[1024] = {0};
wuffs_base__slice_u8 dst_palette =
wuffs_base__make_slice_u8(&dst_palette_array[0], 1024);
size_t num_pixfmts = sizeof(pixfmts) / sizeof(pixfmts[0]);
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 width_in_mcus = (3 & (hash >> 20)) + 1;
uint32_t height_in_mcus = (3 & (hash >> 22)) + 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 possible_hv_values[2][4] = {
{1, 1, 2, 4},
{1, 1, 3, 3},
};
uint32_t h0 = possible_hv_values[allow_hv3][3 & (hash >> 28)];
uint32_t h1 = possible_hv_values[allow_hv3][3 & (hash >> 30)];
uint32_t h2 = possible_hv_values[allow_hv3][3 & (hash >> 32)];
uint32_t h3 =
use_4th_component ? possible_hv_values[allow_hv3][3 & (hash >> 34)] : 0;
uint32_t v0 = possible_hv_values[allow_hv3][3 & (hash >> 36)];
uint32_t v1 = possible_hv_values[allow_hv3][3 & (hash >> 38)];
uint32_t v2 = possible_hv_values[allow_hv3][3 & (hash >> 40)];
uint32_t v3 =
use_4th_component ? possible_hv_values[allow_hv3][3 & (hash >> 42)] : 0;
uint32_t width0 = 8 * width_in_mcus * h0;
uint32_t width1 = 8 * width_in_mcus * h1;
uint32_t width2 = 8 * width_in_mcus * h2;
uint32_t width3 = 8 * width_in_mcus * h3;
uint32_t height0 = 8 * height_in_mcus * v0;
uint32_t height1 = 8 * height_in_mcus * v1;
uint32_t height2 = 8 * height_in_mcus * v2;
uint32_t height3 = 8 * height_in_mcus * v3;
uint32_t hmax = wuffs_base__u32__max(
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);
static size_t dst_alloc_size = 0;
if (dst_alloc_size == 0) {
dst_alloc_size = round_up_to_pagesize(8 * 64 * 64);
}
static uint8_t* dst_alloc = NULL;
if (!dst_alloc) {
const char* z = allocate_guarded_pages(&dst_alloc, dst_alloc_size);
if (z != NULL) {
return z;
}
}
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);
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";
} else {
wuffs_base__status status = wuffs_base__pixel_buffer__set_from_slice(
&dst_pixbuf, &dst_pixcfg,
wuffs_base__make_slice_u8(dst_alloc + dst_alloc_size - dst_pixbuf_len,
dst_pixbuf_len));
if (status.repr) {
return "fuzz: internal error: wuffs_base__pixel_buffer__set_from_slice "
"failed";
}
}
static size_t src_alloc_size = 0;
if (src_alloc_size == 0) {
src_alloc_size = round_up_to_pagesize(8 * 4 * 4 * 8 * 4 * 4);
}
static uint8_t* src_alloc0 = NULL;
static uint8_t* src_alloc1 = NULL;
static uint8_t* src_alloc2 = NULL;
static uint8_t* src_alloc3 = NULL;
if (!src_alloc0) {
const char* z = allocate_guarded_pages(&src_alloc0, src_alloc_size);
if (z != NULL) {
return z;
}
}
if (!src_alloc1) {
const char* z = allocate_guarded_pages(&src_alloc1, src_alloc_size);
if (z != NULL) {
return z;
}
}
if (!src_alloc2) {
const char* z = allocate_guarded_pages(&src_alloc2, src_alloc_size);
if (z != NULL) {
return z;
}
}
if (!src_alloc3) {
const char* z = allocate_guarded_pages(&src_alloc3, src_alloc_size);
if (z != NULL) {
return z;
}
}
uint32_t src_len0 = width0 * height0;
uint32_t src_len1 = width1 * height1;
uint32_t src_len2 = width2 * height2;
uint32_t src_len3 = width3 * height3;
if ((src_len0 > src_alloc_size) || //
(src_len1 > src_alloc_size) || //
(src_len2 > src_alloc_size) || //
(src_len3 > src_alloc_size)) {
return "fuzz: internal error: src_alloc_size is too small";
}
uint8_t s0 = 0x90;
if (src->meta.ri < src->meta.wi) {
s0 = src->data.ptr[src->meta.ri++];
}
uint8_t s1 = 0x91;
if (src->meta.ri < src->meta.wi) {
s1 = src->data.ptr[src->meta.ri++];
}
uint8_t s2 = 0x92;
if (src->meta.ri < src->meta.wi) {
s2 = src->data.ptr[src->meta.ri++];
}
uint8_t s3 = 0x93;
if (src->meta.ri < src->meta.wi) {
s3 = src->data.ptr[src->meta.ri++];
}
wuffs_base__slice_u8 src0 = wuffs_base__make_slice_u8(
src_alloc0 + src_alloc_size - src_len0, src_len0);
memset(src0.ptr, s0, src0.len);
wuffs_base__slice_u8 src1 = wuffs_base__make_slice_u8(
src_alloc1 + src_alloc_size - src_len1, src_len1);
memset(src1.ptr, s1, src1.len);
wuffs_base__slice_u8 src2 = wuffs_base__make_slice_u8(
src_alloc2 + src_alloc_size - src_len2, src_len2);
memset(src2.ptr, s2, src2.len);
wuffs_base__slice_u8 src3 = wuffs_base__empty_slice_u8();
if (use_4th_component) {
wuffs_base__slice_u8 src3 = wuffs_base__make_slice_u8(
src_alloc3 + src_alloc_size - src_len3, src_len3);
memset(src3.ptr, s3, src3.len);
}
wuffs_base__pixel_swizzler swizzler = {0};
uint8_t scratch_buffer[2048];
wuffs_base__status status = wuffs_base__pixel_swizzler__swizzle_ycck(
&swizzler, &dst_pixbuf, dst_palette, //
width, height, //
src0, src1, src2, src3, //
width0, width1, width2, width3, //
height0, height1, height2, height3, //
width0, width1, width2, width3, //
h0, h1, h2, h3, //
v0, v1, v2, v3, //
is_rgb_or_cmyk, //
triangle_filter_for_2to1, //
wuffs_base__make_slice_u8(scratch_buffer, sizeof(scratch_buffer)));
if (status.repr) {
return wuffs_base__status__message(&status);
}
return NULL;
}
const char* //
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
const char* s0 = fuzz_swizzle_interleaved_from_slice(src, hash);
const char* s1 = fuzz_swizzle_ycck(src, hash);
if (s0 && strstr(s0, "internal error:")) {
return s0;
}
if (s1 && strstr(s1, "internal error:")) {
return s1;
}
return s0 ? s0 : s1;
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+1
View File
@@ -19,6 +19,7 @@ bzip2: test/data/*.bz2
cbor: test/data/*.cbor
gif: test/data/*.gif test/data/artificial-gif/*.gif
gzip: test/data/*.gz
jpeg: test/data/*.jpeg ../libjpeg_turbo_corpus/*.jpg
json: test/data/*.json ../rapidjson_corpus/* ../simdjson_corpus/* ../JSONTestSuite/test_*/*.json
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
tga: test/data/*.tga
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+7 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -99,8 +93,8 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
// 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_zlib__decoder__set_quirk_enabled(
&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, hash & 0xFFFE);
wuffs_zlib__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
hash & 0xFFFE);
uint8_t dst_buffer[DST_BUFFER_ARRAY_SIZE];
wuffs_base__io_buffer dst =
+1
View File
@@ -3,6 +3,7 @@ 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
)
+2
View File
@@ -1,3 +1,5 @@
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=
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#include <inttypes.h>
#include <stdio.h>
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#include <inttypes.h>
#include <stdlib.h>
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri status "#not a digit"
pri status "#too large"
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2019 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#include <stdio.h>
+11 -17
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - Base
@@ -102,7 +96,7 @@ Input::BringsItsOwnIOBuffer() {
FileInput::FileInput(FILE* f) : m_f(f) {}
std::string //
FileInput::CopyIn(IOBuffer* dst) {
FileInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
if (!m_f) {
return "wuffs_aux::sync_io::FileInput: nullptr file";
} else if (!dst) {
@@ -110,7 +104,7 @@ FileInput::CopyIn(IOBuffer* dst) {
} else if (dst->meta.closed) {
return "wuffs_aux::sync_io::FileInput: end of file";
} else {
dst->compact();
dst->compact_retaining(history_retain_length);
size_t n = fread(dst->writer_pointer(), 1, dst->writer_length(), m_f);
dst->meta.wi += n;
dst->meta.closed = feof(m_f);
@@ -138,7 +132,7 @@ MemoryInput::BringsItsOwnIOBuffer() {
}
std::string //
MemoryInput::CopyIn(IOBuffer* dst) {
MemoryInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
if (!dst) {
return "wuffs_aux::sync_io::MemoryInput: nullptr IOBuffer";
} else if (dst->meta.closed) {
@@ -148,7 +142,7 @@ MemoryInput::CopyIn(IOBuffer* dst) {
// to it.
return "wuffs_aux::sync_io::MemoryInput: overlapping buffers";
} else {
dst->compact();
dst->compact_retaining(history_retain_length);
size_t nd = dst->writer_length();
size_t ns = m_io.reader_length();
size_t n = (nd < ns) ? nd : ns;
@@ -203,7 +197,7 @@ AdvanceIOBufferTo(const ErrorMessages& error_messages,
if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
std::string error_message = input.CopyIn(&io_buf, 0);
if (!error_message.empty()) {
return error_message;
}
@@ -286,7 +280,7 @@ HandleMetadata(
} else if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
std::string error_message = input.CopyIn(&io_buf, 0);
if (!error_message.empty()) {
return error_message;
}
+8 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - Base
@@ -98,7 +92,7 @@ class Input {
virtual ~Input();
virtual IOBuffer* BringsItsOwnIOBuffer();
virtual std::string CopyIn(IOBuffer* dst) = 0;
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length) = 0;
};
// --------
@@ -110,7 +104,7 @@ class FileInput : public Input {
public:
FileInput(FILE* f);
virtual std::string CopyIn(IOBuffer* dst);
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
private:
FILE* m_f;
@@ -131,7 +125,7 @@ class MemoryInput : public Input {
MemoryInput(const uint8_t* ptr, size_t len);
virtual IOBuffer* BringsItsOwnIOBuffer();
virtual std::string CopyIn(IOBuffer* dst);
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
private:
IOBuffer m_io;
+8 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - CBOR
@@ -70,7 +64,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
goto done;
}
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
dec->set_quirk(quirks.repr.ptr[i], 1);
}
// Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.
@@ -115,14 +109,14 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
"wuffs_aux::DecodeCbor: internal error: io_buf is closed";
goto done;
}
io_buf->compact();
io_buf->compact_retaining(dec->history_retain_length());
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);
io_error_message = input.CopyIn(io_buf, dec->history_retain_length());
} else {
ret_error_message = tok_status.message();
goto done;
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - CBOR
+29 -20
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - Image
@@ -71,16 +65,26 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG)
case WUFFS_BASE__FOURCC__JPEG:
return wuffs_jpeg__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE)
case WUFFS_BASE__FOURCC__NIE:
return wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NETPBM)
case WUFFS_BASE__FOURCC__NPBM:
return wuffs_netpbm__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
case WUFFS_BASE__FOURCC__PNG: {
auto dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
// Favor faster decodes over rejecting invalid checksums.
dec->set_quirk_enabled(WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, true);
dec->set_quirk(WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, 1);
return dec;
}
#endif
@@ -96,7 +100,7 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
#endif
}
return wuffs_base__image_decoder::unique_ptr(nullptr, &free);
return wuffs_base__image_decoder::unique_ptr(nullptr);
}
std::string //
@@ -334,7 +338,7 @@ redirect:
fourcc = 0;
break;
}
std::string error_message = input.CopyIn(&io_buf);
std::string error_message = input.CopyIn(&io_buf, 0);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -376,7 +380,7 @@ redirect:
// Apply quirks.
for (size_t i = 0; i < quirks.len; i++) {
image_decoder->set_quirk_enabled(quirks.ptr[i], true);
image_decoder->set_quirk(quirks.ptr[i], 1);
}
// Apply flags.
@@ -430,7 +434,8 @@ redirect:
} else if (io_buf.meta.closed) {
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
} else {
std::string error_message = input.CopyIn(&io_buf);
std::string error_message =
input.CopyIn(&io_buf, image_decoder->history_retain_length());
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -455,6 +460,7 @@ redirect:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGB:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
break;
@@ -511,7 +517,8 @@ redirect:
} else if (io_buf.meta.closed) {
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
} else {
std::string error_message = input.CopyIn(&io_buf);
std::string error_message =
input.CopyIn(&io_buf, image_decoder->history_retain_length());
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -540,7 +547,8 @@ redirect:
message = DecodeImage_UnexpectedEndOfFile;
break;
} else {
std::string error_message = input.CopyIn(&io_buf);
std::string error_message =
input.CopyIn(&io_buf, image_decoder->history_retain_length());
if (!error_message.empty()) {
message = std::move(error_message);
break;
@@ -568,7 +576,8 @@ redirect:
} else if (io_buf.meta.closed) {
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
} else {
std::string error_message = input.CopyIn(&io_buf);
std::string error_message =
input.CopyIn(&io_buf, image_decoder->history_retain_length());
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -601,7 +610,7 @@ DecodeImage(DecodeImageCallbacks& callbacks,
io_buf = &fallback_io_buf;
}
wuffs_base__image_decoder::unique_ptr image_decoder(nullptr, &free);
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,
+8 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - Image
@@ -89,7 +83,9 @@ class DecodeImageCallbacks {
// WUFFS_CONFIG__MODULE__ETC).
// - WUFFS_BASE__FOURCC__BMP
// - WUFFS_BASE__FOURCC__GIF
// - WUFFS_BASE__FOURCC__JPEG
// - WUFFS_BASE__FOURCC__NIE
// - WUFFS_BASE__FOURCC__NPBM
// - WUFFS_BASE__FOURCC__PNG
// - WUFFS_BASE__FOURCC__TGA
// - WUFFS_BASE__FOURCC__WBMP
@@ -121,6 +117,7 @@ class DecodeImageCallbacks {
// - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL
// - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
// - WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL
// - WUFFS_BASE__PIXEL_FORMAT__RGB
// - WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL
// - WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL
// or return image_config.pixcfg.pixel_format(). The latter means to use the
+8 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - JSON
@@ -77,14 +71,14 @@ DecodeJsonArgJsonPointer::DefaultValue() {
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact(); \
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); \
io_error_message = input.CopyIn(io_buf, dec->history_retain_length()); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \
@@ -391,7 +385,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
}
bool allow_tilde_n_tilde_r_tilde_t = false;
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
dec->set_quirk(quirks.repr.ptr[i], 1);
if (quirks.repr.ptr[i] ==
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {
allow_tilde_n_tilde_r_tilde_t = true;
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Auxiliary - JSON
+10 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#ifndef WUFFS_INCLUDE_GUARD__BASE
#define WUFFS_INCLUDE_GUARD__BASE
@@ -162,7 +156,11 @@ const uint32_t wuffs_base__pixel_format__bits_per_channel[16] = {
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \
defined(WUFFS_CONFIG__MODULE__BASE__PIXCONV)
// ¡ INSERT base/pixconv-submodule.c.
// ¡ INSERT base/pixconv-submodule-regular.c.
// ¡ INSERT base/pixconv-submodule-ycck.c.
// ¡ INSERT base/pixconv-submodule-x86-avx2.c.
#endif // !defined(WUFFS_CONFIG__MODULES) ||
// defined(WUFFS_CONFIG__MODULE__BASE) ||
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- IEEE 754 Floating Point
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- IEEE 754 Floating Point
+58 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Fundamentals
@@ -61,6 +55,20 @@
// --------
#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) {
return wuffs_base__make_empty_struct();
@@ -170,6 +178,17 @@ wuffs_base__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_u16_u32(a) \
((uint32_t)(int32_t)(int16_t)(a))
#define wuffs_base__utility__sign_extend_rshift_u32(a, n) \
((uint32_t)(((int32_t)(a)) >> (n)))
#define wuffs_base__utility__sign_extend_rshift_u64(a, n) \
((uint64_t)(((int64_t)(a)) >> (n)))
// ---------------- Slices and Tables
// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
@@ -206,6 +225,34 @@ wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,
return len;
}
static inline wuffs_base__empty_struct //
wuffs_base__bulk_load_host_endian(void* ptr,
size_t len,
wuffs_base__slice_u8 src) {
if (len && (len <= src.len)) {
memmove(ptr, src.ptr, len);
}
return wuffs_base__make_empty_struct();
}
static inline wuffs_base__empty_struct //
wuffs_base__bulk_memset(void* ptr, size_t len, uint8_t byte_value) {
if (len) {
memset(ptr, byte_value, len);
}
return wuffs_base__make_empty_struct();
}
static inline wuffs_base__empty_struct //
wuffs_base__bulk_save_host_endian(void* ptr,
size_t len,
wuffs_base__slice_u8 dst) {
if (len && (len <= dst.len)) {
memmove(dst.ptr, ptr, len);
}
return wuffs_base__make_empty_struct();
}
// --------
static inline wuffs_base__slice_u8 //
+84 -79
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Version
@@ -82,6 +76,9 @@
#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__)
#endif // !defined(__native_client__)
#endif // defined(__i386__) || defined(__x86_64__)
@@ -103,6 +100,9 @@
#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(_M_X64)
#else // defined(__AVX__) || defined(__clang__)
@@ -157,7 +157,11 @@ wuffs_base__cpu_arch__have_arm_neon() {
static inline bool //
wuffs_base__cpu_arch__have_x86_avx2() {
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
#if defined(__PCLMUL__) && defined(__POPCNT__) && defined(__SSE4_2__) && \
defined(__AVX2__)
return true;
#else
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
// GCC defines these macros but MSVC does not.
// - bit_AVX2 = (1 << 5)
const unsigned int avx2_ebx7 = 0x00000020;
@@ -197,12 +201,17 @@ wuffs_base__cpu_arch__have_x86_avx2() {
#else
#error "WUFFS_BASE__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_BASE__CPU_ARCH__X86_64)
return false;
#endif // defined(__PCLMUL__) && defined(__POPCNT__) && defined(__SSE4_2__) &&
// defined(__AVX2__)
}
static inline bool //
wuffs_base__cpu_arch__have_x86_bmi2() {
#if defined(__BMI2__)
return true;
#else
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
// GCC defines these macros but MSVC does not.
// - bit_BMI2 = (1 << 8)
@@ -229,10 +238,14 @@ wuffs_base__cpu_arch__have_x86_bmi2() {
#endif // defined(__GNUC__); defined(_MSC_VER)
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
return false;
#endif // defined(__BMI2__)
}
static inline bool //
wuffs_base__cpu_arch__have_x86_sse42() {
#if defined(__PCLMUL__) && defined(__POPCNT__) && defined(__SSE4_2__)
return true;
#else
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
// GCC defines these macros but MSVC does not.
// - bit_PCLMUL = (1 << 1)
@@ -261,6 +274,7 @@ wuffs_base__cpu_arch__have_x86_sse42() {
#endif // defined(__GNUC__); defined(_MSC_VER)
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
return false;
#endif // defined(__PCLMUL__) && defined(__POPCNT__) && defined(__SSE4_2__)
}
// ---------------- Fundamentals
@@ -284,6 +298,26 @@ wuffs_base__cpu_arch__have_x86_sse42() {
#define WUFFS_BASE__WARN_UNUSED_RESULT
#endif
// Clang's "-fsanitize=integer" checks for "unsigned-integer-overflow" even
// though, for *unsigned* integers, it is *not* undefined behavior. The check
// is still made because unsigned integer overflow "is often unintentional".
// https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
//
// However, for Wuffs' generated C code, unsigned overflow is intentional. The
// programmer has to use "~mod+" instead of a plain "+" operator in Wuffs code.
// Further runtime checks for unsigned integer overflow can add performance
// overhead (fuzzers can then time out) and can raise false negatives, without
// generating much benefits. We disable the "unsigned-integer-overflow" check.
#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer)
#define WUFFS_BASE__GENERATED_C_CODE \
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
#endif
#if !defined(WUFFS_BASE__GENERATED_C_CODE)
#define WUFFS_BASE__GENERATED_C_CODE
#endif
// --------
// Options (bitwise or'ed together) for wuffs_foo__bar__initialize functions.
@@ -308,6 +342,20 @@ wuffs_base__cpu_arch__have_x86_sse42() {
// --------
#ifdef __cplusplus
// Wuffs structs are just data, not resources (in the RAII sense). They don't
// subclass anything. They don't have virtual destructors. They don't contain
// pointers to dynamically allocated memory. They don't contain file
// descriptors. And so on. Destroying such a struct (e.g. via a
// wuffs_foo__bar::unique_ptr) can just call free, especially as
// sizeof(wuffs_foo__bar) isn't supposed to be part of the public (stable) API.
struct wuffs_unique_ptr_deleter {
void operator()(void* p) { free(p); }
};
#endif // __cplusplus
// --------
// 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()".
@@ -363,6 +411,7 @@ typedef struct wuffs_base__status__struct {
inline bool is_note() const;
inline bool is_ok() const;
inline bool is_suspension() const;
inline bool is_truncated_input_error() const;
inline const char* message() const;
#endif // __cplusplus
@@ -402,6 +451,23 @@ wuffs_base__status__is_suspension(const wuffs_base__status* z) {
return z->repr && (*z->repr == '$');
}
static inline bool //
wuffs_base__status__is_truncated_input_error(const wuffs_base__status* z) {
const char* p = z->repr;
if (!p || (*p != '#')) {
return false;
}
p++;
while (1) {
if (*p == 0) {
return false;
} else if (*p++ == ':') {
break;
}
}
return strcmp(p, " truncated input") == 0;
}
// wuffs_base__status__message strips the leading '$', '#' or '@'.
static inline const char* //
wuffs_base__status__message(const wuffs_base__status* z) {
@@ -440,6 +506,11 @@ wuffs_base__status::is_suspension() const {
return wuffs_base__status__is_suspension(this);
}
inline bool //
wuffs_base__status::is_truncated_input_error() const {
return wuffs_base__status__is_truncated_input_error(this);
}
inline const char* //
wuffs_base__status::message() const {
return wuffs_base__status__message(this);
@@ -1112,72 +1183,6 @@ wuffs_base__poke_u64le__no_bounds_check(uint8_t* p, uint64_t x) {
#endif
}
// --------
// Load and Store functions are deprecated. Use Peek and Poke instead.
#define wuffs_base__load_u8__no_bounds_check \
wuffs_base__peek_u8__no_bounds_check
#define wuffs_base__load_u16be__no_bounds_check \
wuffs_base__peek_u16be__no_bounds_check
#define wuffs_base__load_u16le__no_bounds_check \
wuffs_base__peek_u16le__no_bounds_check
#define wuffs_base__load_u24be__no_bounds_check \
wuffs_base__peek_u24be__no_bounds_check
#define wuffs_base__load_u24le__no_bounds_check \
wuffs_base__peek_u24le__no_bounds_check
#define wuffs_base__load_u32be__no_bounds_check \
wuffs_base__peek_u32be__no_bounds_check
#define wuffs_base__load_u32le__no_bounds_check \
wuffs_base__peek_u32le__no_bounds_check
#define wuffs_base__load_u40be__no_bounds_check \
wuffs_base__peek_u40be__no_bounds_check
#define wuffs_base__load_u40le__no_bounds_check \
wuffs_base__peek_u40le__no_bounds_check
#define wuffs_base__load_u48be__no_bounds_check \
wuffs_base__peek_u48be__no_bounds_check
#define wuffs_base__load_u48le__no_bounds_check \
wuffs_base__peek_u48le__no_bounds_check
#define wuffs_base__load_u56be__no_bounds_check \
wuffs_base__peek_u56be__no_bounds_check
#define wuffs_base__load_u56le__no_bounds_check \
wuffs_base__peek_u56le__no_bounds_check
#define wuffs_base__load_u64be__no_bounds_check \
wuffs_base__peek_u64be__no_bounds_check
#define wuffs_base__load_u64le__no_bounds_check \
wuffs_base__peek_u64le__no_bounds_check
#define wuffs_base__store_u8__no_bounds_check \
wuffs_base__poke_u8__no_bounds_check
#define wuffs_base__store_u16be__no_bounds_check \
wuffs_base__poke_u16be__no_bounds_check
#define wuffs_base__store_u16le__no_bounds_check \
wuffs_base__poke_u16le__no_bounds_check
#define wuffs_base__store_u24be__no_bounds_check \
wuffs_base__poke_u24be__no_bounds_check
#define wuffs_base__store_u24le__no_bounds_check \
wuffs_base__poke_u24le__no_bounds_check
#define wuffs_base__store_u32be__no_bounds_check \
wuffs_base__poke_u32be__no_bounds_check
#define wuffs_base__store_u32le__no_bounds_check \
wuffs_base__poke_u32le__no_bounds_check
#define wuffs_base__store_u40be__no_bounds_check \
wuffs_base__poke_u40be__no_bounds_check
#define wuffs_base__store_u40le__no_bounds_check \
wuffs_base__poke_u40le__no_bounds_check
#define wuffs_base__store_u48be__no_bounds_check \
wuffs_base__poke_u48be__no_bounds_check
#define wuffs_base__store_u48le__no_bounds_check \
wuffs_base__poke_u48le__no_bounds_check
#define wuffs_base__store_u56be__no_bounds_check \
wuffs_base__poke_u56be__no_bounds_check
#define wuffs_base__store_u56le__no_bounds_check \
wuffs_base__poke_u56le__no_bounds_check
#define wuffs_base__store_u64be__no_bounds_check \
wuffs_base__poke_u64be__no_bounds_check
#define wuffs_base__store_u64le__no_bounds_check \
wuffs_base__poke_u64le__no_bounds_check
// ---------------- Slices and Tables
// WUFFS_BASE__SLICE is a 1-dimensional buffer.
+40 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Images
@@ -38,6 +32,41 @@ wuffs_base__pixel_swizzler__swizzle_interleaved_transparent_black(
wuffs_base__slice_u8 dst_palette,
uint64_t num_pixels);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
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,
wuffs_base__slice_u8 src0,
wuffs_base__slice_u8 src1,
wuffs_base__slice_u8 src2,
wuffs_base__slice_u8 src3,
uint32_t width0,
uint32_t width1,
uint32_t width2,
uint32_t width3,
uint32_t height0,
uint32_t height1,
uint32_t height2,
uint32_t height3,
uint32_t stride0,
uint32_t stride1,
uint32_t stride2,
uint32_t stride3,
uint8_t h0,
uint8_t h1,
uint8_t h2,
uint8_t h3,
uint8_t v0,
uint8_t v1,
uint8_t v2,
uint8_t v3,
bool is_rgb_or_cmyk,
bool triangle_filter_for_2to1,
wuffs_base__slice_u8 scratch_buffer_2k);
// ---------------- Images (Utility)
#define wuffs_base__utility__make_pixel_format wuffs_base__make_pixel_format
+90 -63
View File
@@ -1,19 +1,15 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Images
#define WUFFS_BASE__IMAGE__DIMENSION_MAX_INCL 0xFFFFFF
// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied
// Alpha, Red, Green, Blue color, as a uint32_t value. Its value is always
// 0xAARRGGBB (Alpha most significant, Blue least), regardless of endianness.
@@ -199,6 +195,84 @@ wuffs_base__color_u64__as__color_u32(uint64_t c) {
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
}
// wuffs_base__color_ycc__as__color_u32 converts from YCbCr to 0xAARRGGBB. The
// alpha bits are always 0xFF.
static inline wuffs_base__color_u32_argb_premul //
wuffs_base__color_ycc__as__color_u32(uint8_t yy, uint8_t cb, uint8_t cr) {
// Work in 16.16 fixed point arithmetic (so that 'one half' is (1 << 15)) and
// bias the chroma values by 0x80.
uint32_t yy32 = (((uint32_t)yy) << 16) | (1 << 15);
uint32_t cb32 = (((uint32_t)cb) - 0x80);
uint32_t cr32 = (((uint32_t)cr) - 0x80);
// The formulae:
//
// R = Y + 1.40200 * Cr
// G = Y - 0.34414 * Cb - 0.71414 * Cr
// B = Y + 1.77200 * Cb
//
// When scaled by 1<<16:
//
// 0.34414 becomes 0x0581A = 22554.
// 0.71414 becomes 0x0B6D2 = 46802.
// 1.40200 becomes 0x166E9 = 91881.
// 1.77200 becomes 0x1C5A2 = 116130.
//
// Since we're working in 16.16 fixed point arithmetic, masking by 0x00FF0000
// (possibly followed by a shift) gives the relevant 8 bits per channel.
//
// However, we need to saturate for overflow (above 0x00FFFFFF, but not so
// high that the MSB Most Significant Bit is set) or for underflow (below
// 0x00000000 as int32_t, which means that the MSB is set as uint32_t). In
// both cases, some of the high 8 bits (bits 24 ..= 31) will be set.
//
// "((uint32_t)(((int32_t)x) >> 31))" just replicates x's MSB across all 32
// bits. Prepending that with "~" inverts those bits. Thus, "~(etc)" is
// either 0xFFFFFFFF (for overflow) or 0x00000000 (for underflow).
uint32_t rr32 = yy32 + (0x166E9 * cr32);
uint32_t gg32 = yy32 - (0x0581A * cb32) - (0x0B6D2 * cr32);
uint32_t bb32 = yy32 + (0x1C5A2 * cb32);
if (rr32 >> 24) {
rr32 = ~((uint32_t)(((int32_t)rr32) >> 31));
}
if (gg32 >> 24) {
gg32 = ~((uint32_t)(((int32_t)gg32) >> 31));
}
if (bb32 >> 24) {
bb32 = ~((uint32_t)(((int32_t)bb32) >> 31));
}
return 0xFF000000 | //
((0x00FF0000 & rr32) >> 0) | //
((0x00FF0000 & gg32) >> 8) | //
((0x00FF0000 & bb32) >> 16);
}
// wuffs_base__color_ycc__as__color_u32_abgr is like
// wuffs_base__color_ycc__as__color_u32 but the uint32_t returned is in
// 0xAABBGGRR order, not 0xAARRGGBB.
static inline uint32_t //
wuffs_base__color_ycc__as__color_u32_abgr(uint8_t yy, uint8_t cb, uint8_t cr) {
uint32_t yy32 = (((uint32_t)yy) << 16) | (1 << 15);
uint32_t cb32 = (((uint32_t)cb) - 0x80);
uint32_t cr32 = (((uint32_t)cr) - 0x80);
uint32_t rr32 = yy32 + (0x166E9 * cr32);
uint32_t gg32 = yy32 - (0x0581A * cb32) - (0x0B6D2 * cr32);
uint32_t bb32 = yy32 + (0x1C5A2 * cb32);
if (rr32 >> 24) {
rr32 = ~((uint32_t)(((int32_t)rr32) >> 31));
}
if (gg32 >> 24) {
gg32 = ~((uint32_t)(((int32_t)gg32) >> 31));
}
if (bb32 >> 24) {
bb32 = ~((uint32_t)(((int32_t)bb32) >> 31));
}
return 0xFF000000 | //
((0x00FF0000 & bb32) >> 0) | //
((0x00FF0000 & gg32) >> 8) | //
((0x00FF0000 & rr32) >> 16);
}
// --------
typedef uint8_t wuffs_base__pixel_blend;
@@ -223,14 +297,13 @@ typedef uint32_t wuffs_base__pixel_alpha_transparency;
#define WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__PREMULTIPLIED_ALPHA 2
#define WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__BINARY_ALPHA 3
// Deprecated: use WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__NONPREMULTIPLIED_ALPHA
// instead.
#define WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__NON_PREMULTIPLIED_ALPHA 1
// --------
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL 4
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__INDEX_PLANE 0
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3
@@ -1098,7 +1171,7 @@ typedef struct wuffs_base__pixel_buffer__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX];
wuffs_base__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL];
// TODO: color spaces.
} private_impl;
@@ -1110,9 +1183,6 @@ typedef struct wuffs_base__pixel_buffer__struct {
inline wuffs_base__status set_from_slice(
const wuffs_base__pixel_config* pixcfg,
wuffs_base__slice_u8 pixbuf_memory);
inline wuffs_base__status set_from_table(
const wuffs_base__pixel_config* pixcfg,
wuffs_base__table_u8 primary_memory);
inline wuffs_base__slice_u8 palette();
inline wuffs_base__slice_u8 palette_or_else(wuffs_base__slice_u8 fallback);
inline wuffs_base__pixel_format pixel_format() const;
@@ -1259,41 +1329,6 @@ wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* pb,
return wuffs_base__make_status(NULL);
}
// Deprecated: does not handle indexed pixel configurations. Use
// wuffs_base__pixel_buffer__set_interleaved instead.
static inline wuffs_base__status //
wuffs_base__pixel_buffer__set_from_table(wuffs_base__pixel_buffer* pb,
const wuffs_base__pixel_config* pixcfg,
wuffs_base__table_u8 primary_memory) {
if (!pb) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
memset(pb, 0, sizeof(*pb));
if (!pixcfg ||
wuffs_base__pixel_format__is_indexed(&pixcfg->private_impl.pixfmt) ||
wuffs_base__pixel_format__is_planar(&pixcfg->private_impl.pixfmt)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
uint32_t bits_per_pixel =
wuffs_base__pixel_format__bits_per_pixel(&pixcfg->private_impl.pixfmt);
if ((bits_per_pixel == 0) || ((bits_per_pixel % 8) != 0)) {
// TODO: support fraction-of-byte pixels, e.g. 1 bit per pixel?
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
uint64_t bytes_per_pixel = bits_per_pixel / 8;
uint64_t width_in_bytes =
((uint64_t)pixcfg->private_impl.width) * bytes_per_pixel;
if ((width_in_bytes > primary_memory.width) ||
(pixcfg->private_impl.height > primary_memory.height)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
pb->pixcfg = *pixcfg;
pb->private_impl.planes[0] = primary_memory;
return wuffs_base__make_status(NULL);
}
// wuffs_base__pixel_buffer__palette returns the palette color data. If
// non-empty, it will have length
// WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH.
@@ -1342,7 +1377,7 @@ wuffs_base__pixel_buffer__pixel_format(const wuffs_base__pixel_buffer* pb) {
static inline wuffs_base__table_u8 //
wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* pb, uint32_t p) {
if (pb && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX)) {
if (pb && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL)) {
return pb->private_impl.planes[p];
}
@@ -1391,14 +1426,6 @@ wuffs_base__pixel_buffer::set_from_slice(
pixbuf_memory);
}
inline wuffs_base__status //
wuffs_base__pixel_buffer::set_from_table(
const wuffs_base__pixel_config* pixcfg_arg,
wuffs_base__table_u8 primary_memory) {
return wuffs_base__pixel_buffer__set_from_table(this, pixcfg_arg,
primary_memory);
}
inline wuffs_base__slice_u8 //
wuffs_base__pixel_buffer::palette() {
return wuffs_base__pixel_buffer__palette(this);
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Integer
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- I/O
+52 -38
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- I/O
//
@@ -36,6 +30,7 @@ typedef struct wuffs_base__io_buffer__struct {
#ifdef __cplusplus
inline bool is_valid() const;
inline void compact();
inline void compact_retaining(uint64_t history_retain_length);
inline size_t reader_length() const;
inline uint8_t* reader_pointer() const;
inline uint64_t reader_position() const;
@@ -44,11 +39,6 @@ typedef struct wuffs_base__io_buffer__struct {
inline uint8_t* writer_pointer() const;
inline uint64_t writer_position() const;
inline wuffs_base__slice_u8 writer_slice() const;
// Deprecated: use reader_position.
inline uint64_t reader_io_position() const;
// Deprecated: use writer_position.
inline uint64_t writer_io_position() const;
#endif // __cplusplus
} wuffs_base__io_buffer;
@@ -165,18 +155,53 @@ wuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {
return;
}
buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri);
size_t n = buf->meta.wi - buf->meta.ri;
if (n != 0) {
memmove(buf->data.ptr, buf->data.ptr + buf->meta.ri, n);
size_t new_wi = buf->meta.wi - buf->meta.ri;
if (new_wi != 0) {
memmove(buf->data.ptr, buf->data.ptr + buf->meta.ri, new_wi);
}
buf->meta.wi = n;
buf->meta.wi = new_wi;
buf->meta.ri = 0;
}
// Deprecated. Use wuffs_base__io_buffer__reader_position.
static inline uint64_t //
wuffs_base__io_buffer__reader_io_position(const wuffs_base__io_buffer* buf) {
return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri) : 0;
// 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.
//
// wuffs_base__io_buffer__compact_retaining(0) is equivalent to
// wuffs_base__io_buffer__compact().
//
// For example, if buf started like this:
//
// +--- ri = 3
// v
// abcdefgh?? len = 10, pos = 900
// ^
// +--- wi = 8
//
// Then, depending on history_retain_length, the resultant buf would be:
//
// HRL = 0 defgh????? ri = 0 wi = 5 pos = 903
// HRL = 1 cdefgh???? ri = 1 wi = 6 pos = 902
// HRL = 2 bcdefgh??? ri = 2 wi = 7 pos = 901
// HRL = 3 abcdefgh?? ri = 3 wi = 8 pos = 900
// HRL = 4+ abcdefgh?? ri = 3 wi = 8 pos = 900
static inline void //
wuffs_base__io_buffer__compact_retaining(wuffs_base__io_buffer* buf,
uint64_t history_retain_length) {
if (!buf || (buf->meta.ri == 0)) {
return;
}
size_t old_ri = buf->meta.ri;
size_t new_ri = (size_t)(wuffs_base__u64__min(old_ri, history_retain_length));
size_t memmove_start = old_ri - new_ri;
buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, memmove_start);
size_t new_wi = buf->meta.wi - memmove_start;
if ((new_wi != 0) && (memmove_start != 0)) {
memmove(buf->data.ptr, buf->data.ptr + memmove_start, new_wi);
}
buf->meta.wi = new_wi;
buf->meta.ri = new_ri;
}
static inline size_t //
@@ -201,12 +226,6 @@ wuffs_base__io_buffer__reader_slice(const wuffs_base__io_buffer* buf) {
: wuffs_base__empty_slice_u8();
}
// Deprecated. Use wuffs_base__io_buffer__writer_position.
static inline uint64_t //
wuffs_base__io_buffer__writer_io_position(const wuffs_base__io_buffer* buf) {
return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.wi) : 0;
}
static inline size_t //
wuffs_base__io_buffer__writer_length(const wuffs_base__io_buffer* buf) {
return buf ? buf->data.len - buf->meta.wi : 0;
@@ -241,9 +260,9 @@ wuffs_base__io_buffer::compact() {
wuffs_base__io_buffer__compact(this);
}
inline uint64_t //
wuffs_base__io_buffer::reader_io_position() const {
return wuffs_base__io_buffer__reader_io_position(this);
inline void //
wuffs_base__io_buffer::compact_retaining(uint64_t history_retain_length) {
wuffs_base__io_buffer__compact_retaining(this, history_retain_length);
}
inline size_t //
@@ -266,11 +285,6 @@ wuffs_base__io_buffer::reader_slice() const {
return wuffs_base__io_buffer__reader_slice(this);
}
inline uint64_t //
wuffs_base__io_buffer::writer_io_position() const {
return wuffs_base__io_buffer__writer_io_position(this);
}
inline size_t //
wuffs_base__io_buffer::writer_length() const {
return wuffs_base__io_buffer__writer_length(this);
+10 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Magic Numbers
@@ -157,11 +151,16 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA
{+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
};
static const size_t table_len = sizeof(table) / sizeof(table[0]);
+5 -11
View File
@@ -1,15 +1,9 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Memory Allocation
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Memory Allocation
@@ -1,19 +1,44 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Pixel Swizzler
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
static uint64_t //
wuffs_base__pixel_swizzler__bgrw__rgb__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);
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,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len);
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
static uint64_t //
wuffs_base__pixel_swizzler__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)
// --------
static inline uint32_t //
wuffs_base__swap_u32_argb_abgr(uint32_t u) {
uint32_t o = u & 0xFF00FF00ul;
@@ -831,7 +856,7 @@ wuffs_base__pixel_swizzler__swap_rgb_bgr(uint8_t* dst_ptr,
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
static uint64_t //
wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42(uint8_t* dst_ptr,
wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
@@ -1990,6 +2015,37 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__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_len8 = src_len / 8;
size_t len = (dst_len3 < src_len8) ? dst_len3 : src_len8;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__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);
s += 1 * 8;
d += 1 * 3;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
uint8_t* dst_ptr,
@@ -2038,6 +2094,54 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
return len;
}
static uint64_t //
wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__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_len8 = src_len / 8;
size_t len = (dst_len3 < src_len8) ? dst_len3 : src_len8;
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 dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
// 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 = ((sr * sa) + (dr * ia)) / 0xFFFF;
dg = ((sg * sa) + (dg * ia)) / 0xFFFF;
db = ((sb * sa) + (db * ia)) / 0xFFFF;
// Convert from 16-bit color to 8-bit color.
d[0] = (uint8_t)(db >> 8);
d[1] = (uint8_t)(dg >> 8);
d[2] = (uint8_t)(dr >> 8);
s += 1 * 8;
d += 1 * 3;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_base__pixel_swizzler__bgr__rgba_premul__src(uint8_t* dst_ptr,
size_t dst_len,
@@ -2113,6 +2217,38 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_base__pixel_swizzler__bgr__rgbx(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_len4 = src_len / 4;
size_t len = (dst_len3 < src_len4) ? dst_len3 : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint8_t b0 = s[0];
uint8_t b1 = s[1];
uint8_t b2 = s[2];
d[0] = b2;
d[1] = b1;
d[2] = b0;
s += 1 * 4;
d += 1 * 3;
n -= 1;
}
return len;
}
// --------
static uint64_t //
@@ -3154,7 +3290,7 @@ wuffs_base__pixel_swizzler__bgrw__bgrx(uint8_t* dst_ptr,
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
static uint64_t //
wuffs_base__pixel_swizzler__bgrw__rgb__sse42(uint8_t* dst_ptr,
wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
@@ -3409,6 +3545,39 @@ 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,
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) {
wuffs_base__poke_u24le__no_bounds_check(
d + (0 * 3),
wuffs_base__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)))));
s += 1 * 2;
d += 1 * 3;
n -= 1;
}
return len;
}
// --------
static uint64_t //
wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src(
uint8_t* dst_ptr,
@@ -3866,7 +4035,7 @@ wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over(
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2")
static uint64_t //
wuffs_base__pixel_swizzler__xxxx__y__sse42(uint8_t* dst_ptr,
wuffs_base__pixel_swizzler__xxxx__y__x86_sse42(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
@@ -4200,7 +4369,7 @@ wuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p,
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_base__pixel_swizzler__xxxx__y__sse42;
return wuffs_base__pixel_swizzler__xxxx__y__x86_sse42;
}
#endif
return wuffs_base__pixel_swizzler__xxxx__y;
@@ -4359,8 +4528,25 @@ wuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
// TODO.
break;
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
if (wuffs_base__pixel_swizzler__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;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
if (wuffs_base__pixel_swizzler__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 NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(
@@ -4542,6 +4728,9 @@ wuffs_base__pixel_swizzler__prepare__bgr_565(
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
return wuffs_base__pixel_swizzler__bgrw_4x16le__bgr_565;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
return wuffs_base__pixel_swizzler__rgb__bgr_565;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
@@ -4583,7 +4772,7 @@ wuffs_base__pixel_swizzler__prepare__bgr(wuffs_base__pixel_swizzler* p,
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_base__pixel_swizzler__bgrw__rgb__sse42;
return wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42;
}
#endif
return wuffs_base__pixel_swizzler__bgrw__rgb;
@@ -4650,15 +4839,20 @@ wuffs_base__pixel_swizzler__prepare__bgra_nonpremul(
break;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
// TODO.
break;
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_base__pixel_swizzler__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 (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
@@ -4743,8 +4937,13 @@ wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
break;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
// TODO.
break;
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul_4x16le__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
switch (blend) {
@@ -4825,6 +5024,15 @@ wuffs_base__pixel_swizzler__prepare__bgra_premul(
}
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;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -4839,7 +5047,7 @@ wuffs_base__pixel_swizzler__prepare__bgra_premul(
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
@@ -4876,8 +5084,7 @@ wuffs_base__pixel_swizzler__prepare__bgrx(wuffs_base__pixel_swizzler* p,
return wuffs_base__pixel_swizzler__copy_4_4;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
// TODO.
break;
return wuffs_base__pixel_swizzler__bgr__rgbx;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
@@ -4907,7 +5114,7 @@ wuffs_base__pixel_swizzler__prepare__rgb(wuffs_base__pixel_swizzler* p,
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_base__pixel_swizzler__bgrw__rgb__sse42;
return wuffs_base__pixel_swizzler__bgrw__rgb__x86_sse42;
}
#endif
return wuffs_base__pixel_swizzler__bgrw__rgb;
@@ -4958,7 +5165,7 @@ wuffs_base__pixel_swizzler__prepare__rgba_nonpremul(
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
@@ -4991,8 +5198,13 @@ wuffs_base__pixel_swizzler__prepare__rgba_nonpremul(
break;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
// TODO.
break;
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
switch (blend) {
@@ -5069,7 +5281,7 @@ wuffs_base__pixel_swizzler__prepare__rgba_premul(
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;
@@ -5078,6 +5290,15 @@ wuffs_base__pixel_swizzler__prepare__rgba_premul(
}
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;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -0,0 +1,638 @@
// 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.
// --------
// ‼ WUFFS MULTI-FILE SECTION +x86_avx2
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
static void //
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2(
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) {
if ((x + 32u) > x_end) {
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx( //
dst, x, x_end, y, up0, up1, up2);
return;
}
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));
// u0001 = u16x16 [0x0001 .. 0x0001]
// u00FF = u16x16 [0x00FF .. 0x00FF]
// uFF80 = u16x16 [0xFF80 .. 0xFF80]
// uFFFF = u16x16 [0xFFFF .. 0xFFFF]
const __m256i u0001 = _mm256_set1_epi16(+0x0001);
const __m256i u00FF = _mm256_set1_epi16(+0x00FF);
const __m256i uFF80 = _mm256_set1_epi16(-0x0080);
const __m256i uFFFF = _mm256_set1_epi16(-0x0001);
// p8000_p0000 = u16x16 [0x8000 0x0000 .. 0x8000 0x0000]
const __m256i p8000_p0000 = _mm256_set_epi16( //
+0x0000, -0x8000, +0x0000, -0x8000, //
+0x0000, -0x8000, +0x0000, -0x8000, //
+0x0000, -0x8000, +0x0000, -0x8000, //
+0x0000, -0x8000, +0x0000, -0x8000);
// Per wuffs_base__color_ycc__as__color_u32, the formulae:
//
// R = Y + 1.40200 * Cr
// G = Y - 0.34414 * Cb - 0.71414 * Cr
// B = Y + 1.77200 * Cb
//
// When scaled by 1<<16:
//
// 0.34414 becomes 0x0581A = 22554.
// 0.71414 becomes 0x0B6D2 = 46802.
// 1.40200 becomes 0x166E9 = 91881.
// 1.77200 becomes 0x1C5A2 = 116130.
//
// Separate the integer and fractional parts, since we work with signed
// 16-bit SIMD lanes. The fractional parts range from -0.5 .. +0.5 (as
// floating-point) which is from -0x8000 .. +0x8000 (as fixed-point).
//
// -0x3A5E = -0x20000 + 0x1C5A2 The B:Cb factor.
// +0x66E9 = -0x10000 + 0x166E9 The R:Cr factor.
// -0x581A = +0x00000 - 0x0581A The G:Cb factor.
// +0x492E = +0x10000 - 0x0B6D2 The G:Cr factor.
const __m256i m3A5E = _mm256_set1_epi16(-0x3A5E);
const __m256i p66E9 = _mm256_set1_epi16(+0x66E9);
const __m256i m581A_p492E = _mm256_set_epi16( //
+0x492E, -0x581A, +0x492E, -0x581A, //
+0x492E, -0x581A, +0x492E, -0x581A, //
+0x492E, -0x581A, +0x492E, -0x581A, //
+0x492E, -0x581A, +0x492E, -0x581A);
while (x < x_end) {
// Load chroma values in even and odd columns (the high 8 bits of each
// u16x16 element are zero) and then subtract 0x0080.
//
// cb_all = u8x32 [cb.00 cb.01 cb.02 cb.03 .. cb.1C cb.1D cb.1E cb.1F]
// cb_eve = i16x16 [cb.00-0x80 cb.02-0x80 .. cb.1C-0x80 cb.1E-0x80 ]
// cb_odd = i16x16 [cb.01-0x80 cb.03-0x80 .. cb.1D-0x80 cb.1F-0x80 ]
//
// Ditto for the cr_xxx Chroma-Red values.
__m256i cb_all = _mm256_lddqu_si256((const __m256i*)(const void*)up1);
__m256i cr_all = _mm256_lddqu_si256((const __m256i*)(const void*)up2);
__m256i cb_eve = _mm256_add_epi16(uFF80, _mm256_and_si256(cb_all, u00FF));
__m256i cr_eve = _mm256_add_epi16(uFF80, _mm256_and_si256(cr_all, u00FF));
__m256i cb_odd = _mm256_add_epi16(uFF80, _mm256_srli_epi16(cb_all, 8));
__m256i cr_odd = _mm256_add_epi16(uFF80, _mm256_srli_epi16(cr_all, 8));
// ----
// Calculate:
//
// B-Y = (+1.77200 * Cb) as floating-point
// R-Y = (+1.40200 * Cr) as floating-point
//
// B-Y = ((0x2_0000 - 0x3A5E) * Cb) as fixed-point
// R-Y = ((0x1_0000 + 0x66E9) * Cr) as fixed-point
//
// B-Y = ((-0x3A5E * Cb) + ("2.0" * Cb))
// R-Y = ((+0x66E9 * Cr) + ("1.0" * Cr))
// Multiply by m3A5E or p66E9, taking the high 16 bits. There's also a
// doubling (add x to itself), adding-of-1 and halving (shift right by 1).
// That makes multiply-and-take-high round to nearest (instead of down).
__m256i tmp_by_eve = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cb_eve, cb_eve), m3A5E), u0001),
1);
__m256i tmp_by_odd = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cb_odd, cb_odd), m3A5E), u0001),
1);
__m256i tmp_ry_eve = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cr_eve, cr_eve), p66E9), u0001),
1);
__m256i tmp_ry_odd = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cr_odd, cr_odd), p66E9), u0001),
1);
// Add (2 * Cb) and (1 * Cr).
__m256i by_eve =
_mm256_add_epi16(tmp_by_eve, _mm256_add_epi16(cb_eve, cb_eve));
__m256i by_odd =
_mm256_add_epi16(tmp_by_odd, _mm256_add_epi16(cb_odd, cb_odd));
__m256i ry_eve = _mm256_add_epi16(tmp_ry_eve, cr_eve);
__m256i ry_odd = _mm256_add_epi16(tmp_ry_odd, cr_odd);
// ----
// Calculate:
//
// G-Y = (-0.34414 * Cb) +
// (-0.71414 * Cr) as floating-point
//
// G-Y = ((+0x0_0000 - 0x581A) * Cb) +
// ((-0x1_0000 + 0x492E) * Cr) as fixed-point
//
// G-Y = (-0x581A * Cb) +
// (+0x492E * Cr) - ("1.0" * Cr)
// Multiply-add to get ((-0x581A * Cb) + (+0x492E * Cr)).
__m256i tmp0_gy_eve_lo = _mm256_madd_epi16( //
_mm256_unpacklo_epi16(cb_eve, cr_eve), m581A_p492E);
__m256i tmp0_gy_eve_hi = _mm256_madd_epi16( //
_mm256_unpackhi_epi16(cb_eve, cr_eve), m581A_p492E);
__m256i tmp0_gy_odd_lo = _mm256_madd_epi16( //
_mm256_unpacklo_epi16(cb_odd, cr_odd), m581A_p492E);
__m256i tmp0_gy_odd_hi = _mm256_madd_epi16( //
_mm256_unpackhi_epi16(cb_odd, cr_odd), m581A_p492E);
// Divide the i32x8 vectors by (1 << 16), rounding to nearest.
__m256i tmp1_gy_eve_lo =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_eve_lo, p8000_p0000), 16);
__m256i tmp1_gy_eve_hi =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_eve_hi, p8000_p0000), 16);
__m256i tmp1_gy_odd_lo =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_odd_lo, p8000_p0000), 16);
__m256i tmp1_gy_odd_hi =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_odd_hi, p8000_p0000), 16);
// Pack the ((-0x581A * Cb) + (+0x492E * Cr)) as i16x16 and subtract Cr.
__m256i gy_eve = _mm256_sub_epi16(
_mm256_packs_epi32(tmp1_gy_eve_lo, tmp1_gy_eve_hi), cr_eve);
__m256i gy_odd = _mm256_sub_epi16(
_mm256_packs_epi32(tmp1_gy_odd_lo, tmp1_gy_odd_hi), cr_odd);
// ----
// Add Y to (B-Y), (G-Y) and (R-Y) to produce B, G and R.
//
// For the resultant packed_x_xxx vectors, only elements 0 ..= 7 and 16 ..=
// 23 of the 32-element vectors matter (since we'll unpacklo but not
// unpackhi them). Let … denote 8 ignored consecutive u8 values and let %
// denote 0xFF. We'll end this section with:
//
// packed_b_eve = u8x32 [b00 b02 .. b0C b0E … b10 b12 .. b1C b1E …]
// packed_b_odd = u8x32 [b01 b03 .. b0D b0F … b11 b13 .. b1D b1F …]
// packed_g_eve = u8x32 [g00 g02 .. g0C g0E … g10 g12 .. g1C g1E …]
// packed_g_odd = u8x32 [g01 g03 .. g0D g0F … g11 g13 .. g1D g1F …]
// packed_r_eve = u8x32 [r00 r02 .. r0C r0E … r10 r12 .. r1C r1E …]
// packed_r_odd = u8x32 [r01 r03 .. r0D r0F … r11 r13 .. r1D r1F …]
// uFFFF = u8x32 [ % % .. % % … % % .. % % …]
__m256i yy_all = _mm256_lddqu_si256((const __m256i*)(const void*)up0);
__m256i yy_eve = _mm256_and_si256(yy_all, u00FF);
__m256i yy_odd = _mm256_srli_epi16(yy_all, 8);
__m256i loose_b_eve = _mm256_add_epi16(by_eve, yy_eve);
__m256i loose_b_odd = _mm256_add_epi16(by_odd, yy_odd);
__m256i packed_b_eve = _mm256_packus_epi16(loose_b_eve, loose_b_eve);
__m256i packed_b_odd = _mm256_packus_epi16(loose_b_odd, loose_b_odd);
__m256i loose_g_eve = _mm256_add_epi16(gy_eve, yy_eve);
__m256i loose_g_odd = _mm256_add_epi16(gy_odd, yy_odd);
__m256i packed_g_eve = _mm256_packus_epi16(loose_g_eve, loose_g_eve);
__m256i packed_g_odd = _mm256_packus_epi16(loose_g_odd, loose_g_odd);
__m256i loose_r_eve = _mm256_add_epi16(ry_eve, yy_eve);
__m256i loose_r_odd = _mm256_add_epi16(ry_odd, yy_odd);
__m256i packed_r_eve = _mm256_packus_epi16(loose_r_eve, loose_r_eve);
__m256i packed_r_odd = _mm256_packus_epi16(loose_r_odd, loose_r_odd);
// ----
// Mix those values (unpacking in 8, 16 and then 32 bit units) to get the
// desired BGRX/RGBX order.
//
// From here onwards, all of our __m256i registers are u8x32.
// mix00 = [b00 g00 b02 g02 .. b0E g0E b10 g10 .. b1C g1C b1E g1E]
// mix01 = [b01 g01 b03 g03 .. b0F g0F b11 g11 .. b1D g1D b1F g1F]
// mix02 = [r00 % r02 % .. r0E % r10 % .. r1C % r1E %]
// mix03 = [r01 % r03 % .. r0F % r11 % .. r1D % r1F %]
//
// See also § below.
__m256i mix00 = _mm256_unpacklo_epi8(packed_b_eve, packed_g_eve);
__m256i mix01 = _mm256_unpacklo_epi8(packed_b_odd, packed_g_odd);
__m256i mix02 = _mm256_unpacklo_epi8(packed_r_eve, uFFFF);
__m256i mix03 = _mm256_unpacklo_epi8(packed_r_odd, uFFFF);
// mix10 = [b00 g00 r00 % b02 g02 r02 % b04 g04 r04 % b06 g06 r06 %
// b10 g10 r10 % b12 g12 r12 % b14 g14 r14 % b16 g16 r16 %]
// mix11 = [b01 g01 r01 % b03 g03 r03 % b05 g05 r05 % b07 g07 r07 %
// b11 g11 r11 % b13 g13 r13 % b15 g15 r15 % b17 g17 r17 %]
// mix12 = [b08 g08 r08 % b0A g0A r0A % b0C g0C r0C % b0E g0E r0E %
// b18 g18 r18 % b1A g1A r1A % b1C g1C r1C % b1E g1E r1E %]
// mix13 = [b09 g09 r09 % b0B g0B r0B % b0D g0D r0D % b0F g0F r0F %
// b19 g19 r19 % b1B g1B r1B % b1D g1D r1D % b1F g1F r1F %]
__m256i mix10 = _mm256_unpacklo_epi16(mix00, mix02);
__m256i mix11 = _mm256_unpacklo_epi16(mix01, mix03);
__m256i mix12 = _mm256_unpackhi_epi16(mix00, mix02);
__m256i mix13 = _mm256_unpackhi_epi16(mix01, mix03);
// mix20 = [b00 g00 r00 % b01 g01 r01 % b02 g02 r02 % b03 g03 r03 %
// b10 g10 r10 % b11 g11 r11 % b12 g12 r12 % b13 g13 r13 %]
// mix21 = [b04 g04 r04 % b05 g05 r05 % b06 g06 r06 % b07 g07 r07 %
// b14 g14 r14 % b15 g15 r15 % b16 g16 r16 % b17 g17 r17 %]
// mix22 = [b08 g08 r08 % b09 g09 r09 % b0A g0A r0A % b0B g0B r0B %
// b18 g18 r18 % b19 g19 r19 % b1A g1A r1A % b1B g1B r1B %]
// mix23 = [b0C g0C r0C % b0D g0D r0D % b0E g0E r0E % b0F g0F r0F %
// b1C g1C r1C % b1D g1D r1D % b1E g1E r1E % b1F g1F r1F %]
__m256i mix20 = _mm256_unpacklo_epi32(mix10, mix11);
__m256i mix21 = _mm256_unpackhi_epi32(mix10, mix11);
__m256i mix22 = _mm256_unpacklo_epi32(mix12, mix13);
__m256i mix23 = _mm256_unpackhi_epi32(mix12, mix13);
// mix30 = [b00 g00 r00 % b01 g01 r01 % b02 g02 r02 % b03 g03 r03 %
// b04 g04 r04 % b05 g05 r05 % b06 g06 r06 % b07 g07 r07 %]
// mix31 = [b08 g08 r08 % b09 g09 r09 % b0A g0A r0A % b0B g0B r0B %
// b0C g0C r0C % b0D g0D r0D % b0E g0E r0E % b0F g0F r0F %]
// mix32 = [b10 g10 r10 % b11 g11 r11 % b12 g12 r12 % b13 g13 r13 %
// b14 g14 r14 % b15 g15 r15 % b16 g16 r16 % b17 g17 r17 %]
// mix33 = [b18 g18 r18 % b19 g19 r19 % b1A g1A r1A % b1B g1B r1B %
// b1C g1C r1C % b1D g1D r1D % b1E g1E r1E % b1F g1F r1F %]
__m256i mix30 = _mm256_permute2x128_si256(mix20, mix21, 0x20);
__m256i mix31 = _mm256_permute2x128_si256(mix22, mix23, 0x20);
__m256i mix32 = _mm256_permute2x128_si256(mix20, mix21, 0x31);
__m256i mix33 = _mm256_permute2x128_si256(mix22, mix23, 0x31);
// Write out four u8x32 SIMD registers (128 bytes, 32 BGRX/RGBX pixels).
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x00), mix30);
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x20), mix31);
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x40), mix32);
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x60), mix33);
// Advance by up to 32 pixels. The first iteration might be smaller than 32
// so that all of the remaining steps are exactly 32.
uint32_t n = 32u - (31u & (x - x_end));
dst_iter += 4u * n;
up0 += n;
up1 += n;
up2 += n;
x += n;
}
}
// The rgbx flavor (below) is exactly the same as the bgrx flavor (above)
// 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_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) {
if ((x + 32u) > x_end) {
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx( //
dst, x, x_end, y, up0, up1, up2);
return;
}
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));
const __m256i u0001 = _mm256_set1_epi16(+0x0001);
const __m256i u00FF = _mm256_set1_epi16(+0x00FF);
const __m256i uFF80 = _mm256_set1_epi16(-0x0080);
const __m256i uFFFF = _mm256_set1_epi16(-0x0001);
const __m256i p8000_p0000 = _mm256_set_epi16( //
+0x0000, -0x8000, +0x0000, -0x8000, //
+0x0000, -0x8000, +0x0000, -0x8000, //
+0x0000, -0x8000, +0x0000, -0x8000, //
+0x0000, -0x8000, +0x0000, -0x8000);
const __m256i m3A5E = _mm256_set1_epi16(-0x3A5E);
const __m256i p66E9 = _mm256_set1_epi16(+0x66E9);
const __m256i m581A_p492E = _mm256_set_epi16( //
+0x492E, -0x581A, +0x492E, -0x581A, //
+0x492E, -0x581A, +0x492E, -0x581A, //
+0x492E, -0x581A, +0x492E, -0x581A, //
+0x492E, -0x581A, +0x492E, -0x581A);
while (x < x_end) {
__m256i cb_all = _mm256_lddqu_si256((const __m256i*)(const void*)up1);
__m256i cr_all = _mm256_lddqu_si256((const __m256i*)(const void*)up2);
__m256i cb_eve = _mm256_add_epi16(uFF80, _mm256_and_si256(cb_all, u00FF));
__m256i cr_eve = _mm256_add_epi16(uFF80, _mm256_and_si256(cr_all, u00FF));
__m256i cb_odd = _mm256_add_epi16(uFF80, _mm256_srli_epi16(cb_all, 8));
__m256i cr_odd = _mm256_add_epi16(uFF80, _mm256_srli_epi16(cr_all, 8));
__m256i tmp_by_eve = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cb_eve, cb_eve), m3A5E), u0001),
1);
__m256i tmp_by_odd = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cb_odd, cb_odd), m3A5E), u0001),
1);
__m256i tmp_ry_eve = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cr_eve, cr_eve), p66E9), u0001),
1);
__m256i tmp_ry_odd = _mm256_srai_epi16(
_mm256_add_epi16(
_mm256_mulhi_epi16(_mm256_add_epi16(cr_odd, cr_odd), p66E9), u0001),
1);
__m256i by_eve =
_mm256_add_epi16(tmp_by_eve, _mm256_add_epi16(cb_eve, cb_eve));
__m256i by_odd =
_mm256_add_epi16(tmp_by_odd, _mm256_add_epi16(cb_odd, cb_odd));
__m256i ry_eve = _mm256_add_epi16(tmp_ry_eve, cr_eve);
__m256i ry_odd = _mm256_add_epi16(tmp_ry_odd, cr_odd);
__m256i tmp0_gy_eve_lo = _mm256_madd_epi16( //
_mm256_unpacklo_epi16(cb_eve, cr_eve), m581A_p492E);
__m256i tmp0_gy_eve_hi = _mm256_madd_epi16( //
_mm256_unpackhi_epi16(cb_eve, cr_eve), m581A_p492E);
__m256i tmp0_gy_odd_lo = _mm256_madd_epi16( //
_mm256_unpacklo_epi16(cb_odd, cr_odd), m581A_p492E);
__m256i tmp0_gy_odd_hi = _mm256_madd_epi16( //
_mm256_unpackhi_epi16(cb_odd, cr_odd), m581A_p492E);
__m256i tmp1_gy_eve_lo =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_eve_lo, p8000_p0000), 16);
__m256i tmp1_gy_eve_hi =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_eve_hi, p8000_p0000), 16);
__m256i tmp1_gy_odd_lo =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_odd_lo, p8000_p0000), 16);
__m256i tmp1_gy_odd_hi =
_mm256_srai_epi32(_mm256_add_epi32(tmp0_gy_odd_hi, p8000_p0000), 16);
__m256i gy_eve = _mm256_sub_epi16(
_mm256_packs_epi32(tmp1_gy_eve_lo, tmp1_gy_eve_hi), cr_eve);
__m256i gy_odd = _mm256_sub_epi16(
_mm256_packs_epi32(tmp1_gy_odd_lo, tmp1_gy_odd_hi), cr_odd);
__m256i yy_all = _mm256_lddqu_si256((const __m256i*)(const void*)up0);
__m256i yy_eve = _mm256_and_si256(yy_all, u00FF);
__m256i yy_odd = _mm256_srli_epi16(yy_all, 8);
__m256i loose_b_eve = _mm256_add_epi16(by_eve, yy_eve);
__m256i loose_b_odd = _mm256_add_epi16(by_odd, yy_odd);
__m256i packed_b_eve = _mm256_packus_epi16(loose_b_eve, loose_b_eve);
__m256i packed_b_odd = _mm256_packus_epi16(loose_b_odd, loose_b_odd);
__m256i loose_g_eve = _mm256_add_epi16(gy_eve, yy_eve);
__m256i loose_g_odd = _mm256_add_epi16(gy_odd, yy_odd);
__m256i packed_g_eve = _mm256_packus_epi16(loose_g_eve, loose_g_eve);
__m256i packed_g_odd = _mm256_packus_epi16(loose_g_odd, loose_g_odd);
__m256i loose_r_eve = _mm256_add_epi16(ry_eve, yy_eve);
__m256i loose_r_odd = _mm256_add_epi16(ry_odd, yy_odd);
__m256i packed_r_eve = _mm256_packus_epi16(loose_r_eve, loose_r_eve);
__m256i packed_r_odd = _mm256_packus_epi16(loose_r_odd, loose_r_odd);
// § Note the swapped B and R channels.
__m256i mix00 = _mm256_unpacklo_epi8(packed_r_eve, packed_g_eve);
__m256i mix01 = _mm256_unpacklo_epi8(packed_r_odd, packed_g_odd);
__m256i mix02 = _mm256_unpacklo_epi8(packed_b_eve, uFFFF);
__m256i mix03 = _mm256_unpacklo_epi8(packed_b_odd, uFFFF);
__m256i mix10 = _mm256_unpacklo_epi16(mix00, mix02);
__m256i mix11 = _mm256_unpacklo_epi16(mix01, mix03);
__m256i mix12 = _mm256_unpackhi_epi16(mix00, mix02);
__m256i mix13 = _mm256_unpackhi_epi16(mix01, mix03);
__m256i mix20 = _mm256_unpacklo_epi32(mix10, mix11);
__m256i mix21 = _mm256_unpackhi_epi32(mix10, mix11);
__m256i mix22 = _mm256_unpacklo_epi32(mix12, mix13);
__m256i mix23 = _mm256_unpackhi_epi32(mix12, mix13);
__m256i mix30 = _mm256_permute2x128_si256(mix20, mix21, 0x20);
__m256i mix31 = _mm256_permute2x128_si256(mix22, mix23, 0x20);
__m256i mix32 = _mm256_permute2x128_si256(mix20, mix21, 0x31);
__m256i mix33 = _mm256_permute2x128_si256(mix22, mix23, 0x31);
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x00), mix30);
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x20), mix31);
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x40), mix32);
_mm256_storeu_si256((__m256i*)(void*)(dst_iter + 0x60), mix33);
uint32_t n = 32u - (31u & (x - x_end));
dst_iter += 4u * n;
up0 += n;
up1 += n;
up2 += n;
x += n;
}
}
#if defined(__GNUC__) && !defined(__clang__)
// No-op.
#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(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column,
bool last_column) {
uint8_t* dp = dst_ptr;
const uint8_t* sp_major = src_ptr_major;
const uint8_t* sp_minor = src_ptr_minor;
if (first_column) {
src_len--;
if ((src_len <= 0u) && last_column) {
uint32_t sv = (12u * ((uint32_t)(*sp_major++))) + //
(4u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + 8u) >> 4u);
*dp++ = (uint8_t)((sv + 7u) >> 4u);
return dst_ptr;
}
uint32_t sv_major_m1 = sp_major[-0]; // Clamp offset to zero.
uint32_t sv_minor_m1 = sp_minor[-0]; // Clamp offset to zero.
uint32_t sv_major_p1 = sp_major[+1];
uint32_t sv_minor_p1 = sp_minor[+1];
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
(3u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
if (src_len <= 0u) {
return dst_ptr;
}
}
if (last_column) {
src_len--;
}
if (src_len < 32) {
// This fallback is the same as the non-SIMD-capable code path.
for (; src_len > 0u; src_len--) {
uint32_t sv_major_m1 = sp_major[-1];
uint32_t sv_minor_m1 = sp_minor[-1];
uint32_t sv_major_p1 = sp_major[+1];
uint32_t sv_minor_p1 = sp_minor[+1];
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
(3u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
}
} else {
while (src_len > 0u) {
// Load 1+32+1 samples (six u8x32 vectors) from the major (jxx) and minor
// (nxx) rows.
//
// major_p0 = [j00 j01 j02 j03 .. j28 j29 j30 j31] // p0 = "plus 0"
// minor_p0 = [n00 n01 n02 n03 .. n28 n29 n30 n31] // p0 = "plus 0"
// major_m1 = [jm1 j00 j01 j02 .. j27 j28 j29 j30] // m1 = "minus 1"
// minor_m1 = [nm1 n00 n01 n02 .. n27 n28 n29 n30] // m1 = "minus 1"
// major_p1 = [j01 j02 j03 j04 .. j29 j30 j31 j32] // p1 = "plus 1"
// minor_p1 = [n01 n02 n03 n04 .. n29 n30 n31 n32] // p1 = "plus 1"
__m256i major_p0 =
_mm256_lddqu_si256((const __m256i*)(const void*)(sp_major + 0));
__m256i minor_p0 =
_mm256_lddqu_si256((const __m256i*)(const void*)(sp_minor + 0));
__m256i major_m1 =
_mm256_lddqu_si256((const __m256i*)(const void*)(sp_major - 1));
__m256i minor_m1 =
_mm256_lddqu_si256((const __m256i*)(const void*)(sp_minor - 1));
__m256i major_p1 =
_mm256_lddqu_si256((const __m256i*)(const void*)(sp_major + 1));
__m256i minor_p1 =
_mm256_lddqu_si256((const __m256i*)(const void*)(sp_minor + 1));
// Unpack, staying with u8x32 vectors.
//
// step1_p0_lo = [j00 n00 j01 n01 .. j07 n07 j16 n16 j17 n17 .. j23 n23]
// step1_p0_hi = [j08 n08 j09 n09 .. j15 n15 j24 n24 j25 n25 .. j31 n31]
// step1_m1_lo = [jm1 nm1 j00 n00 .. j06 n06 j15 n15 j16 n16 .. j22 n22]
// step1_m1_hi = [j07 n07 j08 n08 .. j14 n14 j23 n23 j24 n24 .. j30 n30]
// step1_p1_lo = [j01 n01 j02 n02 .. j08 n08 j17 n17 j18 n18 .. j24 n24]
// step1_p1_hi = [j09 n09 j10 n10 .. j16 n16 j25 n25 j26 n26 .. j32 n32]
__m256i step1_p0_lo = _mm256_unpacklo_epi8(major_p0, minor_p0);
__m256i step1_p0_hi = _mm256_unpackhi_epi8(major_p0, minor_p0);
__m256i step1_m1_lo = _mm256_unpacklo_epi8(major_m1, minor_m1);
__m256i step1_m1_hi = _mm256_unpackhi_epi8(major_m1, minor_m1);
__m256i step1_p1_lo = _mm256_unpacklo_epi8(major_p1, minor_p1);
__m256i step1_p1_hi = _mm256_unpackhi_epi8(major_p1, minor_p1);
// Multiply-add to get u16x16 vectors.
//
// step2_p0_lo = [9*j00+3*n00 9*j01+3*n01 .. 9*j23+3*n23]
// step2_p0_hi = [9*j08+3*n08 9*j09+3*n09 .. 9*j31+3*n31]
// step2_m1_lo = [3*jm1+1*nm1 3*j00+1*n00 .. 3*j22+1*n22]
// step2_m1_hi = [3*j07+1*n07 3*j08+1*n08 .. 3*j30+1*n30]
// step2_p1_lo = [3*j01+1*n01 3*j02+1*n02 .. 3*j24+1*n24]
// step2_p1_hi = [3*j09+1*n09 3*j10+1*n10 .. 3*j32+1*n32]
const __m256i k0309 = _mm256_set1_epi16(0x0309);
const __m256i k0103 = _mm256_set1_epi16(0x0103);
__m256i step2_p0_lo = _mm256_maddubs_epi16(step1_p0_lo, k0309);
__m256i step2_p0_hi = _mm256_maddubs_epi16(step1_p0_hi, k0309);
__m256i step2_m1_lo = _mm256_maddubs_epi16(step1_m1_lo, k0103);
__m256i step2_m1_hi = _mm256_maddubs_epi16(step1_m1_hi, k0103);
__m256i step2_p1_lo = _mm256_maddubs_epi16(step1_p1_lo, k0103);
__m256i step2_p1_hi = _mm256_maddubs_epi16(step1_p1_hi, k0103);
// Compute the weighted sums of (p0, m1) and (p0, p1). For example:
//
// step3_m1_lo[00] = ((9*j00) + (3*n00) + (3*jm1) + (1*nm1)) as u16
// step3_p1_hi[15] = ((9*j31) + (3*n31) + (3*j32) + (1*n32)) as u16
__m256i step3_m1_lo = _mm256_add_epi16(step2_p0_lo, step2_m1_lo);
__m256i step3_m1_hi = _mm256_add_epi16(step2_p0_hi, step2_m1_hi);
__m256i step3_p1_lo = _mm256_add_epi16(step2_p0_lo, step2_p1_lo);
__m256i step3_p1_hi = _mm256_add_epi16(step2_p0_hi, step2_p1_hi);
// Bias by 8 (on the left) or 7 (on the right) and then divide by 16
// (which is 9+3+3+1) to get a weighted average. On the left (m1), shift
// the u16 right value by 4. On the right (p1), shift right by 4 and then
// shift left by 8 so that, when still in the u16x16 little-endian
// interpretation, we have:
// - m1_element = (etcetera + 8) >> 4
// - p1_element = ((etcetera + 7) >> 4) << 8
//
// step4_m1_lo = [0x00?? 0x00?? ... 0x00?? 0x00??]
// step4_p1_lo = [0x??00 0x??00 ... 0x??00 0x??00]
// step4_m1_hi = [0x00?? 0x00?? ... 0x00?? 0x00??]
// step4_p1_hi = [0x??00 0x??00 ... 0x??00 0x??00]
__m256i step4_m1_lo = _mm256_srli_epi16(
_mm256_add_epi16(step3_m1_lo, _mm256_set1_epi16(8)), 4);
__m256i step4_p1_lo = _mm256_slli_epi16(
_mm256_srli_epi16(_mm256_add_epi16(step3_p1_lo, _mm256_set1_epi16(7)),
4),
8);
__m256i step4_m1_hi = _mm256_srli_epi16(
_mm256_add_epi16(step3_m1_hi, _mm256_set1_epi16(8)), 4);
__m256i step4_p1_hi = _mm256_slli_epi16(
_mm256_srli_epi16(_mm256_add_epi16(step3_p1_hi, _mm256_set1_epi16(7)),
4),
8);
// Bitwise-or two "0x00"-rich u16x16 vectors to get a u8x32 vector. Do
// that twice. Once for the low columns and once for the high columns.
//
// In terms of jxx (major row) or nxx (minor row) source samples:
// - low columns means ( 0 .. 8; 16 .. 24).
// - high columns means ( 8 .. 16; 24 .. 32).
//
// In terms of dxx destination samples (there are twice as many):
// - low columns means ( 0 .. 16; 32 .. 48).
// - high columns means (16 .. 32; 48 .. 64).
//
// step5_lo = [d00 d01 .. d14 d15 d32 d33 .. d46 d47]
// step5_hi = [d16 d17 .. d30 d31 d48 d49 .. d62 d63]
//
// The d00, d02 ... d62 even elements come from (p0, m1) weighted sums.
// The d01, d03 ... d63 odd elements come from (p0, p1) weighted sums.
__m256i step5_lo = _mm256_or_si256(step4_m1_lo, step4_p1_lo);
__m256i step5_hi = _mm256_or_si256(step4_m1_hi, step4_p1_hi);
// Permute and store.
//
// step6_00_31 = [d00 d01 .. d14 d15 d16 d17 .. d30 d31]
// step6_32_63 = [d32 d33 .. d46 d47 d48 d49 .. d62 d63]
__m256i step6_00_31 = _mm256_permute2x128_si256(step5_lo, step5_hi, 0x20);
__m256i step6_32_63 = _mm256_permute2x128_si256(step5_lo, step5_hi, 0x31);
_mm256_storeu_si256((__m256i*)(void*)(dp + 0x00), step6_00_31);
_mm256_storeu_si256((__m256i*)(void*)(dp + 0x20), step6_32_63);
// Advance by up to 32 source samples (64 destination samples). The first
// iteration might be smaller than 32 so that all of the remaining steps
// are exactly 32.
size_t n = 32u - (31u & (0u - src_len));
dp += 2u * n;
sp_major += n;
sp_minor += n;
src_len -= n;
}
}
if (last_column) {
uint32_t sv_major_m1 = sp_major[-1];
uint32_t sv_minor_m1 = sp_minor[-1];
uint32_t sv_major_p1 = sp_major[+0]; // Clamp offset to zero.
uint32_t sv_minor_p1 = sp_minor[+0]; // Clamp offset to zero.
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
(3u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
}
return dst_ptr;
}
#endif
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
// ‼ WUFFS MULTI-FILE SECTION -x86_avx2
+1348
View File
@@ -0,0 +1,1348 @@
// 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.
// --------
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
static void //
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2(
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_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
static void //
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2(
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);
#if defined(__GNUC__) && !defined(__clang__)
// No-op.
#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(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column,
bool last_column);
#endif
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
// --------
static inline uint32_t //
wuffs_base__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) {
return wuffs_base__u32__min( //
wuffs_base__u32__min( //
wuffs_base__u32__min(a, b), //
wuffs_base__u32__min(c, d)), //
e);
}
// --------
typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_4_func)(
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,
const uint8_t* up3);
static void //
wuffs_base__pixel_swizzler__swizzle_cmyk__convert_4_general(
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,
const uint8_t* up3) {
for (; x < x_end; x++) {
// It's called CMYK but, but for Adobe CMYK JPEG images in practice, it's
// RGBW: 0xFFu means no ink instead of full ink. Note that a double
// inversion is a no-op, so inversions might be implicit in the code below.
uint32_t r = ((uint32_t)(*up0++));
uint32_t g = ((uint32_t)(*up1++));
uint32_t b = ((uint32_t)(*up2++));
uint32_t w = ((uint32_t)(*up3++));
r = ((r * w) + 0x7Fu) / 0xFFu;
g = ((g * w) + 0x7Fu) / 0xFFu;
b = ((b * w) + 0x7Fu) / 0xFFu;
wuffs_base__pixel_buffer__set_color_u32_at(
dst, x, y, 0xFF000000u | (r << 16u) | (g << 8u) | (b << 0u));
}
}
static void //
wuffs_base__pixel_swizzler__swizzle_ycck__convert_4_general(
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,
const uint8_t* up3) {
for (; x < x_end; x++) {
// We invert once again: 0xFFu means no ink instead of full ink.
uint32_t color = //
wuffs_base__color_ycc__as__color_u32( //
*up0++, *up1++, *up2++);
uint32_t r = 0xFFu - (0xFFu & (color >> 16u));
uint32_t g = 0xFFu - (0xFFu & (color >> 8u));
uint32_t b = 0xFFu - (0xFFu & (color >> 0u));
uint32_t w = ((uint32_t)(*up3++));
r = ((r * w) + 0x7Fu) / 0xFFu;
g = ((g * w) + 0x7Fu) / 0xFFu;
b = ((b * w) + 0x7Fu) / 0xFFu;
wuffs_base__pixel_buffer__set_color_u32_at(
dst, x, y, 0xFF000000u | (r << 16u) | (g << 8u) | (b << 0u));
}
}
// --------
typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func)(
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);
static void //
wuffs_base__pixel_swizzler__swizzle_rgb__convert_3_general(
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) {
for (; x < x_end; x++) {
uint32_t color = 0xFF000000u | //
(((uint32_t)(*up0++)) << 16u) | //
(((uint32_t)(*up1++)) << 8u) | //
(((uint32_t)(*up2++)) << 0u);
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
}
}
static void //
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_general(
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) {
for (; x < x_end; x++) {
uint32_t color = //
wuffs_base__color_ycc__as__color_u32( //
*up0++, *up1++, *up2++);
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
}
}
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) {
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));
for (; x < x_end; x++) {
uint32_t color = //
wuffs_base__color_ycc__as__color_u32( //
*up0++, *up1++, *up2++);
wuffs_base__poke_u32le__no_bounds_check(dst_iter, color);
dst_iter += 4u;
}
}
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) {
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));
for (; x < x_end; x++) {
uint32_t color = //
wuffs_base__color_ycc__as__color_u32_abgr( //
*up0++, *up1++, *up2++);
wuffs_base__poke_u32le__no_bounds_check(dst_iter, color);
dst_iter += 4u;
}
}
// --------
// 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.
//
// 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:
// 480 = 1 * 8 * 60, 672 = 1 * 8 * 84
// 480 = 2 * 8 * 30, 672 = 2 * 8 * 42
// 480 = 3 * 8 * 20, 672 = 3 * 8 * 28
// 480 = 4 * 8 * 15, 672 = 4 * 8 * 21
//
// Box filters are equivalent to nearest neighbor upsampling. These ignore the
// src_ptr_minor, h1v2_bias, first_column and last_column arguments.
//
// Triangle filters use a 3:1 ratio (in 1 dimension), or 9:3:3:1 (in 2
// dimensions), which is higher quality (less blocky) but also higher
// computational effort.
//
// In theory, we could use triangle filters for any (inv_h, inv_v) combination.
// 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)(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major, // Nearest row.
const uint8_t* src_ptr_minor, // Adjacent row, alternating above or below.
size_t src_len,
uint32_t h1v2_bias,
bool first_column,
bool last_column);
static const uint8_t* //
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1vn_box(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor_ignored,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column_ignored,
bool last_column_ignored) {
return src_ptr_major;
}
static const uint8_t* //
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2vn_box(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor_ignored,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column_ignored,
bool last_column_ignored) {
uint8_t* dp = dst_ptr;
const uint8_t* sp = src_ptr_major;
while (src_len--) {
uint8_t sv = *sp++;
*dp++ = sv;
*dp++ = sv;
}
return dst_ptr;
}
static const uint8_t* //
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h3vn_box(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor_ignored,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column_ignored,
bool last_column_ignored) {
uint8_t* dp = dst_ptr;
const uint8_t* sp = src_ptr_major;
while (src_len--) {
uint8_t sv = *sp++;
*dp++ = sv;
*dp++ = sv;
*dp++ = sv;
}
return dst_ptr;
}
static const uint8_t* //
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h4vn_box(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor_ignored,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column_ignored,
bool last_column_ignored) {
uint8_t* dp = dst_ptr;
const uint8_t* sp = src_ptr_major;
while (src_len--) {
uint8_t sv = *sp++;
*dp++ = sv;
*dp++ = sv;
*dp++ = sv;
*dp++ = sv;
}
return dst_ptr;
}
static const uint8_t* //
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h1v2_triangle(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor,
size_t src_len,
uint32_t h1v2_bias,
bool first_column,
bool last_column) {
uint8_t* dp = dst_ptr;
const uint8_t* sp_major = src_ptr_major;
const uint8_t* sp_minor = src_ptr_minor;
while (src_len--) {
*dp++ = (uint8_t)(((3u * ((uint32_t)(*sp_major++))) + //
(1u * ((uint32_t)(*sp_minor++))) + //
h1v2_bias) >>
2u);
}
return dst_ptr;
}
static const uint8_t* //
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v1_triangle(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column,
bool last_column) {
uint8_t* dp = dst_ptr;
const uint8_t* sp = src_ptr_major;
if (first_column) {
src_len--;
if ((src_len <= 0u) && last_column) {
uint8_t sv = *sp++;
*dp++ = sv;
*dp++ = sv;
return dst_ptr;
}
uint32_t svp1 = sp[+1];
uint8_t sv = *sp++;
*dp++ = sv;
*dp++ = (uint8_t)(((3u * (uint32_t)sv) + svp1 + 2u) >> 2u);
if (src_len <= 0u) {
return dst_ptr;
}
}
if (last_column) {
src_len--;
}
for (; src_len > 0u; src_len--) {
uint32_t svm1 = sp[-1];
uint32_t svp1 = sp[+1];
uint32_t sv3 = 3u * (uint32_t)(*sp++);
*dp++ = (uint8_t)((sv3 + svm1 + 1u) >> 2u);
*dp++ = (uint8_t)((sv3 + svp1 + 2u) >> 2u);
}
if (last_column) {
uint32_t svm1 = sp[-1];
uint8_t sv = *sp++;
*dp++ = (uint8_t)(((3u * (uint32_t)sv) + svm1 + 1u) >> 2u);
*dp++ = sv;
}
return dst_ptr;
}
static const uint8_t* //
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v2_triangle(
uint8_t* dst_ptr,
const uint8_t* src_ptr_major,
const uint8_t* src_ptr_minor,
size_t src_len,
uint32_t h1v2_bias_ignored,
bool first_column,
bool last_column) {
uint8_t* dp = dst_ptr;
const uint8_t* sp_major = src_ptr_major;
const uint8_t* sp_minor = src_ptr_minor;
if (first_column) {
src_len--;
if ((src_len <= 0u) && last_column) {
uint32_t sv = (12u * ((uint32_t)(*sp_major++))) + //
(4u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + 8u) >> 4u);
*dp++ = (uint8_t)((sv + 7u) >> 4u);
return dst_ptr;
}
uint32_t sv_major_m1 = sp_major[-0]; // Clamp offset to zero.
uint32_t sv_minor_m1 = sp_minor[-0]; // Clamp offset to zero.
uint32_t sv_major_p1 = sp_major[+1];
uint32_t sv_minor_p1 = sp_minor[+1];
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
(3u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
if (src_len <= 0u) {
return dst_ptr;
}
}
if (last_column) {
src_len--;
}
for (; src_len > 0u; src_len--) {
uint32_t sv_major_m1 = sp_major[-1];
uint32_t sv_minor_m1 = sp_minor[-1];
uint32_t sv_major_p1 = sp_major[+1];
uint32_t sv_minor_p1 = sp_minor[+1];
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
(3u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
}
if (last_column) {
uint32_t sv_major_m1 = sp_major[-1];
uint32_t sv_minor_m1 = sp_minor[-1];
uint32_t sv_major_p1 = sp_major[+0]; // Clamp offset to zero.
uint32_t sv_minor_p1 = sp_minor[+0]; // Clamp offset to zero.
uint32_t sv = (9u * ((uint32_t)(*sp_major++))) + //
(3u * ((uint32_t)(*sp_minor++)));
*dp++ = (uint8_t)((sv + (3u * sv_major_m1) + (sv_minor_m1) + 8u) >> 4u);
*dp++ = (uint8_t)((sv + (3u * sv_major_p1) + (sv_minor_p1) + 7u) >> 4u);
}
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_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_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_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_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,
},
};
static inline uint32_t //
wuffs_base__pixel_swizzler__has_triangle_upsampler(uint32_t inv_h,
uint32_t inv_v) {
if (inv_h == 1u) {
return inv_v == 2u;
} else if (inv_h == 2u) {
return (inv_v == 1u) || (inv_v == 2u);
}
return false;
}
// --------
// All of the wuffs_base__pixel_swizzler__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_base__pixel_buffer* dst,
uint32_t width,
uint32_t y,
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 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) {
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);
const uint8_t* src3 = src_ptr3 + ((y / inv_v3) * (size_t)stride3);
uint32_t total_src_len0 = 0u;
uint32_t total_src_len1 = 0u;
uint32_t total_src_len2 = 0u;
uint32_t total_src_len3 = 0u;
uint32_t x = 0u;
while (x < width) {
bool first_column = x == 0u;
uint32_t end = x + 480u;
if (end > width) {
end = width;
}
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;
total_src_len0 += src_len0;
total_src_len1 += src_len1;
total_src_len2 += src_len2;
total_src_len3 += src_len3;
const uint8_t* src_ptr_x0 = src0 + (x / inv_h0);
const uint8_t* up0 = (*upfunc0)( //
scratch_buffer_2k_ptr + (0u * 480u), //
src_ptr_x0, //
src_ptr_x0, //
src_len0, //
h1v2_bias, //
first_column, //
(total_src_len0 >= half_width_for_2to1));
const uint8_t* src_ptr_x1 = src1 + (x / inv_h1);
const uint8_t* up1 = (*upfunc1)( //
scratch_buffer_2k_ptr + (1u * 480u), //
src_ptr_x1, //
src_ptr_x1, //
src_len1, //
h1v2_bias, //
first_column, //
(total_src_len1 >= half_width_for_2to1));
const uint8_t* src_ptr_x2 = src2 + (x / inv_h2);
const uint8_t* up2 = (*upfunc2)( //
scratch_buffer_2k_ptr + (2u * 480u), //
src_ptr_x2, //
src_ptr_x2, //
src_len2, //
h1v2_bias, //
first_column, //
(total_src_len2 >= half_width_for_2to1));
const uint8_t* src_ptr_x3 = src3 + (x / inv_h3);
const uint8_t* up3 = (*upfunc3)( //
scratch_buffer_2k_ptr + (3u * 480u), //
src_ptr_x3, //
src_ptr_x3, //
src_len3, //
h1v2_bias, //
first_column, //
(total_src_len3 >= half_width_for_2to1));
(*conv4func)(dst, x, end, y, up0, up1, up2, up3);
x = end;
}
}
static void //
wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter(
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,
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_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 =
(*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u];
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 =
(*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u];
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2 =
(*upfuncs)[(inv_h2 - 1u) & 3u][(inv_v2 - 1u) & 3u];
wuffs_base__pixel_swizzler__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, //
src_ptr0, src_ptr1, src_ptr2, src_ptr3, //
stride0, stride1, stride2, stride3, //
inv_h0, inv_h1, inv_h2, inv_h3, //
inv_v0, inv_v1, inv_v2, inv_v3, //
half_width_for_2to1, //
h1v2_bias, //
scratch_buffer_2k_ptr, //
upfunc0, upfunc1, upfunc2, upfunc3, conv4func);
h1v2_bias = 2u;
// Middle rows.
bool last_row = height == 2u * half_height_for_2to1;
uint32_t y_max_excl = last_row ? (height - 1u) : height;
uint32_t y;
for (y = 1u; y < 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)
? src0_major
: ((y & 1u) ? (src0_major + stride0) : (src0_major - stride0));
const uint8_t* src1_major = src_ptr1 + ((y / inv_v1) * (size_t)stride1);
const uint8_t* src1_minor =
(inv_v1 != 2u)
? src1_major
: ((y & 1u) ? (src1_major + stride1) : (src1_major - stride1));
const uint8_t* src2_major = src_ptr2 + ((y / inv_v2) * (size_t)stride2);
const uint8_t* src2_minor =
(inv_v2 != 2u)
? src2_major
: ((y & 1u) ? (src2_major + stride2) : (src2_major - stride2));
const uint8_t* src3_major = src_ptr3 + ((y / inv_v3) * (size_t)stride3);
const uint8_t* src3_minor =
(inv_v3 != 2u)
? src3_major
: ((y & 1u) ? (src3_major + stride3) : (src3_major - stride3));
uint32_t total_src_len0 = 0u;
uint32_t total_src_len1 = 0u;
uint32_t total_src_len2 = 0u;
uint32_t total_src_len3 = 0u;
uint32_t x = 0u;
while (x < width) {
bool first_column = x == 0u;
uint32_t end = x + 480u;
if (end > width) {
end = width;
}
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;
total_src_len0 += src_len0;
total_src_len1 += src_len1;
total_src_len2 += src_len2;
total_src_len3 += src_len3;
const uint8_t* up0 = (*upfunc0)( //
scratch_buffer_2k_ptr + (0u * 480u), //
src0_major + (x / inv_h0), //
src0_minor + (x / inv_h0), //
src_len0, //
h1v2_bias, //
first_column, //
(total_src_len0 >= half_width_for_2to1));
const uint8_t* up1 = (*upfunc1)( //
scratch_buffer_2k_ptr + (1u * 480u), //
src1_major + (x / inv_h1), //
src1_minor + (x / inv_h1), //
src_len1, //
h1v2_bias, //
first_column, //
(total_src_len1 >= half_width_for_2to1));
const uint8_t* up2 = (*upfunc2)( //
scratch_buffer_2k_ptr + (2u * 480u), //
src2_major + (x / inv_h2), //
src2_minor + (x / inv_h2), //
src_len2, //
h1v2_bias, //
first_column, //
(total_src_len2 >= half_width_for_2to1));
const uint8_t* up3 = (*upfunc3)( //
scratch_buffer_2k_ptr + (3u * 480u), //
src3_major + (x / inv_h3), //
src3_minor + (x / inv_h3), //
src_len3, //
h1v2_bias, //
first_column, //
(total_src_len3 >= half_width_for_2to1));
(*conv4func)(dst, x, end, y, up0, up1, up2, up3);
x = end;
}
h1v2_bias ^= 3u;
}
// Last row.
if (y_max_excl != height) {
wuffs_base__pixel_swizzler__swizzle_ycck__general__triangle_filter_edge_row(
dst, width, height - 1u, //
src_ptr0, src_ptr1, src_ptr2, src_ptr3, //
stride0, stride1, stride2, stride3, //
inv_h0, inv_h1, inv_h2, inv_h3, //
inv_v0, inv_v1, inv_v2, inv_v3, //
half_width_for_2to1, //
h1v2_bias, //
scratch_buffer_2k_ptr, //
upfunc0, upfunc1, upfunc2, upfunc3, conv4func);
}
}
static void //
wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter_edge_row(
wuffs_base__pixel_buffer* dst,
uint32_t width,
uint32_t y,
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 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) {
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);
uint32_t total_src_len0 = 0u;
uint32_t total_src_len1 = 0u;
uint32_t total_src_len2 = 0u;
uint32_t x = 0u;
while (x < width) {
bool first_column = x == 0u;
uint32_t end = x + 672u;
if (end > width) {
end = width;
}
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;
total_src_len0 += src_len0;
total_src_len1 += src_len1;
total_src_len2 += src_len2;
const uint8_t* src_ptr_x0 = src0 + (x / inv_h0);
const uint8_t* up0 = (*upfunc0)( //
scratch_buffer_2k_ptr + (0u * 672u), //
src_ptr_x0, //
src_ptr_x0, //
src_len0, //
h1v2_bias, //
first_column, //
(total_src_len0 >= half_width_for_2to1));
const uint8_t* src_ptr_x1 = src1 + (x / inv_h1);
const uint8_t* up1 = (*upfunc1)( //
scratch_buffer_2k_ptr + (1u * 672u), //
src_ptr_x1, //
src_ptr_x1, //
src_len1, //
h1v2_bias, //
first_column, //
(total_src_len1 >= half_width_for_2to1));
const uint8_t* src_ptr_x2 = src2 + (x / inv_h2);
const uint8_t* up2 = (*upfunc2)( //
scratch_buffer_2k_ptr + (2u * 672u), //
src_ptr_x2, //
src_ptr_x2, //
src_len2, //
h1v2_bias, //
first_column, //
(total_src_len2 >= half_width_for_2to1));
(*conv3func)(dst, x, end, y, up0, up1, up2);
x = end;
}
}
static void //
wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter(
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__upsample_func upfunc0 =
(*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u];
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 =
(*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u];
wuffs_base__pixel_swizzler__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, //
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);
h1v2_bias = 2u;
// Middle rows.
bool last_row = height == 2u * half_height_for_2to1;
uint32_t y_max_excl = last_row ? (height - 1u) : height;
uint32_t y;
for (y = 1u; y < 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)
? src0_major
: ((y & 1u) ? (src0_major + stride0) : (src0_major - stride0));
const uint8_t* src1_major = src_ptr1 + ((y / inv_v1) * (size_t)stride1);
const uint8_t* src1_minor =
(inv_v1 != 2u)
? src1_major
: ((y & 1u) ? (src1_major + stride1) : (src1_major - stride1));
const uint8_t* src2_major = src_ptr2 + ((y / inv_v2) * (size_t)stride2);
const uint8_t* src2_minor =
(inv_v2 != 2u)
? src2_major
: ((y & 1u) ? (src2_major + stride2) : (src2_major - stride2));
uint32_t total_src_len0 = 0u;
uint32_t total_src_len1 = 0u;
uint32_t total_src_len2 = 0u;
uint32_t x = 0u;
while (x < width) {
bool first_column = x == 0u;
uint32_t end = x + 672u;
if (end > width) {
end = width;
}
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;
total_src_len0 += src_len0;
total_src_len1 += src_len1;
total_src_len2 += src_len2;
const uint8_t* up0 = (*upfunc0)( //
scratch_buffer_2k_ptr + (0u * 672u), //
src0_major + (x / inv_h0), //
src0_minor + (x / inv_h0), //
src_len0, //
h1v2_bias, //
first_column, //
(total_src_len0 >= half_width_for_2to1));
const uint8_t* up1 = (*upfunc1)( //
scratch_buffer_2k_ptr + (1u * 672u), //
src1_major + (x / inv_h1), //
src1_minor + (x / inv_h1), //
src_len1, //
h1v2_bias, //
first_column, //
(total_src_len1 >= half_width_for_2to1));
const uint8_t* up2 = (*upfunc2)( //
scratch_buffer_2k_ptr + (2u * 672u), //
src2_major + (x / inv_h2), //
src2_minor + (x / inv_h2), //
src_len2, //
h1v2_bias, //
first_column, //
(total_src_len2 >= half_width_for_2to1));
(*conv3func)(dst, x, end, y, up0, up1, up2);
x = end;
}
h1v2_bias ^= 3u;
}
// 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, //
upfunc0, upfunc1, upfunc2, conv3func);
}
}
static void //
wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter(
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__upsample_func upfunc0 =
(*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u];
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 =
(*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u];
wuffs_base__pixel_swizzler__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);
uint32_t x = 0u;
while (x < width) {
uint32_t end = x + 672u;
if (end > width) {
end = width;
}
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, //
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, //
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, //
0u, false, false);
(*conv3func)(dst, x, end, y, up0, up1, up2);
x = end;
}
}
}
// --------
// wuffs_base__pixel_swizzler__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,
uint32_t height,
uint32_t stride,
uint32_t inv_h,
uint32_t inv_v) {
uint64_t scaled_width = (((uint64_t)width) + (inv_h - 1u)) / inv_h;
uint64_t scaled_height = (((uint64_t)height) + (inv_v - 1u)) / inv_v;
if (scaled_height <= 0u) {
return 0u;
}
return ((scaled_height - 1u) * stride) + scaled_width;
}
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
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,
wuffs_base__slice_u8 src0,
wuffs_base__slice_u8 src1,
wuffs_base__slice_u8 src2,
wuffs_base__slice_u8 src3,
uint32_t width0,
uint32_t width1,
uint32_t width2,
uint32_t width3,
uint32_t height0,
uint32_t height1,
uint32_t height2,
uint32_t height3,
uint32_t stride0,
uint32_t stride1,
uint32_t stride2,
uint32_t stride3,
uint8_t h0,
uint8_t h1,
uint8_t h2,
uint8_t h3,
uint8_t v0,
uint8_t v1,
uint8_t v2,
uint8_t v3,
bool is_rgb_or_cmyk,
bool triangle_filter_for_2to1,
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)) || //
(scratch_buffer_2k.len < 2048u)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((h3 != 0u) || (v3 != 0u)) {
if ((4u <= ((unsigned int)h3 - 1u)) || //
(4u <= ((unsigned int)v3 - 1u))) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
}
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);
// Calculate the inverse h and v ratios.
//
// It also canonicalizes (h=2 and max_incl_h=4) as equivalent to (h=1 and
// max_incl_h=2). In both cases, the inv_h value is 2.
uint32_t inv_h0 = max_incl_h / h0;
uint32_t inv_h1 = max_incl_h / h1;
uint32_t inv_h2 = max_incl_h / h2;
uint32_t inv_h3 = h3 ? (max_incl_h / h3) : 0u;
uint32_t inv_v0 = max_incl_v / v0;
uint32_t inv_v1 = max_incl_v / v1;
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;
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));
if (((h0 * inv_h0) != max_incl_h) || //
((h1 * inv_h1) != max_incl_h) || //
((h2 * inv_h2) != max_incl_h) || //
((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(
width, height, stride0, inv_h0, inv_v0)) ||
(src1.len < wuffs_base__pixel_swizzler__flattened_length(
width, height, stride1, inv_h1, inv_v1)) ||
(src2.len < wuffs_base__pixel_swizzler__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(
width, height, stride3, inv_h3, inv_v3))) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
}
if (wuffs_base__pixel_format__is_planar(&dst->pixcfg.private_impl.pixfmt)) {
// TODO: see wuffs_base__pixel_buffer__set_color_u32_at's TODO.
return wuffs_base__make_status(
wuffs_base__error__unsupported_pixel_swizzler_option);
}
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__INDEXED__BGRA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
case WUFFS_BASE__PIXEL_FORMAT__BGR:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
case WUFFS_BASE__PIXEL_FORMAT__RGB:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
break;
default:
// TODO: see wuffs_base__pixel_buffer__set_color_u32_at's TODO.
return wuffs_base__make_status(
wuffs_base__error__unsupported_pixel_swizzler_option);
}
if ((width <= 0u) || (height <= 0u)) {
return wuffs_base__make_status(NULL);
}
wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_func conv3func = NULL;
if (is_rgb_or_cmyk) {
conv3func = &wuffs_base__pixel_swizzler__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 (wuffs_base__cpu_arch__have_x86_avx2()) {
conv3func =
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_bgrx_x86_avx2;
break;
}
#endif
conv3func = &wuffs_base__pixel_swizzler__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 (wuffs_base__cpu_arch__have_x86_avx2()) {
conv3func =
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx_x86_avx2;
break;
}
#endif
conv3func = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_3_rgbx;
break;
default:
conv3func = &wuffs_base__pixel_swizzler__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;
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfuncs[4][4];
memcpy(&upfuncs, &wuffs_base__pixel_swizzler__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;
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;
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
#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
// version. Possibly because GCC's auto-vectorizer is smarter (just with
// SSE2, not AVX2) than our hand-written code, but that's just a guess.
//
// See commits 51bc60ef9298cb2efc1b29a9681191f66d49820d and
// cd769a0cdf1b5affee13f6089b995f3d39569cb4 for benchmark numbers.
//
// See also https://godbolt.org/z/MbhbPGEz4 for Debian Bullseye's clang 11
// versus gcc 10, where only gcc auto-vectorizes, although later clang
// versions will also auto-vectorize.
#else
if (wuffs_base__cpu_arch__have_x86_avx2()) {
upfuncs[1][1] =
wuffs_base__pixel_swizzler__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, //
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, //
scratch_buffer_2k.ptr, &upfuncs, conv3func);
}
return wuffs_base__make_status(NULL);
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Ranges and Rects
+5 -32
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Ranges and Rects
@@ -829,8 +823,6 @@ typedef struct wuffs_base__more_information__struct {
inline wuffs_base__range_ie_u64 io_redirect__range() const;
inline uint64_t io_seek__position() const;
inline uint32_t metadata__fourcc() const;
// Deprecated: use metadata_raw_passthrough__range.
inline wuffs_base__range_ie_u64 metadata__range() const;
inline wuffs_base__range_ie_u64 metadata_raw_passthrough__range() const;
inline int32_t metadata_parsed__chrm(uint32_t component) const;
inline uint32_t metadata_parsed__gama() const;
@@ -841,9 +833,6 @@ typedef struct wuffs_base__more_information__struct {
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_REDIRECT 1
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_SEEK 2
// Deprecated: use
// WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH.
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM 4
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED 5
@@ -903,17 +892,6 @@ wuffs_base__more_information__metadata__fourcc(
return m->w;
}
// Deprecated: use
// wuffs_base__more_information__metadata_raw_passthrough__range.
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata__range(
const wuffs_base__more_information* m) {
wuffs_base__range_ie_u64 ret;
ret.min_incl = m->y;
ret.max_excl = m->z;
return ret;
}
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata_raw_passthrough__range(
const wuffs_base__more_information* m) {
@@ -1043,11 +1021,6 @@ wuffs_base__more_information::metadata__fourcc() const {
return wuffs_base__more_information__metadata__fourcc(this);
}
inline wuffs_base__range_ie_u64 //
wuffs_base__more_information::metadata__range() const {
return wuffs_base__more_information__metadata__range(this);
}
inline wuffs_base__range_ie_u64 //
wuffs_base__more_information::metadata_raw_passthrough__range() const {
return wuffs_base__more_information__metadata_raw_passthrough__range(this);
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- String Conversions
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- String Conversions
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Tokens
+57 -15
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Tokens
@@ -321,6 +315,7 @@ typedef struct wuffs_base__token_buffer__struct {
#ifdef __cplusplus
inline bool is_valid() const;
inline void compact();
inline void compact_retaining(uint64_t history_retain_length);
inline uint64_t reader_length() const;
inline wuffs_base__token* reader_pointer() const;
inline wuffs_base__slice_token reader_slice() const;
@@ -421,15 +416,57 @@ wuffs_base__token_buffer__compact(wuffs_base__token_buffer* buf) {
return;
}
buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri);
size_t n = buf->meta.wi - buf->meta.ri;
if (n != 0) {
size_t new_wi = buf->meta.wi - buf->meta.ri;
if (new_wi != 0) {
memmove(buf->data.ptr, buf->data.ptr + buf->meta.ri,
n * sizeof(wuffs_base__token));
new_wi * sizeof(wuffs_base__token));
}
buf->meta.wi = n;
buf->meta.wi = new_wi;
buf->meta.ri = 0;
}
// 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.
//
// wuffs_base__token_buffer__compact_retaining(0) is equivalent to
// wuffs_base__token_buffer__compact().
//
// For example, if buf started like this:
//
// +--- ri = 3
// v
// abcdefgh?? len = 10, pos = 900
// ^
// +--- wi = 8
//
// Then, depending on history_retain_length, the resultant buf would be:
//
// HRL = 0 defgh????? ri = 0 wi = 5 pos = 903
// HRL = 1 cdefgh???? ri = 1 wi = 6 pos = 902
// HRL = 2 bcdefgh??? ri = 2 wi = 7 pos = 901
// HRL = 3 abcdefgh?? ri = 3 wi = 8 pos = 900
// HRL = 4+ abcdefgh?? ri = 3 wi = 8 pos = 900
static inline void //
wuffs_base__token_buffer__compact_retaining(wuffs_base__token_buffer* buf,
uint64_t history_retain_length) {
if (!buf || (buf->meta.ri == 0)) {
return;
}
size_t old_ri = buf->meta.ri;
size_t new_ri = (size_t)(wuffs_base__u64__min(old_ri, history_retain_length));
size_t memmove_start = old_ri - new_ri;
buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, memmove_start);
size_t new_wi = buf->meta.wi - memmove_start;
if ((new_wi != 0) && (memmove_start != 0)) {
memmove(buf->data.ptr, buf->data.ptr + memmove_start,
new_wi * sizeof(wuffs_base__token));
}
buf->meta.wi = new_wi;
buf->meta.ri = new_ri;
}
static inline uint64_t //
wuffs_base__token_buffer__reader_length(const wuffs_base__token_buffer* buf) {
return buf ? buf->meta.wi - buf->meta.ri : 0;
@@ -488,6 +525,11 @@ wuffs_base__token_buffer::compact() {
wuffs_base__token_buffer__compact(this);
}
inline void //
wuffs_base__token_buffer::compact_retaining(uint64_t history_retain_length) {
wuffs_base__token_buffer__compact_retaining(this, history_retain_length);
}
inline uint64_t //
wuffs_base__token_buffer::reader_length() const {
return wuffs_base__token_buffer__reader_length(this);
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ---------------- Unicode and UTF-8
+163 -50
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
@@ -80,9 +74,9 @@ func (g *gen) writeBuiltinCall(b *buffer, n *a.Expr, sideEffectsOnly bool, depth
b.writeb(')')
return nil
case t.IDSlice:
case t.IDRoslice, t.IDSlice:
return g.writeBuiltinSlice(b, recv, method.Ident(), n.Args(), sideEffectsOnly, depth)
case t.IDTable:
case t.IDRotable, t.IDTable:
return g.writeBuiltinTable(b, recv, method.Ident(), n.Args(), sideEffectsOnly, depth)
default:
return errNoSuchBuiltin
@@ -96,7 +90,7 @@ func (g *gen) writeBuiltinCall(b *buffer, n *a.Expr, sideEffectsOnly bool, depth
if qid[1].IsNumType() {
return g.writeBuiltinNumType(b, recv, method.Ident(), n.Args(), depth)
} else if qid[1].IsBuiltInCPUArch() {
return g.writeBuiltinCPUArch(b, recv, method.Ident(), n.Args(), sideEffectsOnly, depth)
return g.writeBuiltinCPUArch(b, recv, method.Ident(), n.MType(), n.Args(), sideEffectsOnly, depth)
} else {
switch qid[1] {
case t.IDIOReader:
@@ -135,7 +129,7 @@ func (g *gen) writeBuiltinCall(b *buffer, n *a.Expr, sideEffectsOnly bool, depth
case t.IDUtility:
switch method.Ident() {
case t.IDCPUArchIs32Bit:
b.writes("(sizeof(void*) == 4)")
b.writes("(sizeof(void*) == 4u)")
return nil
case t.IDEmptyIOReader, t.IDEmptyIOWriter:
if !g.currFunk.usesEmptyIOBuffer {
@@ -233,7 +227,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_base__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
@@ -359,11 +353,11 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
return nil
case t.IDHistoryPosition:
b.printf("(%s ? %s->meta.pos : 0)", recvName, recvName)
b.printf("(%s ? %s->meta.pos : 0u)", recvName, recvName)
return nil
case t.IDPosition:
b.printf("wuffs_base__u64__sat_add((%s ? %s->meta.pos : 0), ((uint64_t)(%s%s - %s%s)))",
b.printf("wuffs_base__u64__sat_add((%s ? %s->meta.pos : 0u), ((uint64_t)(%s%s - %s%s)))",
recvName, recvName, iopPrefix, recvName, io0Prefix, recvName)
return nil
@@ -450,7 +444,7 @@ func (g *gen) writeBuiltinTokenWriter(b *buffer, recv *a.Expr, method t.ID, args
return g.writeBuiltinIO(b, recv, method, args, depth)
}
func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, returnType *a.TypeExpr, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
switch id := recv.MType().QID()[1]; {
case id == t.IDARMCRC32Utility, id == t.IDARMCRC32U32:
return g.writeBuiltinCPUArchARMCRC32(b, recv, method, args, sideEffectsOnly, depth)
@@ -458,7 +452,7 @@ func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, args []*
return g.writeBuiltinCPUArchARMNeon(b, recv, method, args, sideEffectsOnly, depth)
case id == t.IDX86SSE42Utility, id == t.IDX86M128I,
id == t.IDX86AVX2Utility, id == t.IDX86M256I:
return g.writeBuiltinCPUArchX86(b, recv, method, args, sideEffectsOnly, depth)
return g.writeBuiltinCPUArchX86(b, recv, method, returnType, args, sideEffectsOnly, depth)
}
return fmt.Errorf("internal error: unsupported cpu_arch method %s.%s",
recv.MType().Str(g.tm), method.Str(g.tm))
@@ -606,11 +600,14 @@ func (g *gen) writeBuiltinCPUArchARMNeon(b *buffer, recv *a.Expr, method t.ID, a
return nil
}
func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, returnType *a.TypeExpr, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
methodStr := method.Str(g.tm)
if strings.HasPrefix(methodStr, "make_") {
fName, tName, ptr := "", "", false
switch methodStr {
case "make_u64_slice_u16lex4":
fName, tName, ptr = "wuffs_base__peek_u64le__no_bounds_check", "const uint8_t*)(const void*", true
case "make_m128i_multiple_u8":
fName, tName = "_mm_set_epi8", "int8_t"
case "make_m128i_multiple_u16":
@@ -631,7 +628,7 @@ func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, args
fName, tName = "_mm_cvtsi32_si128", "int32_t"
case "make_m128i_single_u64":
fName, tName = "_mm_cvtsi64x_si128", "int64_t"
case "make_m128i_slice128":
case "make_m128i_slice128", "make_m128i_slice_u16lex8":
fName, tName, ptr = "_mm_lddqu_si128", "const __m128i*)(const void*", true
case "make_m128i_zeroes":
fName, tName = "_mm_setzero_si128", ""
@@ -652,7 +649,7 @@ func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, args
fName, tName = "_mm256_set1_epi32", "int32_t"
case "make_m256i_repeat_u64":
fName, tName = "_mm256_set1_epi64x", "int64_t"
case "make_m256i_slice256":
case "make_m256i_slice256", "make_m256i_slice_u16lex16":
fName, tName, ptr = "_mm256_lddqu_si256", "const __m256i*)(const void*", true
case "make_m256i_zeroes":
fName, tName = "_mm256_setzero_si256", ""
@@ -690,19 +687,42 @@ func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, args
// avoid a "expression result unused" compiler error.
b.writes("(")
}
prefix, cast := "", ""
switch recv.MType().QID() {
case [2]t.ID{t.IDBase, t.IDX86M128I}:
switch methodStr {
case "store_slice64":
b.writes("_mm_storeu_si64((void*)(")
prefix = "_mm_storeu_si64((void*)("
case "store_slice128":
b.writes("_mm_storeu_si128((__m128i*)(void*)(")
prefix = "_mm_storeu_si128((__m128i*)(void*)("
}
case [2]t.ID{t.IDBase, t.IDX86M256I}:
switch methodStr {
case "store_slice64":
prefix = "_mm_storeu_si64((void*)("
cast = "_mm256_castsi256_si128("
case "store_slice128":
prefix = "_mm_storeu_si128((__m128i*)(void*)("
cast = "_mm256_castsi256_si128("
case "store_slice256":
prefix = "_mm256_storeu_si256((__m256i*)(void*)("
}
}
if prefix == "" {
return fmt.Errorf("internal error: unsupported cpu_arch method %q", methodStr)
}
b.writes(prefix)
if err := g.writeExprDotPtr(b, args[0].AsArg().Value(), false, depth); err != nil {
return err
}
b.writes("), ")
b.writes(cast)
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
if cast != "" {
b.writes(")")
}
b.writes(")")
if !sideEffectsOnly {
b.writes(", wuffs_base__make_empty_struct())")
@@ -718,19 +738,12 @@ func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, args
b.writes(")))")
return nil
} else if strings.HasPrefix(methodStr, "_mm_extract_epi") {
size := methodStr[len("_mm_extract_epi"):]
b.printf("((uint%s_t)(_mm_extract_epi%s(", size, size)
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.writes(", ")
b.writes("(int32_t)(")
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
return err
}
b.writes("))))")
return nil
if returnType.IsNumType() {
b.writes("((")
b.writes(cTypeNames[returnType.QID()[1]])
b.writes(")(")
}
b.writes(methodStr)
@@ -751,6 +764,10 @@ func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, args
b.writes(argAfter)
}
b.writes(")")
if returnType.IsNumType() {
b.writes("))")
}
return nil
}
@@ -759,7 +776,7 @@ func (g *gen) writeExprDotPtr(b *buffer, n *a.Expr, sideEffectsOnly bool, depth
if err := g.writeExpr(b, arrayOrSlice, sideEffectsOnly, depth); err != nil {
return err
}
if arrayOrSlice.MType().IsSliceType() {
if arrayOrSlice.MType().IsEitherSliceType() {
b.writes(".ptr")
}
if lo != nil {
@@ -774,7 +791,7 @@ func (g *gen) writeExprDotPtr(b *buffer, n *a.Expr, sideEffectsOnly bool, depth
if err := g.writeExpr(b, n, sideEffectsOnly, depth); err != nil {
return err
}
if n.MType().IsSliceType() {
if n.MType().IsEitherSliceType() {
b.writes(".ptr")
}
return nil
@@ -796,7 +813,7 @@ func (g *gen) writeBuiltinNumType(b *buffer, recv *a.Expr, method t.ID, args []*
mask := big.NewInt(0)
mask.Lsh(one, uint(cv.Uint64()))
mask.Sub(mask, one)
b.printf("0x%s", strings.ToUpper(mask.Text(16)))
b.printf("0x%su", strings.ToUpper(mask.Text(16)))
} else {
if sz, err := g.sizeof(recv.MType()); err != nil {
return err
@@ -822,13 +839,13 @@ 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("%d", 8*sz)
b.printf("%du", 8*sz)
}
b.writes(" - (")
b.writes(" - ")
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
return err
}
b.writes(")))")
b.writes("))")
return nil
case t.IDMax:
@@ -872,6 +889,27 @@ 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(")
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(")
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(")
if err := g.writeBuiltinSliceBulkMethodRecv(b, recv, depth); err != nil {
return err
}
return g.writeArgs(b, args, depth)
case t.IDCopyFromSlice:
if err := g.writeBuiltinSliceCopyFromSlice8(b, recv, method, args, depth); err != errOptimizationNotApplicable {
return err
@@ -894,7 +932,7 @@ func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a.
return nil
case t.IDUintptrLow12Bits:
b.writes("((uint32_t)(0xFFF & (uintptr_t)(")
b.writes("((uint32_t)(0xFFFu & (uintptr_t)(")
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
@@ -950,6 +988,79 @@ func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a.
return errNoSuchBuiltin
}
func (g *gen) writeBuiltinSliceBulkMethodRecv(b *buffer, recv *a.Expr, depth uint32) error {
if arrayOrSlice, lo, hi, ok := recv.IsSlice(); !ok || (hi == nil) {
// No-op.
} else if arrayOrSlice.MType().IsBulkNumType() {
b.writes("&")
if err := g.writeExpr(b, arrayOrSlice, false, depth); err != nil {
return err
}
if lo == nil {
b.writes("[0], ")
if err := g.writeExpr(b, hi, false, depth); err != nil {
return err
}
} else {
b.writes("[")
if err := g.writeExpr(b, lo, false, depth); err != nil {
return err
}
b.writes("], ")
if err := g.writeExprXMinusY(b, hi, lo, depth); err != nil {
return err
}
}
if bs := arrayOrSlice.MType().Inner().BulkSize(); (bs != nil) && (bs.Cmp(one) != 0) {
b.writes(" * (size_t)")
b.writes(bs.String())
b.writes("u")
}
b.writes(", ")
return nil
} else if recv.MType().IsContainerOfSpecificNumType(t.IDSlice, t.IDU8) {
if arrayOrSlice.MType().IsContainerOfSpecificNumType(t.IDSlice, t.IDU8) {
if err := g.writeExpr(b, arrayOrSlice, false, depth); err != nil {
return err
}
b.writes(".ptr")
if mhs := recv.MHS(); mhs != nil {
b.writes(" + ")
if err := g.writeExpr(b, mhs.AsExpr(), false, depth); err != nil {
return err
}
}
b.writes(", ")
} else {
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.writes(".ptr, ")
}
if mhs, rhs := recv.MHS(), recv.RHS(); (mhs != nil) && (rhs != nil) {
if err := g.writeExprXMinusY(b, rhs.AsExpr(), mhs.AsExpr(), depth); err != nil {
return err
}
} else if rhs := recv.RHS(); rhs != nil {
if err := g.writeExpr(b, rhs.AsExpr(), false, depth); err != nil {
return err
}
} else {
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.writes(".len")
}
b.writes(", ")
return nil
}
return fmt.Errorf("TODO: bulk_memset for general expressions")
}
// writeBuiltinSliceCopyFromSlice8 writes an optimized version of:
//
// foo[fIndex .. fIndex + 8].copy_from_slice!(s:bar[bIndex .. bIndex + 8])
@@ -966,7 +1077,7 @@ func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.
if err := g.writeExpr(b, foo, false, depth); err != nil {
return err
}
if foo.MType().IsSliceType() {
if foo.MType().IsEitherSliceType() {
b.writes(".ptr")
}
if fIndex != nil {
@@ -979,7 +1090,7 @@ func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.
if err := g.writeExpr(b, bar, false, depth); err != nil {
return err
}
if bar.MType().IsSliceType() {
if bar.MType().IsEitherSliceType() {
b.writes(".ptr")
}
if bIndex != nil {
@@ -989,7 +1100,7 @@ func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.
}
}
// TODO: don't assume that the slice is a slice of base.u8.
b.writes("), 8)")
b.writes("), 8u)")
return nil
}
@@ -1096,7 +1207,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
switch recvTyp.QID()[1] {
case t.IDIOReader:
switch method.Ident() {
case t.IDReadU8, t.IDReadU8AsU32, t.IDReadU8AsU64:
case t.IDReadU8, t.IDReadU8AsU16, t.IDReadU8AsU32, t.IDReadU8AsU64:
if err := g.writeCoroSuspPoint(b, false); err != nil {
return err
}
@@ -1255,7 +1366,7 @@ func (g *gen) writeReadUxxAsUyy(b *buffer, n *a.Expr, preName string, xx uint8,
b.printf("uint32_t num_bits_%d = ((uint32_t)(*scratch", temp)
switch endianness {
case 'b':
b.writes(" & 0xFF));\n*scratch >>= 8;\n*scratch <<= 8;\n")
b.writes(" & 0xFFu));\n*scratch >>= 8;\n*scratch <<= 8;\n")
b.printf("*scratch |= ((uint64_t)(*%s%s++)) << (56 - num_bits_%d);\n",
iopPrefix, preName, temp)
case 'l':
@@ -1274,7 +1385,7 @@ func (g *gen) writeReadUxxAsUyy(b *buffer, n *a.Expr, preName string, xx uint8,
b.printf("break;\n")
b.printf("}\n")
b.printf("num_bits_%d += 8;\n", temp)
b.printf("num_bits_%d += 8u;\n", temp)
switch endianness {
case 'b':
b.printf("*scratch |= ((uint64_t)(num_bits_%d));\n", temp)
@@ -1295,6 +1406,7 @@ var readMethods = [...]struct {
}{
t.IDReadU8 - readMethodsBase: {8, 8, 'b'},
t.IDReadU8AsU16 - readMethodsBase: {16, 8, 'b'},
t.IDReadU16BE - readMethodsBase: {16, 16, 'b'},
t.IDReadU16LE - readMethodsBase: {16, 16, 'l'},
@@ -1332,6 +1444,7 @@ var peekMethods = [...]struct {
}{
t.IDPeekU8 - peekMethodsBase: {8, 8, 'b'},
t.IDPeekU8AsU16 - peekMethodsBase: {16, 8, 'b'},
t.IDPeekU16BE - peekMethodsBase: {16, 16, 'b'},
t.IDPeekU16LE - peekMethodsBase: {16, 16, 'l'},
+31 -23
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
@@ -40,7 +34,9 @@ var (
mibi = big.NewInt(1 << 20)
maxInt64 = big.NewInt((1 << 63) - 1)
maxUint8 = big.NewInt((1 << 8) - 1)
maxUint16 = big.NewInt((1 << 16) - 1)
maxUint32 = big.NewInt((1 << 32) - 1)
typeExprARMCRC32U32 = a.NewTypeExpr(0, t.IDBase, t.IDARMCRC32U32, nil, nil, nil)
typeExprPixelSwizzler = a.NewTypeExpr(0, t.IDBase, t.IDPixelSwizzler, nil, nil, nil)
@@ -122,7 +118,7 @@ func Do(args []string) error {
return nil, fmt.Errorf("base package shouldn't have any .wuffs files")
}
buf := make(buffer, 0, 128*1024)
if err := expandBangBangInsert(&buf, embedBaseAllImplC.Trim(), map[string]func(*buffer) error{
if err := expandBangInsert(&buf, embedBaseAllImplC.Trim(), map[string]func(*buffer) error{
"// ¡ INSERT InterfaceDeclarations.\n": insertInterfaceDeclarations,
"// ¡ INSERT InterfaceDefinitions.\n": insertInterfaceDefinitions,
"// ¡ INSERT base/all-private.h.\n": insertBaseAllPrivateH,
@@ -131,7 +127,9 @@ func Do(args []string) error {
"// ¡ INSERT base/floatconv-submodule.c.\n": insertBaseFloatConvSubmoduleC,
"// ¡ INSERT base/intconv-submodule.c.\n": insertBaseIntConvSubmoduleC,
"// ¡ INSERT base/magic-submodule.c.\n": insertBaseMagicSubmoduleC,
"// ¡ INSERT base/pixconv-submodule.c.\n": insertBasePixConvSubmoduleC,
"// ¡ INSERT base/pixconv-submodule-regular.c.\n": insertBasePixConvSubmoduleRegularC,
"// ¡ INSERT base/pixconv-submodule-x86-avx2.c.\n": insertBasePixConvSubmoduleX86Avx2C,
"// ¡ INSERT base/pixconv-submodule-ycck.c.\n": insertBasePixConvSubmoduleYcckC,
"// ¡ INSERT base/utf8-submodule.c.\n": insertBaseUTF8SubmoduleC,
"// ¡ INSERT vtable names.\n": func(b *buffer) error {
for _, n := range builtin.Interfaces {
@@ -235,7 +233,7 @@ 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 expandBangBangInsert(b *buffer, s string, m map[string]func(*buffer) error) error {
func expandBangInsert(b *buffer, s string, m map[string]func(*buffer) error) error {
for {
remaining := ""
if i := strings.IndexByte(s, '\n'); i >= 0 {
@@ -287,7 +285,7 @@ func insertBaseAllPrivateH(buf *buffer) error {
}
func insertBaseAllPublicH(buf *buffer) error {
if err := expandBangBangInsert(buf, embedBaseFundamentalPublicH.Trim(), map[string]func(*buffer) error{
if err := expandBangInsert(buf, embedBaseFundamentalPublicH.Trim(), map[string]func(*buffer) error{
"// ¡ INSERT FourCCs.\n": func(b *buffer) error {
for i, z := range builtin.FourCCs {
if i != 0 {
@@ -379,8 +377,18 @@ func insertBaseMagicSubmoduleC(buf *buffer) error {
return nil
}
func insertBasePixConvSubmoduleC(buf *buffer) error {
buf.writes(embedBasePixConvSubmoduleC.Trim())
func insertBasePixConvSubmoduleRegularC(buf *buffer) error {
buf.writes(embedBasePixConvSubmoduleRegularC.Trim())
return nil
}
func insertBasePixConvSubmoduleX86Avx2C(buf *buffer) error {
buf.writes(embedBasePixConvSubmoduleX86Avx2C.Trim())
return nil
}
func insertBasePixConvSubmoduleYcckC(buf *buffer) error {
buf.writes(embedBasePixConvSubmoduleYcckC.Trim())
return nil
}
@@ -443,7 +451,7 @@ func insertInterfaceDeclarations(buf *buffer) error {
buf.writes("#ifdef __cplusplus\n")
buf.writes("#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)\n")
buf.printf(" using unique_ptr = std::unique_ptr<wuffs_base__%s, decltype(&free)>;\n", n)
buf.printf(" using unique_ptr = std::unique_ptr<wuffs_base__%s, wuffs_unique_ptr_deleter>;\n", n)
buf.writes("#endif\n\n")
for _, f := range builtInInterfaceMethods[qid] {
@@ -762,7 +770,7 @@ func (g *gen) genHeader(b *buffer) error {
b.writes("// memory allocation fails. If they return non-NULL, there is no need to call\n")
b.writes("// wuffs_foo__bar__initialize, but the caller is responsible for eventually\n")
b.writes("// calling free on the returned pointer. That pointer is effectively a C++\n")
b.writes("// std::unique_ptr<T, decltype(&free)>.\n\n")
b.writes("// std::unique_ptr<T, wuffs_unique_ptr_deleter>.\n\n")
for _, n := range g.structList {
if !n.Public() {
@@ -1226,18 +1234,18 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error {
b.writes("#ifdef __cplusplus\n")
b.writes("#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)\n")
b.printf("using unique_ptr = std::unique_ptr<%s%s, decltype(&free)>;\n\n", g.pkgPrefix, structName)
b.printf("using unique_ptr = std::unique_ptr<%s%s, wuffs_unique_ptr_deleter>;\n\n", g.pkgPrefix, structName)
b.writes("// On failure, the alloc_etc functions return nullptr. They don't throw.\n\n")
b.writes("static inline unique_ptr\n")
b.writes("alloc() {\n")
b.printf("return unique_ptr(%s%s__alloc(), &free);\n", g.pkgPrefix, structName)
b.printf("return unique_ptr(%s%s__alloc());\n", g.pkgPrefix, structName)
b.writes("}\n")
for _, impl := range n.Implements() {
iQID := impl.AsTypeExpr().QID()
iName := fmt.Sprintf("wuffs_%s__%s", iQID[0].Str(g.tm), iQID[1].Str(g.tm))
b.printf("\nstatic inline %s::unique_ptr\n", iName)
b.printf("alloc_as__%s() {\n", iName)
b.printf("return %s::unique_ptr(\n%s%s__alloc_as__%s(), &free);\n",
b.printf("return %s::unique_ptr(\n%s%s__alloc_as__%s());\n",
iName, g.pkgPrefix, structName, iName)
b.printf("}\n")
}
+13 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
@@ -97,8 +91,14 @@ var embedBaseIntConvSubmoduleC EmbeddedString
//go:embed base/magic-submodule.c
var embedBaseMagicSubmoduleC EmbeddedString
//go:embed base/pixconv-submodule.c
var embedBasePixConvSubmoduleC EmbeddedString
//go:embed base/pixconv-submodule-regular.c
var embedBasePixConvSubmoduleRegularC EmbeddedString
//go:embed base/pixconv-submodule-x86-avx2.c
var embedBasePixConvSubmoduleX86Avx2C EmbeddedString
//go:embed base/pixconv-submodule-ycck.c
var embedBasePixConvSubmoduleYcckC EmbeddedString
//go:embed base/utf8-submodule.c
var embedBaseUTF8SubmoduleC EmbeddedString
+110 -20
View File
@@ -1,21 +1,16 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
import (
"fmt"
"math/big"
"strings"
a "github.com/google/wuffs/lang/ast"
@@ -31,7 +26,7 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, sideEffectsOnly bool, depth uint32
if cv := n.ConstValue(); cv != nil {
if typ := n.MType(); typ.IsNumTypeOrIdeal() {
b.writes(cv.String())
if cv.Cmp(maxInt64) > 0 {
if cv.Sign() >= 0 {
b.writeb('u')
}
} else if typ.IsNullptr() {
@@ -139,7 +134,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
if err := g.writeExpr(b, n.LHS().AsExpr(), false, depth); err != nil {
return err
}
if lTyp := n.LHS().AsExpr().MType(); lTyp.IsSliceType() {
if lTyp := n.LHS().AsExpr().MType(); lTyp.IsEitherSliceType() {
// TODO: don't assume that the slice is a slice of base.u8.
b.writes(".ptr")
}
@@ -164,15 +159,22 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
comma = ",\n"
}
if lhs.MType().IsArrayType() {
if lhs.MType().IsEitherArrayType() {
if mhs == nil {
b.writes("wuffs_base__make_slice_u8(")
} else {
b.writes("wuffs_base__make_slice_u8_ij(")
}
lhsIsReadOnly := lhs.MType().IsReadOnly()
if lhsIsReadOnly {
b.writes("wuffs_base__strip_const_from_u8_ptr(")
}
if err := g.writeExpr(b, lhs, false, depth); err != nil {
return err
}
if lhsIsReadOnly {
b.writes(")")
}
if mhs == nil {
// No-op.
} else {
@@ -381,7 +383,74 @@ func (g *gen) writeExprRepr(b *buffer, n *a.Expr, depth uint32) error {
return nil
}
func (g *gen) writeExprXMinusY(b *buffer, x *a.Expr, y *a.Expr, depth uint32) error {
if x.Operator() == t.IDXBinaryPlus {
if x.LHS().AsExpr().Eq(y) {
return g.writeExpr(b, x.RHS().AsExpr(), false, depth)
} else if x.RHS().AsExpr().Eq(y) {
return g.writeExpr(b, x.LHS().AsExpr(), false, depth)
}
}
b.writes("(")
if err := g.writeExpr(b, x, false, depth); err != nil {
return err
}
b.writes(" - ")
if err := g.writeExpr(b, y, false, depth); err != nil {
return err
}
b.writes(")")
return nil
}
func (g *gen) writeExprAs(b *buffer, lhs *a.Expr, rhs *a.TypeExpr, depth uint32) error {
if rhs.IsPointerType() {
if !lhs.MType().IsEitherSliceType() {
// TODO: fix this.
return fmt.Errorf("cannot convert Wuffs conversion from %q to %q to C", lhs.Str(g.tm), rhs.Str(g.tm))
}
if (lhs.Operator() == t.IDDotDot) && (lhs.MHS() == nil) && (lhs.RHS() == nil) {
b.writes("&")
if err := g.writeExpr(b, lhs.LHS().AsExpr(), false, depth); err != nil {
return err
}
b.writes("[0u]")
return nil
}
if err := g.writeExpr(b, lhs, false, depth); err != nil {
return err
}
b.writes(".ptr")
return nil
}
// Drop the "& redundantMask" in "(foo & redundantMask) as base.uxx". It's
// redundant in C/C++ (but not in Wuffs).
if rhs.IsNumType() {
redundantMask := (*big.Int)(nil)
switch rhs.QID()[1] {
case t.IDU8:
redundantMask = maxUint8
case t.IDU16:
redundantMask = maxUint16
case t.IDU32:
redundantMask = maxUint32
// We don't have a case for t.IDU64. the "& redundantMask" in Wuffs
// is typically for a wide-to-narrow conversion and base.u64 is
// already the widest type.
}
if (redundantMask == nil) || (lhs.Operator() != t.IDXBinaryAmp) {
// No-op.
} else if lcv := lhs.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Cmp(redundantMask) == 0) {
lhs = lhs.RHS().AsExpr()
} else if rcv := lhs.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Cmp(redundantMask) == 0) {
lhs = lhs.LHS().AsExpr()
}
}
b.writes("((")
// TODO: watch for passing an array type to writeCTypeName? In C, an array
// type can decay into a pointer.
@@ -449,7 +518,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
// TODO: fix this, allow slices of all types, not just of base.u8's. Also
// allow arrays of slices, slices of pointers, etc.
if n.IsSliceType() {
if n.IsEitherSliceType() {
o := n.Inner()
if o.Decorator() == 0 && o.QID() == (t.QID{t.IDBase, t.IDU8}) && !o.IsRefined() {
b.writes("wuffs_base__slice_u8")
@@ -462,7 +531,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
}
return fmt.Errorf("cannot convert Wuffs type %q to C", n.Str(g.tm))
}
if n.IsTableType() {
if n.IsEitherTableType() {
o := n.Inner()
if o.Decorator() == 0 && o.QID() == (t.QID{t.IDBase, t.IDU8}) && !o.IsRefined() {
b.writes("wuffs_base__table_u8")
@@ -480,12 +549,18 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
const maxNumPointers = 16
x := n
for ; x != nil && x.IsArrayType(); x = x.Inner() {
for ; x != nil && x.IsEitherArrayType(); x = x.Inner() {
}
numPointers, innermost := 0, x
numPointers, innermost, isPointerToArray := 0, x, false
if x.IsPointerType() && x.Inner().IsEitherArrayType() && x.Inner().IsBulkNumType() {
isPointerToArray = true
innermost = x.Inner()
for ; innermost != nil && innermost.Inner() != nil; innermost = innermost.Inner() {
if p := innermost.Decorator(); p == t.IDNptr || p == t.IDPtr {
}
} else {
for ; innermost != nil && innermost.Inner() != nil; innermost = innermost.Inner() {
if innermost.IsPointerType() {
if numPointers == maxNumPointers {
return fmt.Errorf("cannot convert Wuffs type %q to C: too many ptr's", n.Str(g.tm))
}
@@ -495,6 +570,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
// TODO: fix this.
return fmt.Errorf("cannot convert Wuffs type %q to C", n.Str(g.tm))
}
}
fallback := true
if qid := innermost.QID(); qid[0] == t.IDBase {
@@ -510,9 +586,17 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
b.printf("%s%s", g.packagePrefix(qid), qid[1].Str(g.tm))
}
if isPointerToArray {
if x.Inner().Inner().IsNumType() {
b.writes("*")
} else {
b.writes("(*")
}
} else {
for i := 0; i < numPointers; i++ {
b.writeb('*')
}
}
if varNamePrefix != "" {
b.writeb(' ')
@@ -521,7 +605,13 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
}
x = n
for ; x != nil && x.IsArrayType(); x = x.Inner() {
if isPointerToArray {
x = x.Inner().Inner()
if !x.IsNumType() {
b.writes(")")
}
}
for ; x != nil && x.IsEitherArrayType(); x = x.Inner() {
b.writeb('[')
b.writes(x.ArrayLength().ConstValue().String())
b.writeb(']')
+9 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
@@ -39,6 +33,7 @@ type funk struct {
varResumables map[t.ID]bool
derivedVars map[t.ID]struct{}
jumpTargets map[a.Loop]string
activeLoops a.LoopStack
coroSuspPoint uint32
ioManips uint32
tempW uint32
@@ -90,6 +85,7 @@ const (
func (g *gen) writeFuncSignature(b *buffer, n *a.Func, wfs uint32) error {
switch wfs {
case wfsCDecl:
b.writes("WUFFS_BASE__GENERATED_C_CODE\n")
if n.Public() {
b.writes("WUFFS_BASE__MAYBE_STATIC ")
} else {
@@ -97,6 +93,7 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func, wfs uint32) error {
}
case wfsCDeclChoosy:
b.writes("WUFFS_BASE__GENERATED_C_CODE\n")
b.writes("static ")
case wfsCppDecl:
@@ -342,7 +339,7 @@ func writeOutParamZeroValue(b *buffer, tm *t.Map, typ *a.TypeExpr) error {
} else if typ.IsNumType() {
b.writes("0")
return nil
} else if typ.IsSliceType() {
} 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)")
return nil
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
+49 -21
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
@@ -136,7 +130,7 @@ func (g *gen) writeStatementAssign1(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr
return err
}
if lTyp := lhs.MType(); lTyp.IsArrayType() {
if lTyp := lhs.MType(); lTyp.IsEitherArrayType() {
b.writes("memcpy(")
opName, closer = ",", fmt.Sprintf(", sizeof(%s))", lhsBuf)
@@ -281,7 +275,7 @@ func cpuArchCNames(asserts []*a.Node) (caMacro string, caName string, caAttribut
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"pclmul,popcnt,sse4.2\")"
case t.IDX86AVX2:
caMacro, caName, caAttribute =
"X86_FAMILY", "x86_avx2",
"X86_64", "x86_avx2",
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"pclmul,popcnt,sse4.2,avx2\")"
case t.IDX86BMI2:
caMacro, caName, caAttribute =
@@ -430,12 +424,19 @@ func (g *gen) writeStatementIf(b *buffer, n *a.If, depth uint32) error {
}
for {
prefix, suffix := "", ""
switch n.Likelihood() {
case t.IDLikely:
prefix, suffix = "WUFFS_BASE__LIKELY(", ")"
case t.IDUnlikely:
prefix, suffix = "WUFFS_BASE__UNLIKELY(", ")"
}
condition := buffer(nil)
if err := g.writeExpr(&condition, n.Condition(), false, 0); err != nil {
return err
}
// Calling trimParens avoids clang's -Wparentheses-equality warning.
b.printf("if (%s) {\n", trimParens(condition))
b.printf("if (%s%s%s) {\n", prefix, trimParens(condition), suffix)
for _, o := range n.BodyIfTrue() {
if err := g.writeStatement(b, o, depth); err != nil {
return err
@@ -466,6 +467,7 @@ func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error
return nil
}
name0 := assigns[0].AsAssign().LHS().Ident().Str(g.tm)
g.currFunk.activeLoops.Push(n)
b.writes("{\n")
// TODO: don't assume that the slice is a slice of base.u8. In
@@ -519,19 +521,22 @@ func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error
}
b.writes("}\n")
g.currFunk.activeLoops.Pop()
return nil
}
func (g *gen) writeStatementJump(b *buffer, n *a.Jump, depth uint32) error {
jt, err := g.currFunk.jumpTarget(g.tm, n.JumpTarget())
if err != nil {
return err
}
keyword := "continue"
if n.Keyword() == t.IDBreak {
keyword = "break"
}
if n.JumpTarget() == g.currFunk.activeLoops.Top() {
b.printf("%s;\n", keyword)
} else if jt, err := g.currFunk.jumpTarget(g.tm, n.JumpTarget()); err != nil {
return err
} else {
b.printf("goto label__%s__%s;\n", jt, keyword)
}
return nil
}
@@ -617,26 +622,49 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
}
func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error {
if n.HasContinue() {
body, isTrivialLoop := n.Body(), false
if n.IsWhileTrue() && !n.HasContinue() && (len(body) > 0) {
if finalStatement := body[len(body)-1]; finalStatement.Kind() != a.KJump {
// No-op.
} else if j := finalStatement.AsJump(); (j.Keyword() == t.IDBreak) && (j.JumpTarget() == n) {
body, isTrivialLoop = body[:len(body)-1], true
}
}
if n.HasDeepContinue() {
jt, err := g.currFunk.jumpTarget(g.tm, n)
if err != nil {
return err
}
b.printf("label__%s__continue:;\n", jt)
}
g.currFunk.activeLoops.Push(n)
if isTrivialLoop {
b.writes("do {\n")
} else {
condition := buffer(nil)
if err := g.writeExpr(&condition, n.Condition(), false, 0); err != nil {
return err
}
// Calling trimParens avoids clang's -Wparentheses-equality warning.
b.printf("while (%s) {\n", trimParens(condition))
for _, o := range n.Body() {
}
for _, o := range body {
if err := g.writeStatement(b, o, depth); err != nil {
return err
}
}
if isTrivialLoop {
b.writes("} while (0);\n")
} else {
b.writes("}\n")
if n.HasBreak() {
}
g.currFunk.activeLoops.Pop()
if n.HasDeepBreak() {
jt, err := g.currFunk.jumpTarget(g.tm, n)
if err != nil {
return err
+16 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgen
@@ -342,6 +336,10 @@ func (g *gen) writeVars(b *buffer, f *funk, inStructDecl bool) error {
return fmt.Errorf("TODO: support token_{reader,writer} typed variables")
}
if typ.IsPointerType() && typ.IsRecursivelyReadOnly() {
b.writes("const ")
}
if err := g.writeCTypeName(b, typ, vPrefix, name); err != nil {
return err
}
@@ -358,8 +356,15 @@ func (g *gen) writeVars(b *buffer, f *funk, inStructDecl bool) error {
} else if typ.Eq(typeExprARMCRC32U32) {
b.writes(" = 0;\n")
} else {
switch typ.Decorator() {
case t.IDNptr:
b.writes(" = NULL;\n")
case t.IDPtr:
return fmt.Errorf("cannot zero-initialize a non-nullable ptr")
default:
b.writes(" = {0};\n")
}
}
if typ.IsIOType() {
qualifier := ""
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// Package testcut provides support for testing flatecut and zlibcut.
package testcut
+130 -34
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package ast
@@ -100,15 +94,31 @@ const (
FlagsPublic = Flags(0x00000100)
FlagsHasBreak = Flags(0x00000200)
FlagsHasContinue = Flags(0x00000400)
FlagsGlobalIdent = Flags(0x00000800)
FlagsClassy = Flags(0x00001000)
FlagsSubExprHasEffect = Flags(0x00002000)
FlagsRetsError = Flags(0x00004000)
FlagsPrivateData = Flags(0x00008000)
FlagsChoosy = Flags(0x00010000)
FlagsHasChooseCPUArch = Flags(0x00020000)
FlagsHasDeepBreak = Flags(0x00000800)
FlagsHasDeepContinue = Flags(0x00001000)
FlagsGlobalIdent = Flags(0x00002000)
FlagsClassy = Flags(0x00004000)
FlagsSubExprHasEffect = Flags(0x00008000)
FlagsRetsError = Flags(0x00010000)
FlagsPrivateData = Flags(0x00020000)
FlagsChoosy = Flags(0x00040000)
FlagsHasChooseCPUArch = Flags(0x00080000)
)
func breakFlags(deep bool) Flags {
if deep {
return FlagsHasBreak | FlagsHasDeepBreak
}
return FlagsHasBreak
}
func continueFlags(deep bool) Flags {
if deep {
return FlagsHasContinue | FlagsHasDeepContinue
}
return FlagsHasContinue
}
func (f Flags) AsEffect() Effect { return Effect(f) }
type Effect uint8
@@ -170,7 +180,7 @@ type Node struct {
// File . . . File
// Func funcName receiverPkg receiverName Func
// IOManip keyword . . IOManip
// If . . . If
// If . likelihood . If
// Iterate advance label length Iterate
// Jump keyword label . Jump
// Ret keyword . . Ret
@@ -253,12 +263,14 @@ type Loop interface {
AsNode() *Node
HasBreak() bool
HasContinue() bool
HasDeepBreak() bool
HasDeepContinue() bool
Keyword() t.ID
Label() t.ID
Asserts() []*Node
Body() []*Node
SetHasBreak()
SetHasContinue()
SetHasBreak(deep bool)
SetHasContinue(deep bool)
}
type LoopStack []Loop
@@ -282,6 +294,10 @@ func (s *LoopStack) Pop() Loop {
return l
}
func (s *LoopStack) Top() Loop {
return (*s)[len(*s)-1]
}
type Raw Node
func (n *Raw) AsNode() *Node { return (*Node)(n) }
@@ -632,6 +648,8 @@ type Iterate Node
func (n *Iterate) AsNode() *Node { return (*Node)(n) }
func (n *Iterate) HasBreak() bool { return n.flags&FlagsHasBreak != 0 }
func (n *Iterate) HasContinue() bool { return n.flags&FlagsHasContinue != 0 }
func (n *Iterate) HasDeepBreak() bool { return n.flags&FlagsHasDeepBreak != 0 }
func (n *Iterate) HasDeepContinue() bool { return n.flags&FlagsHasDeepContinue != 0 }
func (n *Iterate) Keyword() t.ID { return t.IDIterate }
func (n *Iterate) Advance() t.ID { return n.id0 }
func (n *Iterate) Label() t.ID { return n.id1 }
@@ -645,8 +663,8 @@ func (n *Iterate) Body() []*Node { return n.list2 }
func (n *Iterate) SetBody(body []*Node) { n.list2 = body }
func (n *Iterate) SetElseIterate(o *Iterate) { n.rhs = o.AsNode() }
func (n *Iterate) SetHasBreak() { n.flags |= FlagsHasBreak }
func (n *Iterate) SetHasContinue() { n.flags |= FlagsHasContinue }
func (n *Iterate) SetHasBreak(deep bool) { n.flags |= breakFlags(deep) }
func (n *Iterate) SetHasContinue(deep bool) { n.flags |= continueFlags(deep) }
func NewIterate(label t.ID, assigns []*Node, length t.ID, advance t.ID, unroll t.ID, asserts []*Node) *Iterate {
return &Iterate{
@@ -674,6 +692,8 @@ type While Node
func (n *While) AsNode() *Node { return (*Node)(n) }
func (n *While) HasBreak() bool { return n.flags&FlagsHasBreak != 0 }
func (n *While) HasContinue() bool { return n.flags&FlagsHasContinue != 0 }
func (n *While) HasDeepBreak() bool { return n.flags&FlagsHasDeepBreak != 0 }
func (n *While) HasDeepContinue() bool { return n.flags&FlagsHasDeepContinue != 0 }
func (n *While) Keyword() t.ID { return t.IDWhile }
func (n *While) Label() t.ID { return n.id1 }
func (n *While) Condition() *Expr { return n.mhs.AsExpr() }
@@ -681,8 +701,8 @@ func (n *While) Asserts() []*Node { return n.list1 }
func (n *While) Body() []*Node { return n.list2 }
func (n *While) SetBody(body []*Node) { n.list2 = body }
func (n *While) SetHasBreak() { n.flags |= FlagsHasBreak }
func (n *While) SetHasContinue() { n.flags |= FlagsHasContinue }
func (n *While) SetHasBreak(deep bool) { n.flags |= breakFlags(deep) }
func (n *While) SetHasContinue(deep bool) { n.flags |= continueFlags(deep) }
func (n *While) IsWhileTrue() bool {
condition := n.mhs.AsExpr()
@@ -706,14 +726,16 @@ func NewWhile(label t.ID, condition *Expr, asserts []*Node) *While {
type If Node
func (n *If) AsNode() *Node { return (*Node)(n) }
func (n *If) Likelihood() t.ID { return n.id1 }
func (n *If) Condition() *Expr { return n.mhs.AsExpr() }
func (n *If) ElseIf() *If { return n.rhs.AsIf() }
func (n *If) BodyIfTrue() []*Node { return n.list2 }
func (n *If) BodyIfFalse() []*Node { return n.list1 }
func NewIf(condition *Expr, bodyIfTrue []*Node, bodyIfFalse []*Node, elseIf *If) *If {
func NewIf(likelihood t.ID, condition *Expr, bodyIfTrue []*Node, bodyIfFalse []*Node, elseIf *If) *If {
return &If{
kind: KIf,
id1: likelihood,
mhs: condition.AsNode(),
rhs: elseIf.AsNode(),
list1: bodyIfFalse,
@@ -784,7 +806,8 @@ const MaxTypeExprDepth = 63
// TypeExpr is a type expression, such as "base.u32", "base.u32[..= 8]", "foo",
// "pkg.bar", "ptr T", "array[8] T", "slice T" or "table T":
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDRoarray|IDRoslice|IDRotable|
// .... IDSlice|IDTable>
// - ID1: <0|pkg>
// - ID2: <0|type name>
// - LHS: <nil|Expr>
@@ -825,6 +848,22 @@ func (n *TypeExpr) Min() *Expr { return n.lhs.AsExpr() }
func (n *TypeExpr) Max() *Expr { return n.mhs.AsExpr() }
func (n *TypeExpr) Inner() *TypeExpr { return n.rhs.AsTypeExpr() }
func (n *TypeExpr) CloneReadOnly() *TypeExpr {
ret := *n
switch ret.id0 {
case t.IDArray:
ret.id0 = t.IDRoarray
case t.IDSlice:
ret.id0 = t.IDRoslice
case t.IDTable:
ret.id0 = t.IDRotable
}
if ret.rhs != nil {
ret.rhs = ret.rhs.AsTypeExpr().CloneReadOnly().AsNode()
}
return &ret
}
func (n *TypeExpr) Innermost() *TypeExpr {
for ; n != nil && n.Inner() != nil; n = n.Inner() {
}
@@ -837,6 +876,33 @@ func (n *TypeExpr) Pointee() *TypeExpr {
return n
}
func (n *TypeExpr) BulkSize() *big.Int {
if !n.IsBulkNumType() {
return nil
}
ret := big.NewInt(1)
for ; n.id0 == t.IDArray; n = n.rhs.AsTypeExpr() {
ret = ret.Mul(ret, n.ArrayLength().ConstValue())
}
switch n.id2 {
case t.IDU8:
return ret
case t.IDU16:
return ret.Lsh(ret, 1)
case t.IDU32:
return ret.Lsh(ret, 2)
case t.IDU64:
return ret.Lsh(ret, 3)
}
return nil
}
func (n *TypeExpr) IsBulkNumType() bool {
for ; (n.id0 == t.IDArray) || (n.id0 == t.IDRoarray); n = n.rhs.AsTypeExpr() {
}
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumType()
}
func (n *TypeExpr) IsBool() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDBool
}
@@ -845,6 +911,10 @@ func (n *TypeExpr) IsCPUArchType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsBuiltInCPUArch()
}
func (n *TypeExpr) IsEmptyStruct() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDEmptyStruct
}
func (n *TypeExpr) IsEtcUtilityType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsEtcUtility()
}
@@ -881,6 +951,14 @@ func (n *TypeExpr) IsNumTypeOrIdeal() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumTypeOrIdeal()
}
func (n *TypeExpr) IsRangeType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsRangeType()
}
func (n *TypeExpr) IsRectType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsRectType()
}
func (n *TypeExpr) IsRefined() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumType() && (n.lhs != nil || n.mhs != nil)
}
@@ -889,8 +967,16 @@ func (n *TypeExpr) IsStatus() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDStatus
}
func (n *TypeExpr) IsArrayType() bool {
return n.id0 == t.IDArray
func (n *TypeExpr) IsEitherArrayType() bool {
return (n.id0 == t.IDArray) || (n.id0 == t.IDRoarray)
}
func (n *TypeExpr) IsEitherSliceType() bool {
return (n.id0 == t.IDSlice) || (n.id0 == t.IDRoslice)
}
func (n *TypeExpr) IsEitherTableType() bool {
return (n.id0 == t.IDTable) || (n.id0 == t.IDRotable)
}
func (n *TypeExpr) IsFuncType() bool {
@@ -901,12 +987,22 @@ func (n *TypeExpr) IsPointerType() bool {
return n.id0 == t.IDNptr || n.id0 == t.IDPtr
}
func (n *TypeExpr) IsSliceType() bool {
return n.id0 == t.IDSlice
func (n *TypeExpr) IsReadOnly() bool {
return (n.id0 == t.IDRoarray) || (n.id0 == t.IDRoslice) || (n.id0 == t.IDRotable)
}
func (n *TypeExpr) IsTableType() bool {
return n.id0 == t.IDTable
func (n *TypeExpr) IsRecursivelyReadOnly() bool {
for ; n != nil; n = n.Inner() {
switch n.id0 {
case t.IDRoarray, t.IDRoslice, t.IDRotable:
return true
}
}
return false
}
func (n *TypeExpr) IsContainerOfSpecificNumType(container t.ID, numType t.ID) bool {
return (n.id0 == container) && n.Inner().IsNumType() && (n.Inner().id2 == numType)
}
func (n *TypeExpr) IsUnsignedInteger() bool {
@@ -924,7 +1020,7 @@ func (n *TypeExpr) HasPointers() bool {
return true
}
}
case t.IDNptr, t.IDPtr, t.IDSlice, t.IDTable:
case t.IDNptr, t.IDPtr, t.IDRoslice, t.IDRotable, t.IDSlice, t.IDTable:
return true
}
}
+31 -16
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package ast
@@ -84,16 +78,24 @@ func (n *Expr) Mentions(o *Expr) bool {
// Eq returns whether n and o are equal.
func (n *TypeExpr) Eq(o *TypeExpr) bool {
return n.eq(o, false)
return n.eq(o, false, false)
}
// EqIgnoringRefinements returns whether n and o are equal, ignoring the
// "[i:j]" in "base.u32[i:j]".
func (n *TypeExpr) EqIgnoringRefinements(o *TypeExpr) bool {
return n.eq(o, true)
return n.eq(o, true, false)
}
func (n *TypeExpr) eq(o *TypeExpr, ignoreRefinements bool) bool {
// EqIgnoringRefinementsLHSReadOnly returns whether n and o are equal, ignoring
// the "[i:j]" in "base.u32[i:j]" and allowing n (the Left Hand Side of an
// assignment) to be read-only when o (the Right Hand Side) is read-write, or n
// to be "nptr T" when o is "ptr T".
func (n *TypeExpr) EqIgnoringRefinementsLHSReadOnly(o *TypeExpr) bool {
return n.eq(o, true, true)
}
func (n *TypeExpr) eq(o *TypeExpr, ignoreRefinements bool, lhsReadOnly bool) bool {
for {
if n == o {
return true
@@ -101,10 +103,23 @@ func (n *TypeExpr) eq(o *TypeExpr, ignoreRefinements bool) bool {
if n == nil || o == nil {
return false
}
if n.id0 != o.id0 || n.id1 != o.id1 || n.id2 != o.id2 {
if n.id0 != o.id0 {
if !lhsReadOnly {
return false
}
if n.IsArrayType() || !ignoreRefinements {
switch {
default:
return false
case (n.id0 == t.IDRoarray) && (o.id0 == t.IDArray):
case (n.id0 == t.IDRoslice) && (o.id0 == t.IDSlice):
case (n.id0 == t.IDRotable) && (o.id0 == t.IDTable):
case (n.id0 == t.IDNptr) && (o.id0 == t.IDPtr):
}
}
if n.id1 != o.id1 || n.id2 != o.id2 {
return false
}
if !ignoreRefinements || !n.IsNumType() {
if !n.lhs.AsExpr().Eq(o.lhs.AsExpr()) || !n.mhs.AsExpr().Eq(o.mhs.AsExpr()) {
return false
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package ast
+18 -15
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package ast
@@ -208,7 +202,7 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
return append(buf, "!invalid_type!"...)
}
switch n.Decorator() {
switch dec := n.Decorator(); dec {
case 0:
buf = append(buf, n.QID().Str(tm)...)
case t.IDNptr:
@@ -217,15 +211,24 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
case t.IDPtr:
buf = append(buf, "ptr "...)
return n.Inner().appendStr(buf, tm, depth)
case t.IDArray:
case t.IDArray, t.IDRoarray:
if dec == t.IDRoarray {
buf = append(buf, "ro"...)
}
buf = append(buf, "array["...)
buf = n.ArrayLength().appendStr(buf, tm, false, 0)
buf = append(buf, "] "...)
return n.Inner().appendStr(buf, tm, depth)
case t.IDSlice:
case t.IDRoslice, t.IDSlice:
if dec == t.IDRoslice {
buf = append(buf, "ro"...)
}
buf = append(buf, "slice "...)
return n.Inner().appendStr(buf, tm, depth)
case t.IDTable:
case t.IDRotable, t.IDTable:
if dec == t.IDRotable {
buf = append(buf, "ro"...)
}
buf = append(buf, "table "...)
return n.Inner().appendStr(buf, tm, depth)
case t.IDFunc:
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package ast_test
+148 -39
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:generate go run gen.go
@@ -55,16 +49,17 @@ var FourCCs = [...][2]string{
{"KVPK", "Key-Value Pair (Key)"},
{"KVPV", "Key-Value Pair (Value)"},
{"LZ4 ", "Lempel–Ziv 4"},
{"LZMA", "Lempel–Ziv Markov-chain Algorithm"},
{"MD ", "Markdown"},
{"MTIM", "Modification Time"},
{"MP3 ", "MPEG-1 Audio Layer III"},
{"NIE ", "Naive Image"},
{"NPBM", "Netpbm (Portable Anymap)"},
{"OFS2", "Offset (2-Dimensional)"},
{"OTF ", "Open Type Format"},
{"PDF ", "Portable Document Format"},
{"PHYD", "Physical Dimensions"},
{"PNG ", "Portable Network Graphics"},
{"PNM ", "Portable Anymap"},
{"PS ", "PostScript"},
{"QOI ", "Quite OK Image"},
{"RAC ", "Random Access Compression"},
@@ -270,6 +265,7 @@ var Statuses = [...]string{
`"#no more information"`,
`"#not enough data"`,
`"#out of bounds"`,
`"#unsupported image dimension"`,
`"#unsupported method"`,
`"#unsupported option"`,
`"#unsupported pixel swizzler option"`,
@@ -346,23 +342,23 @@ var Funcs = [][]string{
var funcsOther = [...]string{
"u8.high_bits(n: u32[..= 7]) u8",
"u8.low_bits(n: u32[..= 7]) u8",
"u8.max(a: u8) u8",
"u8.min(a: u8) u8",
"u8.max(no_less_than: u8) u8",
"u8.min(no_more_than: u8) u8",
"u16.high_bits(n: u32[..= 15]) u16",
"u16.low_bits(n: u32[..= 15]) u16",
"u16.max(a: u16) u16",
"u16.min(a: u16) u16",
"u16.max(no_less_than: u16) u16",
"u16.min(no_more_than: u16) u16",
"u32.high_bits(n: u32[..= 31]) u32",
"u32.low_bits(n: u32[..= 31]) u32",
"u32.max(a: u32) u32",
"u32.min(a: u32) u32",
"u32.max(no_less_than: u32) u32",
"u32.min(no_more_than: u32) u32",
"u64.high_bits(n: u32[..= 63]) u64",
"u64.low_bits(n: u32[..= 63]) u64",
"u64.max(a: u64) u64",
"u64.min(a: u64) u64",
"u64.max(no_less_than: u64) u64",
"u64.min(no_more_than: u64) u64",
// ---- utility
@@ -385,6 +381,9 @@ 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_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",
// ---- ranges
@@ -427,6 +426,7 @@ var funcsOther = [...]string{
"io_reader.read_u8?() u8",
"io_reader.read_u8_as_u16?() u16[..= 0xFF]",
"io_reader.read_u16be?() u16",
"io_reader.read_u16le?() u16",
@@ -463,6 +463,7 @@ var funcsOther = [...]string{
"io_reader.peek_u8() u8",
"io_reader.peek_u8_as_u16() u16[..= 0xFF]",
"io_reader.peek_u16be() u16",
"io_reader.peek_u16le() u16",
@@ -501,7 +502,7 @@ var funcsOther = [...]string{
"io_reader.mark() u64",
"io_reader.match7(a: u64) u32[..= 2]",
"io_reader.position() u64",
"io_reader.since(mark: u64) slice u8",
"io_reader.since(mark: u64) roslice u8",
"io_reader.valid_utf_8_length(up_to: u64) u64",
"io_reader.limited_copy_u32_to_slice!(up_to: u32, s: slice u8) u32",
@@ -561,10 +562,10 @@ var funcsOther = [...]string{
"io_writer.position() u64",
"io_writer.since(mark: u64) slice u8",
"io_writer.copy_from_slice!(s: slice u8) u64",
"io_writer.copy_from_slice!(s: roslice u8) u64",
"io_writer.limited_copy_u32_from_history!(up_to: u32, distance: u32) u32",
"io_writer.limited_copy_u32_from_reader!(up_to: u32, r: io_reader) u32",
"io_writer.limited_copy_u32_from_slice!(up_to: u32, s: slice u8) u32",
"io_writer.limited_copy_u32_from_slice!(up_to: u32, s: roslice u8) u32",
// TODO: this should have explicit pre-conditions:
// - up_to <= this.length()
@@ -612,7 +613,7 @@ var funcsOther = [...]string{
// ---- image_config
"image_config.set!(pixfmt: u32, pixsub: u32, width: u32, height: u32," +
"image_config.set!(pixfmt: u32, pixsub: u32, width: u32[..= 0xFF_FFFF], height: u32[..= 0xFF_FFFF]," +
"first_frame_io_position: u64, first_frame_is_opaque: bool)",
// ---- pixel_buffer
@@ -630,16 +631,48 @@ var funcsOther = [...]string{
"pixel_swizzler.prepare!(" +
"dst_pixfmt: pixel_format, dst_palette: slice u8," +
"src_pixfmt: pixel_format, src_palette: slice u8, blend: pixel_blend) status",
"src_pixfmt: pixel_format, src_palette: roslice u8, blend: pixel_blend) status",
"pixel_swizzler.limited_swizzle_u32_interleaved_from_reader!(" +
"up_to_num_pixels: u32, dst: slice u8, dst_palette: slice u8, src: io_reader) u64",
"pixel_swizzler.swizzle_interleaved_from_reader!(" +
"dst: slice u8, dst_palette: slice u8, src: io_reader) u64",
"pixel_swizzler.swizzle_interleaved_from_slice!(" +
"dst: slice u8, dst_palette: slice u8, src: slice u8) u64",
"dst: slice u8, dst_palette: slice u8, src: roslice u8) u64",
"pixel_swizzler.swizzle_interleaved_transparent_black!(" +
"dst: slice u8, dst_palette: slice u8, num_pixels: u64) u64",
"pixel_swizzler.swizzle_ycck!(" +
"dst: ptr pixel_buffer," +
"dst_palette: slice u8," +
"width: u32[..= 0xFFFF]," +
"height: u32[..= 0xFFFF]," +
"src0: slice u8," +
"src1: slice u8," +
"src2: slice u8," +
"src3: slice u8," +
"width0: u32[..= 0x4_0000]," +
"width1: u32[..= 0x4_0000]," +
"width2: u32[..= 0x4_0000]," +
"width3: u32[..= 0x4_0000]," +
"height0: u32[..= 0x4_0000]," +
"height1: u32[..= 0x4_0000]," +
"height2: u32[..= 0x4_0000]," +
"height3: u32[..= 0x4_0000]," +
"stride0: u32," +
"stride1: u32," +
"stride2: u32," +
"stride3: u32," +
"h0: u8[..= 4]," +
"h1: u8[..= 4]," +
"h2: u8[..= 4]," +
"h3: u8[..= 4]," +
"v0: u8[..= 4]," +
"v1: u8[..= 4]," +
"v2: u8[..= 4]," +
"v3: u8[..= 4]," +
"is_rgb_or_cmyk: bool," +
"triangle_filter_for_2to1: bool," +
"scratch_buffer_2k: slice u8) status",
// ---- arm_crc32_utility
@@ -688,8 +721,8 @@ var funcsOther = [...]string{
"arm_neon_utility.make_u32x4_repeat(a: u32) arm_neon_u32x4",
"arm_neon_utility.make_u64x2_repeat(a: u64) arm_neon_u64x2",
"arm_neon_utility.make_u8x8_slice64(a: slice base.u8) arm_neon_u8x8",
"arm_neon_utility.make_u8x16_slice128(a: slice base.u8) arm_neon_u8x16",
"arm_neon_utility.make_u8x8_slice64(a: roslice base.u8) arm_neon_u8x8",
"arm_neon_utility.make_u8x16_slice128(a: roslice base.u8) arm_neon_u8x16",
// ---- arm_neon_uAxB.as_uCxD
@@ -732,10 +765,13 @@ var funcsOther = [...]string{
"x86_sse42_utility.make_m128i_single_u32(a: u32) x86_m128i",
"x86_sse42_utility.make_m128i_single_u64(a: u64) x86_m128i",
"x86_sse42_utility.make_m128i_slice128(a: slice base.u8) x86_m128i",
"x86_sse42_utility.make_m128i_slice128(a: roslice base.u8) x86_m128i",
"x86_sse42_utility.make_m128i_slice_u16lex8(a: roslice base.u16) x86_m128i",
"x86_sse42_utility.make_m128i_zeroes() x86_m128i",
"x86_sse42_utility.make_u64_slice_u16lex4(a: roslice base.u16) u64",
// ---- x86_m128i
"x86_m128i.store_slice64!(a: slice base.u8)",
@@ -779,6 +815,9 @@ var funcsOther = [...]string{
"x86_m128i._mm_min_epu16(b: x86_m128i) x86_m128i",
"x86_m128i._mm_min_epu32(b: x86_m128i) x86_m128i",
"x86_m128i._mm_min_epu8(b: x86_m128i) x86_m128i",
"x86_m128i._mm_mullo_epi32(b: x86_m128i) x86_m128i",
"x86_m128i._mm_or_si128(b: x86_m128i) x86_m128i",
"x86_m128i._mm_packs_epi16(b: x86_m128i) x86_m128i",
"x86_m128i._mm_packus_epi16(b: x86_m128i) x86_m128i",
"x86_m128i._mm_sad_epu8(b: x86_m128i) x86_m128i",
"x86_m128i._mm_shuffle_epi32(imm8: u32) x86_m128i",
@@ -832,34 +871,72 @@ var funcsOther = [...]string{
"x86_avx2_utility.make_m256i_repeat_u32(a: u32) x86_m256i",
"x86_avx2_utility.make_m256i_repeat_u64(a: u64) x86_m256i",
"x86_avx2_utility.make_m256i_slice256(a: slice base.u8) x86_m256i",
"x86_avx2_utility.make_m256i_slice256(a: roslice base.u8) x86_m256i",
"x86_avx2_utility.make_m256i_slice_u16lex16(a: roslice base.u16) x86_m256i",
"x86_avx2_utility.make_m256i_zeroes() x86_m256i",
"x86_avx2_utility.make_u64_slice_u16lex4(a: roslice base.u16) u64",
// ---- x86_m256i
"x86_m256i.store_slice64!(a: slice base.u8)",
"x86_m256i.store_slice128!(a: slice base.u8)",
"x86_m256i.store_slice256!(a: slice base.u8)",
// TODO: generate these methods automatically?
"x86_m256i._mm256_add_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_add_epi32(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_add_epi64(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_add_epi8(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_and_si256(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_castsi256_si128() x86_m128i",
"x86_m256i._mm256_extract_epi64(index: u32) u64",
"x86_m256i._mm256_extracti128_si256(imm8: u32) x86_m128i",
"x86_m256i._mm256_inserti128_si256(b: x86_m128i, imm8: u32) x86_m256i",
"x86_m256i._mm256_madd_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_maddubs_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_mullo_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_or_si256(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_packs_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_packs_epi32(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_permute2x128_si256(b: x86_m256i, imm8: u32) x86_m256i",
"x86_m256i._mm256_permute4x64_epi64(imm8: u32) x86_m256i",
"x86_m256i._mm256_sad_epu8(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_shuffle_epi32(imm8: u32) x86_m256i",
"x86_m256i._mm256_sign_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_slli_epi16(imm8: u32) x86_m256i",
"x86_m256i._mm256_slli_epi32(imm8: u32) x86_m256i",
"x86_m256i._mm256_slli_epi64(imm8: u32) x86_m256i",
"x86_m256i._mm256_slli_si256(imm8: u32) x86_m256i",
"x86_m256i._mm256_srai_epi16(imm8: u32) x86_m256i",
"x86_m256i._mm256_srai_epi32(imm8: u32) x86_m256i",
"x86_m256i._mm256_srai_epi64(imm8: u32) x86_m256i",
"x86_m256i._mm256_srai_si256(imm8: u32) x86_m256i",
"x86_m256i._mm256_srli_epi16(imm8: u32) x86_m256i",
"x86_m256i._mm256_srli_epi32(imm8: u32) x86_m256i",
"x86_m256i._mm256_srli_epi64(imm8: u32) x86_m256i",
"x86_m256i._mm256_srli_si256(imm8: u32) x86_m256i",
"x86_m256i._mm256_sub_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_sub_epi32(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_sub_epi64(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_sub_epi8(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_testz_si256(b: x86_m256i) u32",
"x86_m256i._mm256_unpackhi_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_unpackhi_epi32(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_unpackhi_epi64(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_unpackhi_epi8(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_unpacklo_epi16(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_unpacklo_epi32(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_unpacklo_epi64(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_unpacklo_epi8(b: x86_m256i) x86_m256i",
"x86_m256i._mm256_xor_si256(b: x86_m256i) x86_m256i",
}
var Interfaces = []string{
"hasher_u32",
"hasher_u64",
"image_decoder",
"io_transformer",
"token_decoder",
@@ -867,6 +944,7 @@ var Interfaces = []string{
var InterfacesMap = map[string]bool{
"hasher_u32": true,
"hasher_u64": true,
"image_decoder": true,
"io_transformer": true,
"token_decoder": true,
@@ -875,8 +953,19 @@ var InterfacesMap = map[string]bool{
var InterfaceFuncs = []string{
// ---- hasher_u32
"hasher_u32.set_quirk_enabled!(quirk: u32, enabled: bool)",
"hasher_u32.update_u32!(x: slice u8) u32",
"hasher_u32.checksum_u32() u32",
"hasher_u32.get_quirk(key: u32) u64",
"hasher_u32.set_quirk!(key: u32, value: u64) status",
"hasher_u32.update!(x: roslice u8)",
"hasher_u32.update_u32!(x: roslice u8) u32",
// ---- hasher_u64
"hasher_u64.checksum_u64() u64",
"hasher_u64.get_quirk(key: u32) u64",
"hasher_u64.set_quirk!(key: u32, value: u64) status",
"hasher_u64.update!(x: roslice u8)",
"hasher_u64.update_u64!(x: roslice u8) u64",
// ---- image_decoder
@@ -886,25 +975,31 @@ var InterfaceFuncs = []string{
"image_decoder.decode_frame_config?(dst: nptr frame_config, src: io_reader)",
"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",
"image_decoder.restart_frame!(index: u64, io_position: u64) status",
"image_decoder.set_quirk_enabled!(quirk: u32, enabled: bool)",
"image_decoder.set_quirk!(key: u32, value: u64) status",
"image_decoder.set_report_metadata!(fourcc: u32, report: bool)",
"image_decoder.tell_me_more?(dst: io_writer, minfo: nptr more_information, src: io_reader)",
"image_decoder.workbuf_len() range_ii_u64",
// ---- io_transformer
"io_transformer.set_quirk_enabled!(quirk: u32, enabled: bool)",
"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",
// ---- token_decoder
"token_decoder.decode_tokens?(dst: token_writer, src: io_reader, workbuf: slice u8)",
"token_decoder.set_quirk_enabled!(quirk: u32, enabled: bool)",
"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",
}
@@ -912,20 +1007,31 @@ var InterfaceFuncs = []string{
// "table T" types. After tokenizing (but before parsing) these XxxFunc strings
// (e.g. in the lang/check package), replace "T1" and "T2" with "†" or "‡"
// daggers, to avoid collision with a user-defined "T1" or "T2" type.
//
// Ditto for "R1" / "ρ", for a read-only flavor of "T1" / "†".
const (
genericOldName1 = t.IDT1
genericOldName2 = t.IDT2
genericOldNameRo1 = t.IDR1
genericNewName1 = t.IDDagger1
genericNewName2 = t.IDDagger2
genericNewNameRo1 = t.IDRho1
)
var SliceFuncs = []string{
"GENERIC T1.copy_from_slice!(s: T1) u64",
"GENERIC T1.copy_from_slice!(s: R1) u64",
"GENERIC T1.length() u64",
"GENERIC T1.prefix(up_to: u64) T1",
"GENERIC T1.uintptr_low_12_bits() u32[..= 4095]",
"GENERIC T1.suffix(up_to: u64) T1",
// The bulk_etc methods are further restricted to those T1 slices whose
// elements are bulk-numeric types: numerics (e.g. base.u32), arrays of
// numerics, arrays of arrays of numerics, etc.
"GENERIC T1.bulk_load_host_endian!(src: slice u8)",
"GENERIC T1.bulk_memset!(byte_value: u8)",
"GENERIC T1.bulk_save_host_endian!(dst: slice u8)",
}
var SliceU8Funcs = []string{
@@ -997,10 +1103,13 @@ func ParseFuncs(tm *t.Map, ss []string, callback func(*a.Func) error) error {
if generic {
for i := range tokens {
if id := tokens[i].ID; id == genericOldName1 {
tokens[i].ID = genericNewName1
tok := &tokens[i]
if id := tok.ID; id == genericOldName1 {
tok.ID = genericNewName1
} else if id == genericOldName2 {
tokens[i].ID = genericNewName2
tok.ID = genericNewName2
} else if id == genericOldNameRo1 {
tok.ID = genericNewNameRo1
}
}
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Code generated by running "go generate". DO NOT EDIT.
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 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.
// See the License for the specific language governing permissions and
// limitations under the License.
+10 -22
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
@@ -171,17 +165,11 @@ const header = `// Code generated by running "go generate". DO NOT EDIT.
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package builtin
+33 -11
View File
@@ -1,22 +1,17 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
import (
"errors"
"fmt"
"math/big"
a "github.com/google/wuffs/lang/ast"
t "github.com/google/wuffs/lang/token"
@@ -367,3 +362,30 @@ func proveReasonRequirementForRHSLength(q *checker, op t.ID, lhs *a.Expr, rhs *a
}
return nil
}
func (q *checker) proveRecvNotEqNullptr(recv *a.Expr) error {
for _, x := range q.facts {
if x.Operator() != t.IDXBinaryNotEq {
continue
}
xLHS := x.LHS().AsExpr()
xRHS := x.RHS().AsExpr()
if (xLHS.Eq(exprNullptr) && xRHS.Eq(recv)) ||
(xRHS.Eq(exprNullptr) && xLHS.Eq(recv)) {
return nil
}
}
return fmt.Errorf("check: cannot prove %q", recv.Str(q.tm)+" <> nullptr")
}
func (q *checker) proveSliceLengthAtLeast(n *a.Expr, minInclLength *big.Int) error {
if (n.Operator() == t.IDDotDot) && (n.MHS() == nil) && (n.RHS() == nil) {
if lTyp := n.LHS().AsExpr().MType(); lTyp.IsEitherArrayType() &&
lTyp.ArrayLength().ConstValue().Cmp(minInclLength) >= 0 {
return nil
}
}
// TODO: the general case, where n isn't "foo[..]" and foo isn't an array
// of length >= minInclLength.
return fmt.Errorf("check: cannot prove %q", n.Str(q.tm)+".length() >= "+minInclLength.String())
}
+105 -44
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
@@ -65,6 +59,20 @@ var (
oneTwentyEight = big.NewInt(+128)
ffff = big.NewInt(0xFFFF)
// maxPointerBounds is the artificial value in the [0 ..= maxPointerBounds]
// range for bounds-checking pointer-typed values. Its value is arbitrary
// (but greater than 1).
//
// It is positive (not 0) to distinguish nullptr from non-nullptr. More
// subtly, it is greater than 1 so that two non-nullptr pointer-typed
// values aren't necessarily equal.
maxPointerBounds = big.NewInt(1234)
// funcBounds is the artificial value in the [1 ..= funcBounds] range for
// bounds-checking function-typed values. Its value is arbitrary (but
// greater than 1) for the same reasons as maxPointerBounds.
funcBounds = big.NewInt(5678)
minIdeal = big.NewInt(0).Lsh(minusOne, 1000)
maxIdeal = big.NewInt(0).Lsh(one, 1000)
@@ -507,7 +515,10 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
return err
}
if lhs.MType().IsNumType() && rhs.Effect().Pure() {
if !rhs.Effect().Pure() {
// No-op.
} else if lhs.MType().IsNumType() {
q.facts.appendBinaryOpFact(t.IDXBinaryEqEq, lhs, rhs)
if rhs.Operator() == a.ExprOperatorCall {
@@ -520,6 +531,16 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
}
}
}
} else if lhs.MType().IsPointerType() {
if cv := rhs.ConstValue(); (cv != nil) && (cv.Sign() == 0) {
q.facts.appendBinaryOpFact(t.IDXBinaryEqEq, lhs, exprNullptr)
} else {
q.facts.appendBinaryOpFact(t.IDXBinaryEqEq, lhs, rhs)
if (lhs.MType().Decorator() == t.IDNptr) && (rhs.MType().Decorator() == t.IDPtr) {
q.facts.appendBinaryOpFact(t.IDXBinaryNotEq, lhs, exprNullptr)
}
}
}
// Look for "lhs = x[i .. j]" where i and j are constants.
@@ -926,10 +947,28 @@ func (q *checker) bcheckExpr1(n *a.Expr, depth uint32) (bounds, error) {
case op.IsXUnaryOp():
return q.bcheckExprUnaryOp(n, depth)
case op.IsXBinaryOp():
if op == t.IDXBinaryAs {
return q.bcheckExpr(n.LHS().AsExpr(), depth)
}
if op != t.IDXBinaryAs {
return q.bcheckExprBinaryOp(op, n.LHS().AsExpr(), n.RHS().AsExpr(), depth)
}
b, err := q.bcheckExpr(n.LHS().AsExpr(), depth)
if err != nil {
return bounds{}, err
} else if lhs := n.LHS().AsExpr(); lhs.MType().IsEitherSliceType() {
cv := (*big.Int)(nil)
rhs := n.RHS().AsTypeExpr()
if (rhs.Decorator() == t.IDPtr) && (rhs.Inner().IsEitherArrayType()) {
cv = rhs.Inner().ArrayLength().ConstValue()
}
if cv == nil {
// TODO: fix this.
return bounds{}, fmt.Errorf("check: cannot bounds-check conversion to %q", rhs.Str(q.tm))
}
if err := q.proveSliceLengthAtLeast(lhs, cv); err != nil {
return bounds{}, err
}
b = bounds{one, maxPointerBounds}
}
return b, nil
case op.IsXAssociativeOp():
return q.bcheckExprAssociativeOp(n, depth)
}
@@ -977,8 +1016,15 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (bounds, error) {
}
lengthExpr := (*a.Expr)(nil)
if lTyp := lhs.MType(); lTyp.IsArrayType() {
if lTyp := lhs.MType(); lTyp.IsEitherArrayType() {
lengthExpr = lTyp.ArrayLength()
} else if lTyp.IsPointerType() && lTyp.Inner().IsEitherArrayType() {
lengthExpr = lTyp.Inner().ArrayLength()
if lTyp.Decorator() == t.IDPtr {
// No-op.
} else if err := q.proveRecvNotEqNullptr(lhs); err != nil {
return bounds{}, err
}
} else {
lengthExpr = makeSliceLength(lhs)
}
@@ -1013,7 +1059,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (bounds, error) {
}
lengthExpr := (*a.Expr)(nil)
if lTyp := lhs.MType(); lTyp.IsArrayType() {
if lTyp := lhs.MType(); lTyp.IsEitherArrayType() {
lengthExpr = lTyp.ArrayLength()
} else {
lengthExpr = makeSliceLength(lhs)
@@ -1093,19 +1139,7 @@ func (q *checker) bcheckExprCall(n *a.Expr, depth uint32) error {
if recv.MType().Decorator() != t.IDNptr {
return nil
}
// Check that q.facts contain "recv != nullptr".
for _, x := range q.facts {
if x.Operator() != t.IDXBinaryNotEq {
continue
}
xLHS := x.LHS().AsExpr()
xRHS := x.RHS().AsExpr()
if (xLHS.Eq(exprNullptr) && xRHS.Eq(recv)) ||
(xRHS.Eq(exprNullptr) && xLHS.Eq(recv)) {
return nil
}
}
return fmt.Errorf("check: cannot prove %q", recv.Str(q.tm)+" != nullptr")
return q.proveRecvNotEqNullptr(recv)
}
var errNotASpecialCase = errors.New("not a special case")
@@ -1115,7 +1149,7 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
recv := lhs.LHS().AsExpr()
method := lhs.Ident()
advance, advanceExpr, update := (*big.Int)(nil), (*a.Expr)(nil), false
actualAdvanceIsAlwaysPositive, advance, advanceExpr, update := false, (*big.Int)(nil), (*a.Expr)(nil), false
if recvTyp := recv.MType(); recvTyp == nil {
return bounds{}, errNotASpecialCase
@@ -1195,6 +1229,9 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
} else if err != nil {
return bounds{}, err
}
if cv := actual.ConstValue(); (cv != nil) && (cv.Sign() > 0) {
actualAdvanceIsAlwaysPositive = true
}
if cv := worstCase.ConstValue(); cv != nil {
advance, update = cv, true
} else {
@@ -1239,6 +1276,16 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
advance = thirtyTwo
case strings.HasSuffix(s, "_slice512"): // 512 bits is 64 bytes.
advance = sixtyFour
case strings.HasSuffix(s, "_slice_u16lex4"): // 4 u16 values is 8 bytes.
advance = four
case strings.HasSuffix(s, "_slice_u16lex8"): // 8 u16 values is 16 bytes.
advance = eight
case strings.HasSuffix(s, "_slice_u16lex16"): // 16 u16 values is 32 bytes.
advance = sixteen
case strings.HasSuffix(s, "_slice_u16lex32"): // 32 u16 values is 64 bytes.
advance = thirtyTwo
case strings.Contains(s, "_slice"):
return bounds{}, fmt.Errorf("check: internal error: unrecognized %s method", s)
}
}
}
@@ -1260,6 +1307,9 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
return bounds{}, fmt.Errorf("check: could not prove %s pre-condition: %s.length() >= %s",
method.Str(q.tm), subject.Str(q.tm), adv)
}
if actualAdvanceIsAlwaysPositive {
q.facts = append(q.facts, makeCanUndoByte(recv))
}
// TODO: drop other subject-related facts?
}
@@ -1498,15 +1548,26 @@ func makeConstValueExpr(tm *t.Map, cv *big.Int) (*a.Expr, error) {
return o, nil
}
// makeSliceLength returns "x.length()".
func makeSliceLength(slice *a.Expr) *a.Expr {
x := a.NewExpr(0, t.IDDot, t.IDLength, slice.AsNode(), nil, nil, nil)
x.SetMBounds(bounds{one, one})
x.SetMType(a.NewTypeExpr(t.IDFunc, 0, t.IDLength, slice.MType().AsNode(), nil, nil))
x = a.NewExpr(0, t.IDOpenParen, 0, x.AsNode(), nil, nil, nil)
// makeCanUndoByte returns "x.can_undo_byte()".
func makeCanUndoByte(x *a.Expr) *a.Expr {
ret := a.NewExpr(0, t.IDDot, t.IDCanUndoByte, x.AsNode(), nil, nil, nil)
ret.SetMBounds(bounds{funcBounds, funcBounds})
ret.SetMType(a.NewTypeExpr(t.IDFunc, 0, t.IDCanUndoByte, x.MType().AsNode(), nil, nil))
ret = a.NewExpr(0, t.IDOpenParen, 0, ret.AsNode(), nil, nil, nil)
// TODO: call SetMBounds?
x.SetMType(typeExprU64)
return x
ret.SetMType(typeExprBool)
return ret
}
// makeSliceLength returns "x.length()".
func makeSliceLength(x *a.Expr) *a.Expr {
ret := a.NewExpr(0, t.IDDot, t.IDLength, x.AsNode(), nil, nil, nil)
ret.SetMBounds(bounds{funcBounds, funcBounds})
ret.SetMType(a.NewTypeExpr(t.IDFunc, 0, t.IDLength, x.MType().AsNode(), nil, nil))
ret = a.NewExpr(0, t.IDOpenParen, 0, ret.AsNode(), nil, nil, nil)
// TODO: call SetMBounds?
ret.SetMType(typeExprU64)
return ret
}
// makeSliceLengthEqEq returns "x.length() == n".
@@ -1770,7 +1831,7 @@ func (q *checker) bcheckTypeExpr1(typ *a.TypeExpr) (bounds, error) {
switch typ.Decorator() {
case 0:
// No-op.
case t.IDArray:
case t.IDArray, t.IDRoarray:
if _, err := q.bcheckExpr(typ.ArrayLength(), 0); err != nil {
return bounds{}, err
}
@@ -1779,12 +1840,12 @@ func (q *checker) bcheckTypeExpr1(typ *a.TypeExpr) (bounds, error) {
if _, err := q.bcheckTypeExpr(typ.Receiver()); err != nil {
return bounds{}, err
}
return bounds{one, one}, nil
return bounds{one, funcBounds}, nil
case t.IDNptr:
return bounds{zero, one}, nil
return bounds{zero, maxPointerBounds}, nil
case t.IDPtr:
return bounds{one, one}, nil
case t.IDSlice, t.IDTable:
return bounds{one, maxPointerBounds}, nil
case t.IDRoslice, t.IDRotable, t.IDSlice, t.IDTable:
return bounds{zero, zero}, nil
default:
return bounds{}, fmt.Errorf("check: internal error: unrecognized decorator")
+21 -21
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:generate go run gen.go
@@ -92,6 +86,9 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
funcs: map[t.QQID]*a.Func{},
localVars: map[t.QQID]typeMap{},
builtInRosliceFuncs: map[t.QQID]*a.Func{},
builtInRosliceU8Funcs: map[t.QQID]*a.Func{},
builtInRotableFuncs: map[t.QQID]*a.Func{},
builtInSliceFuncs: map[t.QQID]*a.Func{},
builtInSliceU8Funcs: map[t.QQID]*a.Func{},
builtInTableFuncs: map[t.QQID]*a.Func{},
@@ -102,20 +99,20 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
}
for _, funcs := range builtin.Funcs {
if err := c.parseBuiltInFuncs(nil, funcs); err != nil {
if err := c.parseBuiltInFuncs(nil, nil, funcs); err != nil {
return nil, err
}
}
if err := c.parseBuiltInFuncs(c.builtInSliceFuncs, builtin.SliceFuncs); err != nil {
if err := c.parseBuiltInFuncs(c.builtInSliceFuncs, c.builtInRosliceFuncs, builtin.SliceFuncs); err != nil {
return nil, err
}
if err := c.parseBuiltInFuncs(c.builtInSliceU8Funcs, builtin.SliceU8Funcs); err != nil {
if err := c.parseBuiltInFuncs(c.builtInSliceU8Funcs, c.builtInRosliceU8Funcs, builtin.SliceU8Funcs); err != nil {
return nil, err
}
if err := c.parseBuiltInFuncs(c.builtInTableFuncs, builtin.TableFuncs); err != nil {
if err := c.parseBuiltInFuncs(c.builtInTableFuncs, c.builtInRotableFuncs, builtin.TableFuncs); err != nil {
return nil, err
}
if err := c.parseBuiltInFuncs(c.builtInInterfaceFuncs, builtin.InterfaceFuncs); err != nil {
if err := c.parseBuiltInFuncs(c.builtInInterfaceFuncs, nil, builtin.InterfaceFuncs); err != nil {
return nil, err
}
@@ -232,6 +229,9 @@ type Checker struct {
funcs map[t.QQID]*a.Func
localVars map[t.QQID]typeMap
builtInRosliceFuncs map[t.QQID]*a.Func
builtInRosliceU8Funcs map[t.QQID]*a.Func
builtInRotableFuncs map[t.QQID]*a.Func
builtInSliceFuncs map[t.QQID]*a.Func
builtInSliceU8Funcs map[t.QQID]*a.Func
builtInTableFuncs map[t.QQID]*a.Func
@@ -375,14 +375,14 @@ func (c *Checker) checkConst(node *a.Node) error {
nLists := 0
for elemTyp := typ; ; {
if elemTyp.IsArrayType() {
if dec := elemTyp.Decorator(); dec == t.IDRoarray {
if nLists == a.MaxTypeExprDepth {
return fmt.Errorf("check: type expression recursion depth too large")
}
nLists++
elemTyp = elemTyp.Inner()
continue
} else if elemTyp.Decorator() != 0 {
} else if dec != 0 {
return fmt.Errorf("check: invalid const type %q for %s", n.XType().Str(c.tm), qid.Str(c.tm))
}
break
@@ -399,7 +399,7 @@ func (c *Checker) checkConst(node *a.Node) error {
func (c *Checker) checkConstElement(typ *a.TypeExpr, n *a.Expr, nb bounds, nLists int) error {
if nLists > 0 {
nLists--
if !typ.IsArrayType() {
if typ.Decorator() != t.IDRoarray {
return fmt.Errorf("internal error: inconsistent element type %q", typ.Str(c.tm))
}
cv := typ.ArrayLength().ConstValue()
@@ -642,7 +642,7 @@ func (c *Checker) checkFuncSignature1(node *a.Node, banCPUArchTypes bool) error
sTyp.AsNode().SetMType(typeExprTypeExpr)
pTyp := a.NewTypeExpr(t.IDPtr, 0, 0, nil, nil, sTyp)
pTyp.AsNode().SetMBounds(bounds{one, one})
pTyp.AsNode().SetMBounds(bounds{one, maxPointerBounds})
pTyp.AsNode().SetMType(typeExprTypeExpr)
localVars[t.IDThis] = pTyp
@@ -679,7 +679,7 @@ func (c *Checker) checkFuncImplements(node *a.Node) error {
return nil
}
if (n.Effect() != o.Effect()) || !n.Out().Eq(o.Out()) {
if !n.Public() || (n.Effect() != o.Effect()) || !n.Out().Eq(o.Out()) {
return nil
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
+5 -11
View File
@@ -2,17 +2,11 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
+10 -22
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
@@ -340,17 +334,11 @@ const header = `// Code generated by running "go generate". DO NOT EDIT.
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
+21 -15
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
@@ -32,6 +26,7 @@ var (
var (
typeExprGeneric1 = a.NewTypeExpr(0, t.IDBase, t.IDDagger1, nil, nil, nil)
typeExprGeneric2 = a.NewTypeExpr(0, t.IDBase, t.IDDagger2, nil, nil, nil)
typeExprGenericRo1 = a.NewTypeExpr(0, t.IDBase, t.IDRho1, nil, nil, nil)
typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDQIdeal, nil, nil, nil)
typeExprList = a.NewTypeExpr(0, t.IDBase, t.IDComma, nil, nil, nil)
typeExprNonNullptr = a.NewTypeExpr(0, t.IDBase, t.IDQNonNullptr, nil, nil, nil)
@@ -94,6 +89,8 @@ var (
typeExprX86AVX2Utility = a.NewTypeExpr(0, t.IDBase, t.IDX86AVX2Utility, nil, nil, nil)
typeExprX86M256I = a.NewTypeExpr(0, t.IDBase, t.IDX86M256I, nil, nil, nil)
typeExprRosliceU8 = a.NewTypeExpr(t.IDRoslice, 0, 0, nil, nil, typeExprU8)
typeExprRotableU8 = a.NewTypeExpr(t.IDRotable, 0, 0, nil, nil, typeExprU8)
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
typeExprTableU8 = a.NewTypeExpr(t.IDTable, 0, 0, nil, nil, typeExprU8)
)
@@ -162,7 +159,7 @@ var builtInTypeMap = typeMap{
t.IDX86M256I: typeExprX86M256I,
}
func (c *Checker) parseBuiltInFuncs(m map[t.QQID]*a.Func, ss []string) error {
func (c *Checker) parseBuiltInFuncs(m map[t.QQID]*a.Func, mRonly map[t.QQID]*a.Func, ss []string) error {
return builtin.ParseFuncs(c.tm, ss, func(f *a.Func) error {
if err := c.checkFuncSignature1(f.AsNode(), false); err != nil {
return err
@@ -170,6 +167,9 @@ func (c *Checker) parseBuiltInFuncs(m map[t.QQID]*a.Func, ss []string) error {
if m != nil {
m[f.QQID()] = f
}
if (mRonly != nil) && f.Effect().Pure() {
mRonly[f.QQID()] = f
}
return nil
})
}
@@ -182,24 +182,30 @@ func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
lQID := lTyp.QID()
qqid := t.QQID{lQID[0], lQID[1], typ.FuncName()}
if lTyp.IsSliceType() {
if lTyp.IsEitherSliceType() {
qqid[0] = t.IDBase
qqid[1] = t.IDDagger1
if f := c.builtInSliceFuncs[qqid]; f != nil {
if (lTyp.Decorator() == t.IDSlice) || f.Effect().Pure() {
return f, nil
}
if lTyp.Eq(typeExprSliceU8) {
}
if lTyp.Eq(typeExprSliceU8) || lTyp.Eq(typeExprRosliceU8) {
if f := c.builtInSliceU8Funcs[qqid]; f != nil {
if (lTyp.Decorator() == t.IDSlice) || f.Effect().Pure() {
return f, nil
}
}
}
} else if lTyp.IsTableType() {
} else if lTyp.IsEitherTableType() {
qqid[0] = t.IDBase
qqid[1] = t.IDDagger2
if f := c.builtInTableFuncs[qqid]; f != nil {
if (lTyp.Decorator() == t.IDTable) || f.Effect().Pure() {
return f, nil
}
}
} else if f := c.funcs[qqid]; f != nil {
return f, nil
+125 -32
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package check
@@ -171,7 +165,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if err := q.tcheckExpr(n.Arg1(), 0); err != nil {
return err
}
if typ := n.Arg1().MType(); !typ.EqIgnoringRefinements(arg1Typ) {
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))
}
@@ -204,7 +198,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
return err
}
o := o.AsAssign()
if typ := o.LHS().MType(); !typ.IsSliceType() {
if typ := o.LHS().MType(); !typ.IsEitherSliceType() {
return fmt.Errorf("check: iterate assignment to %q, of type %q, does not have slice type",
o.LHS().Str(q.tm), typ.Str(q.tm))
}
@@ -236,10 +230,26 @@ func (q *checker) tcheckStatement(n *a.Node) error {
return err
}
rTyp := value.MType()
if !(rTyp.IsIdeal() && lTyp.IsNumType()) && !lTyp.EqIgnoringRefinements(rTyp) {
if !(rTyp.IsIdeal() && lTyp.IsNumType()) && !lTyp.EqIgnoringRefinementsLHSReadOnly(rTyp) {
return fmt.Errorf("check: cannot return %q (of type %q) as type %q",
value.Str(q.tm), rTyp.Str(q.tm), lTyp.Str(q.tm))
}
if rTyp.IsEitherSliceType() || rTyp.IsPointerType() {
// TODO: just reject all "return x" when x has slice or pointer
// type, after removing the (deprecated) lzw.decoder.flush! method.
ok := false
if value.Operator() != t.IDDotDot {
// No-op.
} else if lhs := value.LHS().AsExpr(); lhs.Operator() != t.IDDot {
// No-op.
} else if llhs := lhs.LHS().AsExpr(); true {
ok = (llhs.Operator() == 0) && (llhs.Ident() == t.IDThis)
}
if !ok {
return fmt.Errorf("check: cannot return %q, need something of the form this.etc[i .. j]",
value.Str(q.tm))
}
}
case a.KVar:
n := n.AsVar()
@@ -305,7 +315,7 @@ func (q *checker) tcheckAssert(n *a.Assert) error {
func (q *checker) tcheckEq(lID t.ID, lhs *a.Expr, lTyp *a.TypeExpr, rhs *a.Expr, rTyp *a.TypeExpr) error {
if (rTyp.IsIdeal() && lTyp.IsNumType()) ||
(rTyp.EqIgnoringRefinements(lTyp)) ||
(lTyp.EqIgnoringRefinementsLHSReadOnly(rTyp)) ||
(rTyp.IsNullptr() && lTyp.Decorator() == t.IDNptr) {
return nil
}
@@ -331,6 +341,14 @@ func (q *checker) tcheckAssign(n *a.Assign) error {
if err := q.tcheckExpr(lhs, 0); err != nil {
return err
}
for l := lhs; l != nil; l = l.LHS().AsExpr() {
if l.Operator() != t.IDOpenBracket {
// No-op.
} else if lTyp := l.LHS().MType(); lTyp.IsRecursivelyReadOnly() {
return fmt.Errorf("check: assignment %q: assignee fragment %q, of type %q, has read-only type",
n.Operator().Str(q.tm), l.LHS().AsExpr().Str(q.tm), lTyp.Str(q.tm))
}
}
lTyp := lhs.MType()
rTyp := rhs.MType()
@@ -363,7 +381,7 @@ func (q *checker) tcheckAssign(n *a.Assign) error {
}
}
if !(rTyp.IsIdeal() && lTyp.IsNumType()) && !lTyp.EqIgnoringRefinements(rTyp) {
if !(rTyp.IsIdeal() && lTyp.IsNumType()) && !lTyp.EqIgnoringRefinementsLHSReadOnly(rTyp) {
return fmt.Errorf("check: assignment %q: %q and %q, of types %q and %q, do not have compatible types",
n.Operator().Str(q.tm),
lhs.Str(q.tm), rhs.Str(q.tm),
@@ -508,8 +526,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
return err
}
lTyp := lhs.MType()
if key := lTyp.Decorator(); key != t.IDArray && key != t.IDSlice {
return fmt.Errorf("check: %s is an index expression but %s has type %s, not an array or slice type",
if lTyp.IsEitherArrayType() || lTyp.IsEitherSliceType() {
// No-op.
} else if lTyp.IsPointerType() && lTyp.Inner().IsEitherArrayType() {
// No-op.
} else {
return fmt.Errorf("check: %s is an index expression but %s has type %s, not an array, slice or pointer-to-array type",
n.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
rTyp := rhs.MType()
@@ -517,7 +539,11 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
return fmt.Errorf("check: %s is an index expression but %s has type %s, not a numeric type",
n.Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
if lTyp.IsPointerType() {
n.SetMType(lTyp.Inner().Inner())
} else {
n.SetMType(lTyp.Inner())
}
return nil
case t.IDDotDot:
@@ -555,7 +581,9 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
case t.IDArray:
n.SetMType(a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, lTyp.Inner()))
case t.IDSlice:
case t.IDRoarray:
n.SetMType(a.NewTypeExpr(t.IDRoslice, 0, 0, nil, nil, lTyp.Inner()))
case t.IDRoslice, t.IDSlice:
n.SetMType(lTyp)
}
return nil
@@ -616,16 +644,29 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
genericType1 := (*a.TypeExpr)(nil)
genericType2 := (*a.TypeExpr)(nil)
genericTypeRo1 := (*a.TypeExpr)(nil)
if recv := f.Receiver(); recv[0] == t.IDBase {
switch recv[1] {
case t.IDDagger1:
decorator := t.ID(0)
genericType1 = lhs.MType().Receiver()
if gt1Dec := genericType1.Decorator(); (gt1Dec == t.IDRoslice) || (gt1Dec == t.IDSlice) {
decorator = t.IDRoslice
} else {
return fmt.Errorf("check: internal error: %q is not a generic slice", genericType1.Str(q.tm))
}
genericTypeRo1 = a.NewTypeExpr(decorator, 0, 0, nil, nil, genericType1.Inner())
case t.IDDagger2:
decorator := t.ID(0)
genericType2 = lhs.MType().Receiver()
if genericType2.Decorator() != t.IDTable {
if gt2Dec := genericType2.Decorator(); gt2Dec == t.IDRotable {
decorator = t.IDRoslice
} else if gt2Dec == t.IDTable {
decorator = t.IDSlice
} else {
return fmt.Errorf("check: internal error: %q is not a generic table", genericType2.Str(q.tm))
}
genericType1 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, genericType2.Inner())
genericType1 = a.NewTypeExpr(decorator, 0, 0, nil, nil, genericType2.Inner())
}
}
@@ -651,6 +692,8 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
inFieldTyp = genericType1
} else if genericType2 != nil && inFieldTyp.Eq(typeExprGeneric2) {
inFieldTyp = genericType2
} else if genericTypeRo1 != nil && inFieldTyp.Eq(typeExprGenericRo1) {
inFieldTyp = genericTypeRo1
}
if err := q.tcheckEq(inField.Name(), nil, inFieldTyp, o.Value(), o.Value().MType()); err != nil {
return err
@@ -675,6 +718,22 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
return nil
}
func (c *Checker) isBuiltInSliceFunc(qqid t.QQID, typ *a.TypeExpr) bool {
if typ.Decorator() == t.IDRoslice {
return (c.builtInRosliceFuncs[qqid] != nil) ||
(typ.Eq(typeExprRosliceU8) && c.builtInRosliceU8Funcs[qqid] != nil)
}
return (c.builtInSliceFuncs[qqid] != nil) ||
(typ.Eq(typeExprSliceU8) && c.builtInSliceU8Funcs[qqid] != nil)
}
func (c *Checker) isBuiltInTableFunc(qqid t.QQID, typ *a.TypeExpr) bool {
if typ.Decorator() == t.IDRotable {
return c.builtInRotableFuncs[qqid] != nil
}
return c.builtInTableFuncs[qqid] != nil
}
func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
lhs := n.LHS().AsExpr()
if err := q.tcheckExpr(lhs, depth); err != nil {
@@ -687,20 +746,30 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
lQID := lTyp.QID()
qqid := t.QQID{lQID[0], lQID[1], n.Ident()}
if lTyp.IsSliceType() {
if lTyp.IsEitherSliceType() {
qqid[0] = t.IDBase
qqid[1] = t.IDDagger1
if (q.c.builtInSliceFuncs[qqid] != nil) ||
((q.c.builtInSliceU8Funcs[qqid] != nil) && lTyp.Eq(typeExprSliceU8)) {
if q.c.isBuiltInSliceFunc(qqid, lTyp) {
bulky := false
switch qqid[2] {
case t.IDBulkLoadHostEndian, t.IDBulkMemset, t.IDBulkSaveHostEndian:
bulky = true
if lTyp.Innermost().IsRefined() {
return fmt.Errorf("check: cannot apply bulk methods to slices of refined numeric types")
}
}
if !bulky || lTyp.Inner().IsBulkNumType() {
n.SetMType(a.NewTypeExpr(t.IDFunc, 0, n.Ident(), lTyp.AsNode(), nil, nil))
return nil
}
return fmt.Errorf("check: no slice method %q", n.Ident().Str(q.tm))
}
return fmt.Errorf("check: no %s method %q", lTyp.Decorator().Str(q.tm), n.Ident().Str(q.tm))
} else if lTyp.IsTableType() {
} else if lTyp.IsEitherTableType() {
qqid[0] = t.IDBase
qqid[1] = t.IDDagger2
if q.c.builtInTableFuncs[qqid] != nil {
if q.c.isBuiltInTableFunc(qqid, lTyp) {
n.SetMType(a.NewTypeExpr(t.IDFunc, 0, n.Ident(), lTyp.AsNode(), nil, nil))
return nil
}
@@ -732,7 +801,11 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
for _, field := range s.Fields() {
f := field.AsField()
if f.Name() == n.Ident() {
if q.astFunc.Effect().Pure() {
n.SetMType(f.XType().CloneReadOnly())
} else {
n.SetMType(f.XType())
}
return nil
}
}
@@ -792,6 +865,23 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
if lTyp.IsNumTypeOrIdeal() && rhs.IsNumType() {
n.SetMType(rhs)
return nil
} else if lTyp.IsEitherSliceType() &&
(rhs.Decorator() == t.IDPtr) &&
rhs.Inner().IsEitherArrayType() &&
lTyp.Inner().Eq(rhs.Inner().Inner()) {
if !lTyp.IsReadOnly() && rhs.Innermost().IsNumType() {
n.SetMType(rhs)
return nil
}
for r := rhs.Inner(); ; r = r.Inner() {
if r.IsNumType() {
n.SetMType(rhs)
return nil
} else if r.Decorator() != t.IDRoarray {
break
}
}
}
return fmt.Errorf("check: cannot convert expression %q, of type %q, as type %q",
lhs.Str(q.tm), lTyp.Str(q.tm), rhs.Str(q.tm))
@@ -1121,7 +1211,8 @@ swtch:
// TODO: reject. You can only refine numeric types.
}
if qid[0] == t.IDBase {
if _, ok := builtInTypeMap[qid[1]]; ok || qid[1] == t.IDDagger1 || qid[1] == t.IDDagger2 {
if _, ok := builtInTypeMap[qid[1]]; ok ||
qid[1] == t.IDDagger1 || qid[1] == t.IDDagger2 || qid[1] == t.IDRho1 {
break swtch
}
}
@@ -1132,17 +1223,19 @@ swtch:
}
return fmt.Errorf("check: %q is not a type", typ.Str(q.tm))
case t.IDArray:
case t.IDArray, t.IDRoarray:
aLen := typ.ArrayLength()
if err := q.tcheckExpr(aLen, 0); err != nil {
return err
}
if aLen.ConstValue() == nil {
if cv := aLen.ConstValue(); cv == nil {
return fmt.Errorf("check: %q is not constant", aLen.Str(q.tm))
} else if cv.Sign() <= 0 {
return fmt.Errorf("check: array length %q is not positive", aLen.Str(q.tm))
}
fallthrough
case t.IDNptr, t.IDPtr, t.IDSlice, t.IDTable:
case t.IDNptr, t.IDPtr, t.IDRoslice, t.IDRotable, t.IDSlice, t.IDTable:
if err := q.tcheckTypeExpr(typ.Inner(), depth); err != nil {
return err
}
@@ -1173,7 +1266,7 @@ func (q *checker) tcheckChoose(n *a.Choose) error {
return fmt.Errorf("check: incompatible choose functions %q and %q: %v",
fQQID.Str(q.tm), gQQID.Str(q.tm), err)
}
o.SetMBounds(bounds{one, one})
o.SetMBounds(bounds{one, maxPointerBounds})
o.SetMType(typeExprNonNullptr)
}
return nil
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package generate
+31 -25
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package parse
@@ -344,7 +338,12 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
if err != nil {
return nil, err
}
if x := p.peek1(); x == t.IDOpenParen {
if x := p.peek1(); x == t.IDPlus {
p.src = p.src[1:]
if x := p.peek1(); x != t.IDOpenParen {
return nil, fmt.Errorf(`parse: expected "(", got %q at %s:%d`,
p.tm.ByID(x), p.filename, p.line())
}
extraFields, err := p.parseList(t.IDCloseParen, (*parser).parseExtraFieldNode)
if err != nil {
return nil, err
@@ -505,9 +504,9 @@ func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
}
decorator, arrayLength := t.ID(0), (*a.Expr)(nil)
switch p.peek1() {
case t.IDArray:
decorator = t.IDArray
switch peek1 := p.peek1(); peek1 {
case t.IDArray, t.IDRoarray:
decorator = peek1
p.src = p.src[1:]
if x := p.peek1(); x != t.IDOpenBracket {
@@ -528,12 +527,8 @@ func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
}
p.src = p.src[1:]
case t.IDSlice:
decorator = t.IDSlice
p.src = p.src[1:]
case t.IDTable:
decorator = t.IDTable
case t.IDRoslice, t.IDRotable, t.IDSlice, t.IDTable:
decorator = peek1
p.src = p.src[1:]
}
@@ -804,7 +799,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
if len(p.loops) == 0 {
// No-op.
} else if label == 0 {
loop = p.loops[len(p.loops)-1]
loop = p.loops.Top()
if loop.Label() != 0 {
return nil, fmt.Errorf(`parse: unlabeled %s for labeled %s.%s at %s:%d`,
x.Str(p.tm), loop.Keyword().Str(p.tm), loop.Label().Str(p.tm), p.filename, p.line())
@@ -826,10 +821,11 @@ func (p *parser) parseStatement1() (*a.Node, error) {
x.Str(p.tm), sepStr, labelStr, p.filename, p.line())
}
deep := loop != p.loops.Top()
if x == t.IDBreak {
loop.SetHasBreak()
loop.SetHasBreak(deep)
} else {
loop.SetHasContinue()
loop.SetHasContinue(deep)
}
n := a.NewJump(x, label)
n.SetJumpTarget(loop)
@@ -1173,6 +1169,16 @@ func (p *parser) parseIf() (*a.If, error) {
return nil, fmt.Errorf(`parse: expected "if", got %q at %s:%d`, got, p.filename, p.line())
}
p.src = p.src[1:]
likelihood, err := p.parseLabel()
if err != nil {
return nil, err
}
switch likelihood {
case 0, t.IDLikely, t.IDUnlikely:
default:
got := p.tm.ByID(likelihood)
return nil, fmt.Errorf(`parse: expected "if.likely" or "if.unlikely", got %q at %s:%d`, "if."+got, p.filename, p.line())
}
condition, err := p.parseExpr()
if err != nil {
return nil, err
@@ -1200,7 +1206,7 @@ func (p *parser) parseIf() (*a.If, error) {
}
}
}
return a.NewIf(condition, bodyIfTrue, bodyIfFalse, elseIf), nil
return a.NewIf(likelihood, condition, bodyIfTrue, bodyIfFalse, elseIf), nil
}
func (p *parser) parseIterateNode() (*a.Node, error) {
+19 -20
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package render
@@ -65,7 +59,7 @@ func Render(w io.Writer, tm *t.Map, src []t.Token, comments []string) (err error
// Print any previous comments.
commentIndent := indent
if prevLineHanging {
commentIndent++
commentIndent += 2
}
for ; commentLine < line; commentLine++ {
buf = buf[:0]
@@ -115,12 +109,12 @@ func Render(w io.Writer, tm *t.Map, src []t.Token, comments []string) (err error
} else if id.IsClose() {
indentAdjustment--
} else if hanging && ((id != t.IDOpenCurly) && (id != t.IDOpenDoubleCurly)) {
indentAdjustment++
indentAdjustment += 2
}
buf = appendTabs(buf, indent+indentAdjustment)
// Apply or update varNameLength.
if len(lineTokens) < 3 {
if len(lineTokens) < 4 {
varNameLength = 0
} else {
id0 := lineTokens[0].ID
@@ -294,13 +288,18 @@ func appendNum(buf []byte, s string) []byte {
return buf
}
func appendTabs(buf []byte, n int) []byte {
if n > 0 {
const tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
for ; n > len(tabs); n -= len(tabs) {
buf = append(buf, tabs...)
func appendTabs(buf []byte, nTabs int) []byte {
nSpaces := 4 * nTabs // Hard-code 4 spaces per tab.
if nSpaces > 0 {
const spaces = "" + // 256 spaces.
" " +
" " +
" " +
" "
for ; nSpaces > len(spaces); nSpaces -= len(spaces) {
buf = append(buf, spaces...)
}
buf = append(buf, tabs[:n]...)
buf = append(buf, spaces[:nSpaces]...)
}
return buf
}
+59 -34
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package token
@@ -123,6 +117,8 @@ func (x ID) IsClose() bool { return minClose <= x && x <= maxClose }
func (x ID) IsKeyword() bool { return minKeyword <= x && x <= maxKeyword }
func (x ID) IsNumType() bool { return minNumType <= x && x <= maxNumType }
func (x ID) IsNumTypeOrIdeal() bool { return minNumTypeOrIdeal <= x && x <= maxNumTypeOrIdeal }
func (x ID) IsRangeType() bool { return minRangeType <= x && x <= maxRangeType }
func (x ID) IsRectType() bool { return minRectType <= x && x <= maxRectType }
func (x ID) IsOpen() bool { return minOpen <= x && x <= maxOpen }
func (x ID) IsImplicitSemicolon(m *Map) bool {
@@ -401,8 +397,11 @@ const (
IDArray = ID(0xD0)
IDNptr = ID(0xD1)
IDPtr = ID(0xD2)
IDSlice = ID(0xD3)
IDTable = ID(0xD4)
IDRoarray = ID(0xD3)
IDRoslice = ID(0xD4)
IDRotable = ID(0xD5)
IDSlice = ID(0xD6)
IDTable = ID(0xD7)
)
const (
@@ -428,6 +427,10 @@ const (
minNumType = 0x110
maxNumType = 0x117
maxNumTypeOrIdeal = 0x117
minRangeType = 0x130
maxRangeType = 0x133
minRectType = 0x134
maxRectType = 0x135
maxBuiltInIdent = 0x3FF
// -------- 0x100 block.
@@ -436,10 +439,12 @@ const (
IDCoroutineResumed = ID(0x101)
IDThis = ID(0x102)
IDT1 = ID(0x104)
IDT2 = ID(0x105)
IDDagger1 = ID(0x106)
IDDagger2 = ID(0x107)
IDR1 = ID(0x104)
IDT1 = ID(0x105)
IDT2 = ID(0x106)
IDRho1 = ID(0x107)
IDDagger1 = ID(0x108)
IDDagger2 = ID(0x109)
IDQNonNullptr = ID(0x10A)
IDQNullptr = ID(0x10B)
@@ -519,8 +524,9 @@ const (
IDUndoByte = ID(0x180)
IDReadU8 = ID(0x181)
IDReadU16BE = ID(0x182)
IDReadU16LE = ID(0x183)
IDReadU8AsU16 = ID(0x185)
IDReadU16BE = ID(0x186)
IDReadU16LE = ID(0x187)
IDReadU8AsU32 = ID(0x189)
IDReadU16BEAsU32 = ID(0x18A)
@@ -552,8 +558,9 @@ const (
IDPeekU8 = ID(0x1A1)
IDPeekU16BE = ID(0x1A2)
IDPeekU16LE = ID(0x1A3)
IDPeekU8AsU16 = ID(0x1A5)
IDPeekU16BE = ID(0x1A6)
IDPeekU16LE = ID(0x1A7)
IDPeekU8AsU32 = ID(0x1A9)
IDPeekU16BEAsU32 = ID(0x1AA)
@@ -647,10 +654,12 @@ const (
IDCPUArchIs32Bit = ID(0x202)
IDInitialize = ID(0x203)
IDLength = ID(0x204)
IDReset = ID(0x205)
IDSet = ID(0x206)
IDUnroll = ID(0x207)
IDUpdate = ID(0x208)
IDLikely = ID(0x205)
IDReset = ID(0x206)
IDSet = ID(0x207)
IDUnlikely = ID(0x208)
IDUnroll = ID(0x209)
IDUpdate = ID(0x20A)
// TODO: range/rect methods like intersection and contains?
@@ -663,6 +672,10 @@ const (
IDIsOK = ID(0x231)
IDIsSuspension = ID(0x232)
IDBulkLoadHostEndian = ID(0x238)
IDBulkMemset = ID(0x239)
IDBulkSaveHostEndian = ID(0x23A)
IDData = ID(0x240)
IDHeight = ID(0x241)
IDIO = ID(0x242)
@@ -670,12 +683,11 @@ const (
IDPrefix = ID(0x244)
IDRowU32 = ID(0x245)
IDStride = ID(0x246)
IDSubslice = ID(0x247)
IDSubtable = ID(0x248)
IDSuffix = ID(0x249)
IDUintptrLow12Bits = ID(0x24A)
IDValidUTF8Length = ID(0x24B)
IDWidth = ID(0x24C)
IDSubtable = ID(0x247)
IDSuffix = ID(0x248)
IDUintptrLow12Bits = ID(0x249)
IDValidUTF8Length = ID(0x24A)
IDWidth = ID(0x24B)
IDLimitedSwizzleU32InterleavedFromReader = ID(0x280)
IDSwizzleInterleavedFromReader = ID(0x281)
@@ -823,6 +835,9 @@ var builtInsByID = [nBuiltInIDs]string{
IDArray: "array",
IDNptr: "nptr",
IDPtr: "ptr",
IDRoarray: "roarray",
IDRoslice: "roslice",
IDRotable: "rotable",
IDSlice: "slice",
IDTable: "table",
@@ -845,10 +860,13 @@ var builtInsByID = [nBuiltInIDs]string{
// specifically non-ASCII so that no user-defined (non built-in) identifier
// will conflict with them.
// IDDaggerN is used by the type checker as a placeholder built-in ID to
// represent a generic type.
// IDRhoN and IDDaggerN are used by the type checker as placeholder
// built-in IDs to represent generic 1-dimensional (slice) or 2-dimensional
// (table) types. The Rho flavor is read-only.
IDR1: "R1",
IDT1: "T1",
IDT2: "T2",
IDRho1: "ρ", // U+03C1 GREEK SMALL LETTER RHO
IDDagger1: "†", // U+2020 DAGGER
IDDagger2: "‡", // U+2021 DOUBLE DAGGER
@@ -949,6 +967,7 @@ var builtInsByID = [nBuiltInIDs]string{
IDUndoByte: "undo_byte",
IDReadU8: "read_u8",
IDReadU8AsU16: "read_u8_as_u16",
IDReadU16BE: "read_u16be",
IDReadU16LE: "read_u16le",
@@ -982,6 +1001,7 @@ var builtInsByID = [nBuiltInIDs]string{
IDPeekU8: "peek_u8",
IDPeekU8AsU16: "peek_u8_as_u16",
IDPeekU16BE: "peek_u16be",
IDPeekU16LE: "peek_u16le",
@@ -1075,8 +1095,10 @@ var builtInsByID = [nBuiltInIDs]string{
IDCPUArchIs32Bit: "cpu_arch_is_32_bit",
IDInitialize: "initialize",
IDLength: "length",
IDLikely: "likely",
IDReset: "reset",
IDSet: "set",
IDUnlikely: "unlikely",
IDUnroll: "unroll",
IDUpdate: "update",
@@ -1089,6 +1111,10 @@ var builtInsByID = [nBuiltInIDs]string{
IDIsOK: "is_ok",
IDIsSuspension: "is_suspension",
IDBulkLoadHostEndian: "bulk_load_host_endian",
IDBulkMemset: "bulk_memset",
IDBulkSaveHostEndian: "bulk_save_host_endian",
IDData: "data",
IDHeight: "height",
IDIO: "io",
@@ -1096,7 +1122,6 @@ var builtInsByID = [nBuiltInIDs]string{
IDPrefix: "prefix",
IDRowU32: "row_u32",
IDStride: "stride",
IDSubslice: "subslice",
IDSubtable: "subtable",
IDSuffix: "suffix",
IDUintptrLow12Bits: "uintptr_low_12_bits",
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package token
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package wuffsroot
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -2,17 +2,11 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package armneonintrinsics
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package armneonintrinsics_test
+10 -22
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -382,17 +376,11 @@ const header = `// Code generated by running "go generate". DO NOT EDIT.
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package armneonintrinsics
`
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package armneonintrinsics
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package base38
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgolz4
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgozlib
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package cgozstd
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package compression
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package dumbindent
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package flatecut
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package interval
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package interval
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package litonlylzma_test
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package litonlylzma
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package rac
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package rac
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package rac
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package rac_test
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package rac
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package rac
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package rac
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package raclz4_test
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package raczlib_test
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build cgo
// +build cgo
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build !cgo
// +build !cgo
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package raczlib
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package raczstd_test
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package zlibcut_test
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
package zlibcut
File diff suppressed because it is too large. Load diff
+64191
View File
File diff suppressed because it is too large. Load diff
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+162
View File
@@ -0,0 +1,162 @@
// 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.
//go:build ignore
// +build ignore
package main
// This program exercises the Go standard library's JPEG decoder.
//
// Wuffs' C code doesn't depend on Go per se, but this program gives some
// performance data for specific Go JPEG implementations. The equivalent Wuffs
// benchmarks (on the same test images) are run via:
//
// wuffs bench std/jpeg
import (
"bytes"
"fmt"
"image"
"image/draw"
"image/jpeg"
"os"
"runtime"
"time"
)
const (
iterscale = 20
reps = 5
)
type testCase = struct {
benchname string
src []byte
itersUnscaled uint32
}
var testCases = []testCase{{
benchname: "go_jpeg_decode_19k_8bpp",
src: mustLoad("test/data/bricks-gray.jpeg"),
itersUnscaled: 100,
}, {
benchname: "go_jpeg_decode_30k_24bpp_progressive",
src: mustLoad("test/data/peacock.progressive.jpeg"),
itersUnscaled: 50,
}, {
benchname: "go_jpeg_decode_30k_24bpp_sequential",
src: mustLoad("test/data/peacock.default.jpeg"),
itersUnscaled: 50,
}, {
benchname: "go_jpeg_decode_77k_24bpp",
src: mustLoad("test/data/bricks-color.jpeg"),
itersUnscaled: 30,
}, {
benchname: "go_jpeg_decode_552k_24bpp_420",
src: mustLoad("test/data/hibiscus.regular.jpeg"),
itersUnscaled: 5,
}, {
benchname: "go_jpeg_decode_552k_24bpp_444",
src: mustLoad("test/data/hibiscus.primitive.jpeg"),
itersUnscaled: 5,
}, {
benchname: "go_jpeg_decode_4002k_24bpp",
src: mustLoad("test/data/harvesters.jpeg"),
itersUnscaled: 1,
}}
func mustLoad(filename string) []byte {
src, err := os.ReadFile("../../" + filename)
if err != nil {
panic(err.Error())
}
return src
}
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
fmt.Printf("# Go %s\n", runtime.Version())
fmt.Printf("#\n")
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
for i := -1; i < reps; i++ {
for _, tc := range testCases {
runtime.GC()
start := time.Now()
iters := uint64(tc.itersUnscaled) * iterscale
numBytes, err := decode(tc.src)
if err != nil {
return err
}
for j := uint64(1); j < iters; j++ {
decode(tc.src)
}
elapsedNanos := time.Since(start)
kbPerS := numBytes * uint64(iters) * 1000000 / uint64(elapsedNanos)
if i < 0 {
continue // Warm up rep.
}
fmt.Printf("Benchmark%-30s %8d %12d ns/op %8d.%03d MB/s\n",
tc.benchname, iters, uint64(elapsedNanos)/iters, kbPerS/1000, kbPerS%1000)
}
}
return nil
}
func decode(src []byte) (numBytes uint64, retErr error) {
m, err := jpeg.Decode(bytes.NewReader(src))
if err != nil {
return 0, err
}
b := m.Bounds()
n := uint64(b.Dx()) * uint64(b.Dy())
// Convert YCbCr to RGBA.
if _, ok := m.(*image.YCbCr); ok {
dst := image.NewRGBA(b)
draw.Draw(dst, b, m, b.Min, draw.Src)
m = dst
}
pix := []byte(nil)
switch m := m.(type) {
case *image.Gray:
n *= 1
case *image.RGBA:
n *= 4
pix = m.Pix
default:
return 0, fmt.Errorf("unexpected image type %T", m)
}
// Convert RGBA => BGRA.
if pix != nil {
for i, iEnd := 0, len(pix)/4; i < iEnd; i += 4 {
pix[(4*i)+0], pix[(4*i)+2] = pix[(4*i)+2], pix[(4*i)+0]
}
}
return n, nil
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2019 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//// 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.
// ----------------
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "bench_rust_jpeg"
version = "0.0.1"
authors = ["Nigel Tao <nigeltao@golang.org>"]
[dependencies]
jpeg-decoder = "0.3"
rustc_version_runtime = "*"
+200
View File
@@ -0,0 +1,200 @@
// 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.
// ----------------
// This program exercises the Rust JPEG decoder at
// https://github.com/image-rs/jpeg-decoder
// which is a popular result for https://crates.io/search?q=jpeg&sort=downloads
//
// Wuffs' C code doesn't depend on Rust per se, but this program gives some
// performance data for specific Rust JPEG implementations. The equivalent Wuffs
// benchmarks (on the same test images) are run via:
//
// wuffs bench std/jpeg
//
// To run this program: "RUSTFLAGS='-C target-cpu=native' cargo run --release"
// from the parent directory (the directory containing the Cargo.toml file).
extern crate jpeg_decoder;
extern crate rustc_version_runtime;
use std::time::Instant;
use std::convert::TryInto;
const ITERSCALE: u64 = 50;
const REPS: u64 = 5;
fn main() {
let version = rustc_version_runtime::version();
print!(
"# Rust {}.{}.{}\n",
version.major, version.minor, version.patch,
);
print!("#\n");
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
let mut dst1 = vec![0u8; 64 * 1024 * 1024];
// The various magic constants below are copied from test/c/std/jpeg.c
for i in 0..(1 + REPS) {
bench(
"19k_8bpp",
&mut dst1[..],
include_bytes!("../../../test/data/bricks-gray.jpeg"),
i == 0, // warm_up
160 * 120 * 1, // want_num_bytes = 19_200
100, // iters_unscaled
);
bench(
"30k_24bpp_progressive",
&mut dst1[..],
include_bytes!("../../../test/data/peacock.progressive.jpeg"),
i == 0, // warm_up
100 * 75 * 4, // want_num_bytes = 30_000
50, // iters_unscaled
);
bench(
"30k_24bpp_sequential",
&mut dst1[..],
include_bytes!("../../../test/data/peacock.default.jpeg"),
i == 0, // warm_up
100 * 75 * 4, // want_num_bytes = 30_000
50, // iters_unscaled
);
bench(
"77k_24bpp",
&mut dst1[..],
include_bytes!("../../../test/data/bricks-color.jpeg"),
i == 0, // warm_up
160 * 120 * 4, // want_num_bytes = 30_000
30, // iters_unscaled
);
bench(
"552k_24bpp_420",
&mut dst1[..],
include_bytes!("../../../test/data/hibiscus.regular.jpeg"),
i == 0, // warm_up
312 * 442 * 4, // want_num_bytes = 551_616
5, // iters_unscaled
);
bench(
"552k_24bpp_444",
&mut dst1[..],
include_bytes!("../../../test/data/hibiscus.primitive.jpeg"),
i == 0, // warm_up
312 * 442 * 4, // want_num_bytes = 551_616
5, // iters_unscaled
);
bench(
"4002k_24bpp",
&mut dst1[..],
include_bytes!("../../../test/data/harvesters.jpeg"),
i == 0, // warm_up
1165 * 859 * 4, // want_num_bytes = 4_002_940
1, // iters_unscaled
);
}
}
fn bench(
name: &str, // Benchmark name.
dst1: &mut [u8], // Destination buffer #1.
src: &[u8], // Source data.
warm_up: bool, // Whether this is a warm up rep.
want_num_bytes: u64, // Expected num_bytes per iteration.
iters_unscaled: u64, // Base number of iterations.
) {
let iters = iters_unscaled * ITERSCALE;
let mut total_num_bytes = 0u64;
let start = Instant::now();
for _ in 0..iters {
let n = decode(&mut dst1[..], src);
if n != want_num_bytes {
panic!("num_bytes: got {}, want {}", n, want_num_bytes);
}
total_num_bytes += n;
}
let elapsed = start.elapsed();
let elapsed_nanos = (elapsed.as_secs() * 1_000_000_000) + (elapsed.subsec_nanos() as u64);
let kb_per_s: u64 = total_num_bytes * 1_000_000 / elapsed_nanos;
if warm_up {
return;
}
print!(
"Benchmarkrust_jpeg_decode_image_{:16} {:8} {:12} ns/op {:3}.{:03} MB/s\n",
name,
iters,
elapsed_nanos / iters,
kb_per_s / 1_000,
kb_per_s % 1_000
);
}
// decode returns the number of bytes processed.
fn decode(dst1: &mut [u8], src: &[u8]) -> u64 {
let mut decoder = jpeg_decoder::Decoder::new(src);
let pixels = decoder.decode().expect("failed to decode image");
let metadata = decoder.info().unwrap();
let w = metadata.width as u64;
let h = metadata.height as u64;
if metadata.pixel_format == jpeg_decoder::PixelFormat::L8 {
// No conversion necessary.
return w * h;
} else if metadata.pixel_format == jpeg_decoder::PixelFormat::RGB24 {
// Convert RGB => BGRA.
rgb_to_bgra(&pixels, &mut dst1[..(w * h * 4) as usize]);
return w * h * 4;
}
// Returning 0 should lead to a panic (when want_num_bytes != 0).
0
}
/// Copy `src` (treated as 3-byte chunks) into `dst`
/// (treated as 4-byte chunks), filling out `dst` by adding
/// a `0xff` "alpha value" at the end of each entry.
///
/// # Panics:
///
/// Will panic if
///
/// * The length of `src` is not a multiple of 3.
/// * The length of `dst` is not a multiple of 4.
/// * `src` and `dst` do not have the same length in chunks.
#[inline]
pub fn rgb_to_bgra(src: &[u8], dst: &mut [u8]) {
let nsrc = src.len();
let ndst = dst.len();
assert_eq!(0, nsrc % 3);
assert_eq!(0, ndst % 4);
assert_eq!(nsrc, (ndst / 4) * 3);
for (s, d) in src.chunks_exact(3).zip(dst.chunks_exact_mut(4)) {
let s: &[u8; 3] = s.try_into().unwrap();
let d: &mut [u8; 4] = d.try_into().unwrap();
// R
d[0] = s[2];
// G
d[1] = s[1];
// B
d[2] = s[0];
// A
d[3] = 0xff;
}
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+13 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
@@ -18,7 +12,7 @@
package main
// checksum.go prints a checksum of stdin's bytes, or of the opening digits of
// π. Checksum algorithms include "adler32" and "crc32/ieee".
// π. Checksum algorithms include "adler32", "crc32/ieee" and "xxhash32".
//
// Usage: go run checksum.go -algorithm=crc32/ieee < foo.bar
@@ -31,6 +25,9 @@ import (
"io"
"os"
"strings"
"github.com/pierrec/xxHash/xxHash32"
"github.com/pierrec/xxHash/xxHash64"
)
var (
@@ -78,6 +75,10 @@ func do(r io.Reader) error {
h = adler32.New()
case "crc32/ieee":
h = crc32.NewIEEE()
case "xxhash32":
h = xxHash32.New(0)
case "xxhash64":
h = xxHash64.New(0)
default:
return fmt.Errorf("unknown algorithm %q", *algorithm)
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+98
View File
@@ -0,0 +1,98 @@
#!/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.
# ----------------
# This script checks that Wuffs's JPEG decoder and djpeg (from libjpeg or
# libjpeg-turbo) produce the same output (using djpeg's default configuration,
# with no further command line arguments).
DJPEG_BINARY=${DJPEG_BINARY:-djpeg}
if [ ! -e wuffs-root-directory.txt ]; then
echo "$0 should be run from the Wuffs root directory."
exit 1
elif [ ! -e gen/bin/example-convert-to-nia ]; then
echo "Run \"./build-example.sh example/convert-to-nia\" first."
exit 1
elif [ ! -e gen/bin/example-crc32 ]; then
echo "Run \"./build-example.sh example/crc32\" first."
exit 1
elif [ -z $(which $DJPEG_BINARY) ]; then
echo "Could not find DJPEG_BINARY \"$DJPEG_BINARY\"."
exit 1
elif [[ ! $($DJPEG_BINARY -version 2>&1 >/dev/null) =~ ^libjpeg ]]; then
echo "Could not get libjpeg version from DJPEG_BINARY \"$DJPEG_BINARY\"."
exit 1
fi
djpeg_version=$($DJPEG_BINARY -version 2>&1 >/dev/null)
if [[ $djpeg_version =~ ^libjpeg.*version.2\.0 ||
$djpeg_version =~ ^libjpeg.*version.2\.1 ||
$djpeg_version =~ ^libjpeg.*version.3\.0\.0 ]]; then
# "Wuffs's std/jpeg matches djpeg" needs these libjpeg-turbo commits:
# - 6d91e950 Use 5x5 win & 9 AC coeffs when smoothing DC scans (in 2.1.0)
# - dbae5928 Fix interblock smoothing with narrow prog. JPEGs (in 3.0.1)
# - 9b704f96 Fix block smoothing w/vert.-subsampled prog. JPEGs (in 3.0.1)
# https://github.com/libjpeg-turbo/libjpeg-turbo/commit/6d91e950c871103a11bac2f10c63bf998796c719
# https://github.com/libjpeg-turbo/libjpeg-turbo/commit/dbae59281fdc6b3a6304a40134e8576d50d662c0
# https://github.com/libjpeg-turbo/libjpeg-turbo/commit/9b704f96b2dccc54363ad7a2fe8e378fc1a2893b
echo "\"$djpeg_version\" too old from DJPEG_BINARY \"$DJPEG_BINARY\"."
exit 1
fi
sources=$@
if [ $# -eq 0 ]; then
sources=test/data/*.jpeg
fi
# ----
result=0
handle() {
local want=$($DJPEG_BINARY $1 2>/dev/null | gen/bin/example-crc32)
if [ "$want" == "00000000" ]; then
return
fi
local have=$(gen/bin/example-convert-to-nia -output-netpbm <$1 2>/dev/null | gen/bin/example-crc32)
if [ "$want" == "$have" ]; then
echo "Match $1"
return
fi
# Image file format specifications cover how to correctly decode complete
# input but usually do not mandate exactly how to decode truncated input.
# Print "trunc" vs "other" to distinguish these cases.
local error=$(gen/bin/example-convert-to-nia -output-netpbm <$1 2>&1 >/dev/null)
if [[ $error =~ :\ truncated.input$ ]]; then
echo "Differ (trunc) $1"
else
echo "Differ (other) $1"
result=1
fi
}
# ----
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
exit $result
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+15 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2023 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -65,7 +59,8 @@
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__GZIP
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
@@ -106,7 +101,7 @@ static const char* //
handle_image_decoder(wuffs_base__io_buffer src,
int32_t fourcc,
bool full_decode) {
wuffs_base__image_decoder::unique_ptr dec(nullptr, &free);
wuffs_base__image_decoder::unique_ptr dec;
switch (fourcc) {
case WUFFS_BASE__FOURCC__BMP:
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
@@ -114,9 +109,15 @@ handle_image_decoder(wuffs_base__io_buffer src,
case WUFFS_BASE__FOURCC__GIF:
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__JPEG:
dec = wuffs_jpeg__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__NIE:
dec = wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__NPBM:
dec = wuffs_netpbm__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__PNG:
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
break;
@@ -176,7 +177,7 @@ handle_image_decoder(wuffs_base__io_buffer src,
static const char* //
handle_io_transformer(wuffs_base__io_buffer src, int32_t fourcc) {
wuffs_base__io_transformer::unique_ptr dec(nullptr, &free);
wuffs_base__io_transformer::unique_ptr dec;
switch (fourcc) {
case WUFFS_BASE__FOURCC__BZ2:
dec = wuffs_bzip2__decoder::alloc_as__wuffs_base__io_transformer();
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+7 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -57,7 +51,8 @@ to use the wuffs_aux C++ API to decode an image and iterate over its pixels.
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+14 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -53,7 +47,8 @@ print-image-metadata prints images' metadata.
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
@@ -368,7 +363,7 @@ handle(const char* filename, FILE* f) {
redirect:
do {
print_fourcc(fourcc);
wuffs_base__image_decoder::unique_ptr dec(nullptr, &free);
wuffs_base__image_decoder::unique_ptr dec;
switch (fourcc) {
case WUFFS_BASE__FOURCC__BMP:
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
@@ -376,9 +371,15 @@ redirect:
case WUFFS_BASE__FOURCC__GIF:
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__JPEG:
dec = wuffs_jpeg__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__NIE:
dec = wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__NPBM:
dec = wuffs_netpbm__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__PNG:
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
break;
+430
View File
@@ -0,0 +1,430 @@
// 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.
//go:build ignore
// +build ignore
package main
// print-jpeg-idct-code.go prints the "func jpeg.decoder.decode_idct" code.
//
// Usage: go run print-jpeg-idct-code.go
import (
"fmt"
"os"
"strings"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
fmt.Printf("// -------- BEGIN generated by script/print-jpeg-idct-code.go\n")
fmt.Println()
fmt.Printf("// p0_298631336 = %s = %10d\n", format8X(p0_298631336), round(p0_298631336))
fmt.Printf("// p0_390180644 = %s = %10d\n", format8X(p0_390180644), round(p0_390180644))
fmt.Printf("// p0_509795579 = %s = %10d\n", format8X(p0_509795579), round(p0_509795579))
fmt.Printf("// p0_541196100 = %s = %10d\n", format8X(p0_541196100), round(p0_541196100))
fmt.Printf("// p0_601344887 = %s = %10d\n", format8X(p0_601344887), round(p0_601344887))
fmt.Printf("// p0_765366865 = %s = %10d\n", format8X(p0_765366865), round(p0_765366865))
fmt.Printf("// p0_785694958 = %s = %10d\n", format8X(p0_785694958), round(p0_785694958))
fmt.Printf("// p0_899976223 = %s = %10d\n", format8X(p0_899976223), round(p0_899976223))
fmt.Printf("// p1_175875602 = %s = %10d\n", format8X(p1_175875602), round(p1_175875602))
fmt.Printf("// p1_306562965 = %s = %10d\n", format8X(p1_306562965), round(p1_306562965))
fmt.Printf("// p1_501321110 = %s = %10d\n", format8X(p1_501321110), round(p1_501321110))
fmt.Printf("// p1_847759065 = %s = %10d\n", format8X(p1_847759065), round(p1_847759065))
fmt.Printf("// p1_961570560 = %s = %10d\n", format8X(p1_961570560), round(p1_961570560))
fmt.Printf("// p2_053119869 = %s = %10d\n", format8X(p2_053119869), round(p2_053119869))
fmt.Printf("// p2_562915447 = %s = %10d\n", format8X(p2_562915447), round(p2_562915447))
fmt.Printf("// p3_072711026 = %s = %10d\n", format8X(p3_072711026), round(p3_072711026))
fmt.Printf("//\n")
fmt.Printf("// m0_390180644 = %s = %10d\n", format8X(m0_390180644), round(m0_390180644))
fmt.Printf("// m0_509795579 = %s = %10d\n", format8X(m0_509795579), round(m0_509795579))
fmt.Printf("// m0_601344887 = %s = %10d\n", format8X(m0_601344887), round(m0_601344887))
fmt.Printf("// m0_785694958 = %s = %10d\n", format8X(m0_785694958), round(m0_785694958))
fmt.Printf("// m0_899976223 = %s = %10d\n", format8X(m0_899976223), round(m0_899976223))
fmt.Printf("// m1_306562965 = %s = %10d\n", format8X(m1_306562965), round(m1_306562965))
fmt.Printf("// m1_961570560 = %s = %10d\n", format8X(m1_961570560), round(m1_961570560))
fmt.Printf("// m2_562915447 = %s = %10d\n", format8X(m2_562915447), round(m2_562915447))
fmt.Println()
for x := 0; x < 8; x++ {
fmt.Println(strings.TrimSpace(replace(pass0, addConsts(map[string]string{
"$colX$": fmt.Sprint(x),
"$row0colX$": fmt.Sprintf("0x%02X", (8*0)|x),
"$row1colX$": fmt.Sprintf("0x%02X", (8*1)|x),
"$row2colX$": fmt.Sprintf("0x%02X", (8*2)|x),
"$row3colX$": fmt.Sprintf("0x%02X", (8*3)|x),
"$row4colX$": fmt.Sprintf("0x%02X", (8*4)|x),
"$row5colX$": fmt.Sprintf("0x%02X", (8*5)|x),
"$row6colX$": fmt.Sprintf("0x%02X", (8*6)|x),
"$row7colX$": fmt.Sprintf("0x%02X", (8*7)|x),
}))))
fmt.Println()
}
for y := 0; y < 8; y++ {
fmt.Println(strings.TrimSpace(replace(pass1, addConsts(map[string]string{
"$rowY$": fmt.Sprint(y),
"$rowYcol0$": fmt.Sprintf("0x%02X", (8*y)|0),
"$rowYcol1$": fmt.Sprintf("0x%02X", (8*y)|1),
"$rowYcol2$": fmt.Sprintf("0x%02X", (8*y)|2),
"$rowYcol3$": fmt.Sprintf("0x%02X", (8*y)|3),
"$rowYcol4$": fmt.Sprintf("0x%02X", (8*y)|4),
"$rowYcol5$": fmt.Sprintf("0x%02X", (8*y)|5),
"$rowYcol6$": fmt.Sprintf("0x%02X", (8*y)|6),
"$rowYcol7$": fmt.Sprintf("0x%02X", (8*y)|7),
"$bounds_check$": boundsCheck(y == 7),
"$advance$": advance(y == 7),
}))))
fmt.Println()
}
fmt.Printf("// -------- END generated by script/print-jpeg-idct-code.go\n")
return nil
}
func replace(s string, m map[string]string) string {
for k, v := range m {
s = strings.ReplaceAll(s, k, v)
}
return s
}
func addConsts(m map[string]string) map[string]string {
m["$p0_298631336$"] = format8X(p0_298631336)
m["$p0_509795579$"] = format8X(p0_509795579)
m["$p0_541196100$"] = format8X(p0_541196100)
m["$p0_601344887$"] = format8X(p0_601344887)
m["$p0_765366865$"] = format8X(p0_765366865)
m["$p0_785694958$"] = format8X(p0_785694958)
m["$p1_175875602$"] = format8X(p1_175875602)
m["$p1_306562965$"] = format8X(p1_306562965)
m["$p1_501321110$"] = format8X(p1_501321110)
m["$p1_847759065$"] = format8X(p1_847759065)
m["$p2_053119869$"] = format8X(p2_053119869)
m["$p3_072711026$"] = format8X(p3_072711026)
m["$m0_390180644$"] = format8X(m0_390180644)
m["$m0_509795579$"] = format8X(m0_509795579)
m["$m0_601344887$"] = format8X(m0_601344887)
m["$m0_785694958$"] = format8X(m0_785694958)
m["$m0_899976223$"] = format8X(m0_899976223)
m["$m1_306562965$"] = format8X(m1_306562965)
m["$m1_961570560$"] = format8X(m1_961570560)
m["$m2_562915447$"] = format8X(m2_562915447)
return m
}
func format8X(x float64) string {
s := fmt.Sprintf("0x%08X", round(x))
return s[:6] + "_" + s[6:]
}
func round(x float64) uint32 {
// Hard-code some rounding errors to match libjpeg-turbo exactly.
//
// For example, p1_306562965 is defined precisely as (sqrt2 * (+cos2pi16)).
// Scaling by 8192 gives 10703.36380826727651620162087671551716... which
// rounds down (as a fixed precision approximation) to 10703 = 0x29CF.
//
// Conceptually, m1_306562965 is the negative of that 0x29CF, but it
// appears in libjpeg-turbo's algorithm as the negative of (p1_847759065 -
// p0_541196100). Those two constants (after scaling by 8192 and rounding
// *separately*) fold as (15137 - 4433) = 0x29D0, differing by 1.
adjustment := int32(0)
switch x {
case p0_509795579:
adjustment = +1
case p0_785694958:
adjustment = +1
case m0_601344887:
adjustment = -1
case m1_306562965:
adjustment = -1
}
return uint32(adjustment) + uint32(0.5+(x*(1<<13)))
}
func boundsCheck(final bool) string {
if final {
return "" +
"if 8 > args.dst_buffer.length() {\n" +
" return nothing\n" +
"}"
}
return "" +
"if args.dst_stride > args.dst_buffer.length() {\n" +
" return nothing\n" +
"}\n" +
`assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)`
}
func advance(final bool) string {
if final {
return ""
}
return "args.dst_buffer = args.dst_buffer[args.dst_stride ..]"
}
const (
sqrt2 = 1.4142135623730950488016887242096980785696718753769480731766797379
// cosNpi16 ≈ cos(N * (pi / 16)).
cos1pi16 = 0.9807852804032304491261822361342390369739337308933360950029160885
cos2pi16 = 0.9238795325112867561281831893967882868224166258636424861150977312
cos3pi16 = 0.8314696123025452370787883776179057567385608119872499634461245902
cos5pi16 = 0.5555702330196022247428308139485328743749371907548040459241535282
cos6pi16 = 0.3826834323650897717284599840303988667613445624856270414338006356
cos7pi16 = 0.1950903220161282678482848684770222409276916177519548077545020894
)
const (
p0_541196100 = sqrt2 * (+cos6pi16)
p0_785694958 = sqrt2 * (+cos5pi16)
p1_175875602 = sqrt2 * (+cos3pi16)
p1_306562965 = sqrt2 * (+cos2pi16)
p0_601344887 = sqrt2 * (+cos1pi16 - cos5pi16)
p0_765366865 = sqrt2 * (+cos2pi16 - cos6pi16)
p1_847759065 = sqrt2 * (+cos2pi16 + cos6pi16)
p0_390180644 = sqrt2 * (+cos3pi16 - cos5pi16)
p0_899976223 = sqrt2 * (+cos3pi16 - cos7pi16)
p1_961570560 = sqrt2 * (+cos3pi16 + cos5pi16)
p2_562915447 = sqrt2 * (+cos3pi16 + cos1pi16)
p0_509795579 = sqrt2 * (+cos5pi16 - cos7pi16)
p0_298631336 = sqrt2 * (-cos1pi16 + cos3pi16 + cos5pi16 - cos7pi16)
p1_501321110 = sqrt2 * (+cos1pi16 + cos3pi16 - cos5pi16 - cos7pi16)
p2_053119869 = sqrt2 * (+cos1pi16 + cos3pi16 - cos5pi16 + cos7pi16)
p3_072711026 = sqrt2 * (+cos1pi16 + cos3pi16 + cos5pi16 - cos7pi16)
m0_390180644 = (1 << (32 - 13)) - p0_390180644
m0_509795579 = (1 << (32 - 13)) - p0_509795579
m0_601344887 = (1 << (32 - 13)) - p0_601344887
m0_785694958 = (1 << (32 - 13)) - p0_785694958
m0_899976223 = (1 << (32 - 13)) - p0_899976223
m1_306562965 = (1 << (32 - 13)) - p1_306562965
m1_961570560 = (1 << (32 - 13)) - p1_961570560
m2_562915447 = (1 << (32 - 13)) - p2_562915447
)
const pass0 = `// ==== First pass, column $colX$.
if (0 == (
this.mcu_blocks[0][$row1colX$] |
this.mcu_blocks[0][$row2colX$] |
this.mcu_blocks[0][$row3colX$] |
this.mcu_blocks[0][$row4colX$] |
this.mcu_blocks[0][$row5colX$] |
this.mcu_blocks[0][$row6colX$] |
this.mcu_blocks[0][$row7colX$])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[$row0colX$] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row0colX$]) ~mod*
(this.quant_tables[args.q][$row0colX$] as base.u32)) ~mod<< 2
intermediate[$row1colX$] = intermediate[$row0colX$]
intermediate[$row2colX$] = intermediate[$row0colX$]
intermediate[$row3colX$] = intermediate[$row0colX$]
intermediate[$row4colX$] = intermediate[$row0colX$]
intermediate[$row5colX$] = intermediate[$row0colX$]
intermediate[$row6colX$] = intermediate[$row0colX$]
intermediate[$row7colX$] = intermediate[$row0colX$]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row2colX$]) ~mod* (this.quant_tables[args.q][$row2colX$] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row6colX$]) ~mod* (this.quant_tables[args.q][$row6colX$] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* $p0_541196100$
cb2 = ca ~mod+ (bq2 ~mod* $p0_765366865$)
cb6 = ca ~mod- (bq6 ~mod* $p1_847759065$)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* $p1_306562965$) ~mod+ (bq6 ~mod* $p0_541196100$)
// cb6 = (bq2 ~mod* $p0_541196100$) ~mod+ (bq6 ~mod* $m1_306562965$)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row0colX$]) ~mod* (this.quant_tables[args.q][$row0colX$] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row4colX$]) ~mod* (this.quant_tables[args.q][$row4colX$] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row1colX$]) ~mod* (this.quant_tables[args.q][$row1colX$] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row3colX$]) ~mod* (this.quant_tables[args.q][$row3colX$] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row5colX$]) ~mod* (this.quant_tables[args.q][$row5colX$] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row7colX$]) ~mod* (this.quant_tables[args.q][$row7colX$] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* $p1_175875602$
ck1 = bq1 ~mod* $p1_501321110$
ck3 = bq3 ~mod* $p3_072711026$
ck5 = bq5 ~mod* $p2_053119869$
ck7 = bq7 ~mod* $p0_298631336$
ci51 ~mod*= $m0_390180644$
ci53 ~mod*= $m2_562915447$
ci71 ~mod*= $m0_899976223$
ci73 ~mod*= $m1_961570560$
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* $m0_785694958$) ~mod+ (ci51 ~mod* $p1_175875602$)
// cl51 = (ci73 ~mod* $p1_175875602$) ~mod+ (ci51 ~mod* $p0_785694958$)
// ck1 = cl51 ~mod+ ((bq1 ~mod* $p0_601344887$) ~mod+ (bq7 ~mod* $m0_899976223$))
// ck3 = cl73 ~mod+ ((bq3 ~mod* $p0_509795579$) ~mod+ (bq5 ~mod* $m2_562915447$))
// ck5 = cl51 ~mod+ ((bq3 ~mod* $m2_562915447$) ~mod+ (bq5 ~mod* $m0_509795579$))
// ck7 = cl73 ~mod+ ((bq1 ~mod* $m0_899976223$) ~mod+ (bq7 ~mod* $m0_601344887$))
// Combine rows.
intermediate[$row0colX$] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[$row7colX$] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[$row1colX$] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[$row6colX$] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[$row2colX$] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[$row5colX$] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[$row3colX$] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[$row4colX$] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
`
const pass1 = `// ==== Second pass, row $rowY$.
if (0 == (
intermediate[$rowYcol1$] |
intermediate[$rowYcol2$] |
intermediate[$rowYcol3$] |
intermediate[$rowYcol4$] |
intermediate[$rowYcol5$] |
intermediate[$rowYcol6$] |
intermediate[$rowYcol7$])) {
// Fast path when the 1-dimensional AC terms are all zero.
$bounds_check$
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[$rowYcol0$] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
$advance$
} else {
// Even columns.
in2 = intermediate[$rowYcol2$]
in6 = intermediate[$rowYcol6$]
// This code...
ra = (in2 ~mod+ in6) ~mod* $p0_541196100$
rb2 = ra ~mod+ (in2 ~mod* $p0_765366865$)
rb6 = ra ~mod- (in6 ~mod* $p1_847759065$)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* $p1_306562965$) ~mod+ (in6 ~mod* $p0_541196100$)
// rb6 = (in2 ~mod* $p0_541196100$) ~mod+ (in6 ~mod* $m1_306562965$)
in0 = intermediate[$rowYcol0$]
in4 = intermediate[$rowYcol4$]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[$rowYcol1$]
in3 = intermediate[$rowYcol3$]
in5 = intermediate[$rowYcol5$]
in7 = intermediate[$rowYcol7$]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* $p1_175875602$
rk1 = in1 ~mod* $p1_501321110$
rk3 = in3 ~mod* $p3_072711026$
rk5 = in5 ~mod* $p2_053119869$
rk7 = in7 ~mod* $p0_298631336$
ri51 ~mod*= $m0_390180644$
ri53 ~mod*= $m2_562915447$
ri71 ~mod*= $m0_899976223$
ri73 ~mod*= $m1_961570560$
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* $m0_785694958$) ~mod+ (ri51 ~mod* $p1_175875602$)
// rl51 = (ri73 ~mod* $p1_175875602$) ~mod+ (ri51 ~mod* $p0_785694958$)
// rk1 = rl51 ~mod+ ((in1 ~mod* $p0_601344887$) ~mod+ (in7 ~mod* $m0_899976223$))
// rk3 = rl73 ~mod+ ((in3 ~mod* $p0_509795579$) ~mod+ (in5 ~mod* $m2_562915447$))
// rk5 = rl51 ~mod+ ((in3 ~mod* $m2_562915447$) ~mod+ (in5 ~mod* $m0_509795579$))
// rk7 = rl73 ~mod+ ((in1 ~mod* $m0_899976223$) ~mod+ (in7 ~mod* $m0_601344887$))
// Combine columns.
$bounds_check$
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
$advance$
}
`
+146
View File
@@ -0,0 +1,146 @@
// 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.
//go:build ignore
// +build ignore
package main
// print-jpeg-markers.go prints a JPEG's markers' position and type.
//
// Usage: go run print-jpeg-markers.go foo.jpeg
import (
"fmt"
"os"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
if len(os.Args) < 2 {
return fmt.Errorf("usage: progname filename.jpeg")
}
src, err := os.ReadFile(os.Args[1])
if err != nil {
return err
}
pos := 0
if len(src) < 2 {
return posError(pos)
}
for pos <= (len(src) - 2) {
if src[pos] != 0xFF {
return posError(pos)
}
marker := src[pos+1]
fmt.Printf("pos = 0x%08X = %10d marker = 0xFF 0x%02X %s\n", pos, pos, marker, names[marker])
pos += 2
switch {
case (0xD0 <= marker) && (marker < 0xD9):
// RSTn (Restart) and SOI (Start Of Image) markers have no payload.
continue
case marker == 0xD9:
// EOI (End Of Image) marker.
return nil
}
if pos >= (len(src) - 2) {
return posError(pos)
}
payloadLength := (int(src[pos]) << 8) | int(src[pos+1])
pos += payloadLength
if (payloadLength < 2) || (pos < 0) || (pos > len(src)) {
return posError(pos)
}
if marker != 0xDA { // SOS (Start Of Scan) marker.
continue
}
for pos < len(src) {
if src[pos] != 0xFF {
pos += 1
} else if pos >= (len(src) - 1) {
return posError(pos)
} else if m := src[pos+1]; (m != 0x00) && ((m < 0xD0) || (0xD7 < m)) {
break
} else {
pos += 2
}
}
}
return posError(pos)
}
func posError(pos int) error {
return fmt.Errorf("invalid JPEG at pos = 0x%08X = %10d", pos, pos)
}
var names = [256]string{
0xC0: "SOF0 (Sequential/Baseline)",
0xC1: "SOF1 (Sequential/Extended)",
0xC2: "SOF2 (Progressive)",
0xC3: "SOF3",
0xC4: "DHT",
0xC5: "SOF5",
0xC6: "SOF6",
0xC7: "SOF7",
0xC8: "JPG",
0xC9: "SOF9",
0xCA: "SOF10",
0xCB: "SOF11",
0xCC: "DAC",
0xCD: "SOF13",
0xCE: "SOF14",
0xCF: "SOF15",
0xD0: "RST0",
0xD1: "RST1",
0xD2: "RST2",
0xD3: "RST3",
0xD4: "RST4",
0xD5: "RST5",
0xD6: "RST6",
0xD7: "RST7",
0xD8: "SOI",
0xD9: "EOI",
0xDA: "SOS",
0xDB: "DQT",
0xDC: "DNL",
0xDD: "DRI",
0xDE: "DHP",
0xDF: "EXP",
0xE0: "APP0",
0xE1: "APP1",
0xE2: "APP2",
0xE3: "APP3",
0xE4: "APP4",
0xE5: "APP5",
0xE6: "APP6",
0xE7: "APP7",
0xE8: "APP8",
0xE9: "APP9",
0xEA: "APP10",
0xEB: "APP11",
0xEC: "APP12",
0xED: "APP13",
0xEE: "APP14",
0xEF: "APP15",
0xFE: "COM",
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+6 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -313,7 +307,7 @@ main1(int argc, char** argv) {
0,
};
for (uint32_t i = 0; quirks[i]; i++) {
wuffs_base__token_decoder__set_quirk_enabled(g_dec, quirks[i], true);
wuffs_base__token_decoder__set_quirk(g_dec, quirks[i], 1);
}
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2021 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2020 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
//go:build ignore
// +build ignore
+107
View File
@@ -0,0 +1,107 @@
// 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.
//go:build ignore
// +build ignore
package main
// truncate-progressive-jpeg.go saves truncated editions of a JPEG, cutting
// just after every SOS (Start Of Scan) marker, appending an EOI (End Of Image)
// marker after the cut.
//
// Usage: go run truncate-progressive-jpeg.go foo.jpeg
import (
"fmt"
"os"
"strings"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
if len(os.Args) < 2 {
return fmt.Errorf("usage: progname filename.jpeg")
}
src, err := os.ReadFile(os.Args[1])
if err != nil {
return err
}
prefix, suffix := os.Args[1], ".jpeg"
if strings.HasSuffix(prefix, ".jpg") {
prefix = prefix[:len(prefix)-4]
suffix = ".jpg"
} else if strings.HasSuffix(prefix, ".jpeg") {
prefix = prefix[:len(prefix)-5]
}
pos := 0
if len(src) < 2 {
return posError(pos)
}
scanNumber := 0
for pos <= (len(src) - 2) {
if src[pos] != 0xFF {
return posError(pos)
}
marker := src[pos+1]
pos += 2
switch {
case (0xD0 <= marker) && (marker < 0xD9):
// RSTn (Restart) and SOI (Start Of Image) markers have no payload.
continue
case marker == 0xD9:
// EOI (End Of Image) marker.
return nil
}
if pos >= (len(src) - 2) {
return posError(pos)
}
payloadLength := (int(src[pos]) << 8) | int(src[pos+1])
pos += payloadLength
if (payloadLength < 2) || (pos < 0) || (pos > len(src)) {
return posError(pos)
}
if marker != 0xDA { // SOS (Start Of Scan) marker.
continue
}
for pos < len(src) {
if src[pos] != 0xFF {
pos += 1
} else if pos >= (len(src) - 1) {
return posError(pos)
} else if m := src[pos+1]; (m != 0x00) && ((m < 0xD0) || (0xD7 < m)) {
break
} else {
pos += 2
}
}
outName := fmt.Sprintf("%s.scan%03d%s", prefix, scanNumber, suffix)
scanNumber++
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 {
return err
}
fmt.Printf("Wrote %s (cut at 0x%08X = %6d bytes).\n", outName, pos, pos)
}
return posError(pos)
}
func posError(pos int) error {
return fmt.Errorf("invalid JPEG at pos = 0x%08X = %10d", pos, pos)
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+23 -16
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// TODO: drop the '?' but still generate wuffs_adler32__hasher__initialize?
pub struct hasher? implements base.hasher_u32(
@@ -18,10 +12,15 @@ pub struct hasher? implements base.hasher_u32(
started : base.bool,
)
pub func hasher.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
pub func hasher.get_quirk(key: base.u32) base.u64 {
return 0
}
pub func hasher.update_u32!(x: slice base.u8) base.u32 {
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) {
if not this.started {
this.started = true
this.state = 1
@@ -34,10 +33,14 @@ pub func hasher.update_u32!(x: slice base.u8) base.u32 {
up_x86_sse42]
}
this.up!(x: args.x)
}
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
this.update!(x: args.x)
return this.state
}
pri func hasher.up!(x: slice base.u8),
pri func hasher.up!(x: roslice base.u8),
choosy,
{
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
@@ -45,8 +48,8 @@ pri func hasher.up!(x: slice base.u8),
var s1 : base.u32
var s2 : base.u32
var remaining : slice base.u8
var p : slice base.u8
var remaining : roslice base.u8
var p : roslice base.u8
s1 = this.state.low_bits(n: 16)
s2 = this.state.high_bits(n: 16)
@@ -69,3 +72,7 @@ pri func hasher.up!(x: slice base.u8),
} endwhile
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
}
pub func hasher.checksum_u32() base.u32 {
return this.state
}
+8 -14
View File
@@ -1,25 +1,19 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func hasher.up_arm_neon!(x: slice base.u8),
pri func hasher.up_arm_neon!(x: roslice base.u8),
choose cpu_arch >= arm_neon,
{
// These variables are the same as the non-SIMD version.
var s1 : base.u32
var s2 : base.u32
var remaining : slice base.u8
var p : slice base.u8
var remaining : roslice base.u8
var p : roslice base.u8
// The remaining variables are specific to the SIMD version.
+8 -14
View File
@@ -1,25 +1,19 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func hasher.up_x86_sse42!(x: slice base.u8),
pri func hasher.up_x86_sse42!(x: roslice base.u8),
choose cpu_arch >= x86_sse42,
{
// These variables are the same as the non-SIMD version.
var s1 : base.u32
var s2 : base.u32
var remaining : slice base.u8
var p : slice base.u8
var remaining : roslice base.u8
var p : roslice base.u8
// The remaining variables are specific to the SIMD version.
+66 -48
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad header"
pub status "#bad RLE compression"
@@ -19,6 +13,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
pri const COMPRESSION_NONE : base.u32 = 0
@@ -31,8 +26,8 @@ pri const COMPRESSION_ALPHABITFIELDS : base.u32 = 6
pri const COMPRESSION_LOW_BIT_DEPTH : base.u32 = 0x100
pub struct decoder? implements base.image_decoder(
width : base.u32[..= 0x7FFF_FFFF],
height : base.u32[..= 0x7FFF_FFFF],
width : base.u32[..= 0xFF_FFFF],
height : base.u32[..= 0xFF_FFFF],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
@@ -72,7 +67,7 @@ pub struct decoder? implements base.image_decoder(
swizzler : base.pixel_swizzler,
util : base.utility,
)(
) + (
// scratch is one of:
// - 2048 bytes = 256 * (8 bytes per BGRA_NONPREMUL_4X16LE).
// - 1024 bytes = 1024 * (1 byte per INDEXED__BGRA_BINARY), plus
@@ -82,7 +77,12 @@ pub struct decoder? implements base.image_decoder(
src_palette : array[4 * 256] base.u8,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
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) {
@@ -130,6 +130,10 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
// Read the BITMAPINFOHEADER:
// - OS/2 is 12, 16 or 64 bytes.
// - Windows is 40, 108 or 124 bytes.
//
// https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
// says that width and height are LONG (signed i32) not DWORD (unsigned
// u32) and hence values above 0x7FFF_FFFF are invalid.
this.bitmap_info_len = args.src.read_u32le?()
if this.padding < this.bitmap_info_len {
@@ -148,13 +152,17 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
} else if this.bitmap_info_len == 16 {
width = args.src.read_u32le?()
if width >= 0x8000_0000 {
if width > 0x7FFF_FFFF {
return "#bad header"
} else if width > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.width = width
height = args.src.read_u32le?()
if height >= 0x8000_0000 {
if height > 0x7FFF_FFFF {
return "#bad header"
} else if height > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.height = height
planes = args.src.read_u16le_as_u32?()
@@ -165,19 +173,25 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
} else {
width = args.src.read_u32le?()
if width >= 0x8000_0000 {
if width > 0x7FFF_FFFF {
return "#bad header"
} else if width > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.width = width
height = args.src.read_u32le?()
if height == 0x8000_0000 {
return "#bad header"
} else if height >= 0x8000_0000 {
// The &0x7FFF_FFFF is redundant, but proves to the compiler that
// the result is within this.height's refined bounds.
this.height = (0 ~mod- height) & 0x7FFF_FFFF
} else if height > 0x8000_0000 {
height = 0 ~mod- height
if height > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.height = height
this.top_down = true
} else if height > 0xFF_FFFF {
return base."#unsupported image dimension"
} else {
this.height = height
}
@@ -502,7 +516,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var src_bytes_per_pixel : base.u32[..= 4]
var dst_palette : slice base.u8
@@ -519,8 +533,8 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
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.scratch[1024 ..])
tab = args.dst.plane(p: 0)
@@ -552,7 +566,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
if i >= dst.length() {
if this.bits_per_pixel > 32 {
return "#unsupported BMP file"
@@ -562,7 +576,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
return "#unsupported BMP file"
}
n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
n = n.min(no_more_than: (this.width ~mod- this.dst_x) as base.u64)
j = n
while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
@@ -606,7 +620,7 @@ pri const RLE_STATE_DELTA_Y : base.u32 = 5
pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var dst_palette : slice base.u8
var tab : table base.u8
@@ -631,8 +645,8 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
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.scratch[1024 ..])
tab = args.dst.plane(p: 0)
@@ -645,7 +659,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
}
while.middle true {
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
if i <= row.length() {
dst = row[i ..]
} else {
@@ -755,7 +769,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
p0 = (p0 & 255) + 0x04
chunk_count -= 1
} endwhile
p0 = p0.min(a: this.rle_length)
p0 = p0.min(no_more_than: this.rle_length)
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst,
dst_palette: dst_palette,
@@ -860,7 +874,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var dst_palette : slice base.u8
var tab : table base.u8
@@ -884,8 +898,8 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
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.scratch[1024 ..])
tab = args.dst.plane(p: 0)
@@ -915,7 +929,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
// -------- BEGIN convert to PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE.
p1_temp = this.width ~mod- this.dst_x
p1 = p1_temp.min(a: 256)
p1 = p1_temp.min(no_more_than: 256)
p0 = 0
while p0 < p1 {
assert p0 < 256 via "a < b: a < c; c <= b"(c: p1)
@@ -967,7 +981,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
if i >= dst.length() {
n = p0 as base.u64
} else {
@@ -989,7 +1003,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var dst_palette : slice base.u8
var tab : table base.u8
@@ -1010,8 +1024,8 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
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.scratch[1024 ..])
tab = args.dst.plane(p: 0)
@@ -1028,7 +1042,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
if i >= dst.length() {
if this.bits_per_pixel == 1 {
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
@@ -1042,12 +1056,12 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
}
while (chunk_count >= 64) and (args.src.length() >= 256) {
args.src.skip_u32_fast!(actual: 256, worst_case: 256)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 64))
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(a: this.dst_x ~mod+ (pixels_per_chunk * 8))
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 {
@@ -1055,7 +1069,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
return "@internal note: short read"
}
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 1))
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 1))
chunk_count -= 1
} endwhile
continue.loop
@@ -1067,7 +1081,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 1 bit per
// pixel there are 32 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
chunk_count = chunk_count.min(a: 16) // Keep p0 <= 512.
chunk_count = chunk_count.min(no_more_than: 16) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
@@ -1111,7 +1125,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 2 bits per
// pixel there are 16 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 15) / 16
chunk_count = chunk_count.min(a: 32) // Keep p0 <= 512.
chunk_count = chunk_count.min(no_more_than: 32) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
@@ -1139,7 +1153,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 4 bits per
// pixel there are 8 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
chunk_count = chunk_count.min(a: 64) // Keep p0 <= 512.
chunk_count = chunk_count.min(no_more_than: 64) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
@@ -1156,7 +1170,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
} endwhile
}
p0 = p0.min(a: this.width ~sat- this.dst_x)
p0 = p0.min(no_more_than: this.width ~sat- this.dst_x)
n = this.swizzler.swizzle_interleaved_from_slice!(
dst: dst,
dst_palette: dst_palette,
@@ -1241,6 +1255,10 @@ 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)
}
+22 -17
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad Huffman code (over-subscribed)"
pub status "#bad Huffman code (under-subscribed)"
@@ -24,9 +18,10 @@ 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
pri const CLAMP_TO_5 : array[8] base.u8[..= 5] = [0, 1, 2, 3, 4, 5, 5, 5]
pri const CLAMP_TO_5 : roarray[8] base.u8[..= 5] = [0, 1, 2, 3, 4, 5, 5, 5]
pub struct decoder? implements base.io_transformer(
bits : base.u32,
@@ -57,7 +52,7 @@ pub struct decoder? implements base.io_transformer(
code_lengths_bitmask : base.u32,
util : base.utility,
)(
) + (
scratch : base.u32,
letter_counts : array[256] base.u32,
@@ -109,10 +104,20 @@ pub struct decoder? implements base.io_transformer(
bwt : array[1_048576] base.u32,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
this.ignore_checksum = args.enabled
pub func decoder.get_quirk(key: base.u32) base.u64 {
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.history_retain_length() base.u64 {
return 0
}
pub func decoder.workbuf_len() base.range_ii_u64 {
@@ -755,7 +760,7 @@ pri func decoder.invert_bwt!() {
// The table below was created by script/print-crc32-magic-numbers.go with the
// -reverse flag set.
pri const REV_CRC32_TABLE : array[256] base.u32 = [
pri const REV_CRC32_TABLE : roarray[256] base.u32 = [
0x0000_0000, 0x04C1_1DB7, 0x0982_3B6E, 0x0D43_26D9, 0x1304_76DC, 0x17C5_6B6B, 0x1A86_4DB2, 0x1E47_5005,
0x2608_EDB8, 0x22C9_F00F, 0x2F8A_D6D6, 0x2B4B_CB61, 0x350C_9B64, 0x31CD_86D3, 0x3C8E_A00A, 0x384F_BDBD,
0x4C11_DB70, 0x48D0_C6C7, 0x4593_E01E, 0x4152_FDA9, 0x5F15_ADAC, 0x5BD4_B01B, 0x5697_96C2, 0x5256_8B75,
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func decoder.flush_fast!(dst: base.io_writer) {
var flush_pointer : base.u32[..= 1_048575]
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func decoder.flush_slow?(dst: base.io_writer) {
var flush_pointer : base.u32[..= 1_048575]
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
var bits : base.u32
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func decoder.decode_huffman_slow?(src: base.io_reader) {
var c : base.u8
+25 -18
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad input"
pub status "#unsupported recursion depth"
@@ -20,6 +14,10 @@ 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
@@ -76,14 +74,14 @@ pub const TOKEN_VALUE_MINOR__TAG : base.u32 = 0x040_0000
// --------
pri const LITERALS : array[4] base.u32[..= 0x1FF_FFFF] = [
pri const LITERALS : roarray[4] base.u32[..= 0x1FF_FFFF] = [
(base.TOKEN__VBC__LITERAL << 21) | base.TOKEN__VBD__LITERAL__FALSE,
(base.TOKEN__VBC__LITERAL << 21) | base.TOKEN__VBD__LITERAL__TRUE,
(base.TOKEN__VBC__LITERAL << 21) | base.TOKEN__VBD__LITERAL__NULL,
(base.TOKEN__VBC__LITERAL << 21) | base.TOKEN__VBD__LITERAL__UNDEFINED,
]
pri const TOKEN_LENGTHS : array[32] base.u8[..= 9] = [
pri const TOKEN_LENGTHS : roarray[32] base.u8[..= 9] = [
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
@@ -94,7 +92,7 @@ pub struct decoder? implements base.token_decoder(
end_of_data : base.bool,
util : base.utility,
)(
) + (
// stack is conceptually an array of 2-bit integers, implemented as an
// array of u32. The N'th 2-bit pair is whether we're in an array or
// object, where N is the recursion depth:
@@ -113,7 +111,16 @@ pub struct decoder? implements base.token_decoder(
container_num_remaining : array[1024] base.u64,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
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.history_retain_length() base.u64 {
return 0
}
pub func decoder.workbuf_len() base.range_ii_u64 {
@@ -258,7 +265,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
// -------- END Major type 0: an unsigned integer.
} else if c_major == 1 {
// -------- END Major type 1: a negative integer.
// -------- BEGIN Major type 1: a negative integer.
if c_minor < 0x1A {
args.dst.write_simple_token_fast!(
value_major: 0,
@@ -329,7 +336,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
yield? base."$short write"
continue
}
n64 = string_length.min(a: args.src.length())
n64 = string_length.min(no_more_than: args.src.length())
token_length = (n64 & 0xFFFF) as base.u32
if n64 > 0xFFFF {
token_length = 0xFFFF
@@ -412,7 +419,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
yield? base."$short write"
continue
}
n64 = string_length.min(a: 0xFFFF)
n64 = string_length.min(no_more_than: 0xFFFF)
n64 = args.src.valid_utf_8_length(up_to: n64)
token_length = (n64 & 0xFFFF) as base.u32
if token_length <= 0 {
+23 -16
View File
@@ -1,29 +1,28 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// TODO: drop the '?' but still generate wuffs_crc32__ieee_hasher__initialize?
pub struct ieee_hasher? implements base.hasher_u32(
state : base.u32,
)
pub func ieee_hasher.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
pub func ieee_hasher.get_quirk(key: base.u32) base.u64 {
return 0
}
pub func ieee_hasher.set_quirk!(key: base.u32, value: base.u64) base.status {
return base."#unsupported option"
}
// TODO: should it be ? instead of ! because it's public, and might need a way
// to signal "initializer not called"? Should the return type, in the generated
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
pub func ieee_hasher.update_u32!(x: slice base.u8) base.u32 {
pub func ieee_hasher.update!(x: roslice base.u8) {
if this.state == 0 {
choose up = [
up_arm_crc32,
@@ -31,14 +30,18 @@ pub func ieee_hasher.update_u32!(x: slice base.u8) base.u32 {
up_x86_sse42]
}
this.up!(x: args.x)
}
pub func ieee_hasher.update_u32!(x: roslice base.u8) base.u32 {
this.update!(x: args.x)
return this.state
}
pri func ieee_hasher.up!(x: slice base.u8),
pri func ieee_hasher.up!(x: roslice base.u8),
choosy,
{
var s : base.u32
var p : slice base.u8
var p : roslice base.u8
s = 0xFFFF_FFFF ^ this.state
@@ -72,9 +75,13 @@ pri func ieee_hasher.up!(x: slice base.u8),
this.state = 0xFFFF_FFFF ^ s
}
pub func ieee_hasher.checksum_u32() base.u32 {
return this.state
}
// The table below was created by script/print-crc32-magic-numbers.go.
pri const IEEE_TABLE : array[16] array[256] base.u32 = [[
pri const IEEE_TABLE : roarray[16] roarray[256] base.u32 = [[
0x0000_0000, 0x7707_3096, 0xEE0E_612C, 0x9909_51BA, 0x076D_C419, 0x706A_F48F, 0xE963_A535, 0x9E64_95A3,
0x0EDB_8832, 0x79DC_B8A4, 0xE0D5_E91E, 0x97D2_D988, 0x09B6_4C2B, 0x7EB1_7CBD, 0xE7B8_2D07, 0x90BF_1D91,
0x1DB7_1064, 0x6AB0_20F2, 0xF3B9_7148, 0x84BE_41DE, 0x1ADA_D47D, 0x6DDD_E4EB, 0xF4D4_B551, 0x83D3_85C7,
+7 -13
View File
@@ -1,21 +1,15 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func ieee_hasher.up_arm_crc32!(x: slice base.u8),
pri func ieee_hasher.up_arm_crc32!(x: roslice base.u8),
choose cpu_arch >= arm_crc32,
{
var p : slice base.u8
var p : roslice base.u8
var util : base.arm_crc32_utility
var s : base.arm_crc32_u32
+7 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
@@ -20,11 +14,11 @@
// 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: slice base.u8),
pri func ieee_hasher.up_x86_avx2!(x: roslice base.u8),
choose cpu_arch >= x86_avx2,
{
var s : base.u32
var p : slice base.u8
var p : roslice base.u8
var util : base.x86_sse42_utility
var k : base.x86_m128i
+11 -17
View File
@@ -1,27 +1,21 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
// 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: slice base.u8),
pri func ieee_hasher.up_x86_sse42!(x: roslice base.u8),
choose cpu_arch >= x86_sse42,
{
var s : base.u32
var p : slice base.u8
var p : roslice base.u8
var util : base.x86_sse42_utility
var k : base.x86_m128i
@@ -140,22 +134,22 @@ pri func ieee_hasher.up_x86_sse42!(x: slice base.u8),
//
// The k6' constant from the Gopal paper is unused.
pri const IEEE_X86_SSE42_K1K2 : array[16] base.u8 = [
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 : array[16] base.u8 = [
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 : array[16] base.u8 = [
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 : array[16] base.u8 = [
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
]
+7 -13
View File
@@ -1,24 +1,18 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// CODE_ORDER is defined in the RFC section 3.2.7.
pri const CODE_ORDER : array[19] base.u8[..= 18] = [
pri const CODE_ORDER : roarray[19] base.u8[..= 18] = [
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
]
// REVERSE8 reverses the bits in a byte.
pri const REVERSE8 : array[256] base.u8 = [
pri const REVERSE8 : roarray[256] base.u8 = [
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
+20 -15
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad Huffman code (over-subscribed)"
pub status "#bad Huffman code (under-subscribed)"
@@ -32,6 +26,8 @@ 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
// TODO: replace the placeholder 1 value with either 0 or (32768 + 512),
// depending on whether we'll move decoder.history into the workbuf.
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
@@ -44,14 +40,14 @@ pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
//
// Some trailing elements are 0x08000000. Bit 27 indicates an invalid value.
pri const LCODE_MAGIC_NUMBERS : array[32] base.u32 = [
pri const LCODE_MAGIC_NUMBERS : roarray[32] base.u32 = [
0x4000_0000, 0x4000_0100, 0x4000_0200, 0x4000_0300, 0x4000_0400, 0x4000_0500, 0x4000_0600, 0x4000_0700,
0x4000_0810, 0x4000_0A10, 0x4000_0C10, 0x4000_0E10, 0x4000_1020, 0x4000_1420, 0x4000_1820, 0x4000_1C20,
0x4000_2030, 0x4000_2830, 0x4000_3030, 0x4000_3830, 0x4000_4040, 0x4000_5040, 0x4000_6040, 0x4000_7040,
0x4000_8050, 0x4000_A050, 0x4000_C050, 0x4000_E050, 0x4000_FF00, 0x0800_0000, 0x0800_0000, 0x0800_0000,
]
pri const DCODE_MAGIC_NUMBERS : array[32] base.u32 = [
pri const DCODE_MAGIC_NUMBERS : roarray[32] base.u32 = [
0x4000_0000, 0x4000_0100, 0x4000_0200, 0x4000_0300, 0x4000_0410, 0x4000_0610, 0x4000_0820, 0x4000_0C20,
0x4000_1030, 0x4000_1830, 0x4000_2040, 0x4000_3040, 0x4000_4050, 0x4000_6050, 0x4000_8060, 0x4000_C060,
0x4001_0070, 0x4001_8070, 0x4002_0080, 0x4003_0080, 0x4004_0090, 0x4006_0090, 0x4008_00A0, 0x400C_00A0,
@@ -91,7 +87,7 @@ pub struct decoder? implements base.io_transformer(
end_of_block : base.bool,
util : base.utility,
)(
) + (
// huffs and n_huffs_bits are the lookup tables for Huffman decodings.
//
// There are up to 2 Huffman decoders active at any one time. As per this
@@ -199,7 +195,16 @@ pub func decoder.add_history!(hist: slice base.u8) {
this.history[0x8000 ..].copy_from_slice!(s: this.history[..])
}
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
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.history_retain_length() base.u64 {
return 0
}
pub func decoder.workbuf_len() base.range_ii_u64 {
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// decode_huffman_bmi2 is exactly the same as decode_huffman_fast64 except for
// the "choose cpu_arch >= x86_bmi2". Unsurprisingly, having Bit Manipulation
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// TODO: describe how the xxx_fastxx version differs from the xxx_slow one, the
// assumptions that xxx_fastxx makes, and how that makes it fast.
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// TODO: describe how the xxx_fastxx version differs from the xxx_slow one, the
// assumptions that xxx_fastxx makes, and how that makes it fast.
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader) {
var bits : base.u32
+15 -21
View File
@@ -1,19 +1,12 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use "std/lzw"
// 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.
pub status "#bad LZW code"
pub status "#bad extension label"
pub status "#bad frame size"
pub status "#bad graphic control"
@@ -22,8 +15,9 @@ pub status "#bad literal width"
pub status "#bad palette"
pub status "#truncated input"
pri status "#internal error: inconsistent ri/wi"
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
// See the spec appendix E "Interlaced Images" on page 29. The first element
@@ -39,26 +33,26 @@ pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
// accessed after all interlace stages are complete. Being the maximum base.u32
// value means that, after all interlace stages are complete, dst_y will be set
// to that maximum value (and therefore outside the frame rect).
pri const INTERLACE_START : array[5] base.u32 = [0xFFFF_FFFF, 1, 2, 4, 0]
pri const INTERLACE_DELTA : array[5] base.u8 = [1, 2, 4, 8, 8]
pri const INTERLACE_COUNT : array[5] base.u8 = [0, 1, 2, 4, 8]
pri const INTERLACE_START : roarray[5] base.u32 = [0xFFFF_FFFF, 1, 2, 4, 0]
pri const INTERLACE_DELTA : roarray[5] base.u8 = [1, 2, 4, 8, 8]
pri const INTERLACE_COUNT : roarray[5] base.u8 = [0, 1, 2, 4, 8]
// ANIMEXTS1DOT0 is "ANIMEXTS1.0" as bytes.
pri const ANIMEXTS1DOT0 : array[11] base.u8 = [
pri const ANIMEXTS1DOT0 : roarray[11] base.u8 = [
0x41, 0x4E, 0x49, 0x4D, 0x45, 0x58, 0x54, 0x53, 0x31, 0x2E, 0x30,
]
// NETSCAPE2DOT0 is "NETSCAPE2.0" as bytes.
pri const NETSCAPE2DOT0 : array[11] base.u8 = [
pri const NETSCAPE2DOT0 : roarray[11] base.u8 = [
0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30,
]
// ICCRGBG1012 Is "ICCRGBG1012" as bytes.
pri const ICCRGBG1012 : array[11] base.u8 = [
pri const ICCRGBG1012 : roarray[11] base.u8 = [
0x49, 0x43, 0x43, 0x52, 0x47, 0x42, 0x47, 0x31, 0x30, 0x31, 0x32,
]
// XMPDATAXMP IS "XMP DataXMP" as bytes.
pri const XMPDATAXMP : array[11] base.u8 = [
pri const XMPDATAXMP : roarray[11] base.u8 = [
0x58, 0x4D, 0x50, 0x20, 0x44, 0x61, 0x74, 0x61, 0x58, 0x4D, 0x50,
]
+115 -73
View File
@@ -1,20 +1,17 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub struct decoder? implements base.image_decoder(
width : base.u32,
height : base.u32,
// These upper bounds should be 0xFFFF, on a strict reading of the GIF
// spec, but our looser implementation uses 0x1_FFFE. See
// test/data/artificial-gif/frame-out-of-bounds.gif.make-artificial.txt
width : base.u32[..= 0x1_FFFE],
height : base.u32[..= 0x1_FFFE],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
@@ -33,9 +30,13 @@ pub struct decoder? implements base.image_decoder(
quirks : array[QUIRKS_COUNT] base.bool,
delayed_num_decoded_frames : base.bool,
previous_lzw_decode_ended_abruptly : base.bool,
seen_header : base.bool,
// This field used to be called "previous_lzw_decode_ended_abruptly".
// It's no longer used, but removing it changes the subsequent field
// offsets, which can worsen the benchmarks.
ignored_but_affects_benchmarks : base.bool,
has_global_palette : base.bool,
// interlace indexes the INTERLACE_START and INTERLACE_DELTA arrays.
@@ -60,10 +61,10 @@ pub struct decoder? implements base.image_decoder(
num_decoded_frame_configs_value : base.u64,
num_decoded_frames_value : base.u64,
frame_rect_x0 : base.u32,
frame_rect_y0 : base.u32,
frame_rect_x1 : base.u32,
frame_rect_y1 : base.u32,
frame_rect_x0 : base.u32[..= 0x0_FFFF],
frame_rect_y0 : base.u32[..= 0x0_FFFF],
frame_rect_x1 : base.u32[..= 0x1_FFFE],
frame_rect_y1 : base.u32[..= 0x1_FFFE],
// The dst_etc fields are the output cursor during copy_to_image_buffer.
dst_x : base.u32,
@@ -76,8 +77,22 @@ pub struct decoder? implements base.image_decoder(
swizzler : base.pixel_swizzler,
lzw_pending_literal_width_plus_one : base.u32[..= 9],
lzw_literal_width : base.u32[..= 8],
lzw_clear_code : base.u32[..= 256],
lzw_end_code : base.u32[..= 257],
lzw_save_code : base.u32[..= 4096],
lzw_prev_code : base.u32[..= 4095],
lzw_width : base.u32[..= 12],
lzw_bits : base.u32,
lzw_n_bits : base.u32[..= 31],
lzw_output_ri : base.u32[..= 8191],
lzw_output_wi : base.u32[..= 8191],
lzw_read_from_return_value : base.u32,
lzw_prefixes : array[4096] base.u16[..= 4095],
util : base.utility,
)(
) + (
compressed : array[4096] base.u8,
// palettes[0] and palettes[1] are the Global and Local Color Table.
@@ -85,16 +100,34 @@ pub struct decoder? implements base.image_decoder(
// dst_palette is the swizzled color table.
dst_palette : array[4 * 256] base.u8,
lzw : lzw.decoder,
lzw_suffixes : array[4096] array[8] base.u8,
lzw_lm1s : array[4096] base.u16,
lzw_output : array[8192 + 7] base.u8,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
if (this.call_sequence == 0x00) and (args.quirk >= QUIRKS_BASE) {
args.quirk -= QUIRKS_BASE
if args.quirk < QUIRKS_COUNT {
this.quirks[args.quirk] = args.enabled
pub func decoder.get_quirk(key: base.u32) base.u64 {
var key : base.u32
if args.key >= QUIRKS_BASE {
key = args.key - QUIRKS_BASE
if key < QUIRKS_COUNT {
if this.quirks[key] {
return 1
}
}
}
return 0
}
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
if (this.call_sequence == 0x00) and (args.key >= QUIRKS_BASE) {
args.key -= QUIRKS_BASE
if args.key < QUIRKS_COUNT {
this.quirks[args.key] = args.value > 0
return ok
}
}
return base."#unsupported option"
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
@@ -289,13 +322,17 @@ pub func decoder.num_decoded_frames() base.u64 {
}
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
// The "foo.min(a:this.width_or_height)" calls clip the nominal frame_rect
// to the image_rect.
// The "foo.min(no_more_than: this.width_or_height)" calls clip the nominal
// frame_rect to the image_rect.
return this.util.make_rect_ie_u32(
min_incl_x: this.frame_rect_x0.min(a: this.width),
min_incl_y: this.frame_rect_y0.min(a: this.height),
max_excl_x: this.frame_rect_x1.min(a: this.width),
max_excl_y: this.dirty_max_excl_y.min(a: this.height))
min_incl_x: this.frame_rect_x0.min(no_more_than: this.width),
min_incl_y: this.frame_rect_y0.min(no_more_than: this.height),
max_excl_x: this.frame_rect_x1.min(no_more_than: this.width),
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 {
@@ -385,13 +422,13 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
// The "foo.min(a:this.width_or_height)" calls clip the nominal
// frame_rect to the image_rect.
// The "foo.min(no_more_than: this.width_or_height)" calls clip the
// nominal frame_rect to the image_rect.
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: this.frame_rect_x0.min(a: this.width),
min_incl_y: this.frame_rect_y0.min(a: this.height),
max_excl_x: this.frame_rect_x1.min(a: this.width),
max_excl_y: this.frame_rect_y1.min(a: this.height)),
min_incl_x: this.frame_rect_x0.min(no_more_than: this.width),
min_incl_y: this.frame_rect_y0.min(no_more_than: this.height),
max_excl_x: this.frame_rect_x1.min(no_more_than: this.width),
max_excl_y: this.frame_rect_y1.min(no_more_than: this.height)),
duration: this.gc_duration,
index: this.num_decoded_frame_configs_value,
io_position: this.frame_config_io_position,
@@ -786,9 +823,9 @@ pri func decoder.decode_id_part0?(src: base.io_reader) {
this.frame_rect_x0 = args.src.read_u16le_as_u32?()
this.frame_rect_y0 = args.src.read_u16le_as_u32?()
this.frame_rect_x1 = args.src.read_u16le_as_u32?()
this.frame_rect_x1 ~mod+= this.frame_rect_x0
this.frame_rect_x1 += this.frame_rect_x0
this.frame_rect_y1 = args.src.read_u16le_as_u32?()
this.frame_rect_y1 ~mod+= this.frame_rect_y0
this.frame_rect_y1 += this.frame_rect_y0
this.dst_x = this.frame_rect_x0
this.dst_y = this.frame_rect_y0
@@ -799,8 +836,8 @@ pri func decoder.decode_id_part0?(src: base.io_reader) {
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for
// more discussion.
if (this.num_decoded_frame_configs_value == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) {
this.width = this.width.max(a: this.frame_rect_x1)
this.height = this.height.max(a: this.frame_rect_y1)
this.width = this.width.max(no_less_than: this.frame_rect_x1)
this.height = this.height.max(no_less_than: this.frame_rect_y1)
}
}
@@ -886,8 +923,8 @@ pri func decoder.decode_id_part1?(dst: ptr base.pixel_buffer, src: base.io_reade
// code (i.e. returning the "ok" status code), the LZW decoder is stuck in
// a coroutine-in-progress lzw_decoder.decode call, still waiting for that
// end code. To cancel that coroutine, we reset the LZW decoder.
if this.previous_lzw_decode_ended_abruptly {
this.lzw.reset!()
if this.ignored_but_affects_benchmarks {
// No-op. This used to be "this.lzw.reset!()".
}
// Process the LZW literal width. The spec says that "images which have one
@@ -897,9 +934,9 @@ pri func decoder.decode_id_part1?(dst: ptr base.pixel_buffer, src: base.io_reade
if lw > 8 {
return "#bad literal width"
}
this.lzw.set_literal_width!(lw: lw as base.u32)
this.lzw_pending_literal_width_plus_one = (1 + lw) as base.u32
this.previous_lzw_decode_ended_abruptly = true
this.ignored_but_affects_benchmarks = true
}
pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reader, workbuf: slice base.u8) {
@@ -909,10 +946,9 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
var n_compressed : base.u64
var r : base.io_reader
var mark : base.u64
var lzw_status : base.status
var copy_status : base.status
var uncompressed : slice base.u8
this.lzw_init!()
need_block_size = true
while.outer true {
if need_block_size {
@@ -931,7 +967,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
this.compressed_wi = 0
}
while this.compressed_wi <= (4096 - 255) {
n_compressed = block_size.min(a: args.src.length())
n_compressed = block_size.min(no_more_than: args.src.length())
if n_compressed <= 0 {
break
}
@@ -953,50 +989,56 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
while.inner true {
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
return "#internal error: inconsistent ri/wi"
return "#internal error: inconsistent I/O"
}
io_bind (io: r, data: this.compressed[this.compressed_ri .. this.compressed_wi], history_position: 0) {
mark = r.mark()
lzw_status =? this.lzw.transform_io?(
dst: this.util.empty_io_writer(), src: r, workbuf: this.util.empty_slice_u8())
this.lzw_read_from!(src: r)
this.compressed_ri ~sat+= r.count_since(mark: mark)
}
uncompressed = this.lzw.flush!()
if uncompressed.length() > 0 {
copy_status = this.copy_to_image_buffer!(pb: args.dst, src: uncompressed)
if this.lzw_output_ri < this.lzw_output_wi {
copy_status = this.copy_to_image_buffer!(
pb: args.dst, src: this.lzw_output[this.lzw_output_ri .. this.lzw_output_wi])
if copy_status.is_error() {
return copy_status
}
this.lzw_output_ri = 0
this.lzw_output_wi = 0
}
if lzw_status.is_ok() {
this.previous_lzw_decode_ended_abruptly = false
if this.lzw_read_from_return_value == 0 {
this.ignored_but_affects_benchmarks = false
// Skip any trailing blocks.
if need_block_size or (block_size > 0) {
args.src.skip_u32?(n: block_size as base.u32)
this.skip_blocks?(src: args.src)
}
break.outer
} else if lzw_status == base."$short read" {
continue.outer
} else if lzw_status == base."$short write" {
} else if this.lzw_read_from_return_value == 1 {
// This is an LZW flush.
continue.inner
} else if this.lzw_read_from_return_value == 2 {
// This is an LZW "$short read" equivalent.
continue.outer
} else if this.quirks[QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA - QUIRKS_BASE] and
(this.dst_y >= this.frame_rect_y1) and (this.interlace == 0) {
// It's invalid LZW-compressed data, but we still have a full
// frame and have opted in to QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA,
// so treat it like the lzw_status.is_ok() case, other than not
// clearing this.previous_lzw_decode_ended_abruptly.
// so treat it like the OK case, other than not clearing
// this.ignored_but_affects_benchmarks.
if need_block_size or (block_size > 0) {
args.src.skip_u32?(n: block_size as base.u32)
this.skip_blocks?(src: args.src)
}
break.outer
} else if this.lzw_read_from_return_value == 3 {
return "#truncated input"
} else if this.lzw_read_from_return_value == 4 {
return "#bad LZW code"
}
return lzw_status
return "#internal error: inconsistent I/O"
} endwhile.inner
} endwhile.outer
@@ -1010,10 +1052,10 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
}
}
pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice base.u8) base.status {
pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: roslice base.u8) base.status {
// TODO: don't assume an interleaved pixel format.
var dst : slice base.u8
var src : slice base.u8
var src : roslice base.u8
var width_in_bytes : base.u64
var n : base.u64
var src_ri : base.u64
@@ -1026,7 +1068,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
var replicate_y0 : base.u32
var replicate_y1 : base.u32
var replicate_dst : slice base.u8
var replicate_src : slice base.u8
var replicate_src : roslice base.u8
// TODO: the pixfmt variable shouldn't be necessary. We should be able to
// chain the two calls: "args.pb.pixel_format().bits_per_pixel()".
@@ -1037,7 +1079,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
}
bytes_per_pixel = bits_per_pixel >> 3
width_in_bytes = (this.width as base.u64) * (bytes_per_pixel as base.u64)
width_in_bytes = (this.width * bytes_per_pixel) as base.u64
tab = args.pb.plane(p: 0)
while src_ri < args.src.length() {
src = args.src[src_ri ..]
@@ -1073,7 +1115,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
this.dirty_max_excl_y = this.dirty_max_excl_y.max(a: this.dst_y ~sat+ 1)
this.dirty_max_excl_y = this.dirty_max_excl_y.max(no_less_than: this.dst_y ~sat+ 1)
}
if this.frame_rect_x1 <= this.dst_x {
@@ -1097,14 +1139,14 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
replicate_src = tab.row_u32(y: this.dst_y)
replicate_y0 = this.dst_y ~sat+ 1
replicate_y1 = this.dst_y ~sat+ (INTERLACE_COUNT[this.interlace] as base.u32)
replicate_y1 = replicate_y1.min(a: this.frame_rect_y1)
replicate_y1 = replicate_y1.min(no_more_than: this.frame_rect_y1)
while replicate_y0 < replicate_y1 {
assert replicate_y0 < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: replicate_y1)
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(a: replicate_y1)
this.dirty_max_excl_y = this.dirty_max_excl_y.max(no_less_than: replicate_y1)
}
this.dst_y ~sat+= INTERLACE_DELTA[this.interlace] as base.u32
@@ -1118,7 +1160,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
if args.src.length() == src_ri {
break
} else if args.src.length() < src_ri {
return "#internal error: inconsistent ri/wi"
return "#internal error: inconsistent I/O"
}
// Second, skip over src for that part of the frame rect that is
@@ -1126,7 +1168,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
// Set n to the number of pixels (i.e. the number of bytes) to skip.
n = (this.frame_rect_x1 - this.dst_x) as base.u64
n = n.min(a: args.src.length() - src_ri)
n = n.min(no_more_than: args.src.length() - src_ri)
src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
@@ -1142,7 +1184,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
}
if src_ri <> args.src.length() {
return "#internal error: inconsistent ri/wi"
return "#internal error: inconsistent I/O"
}
break
} endwhile
+258
View File
@@ -0,0 +1,258 @@
// 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.
// --------
// This file (in std/gif) is a fork of std/lzw/decode_lzw.wuffs, inlined so
// that the gif 'caller' can take the this.lzw_output[this.lzw_output_ri ..
// this.lzw_output_wi] slice directly. Wuffs version 0.3 provided this as the
// lzw.decoder.flush!() method, but we'd like to deprecate (and eventually
// remove) methods that return anything pointer-y (including slices).
//
// It also changes the ? methods to ! methods, so that the LZW-decoder does not
// need a "this.lzw.reset!()" call in case of a recoverable error.
pri func decoder.lzw_init!() {
var i : base.u32[..= 8191]
this.lzw_literal_width = 8
if this.lzw_pending_literal_width_plus_one > 0 {
this.lzw_literal_width = this.lzw_pending_literal_width_plus_one - 1
}
this.lzw_clear_code = (1 as base.u32) << this.lzw_literal_width
this.lzw_end_code = this.lzw_clear_code + 1
this.lzw_save_code = this.lzw_end_code
this.lzw_prev_code = this.lzw_end_code
this.lzw_width = this.lzw_literal_width + 1
this.lzw_bits = 0
this.lzw_n_bits = 0
this.lzw_output_ri = 0
this.lzw_output_wi = 0
i = 0
while i < this.lzw_clear_code {
assert i < 256 via "a < b: a < c; c <= b"(c: this.lzw_clear_code)
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) {
var clear_code : base.u32[..= 256]
var end_code : base.u32[..= 257]
var save_code : base.u32[..= 4096]
var prev_code : base.u32[..= 4095]
var width : base.u32[..= 12]
var bits : base.u32
var n_bits : base.u32[..= 31]
var output_wi : base.u32[..= 8191]
var code : base.u32[..= 4095]
var c : base.u32[..= 4095]
var o : base.u32[..= 8191]
var steps : base.u32
var first_byte : base.u8
var lm1_b : base.u16[..= 4095]
var lm1_a : base.u16[..= 4095]
clear_code = this.lzw_clear_code
end_code = this.lzw_end_code
save_code = this.lzw_save_code
prev_code = this.lzw_prev_code
width = this.lzw_width
bits = this.lzw_bits
n_bits = this.lzw_n_bits
output_wi = this.lzw_output_wi
while true {
if n_bits < width {
assert n_bits < 12 via "a < b: a < c; c <= b"(c: width)
if args.src.length() >= 4 {
// Read 4 bytes, using the "Variant 4" technique of
// https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/
bits |= args.src.peek_u32le() ~mod<< n_bits
args.src.skip_u32_fast!(actual: (31 - n_bits) >> 3, worst_case: 3)
n_bits |= 24
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
assert n_bits >= width via "a >= b: b <= a"()
} else if args.src.length() <= 0 {
if args.src.is_closed() {
this.lzw_read_from_return_value = 3
} else {
this.lzw_read_from_return_value = 2
}
break
} else {
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
n_bits += 8
if n_bits >= width {
// No-op.
} else if args.src.length() <= 0 {
if args.src.is_closed() {
this.lzw_read_from_return_value = 3
} else {
this.lzw_read_from_return_value = 2
}
break
} else {
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
assert n_bits >= width via "a >= b: b <= a"()
// This if condition is always false, but for some unknown
// reason, removing it worsens the benchmarks slightly.
if n_bits < width {
this.lzw_read_from_return_value = 5
break
}
}
}
}
code = bits.low_bits(n: width)
bits >>= width
n_bits -= width
if code < clear_code {
assert code < 256 via "a < b: a < c; c <= b"(c: clear_code)
this.lzw_output[output_wi] = code as base.u8
output_wi = (output_wi + 1) & 8191
if save_code <= 4095 {
lm1_a = (this.lzw_lm1s[prev_code] ~mod+ 1) & 4095
this.lzw_lm1s[save_code] = lm1_a
if (lm1_a % 8) <> 0 {
this.lzw_prefixes[save_code] = this.lzw_prefixes[prev_code]
this.lzw_suffixes[save_code] = this.lzw_suffixes[prev_code]
this.lzw_suffixes[save_code][lm1_a % 8] = code as base.u8
} else {
this.lzw_prefixes[save_code] = prev_code as base.u16
this.lzw_suffixes[save_code][0] = code as base.u8
}
save_code += 1
if width < 12 {
width += 1 & (save_code >> width)
}
prev_code = code
}
} else if code <= end_code {
if code == end_code {
this.lzw_read_from_return_value = 0
break
}
save_code = end_code
prev_code = end_code
width = this.lzw_literal_width + 1
} else if code <= save_code {
c = code
if code == save_code {
c = prev_code
}
// Letting old_wi and new_wi denote the values of output_wi before
// and after these two lines of code, the decoded bytes will be
// written to output[old_wi:new_wi]. They will be written
// back-to-front, 8 bytes at a time, starting by writing
// output[o:o + 8], which will contain output[new_wi - 1].
//
// In the special case that code == save_code, the decoded bytes
// contain an extra copy (at the end) of the first byte, and will
// be written to output[old_wi:new_wi + 1].
o = (output_wi + ((this.lzw_lm1s[c] as base.u32) & 0xFFFF_FFF8)) & 8191
output_wi = (output_wi + 1 + (this.lzw_lm1s[c] as base.u32)) & 8191
steps = (this.lzw_lm1s[c] as base.u32) >> 3
while true {
assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b: 8)
// The final "8" is redundant semantically, but helps the
// wuffs-c code generator recognize that both slices have the
// same constant length, and hence produce efficient C code.
this.lzw_output[o .. o + 8].copy_from_slice!(s: this.lzw_suffixes[c][.. 8])
if steps <= 0 {
break
}
steps -= 1
// This line is essentially "o -= 8". The "& 8191" is a no-op
// 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 {
this.lzw_output[output_wi] = first_byte
output_wi = (output_wi + 1) & 8191
}
if save_code <= 4095 {
lm1_b = (this.lzw_lm1s[prev_code] ~mod+ 1) & 4095
this.lzw_lm1s[save_code] = lm1_b
if (lm1_b % 8) <> 0 {
this.lzw_prefixes[save_code] = this.lzw_prefixes[prev_code]
this.lzw_suffixes[save_code] = this.lzw_suffixes[prev_code]
this.lzw_suffixes[save_code][lm1_b % 8] = first_byte
} else {
this.lzw_prefixes[save_code] = prev_code as base.u16
this.lzw_suffixes[save_code][0] = first_byte as base.u8
}
save_code += 1
if width < 12 {
width += 1 & (save_code >> width)
}
prev_code = code
}
} else {
this.lzw_read_from_return_value = 4
break
}
// Flush the output if it could be too full to contain the entire
// decoding of the next code. The longest possible decoding is slightly
// less than 4096 and output's length is 8192, so a conservative
// threshold is ensuring that output_wi <= 4095.
if output_wi > 4095 {
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.
if this.lzw_read_from_return_value <> 2 {
while n_bits >= 8 {
n_bits -= 8
if args.src.can_undo_byte() {
args.src.undo_byte!()
} else {
this.lzw_read_from_return_value = 5
break
}
} endwhile
}
this.lzw_save_code = save_code
this.lzw_prev_code = prev_code
this.lzw_width = width
this.lzw_bits = bits
this.lzw_n_bits = n_bits
this.lzw_output_wi = output_wi
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
+23 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
use "std/crc32"
use "std/deflate"
@@ -21,6 +15,8 @@ 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
// TODO: reference deflate.DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE.
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
@@ -33,10 +29,23 @@ pub struct decoder? implements base.io_transformer(
util : base.utility,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
this.ignore_checksum = args.enabled
pub func decoder.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.history_retain_length() base.u64 {
return 0
}
pub func decoder.workbuf_len() base.range_ii_u64 {
+5
View File
@@ -0,0 +1,5 @@
# JPEG
JPEG ([Joint Photographic Experts
Group](https://www.w3.org/Graphics/JPEG/itu-t81.pdf)) is a lossy image
compression format for opaque, still images.
+229
View File
@@ -0,0 +1,229 @@
// 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.
// --------
// UNZIG maps from the zig-zag ordering to the natural ordering. Its indices
// start at 1, simplifying while.ac_components loops in decode_mcu_*.wuffs
//
// For example, UNZIG[4] is the column and row of the fourth element in zig-zag
// order. The value is 16, which means first column (16%8 == 0) and third row
// (16/8 == 2).
pri const UNZIG : roarray[80] base.u8[..= 63] = [
0x00,
// The 8x8 indexes are below.
0x00, 0x01, 0x08, 0x10, 0x09, 0x02, 0x03, 0x0A,
0x11, 0x18, 0x20, 0x19, 0x12, 0x0B, 0x04, 0x05,
0x0C, 0x13, 0x1A, 0x21, 0x28, 0x30, 0x29, 0x22,
0x1B, 0x14, 0x0D, 0x06, 0x07, 0x0E, 0x15, 0x1C,
0x23, 0x2A, 0x31, 0x38, 0x39, 0x32, 0x2B, 0x24,
0x1D, 0x16, 0x0F, 0x17, 0x1E, 0x25, 0x2C, 0x33,
0x3A, 0x3B, 0x34, 0x2D, 0x26, 0x1F, 0x27, 0x2E,
0x35, 0x3C, 0x3D, 0x36, 0x2F, 0x37, 0x3E, 0x3F,
// The 15 extra elements are for invalid JPEGs where "the z in UNZIG[z]
// overflows 64, when saving the AC value". This isn't in the spec but
// matches how libjpeg-turbo treats "above 64" ("above 63" in the
// equivalent libjpeg-turbo code, since our UNZIG indices start at 1).
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
]
// BIAS_AND_CLAMP maps 10-bit signed values (0 centered, in the range -512 ..
// +512) to 8-bit unsigned values (128 centered, in the range 0 .. 256).
pri const BIAS_AND_CLAMP : roarray[1024] base.u8 = [
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
]
// EXTEND is a look-up table that helps implement Figure F.12 "Extending the
// sign bit of a decoded value in V".
//
// If ssss is the low 4 bits of the Huffman table's symbol, then EXTEND[ssss]
// is the selectively applied bias for an ssss-bit number arranged so that:
//
// - when ssss=0, the 0-bit number is -0.
// - when ssss=1, the 1-bit numbers are -1, +1.
// - when ssss=2, the 2-bit numbers are -3, -2, +2, +3.
// - when ssss=3, the 3-bit numbers are -7, -6, -5, -4, +4, +5, +6, +7.
// - etc
//
// EXTEND[0] = -0, EXTEND[1] = -1, EXTEND[2] = -3, EXTEND[3] = -7, etc.
//
// It was generated by this Go code (and then wuffsfmt'ed).
//
// --------
//
// package main
//
// import (
// "fmt"
// )
//
// func main() {
// for t := 0; t < 16; t++ {
// // "V = (SLL –1 T) + 1" and SLL is "Shift Left Logical".
// v := (uint16(0xFFFF) << t) + 1
// fmt.Printf("0x%04X,", v)
// if (t & 7) == 7 {
// fmt.Println()
// }
// }
// }
pri const EXTEND : roarray[16] base.u16 = [
0x0000, 0xFFFF, 0xFFFD, 0xFFF9, 0xFFF1, 0xFFE1, 0xFFC1, 0xFF81,
0xFF01, 0xFE01, 0xFC01, 0xF801, 0xF001, 0xE001, 0xC001, 0x8001,
]
// The DEFAULT_HUFF_TABLE_ETC numbers come from section K.3 "Typical Huffman
// tables for 8-bit precision luminance and chrominance" and
// https://github.com/libjpeg-turbo/libjpeg-turbo/commit/a113506d175d03ae0e40965c3d3d21a5d561e119
pri const DEFAULT_HUFF_TABLE_DC_LUMA : roarray[1 + 16 + 12] base.u8 = [
// tc=0, th=0.
0x00,
// 16 counts (totalling 12).
0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
// 12 symbols.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
]
pri const DEFAULT_HUFF_TABLE_DC_CHROMA : roarray[1 + 16 + 12] base.u8 = [
// tc=0, th=1.
0x01,
// 16 counts (totalling 12).
0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
// 12 symbols.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
]
pri const DEFAULT_HUFF_TABLE_AC_LUMA : roarray[1 + 16 + 162] base.u8 = [
// tc=1, th=0.
0x10,
// 16 counts (totalling 162).
0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125,
// 162 symbols.
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08,
0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0,
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16,
0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6,
0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5,
0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4,
0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2,
0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA,
0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
0xF9, 0xFA,
]
pri const DEFAULT_HUFF_TABLE_AC_CHROMA : roarray[1 + 16 + 162] base.u8 = [
// tc=1, th=1.
0x11,
// 16 counts (totalling 162).
0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119,
// 162 symbols.
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0,
0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34,
0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26,
0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38,
0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5,
0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4,
0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3,
0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2,
0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA,
0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9,
0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
0xF9, 0xFA,
]
+1786
View File
@@ -0,0 +1,1786 @@
// 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.
pri func decoder.decode_idct!(dst_buffer: slice base.u8, dst_stride: base.u64, q: base.u32[..= 3]),
choosy,
{
// This method implements the same algorithm as libjpeg-turbo's jidctint.c.
// It defines CONST_BITS = 13 and PASS1_BITS = 2, so that right-shifting by
// 11 is to shift by (CONST_BITS - PASS1_BITS).
var bq0 : base.u32
var bq2 : base.u32
var bq4 : base.u32
var bq6 : base.u32
var ca : base.u32
var cb2 : base.u32
var cb6 : base.u32
var ccp : base.u32
var ccm : base.u32
var cd0 : base.u32
var cd1 : base.u32
var cd2 : base.u32
var cd3 : base.u32
var bq1 : base.u32
var bq3 : base.u32
var bq5 : base.u32
var bq7 : base.u32
var ci51 : base.u32
var ci53 : base.u32
var ci71 : base.u32
var ci73 : base.u32
var cj : base.u32
var ck1 : base.u32
var ck3 : base.u32
var ck5 : base.u32
var ck7 : base.u32
var cl51 : base.u32
var cl73 : base.u32
var in0 : base.u32
var in2 : base.u32
var in4 : base.u32
var in6 : base.u32
var ra : base.u32
var rb2 : base.u32
var rb6 : base.u32
var rcp : base.u32
var rcm : base.u32
var rd0 : base.u32
var rd1 : base.u32
var rd2 : base.u32
var rd3 : base.u32
var in1 : base.u32
var in3 : base.u32
var in5 : base.u32
var in7 : base.u32
var ri51 : base.u32
var ri53 : base.u32
var ri71 : base.u32
var ri73 : base.u32
var rj : base.u32
var rk1 : base.u32
var rk3 : base.u32
var rk5 : base.u32
var rk7 : base.u32
var rl51 : base.u32
var rl73 : base.u32
var intermediate : array[64] base.u32
if 8 > args.dst_stride {
return nothing
}
// -------- BEGIN generated by script/print-jpeg-idct-code.go
// p0_298631336 = 0x0000_098E = 2446
// p0_390180644 = 0x0000_0C7C = 3196
// p0_509795579 = 0x0000_1051 = 4177
// p0_541196100 = 0x0000_1151 = 4433
// p0_601344887 = 0x0000_133E = 4926
// p0_765366865 = 0x0000_187E = 6270
// p0_785694958 = 0x0000_1925 = 6437
// p0_899976223 = 0x0000_1CCD = 7373
// p1_175875602 = 0x0000_25A1 = 9633
// p1_306562965 = 0x0000_29CF = 10703
// p1_501321110 = 0x0000_300B = 12299
// p1_847759065 = 0x0000_3B21 = 15137
// p1_961570560 = 0x0000_3EC5 = 16069
// p2_053119869 = 0x0000_41B3 = 16819
// p2_562915447 = 0x0000_5203 = 20995
// p3_072711026 = 0x0000_6254 = 25172
//
// m0_390180644 = 0xFFFF_F384 = 4294964100
// m0_509795579 = 0xFFFF_EFB0 = 4294963120
// m0_601344887 = 0xFFFF_ECC1 = 4294962369
// m0_785694958 = 0xFFFF_E6DC = 4294960860
// m0_899976223 = 0xFFFF_E333 = 4294959923
// m1_306562965 = 0xFFFF_D630 = 4294956592
// m1_961570560 = 0xFFFF_C13B = 4294951227
// m2_562915447 = 0xFFFF_ADFD = 4294946301
// ==== First pass, column 0.
if (0 == (
this.mcu_blocks[0][0x08] |
this.mcu_blocks[0][0x10] |
this.mcu_blocks[0][0x18] |
this.mcu_blocks[0][0x20] |
this.mcu_blocks[0][0x28] |
this.mcu_blocks[0][0x30] |
this.mcu_blocks[0][0x38])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x00] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x00]) ~mod*
(this.quant_tables[args.q][0x00] as base.u32)) ~mod<< 2
intermediate[0x08] = intermediate[0x00]
intermediate[0x10] = intermediate[0x00]
intermediate[0x18] = intermediate[0x00]
intermediate[0x20] = intermediate[0x00]
intermediate[0x28] = intermediate[0x00]
intermediate[0x30] = intermediate[0x00]
intermediate[0x38] = intermediate[0x00]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x10]) ~mod* (this.quant_tables[args.q][0x10] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x30]) ~mod* (this.quant_tables[args.q][0x30] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x00]) ~mod* (this.quant_tables[args.q][0x00] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x20]) ~mod* (this.quant_tables[args.q][0x20] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x08]) ~mod* (this.quant_tables[args.q][0x08] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x18]) ~mod* (this.quant_tables[args.q][0x18] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x28]) ~mod* (this.quant_tables[args.q][0x28] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x38]) ~mod* (this.quant_tables[args.q][0x38] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x00] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x38] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x08] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x30] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x10] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x28] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x18] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x20] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== First pass, column 1.
if (0 == (
this.mcu_blocks[0][0x09] |
this.mcu_blocks[0][0x11] |
this.mcu_blocks[0][0x19] |
this.mcu_blocks[0][0x21] |
this.mcu_blocks[0][0x29] |
this.mcu_blocks[0][0x31] |
this.mcu_blocks[0][0x39])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x01] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x01]) ~mod*
(this.quant_tables[args.q][0x01] as base.u32)) ~mod<< 2
intermediate[0x09] = intermediate[0x01]
intermediate[0x11] = intermediate[0x01]
intermediate[0x19] = intermediate[0x01]
intermediate[0x21] = intermediate[0x01]
intermediate[0x29] = intermediate[0x01]
intermediate[0x31] = intermediate[0x01]
intermediate[0x39] = intermediate[0x01]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x11]) ~mod* (this.quant_tables[args.q][0x11] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x31]) ~mod* (this.quant_tables[args.q][0x31] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x01]) ~mod* (this.quant_tables[args.q][0x01] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x21]) ~mod* (this.quant_tables[args.q][0x21] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x09]) ~mod* (this.quant_tables[args.q][0x09] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x19]) ~mod* (this.quant_tables[args.q][0x19] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x29]) ~mod* (this.quant_tables[args.q][0x29] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x39]) ~mod* (this.quant_tables[args.q][0x39] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x01] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x39] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x09] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x31] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x11] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x29] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x19] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x21] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== First pass, column 2.
if (0 == (
this.mcu_blocks[0][0x0A] |
this.mcu_blocks[0][0x12] |
this.mcu_blocks[0][0x1A] |
this.mcu_blocks[0][0x22] |
this.mcu_blocks[0][0x2A] |
this.mcu_blocks[0][0x32] |
this.mcu_blocks[0][0x3A])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x02] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x02]) ~mod*
(this.quant_tables[args.q][0x02] as base.u32)) ~mod<< 2
intermediate[0x0A] = intermediate[0x02]
intermediate[0x12] = intermediate[0x02]
intermediate[0x1A] = intermediate[0x02]
intermediate[0x22] = intermediate[0x02]
intermediate[0x2A] = intermediate[0x02]
intermediate[0x32] = intermediate[0x02]
intermediate[0x3A] = intermediate[0x02]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x12]) ~mod* (this.quant_tables[args.q][0x12] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x32]) ~mod* (this.quant_tables[args.q][0x32] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x02]) ~mod* (this.quant_tables[args.q][0x02] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x22]) ~mod* (this.quant_tables[args.q][0x22] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x0A]) ~mod* (this.quant_tables[args.q][0x0A] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x1A]) ~mod* (this.quant_tables[args.q][0x1A] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x2A]) ~mod* (this.quant_tables[args.q][0x2A] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x3A]) ~mod* (this.quant_tables[args.q][0x3A] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x02] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x3A] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x0A] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x32] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x12] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x2A] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x1A] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x22] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== First pass, column 3.
if (0 == (
this.mcu_blocks[0][0x0B] |
this.mcu_blocks[0][0x13] |
this.mcu_blocks[0][0x1B] |
this.mcu_blocks[0][0x23] |
this.mcu_blocks[0][0x2B] |
this.mcu_blocks[0][0x33] |
this.mcu_blocks[0][0x3B])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x03] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x03]) ~mod*
(this.quant_tables[args.q][0x03] as base.u32)) ~mod<< 2
intermediate[0x0B] = intermediate[0x03]
intermediate[0x13] = intermediate[0x03]
intermediate[0x1B] = intermediate[0x03]
intermediate[0x23] = intermediate[0x03]
intermediate[0x2B] = intermediate[0x03]
intermediate[0x33] = intermediate[0x03]
intermediate[0x3B] = intermediate[0x03]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x13]) ~mod* (this.quant_tables[args.q][0x13] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x33]) ~mod* (this.quant_tables[args.q][0x33] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x03]) ~mod* (this.quant_tables[args.q][0x03] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x23]) ~mod* (this.quant_tables[args.q][0x23] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x0B]) ~mod* (this.quant_tables[args.q][0x0B] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x1B]) ~mod* (this.quant_tables[args.q][0x1B] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x2B]) ~mod* (this.quant_tables[args.q][0x2B] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x3B]) ~mod* (this.quant_tables[args.q][0x3B] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x03] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x3B] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x0B] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x33] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x13] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x2B] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x1B] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x23] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== First pass, column 4.
if (0 == (
this.mcu_blocks[0][0x0C] |
this.mcu_blocks[0][0x14] |
this.mcu_blocks[0][0x1C] |
this.mcu_blocks[0][0x24] |
this.mcu_blocks[0][0x2C] |
this.mcu_blocks[0][0x34] |
this.mcu_blocks[0][0x3C])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x04] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x04]) ~mod*
(this.quant_tables[args.q][0x04] as base.u32)) ~mod<< 2
intermediate[0x0C] = intermediate[0x04]
intermediate[0x14] = intermediate[0x04]
intermediate[0x1C] = intermediate[0x04]
intermediate[0x24] = intermediate[0x04]
intermediate[0x2C] = intermediate[0x04]
intermediate[0x34] = intermediate[0x04]
intermediate[0x3C] = intermediate[0x04]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x14]) ~mod* (this.quant_tables[args.q][0x14] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x34]) ~mod* (this.quant_tables[args.q][0x34] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x04]) ~mod* (this.quant_tables[args.q][0x04] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x24]) ~mod* (this.quant_tables[args.q][0x24] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x0C]) ~mod* (this.quant_tables[args.q][0x0C] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x1C]) ~mod* (this.quant_tables[args.q][0x1C] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x2C]) ~mod* (this.quant_tables[args.q][0x2C] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x3C]) ~mod* (this.quant_tables[args.q][0x3C] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x04] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x3C] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x0C] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x34] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x14] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x2C] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x1C] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x24] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== First pass, column 5.
if (0 == (
this.mcu_blocks[0][0x0D] |
this.mcu_blocks[0][0x15] |
this.mcu_blocks[0][0x1D] |
this.mcu_blocks[0][0x25] |
this.mcu_blocks[0][0x2D] |
this.mcu_blocks[0][0x35] |
this.mcu_blocks[0][0x3D])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x05] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x05]) ~mod*
(this.quant_tables[args.q][0x05] as base.u32)) ~mod<< 2
intermediate[0x0D] = intermediate[0x05]
intermediate[0x15] = intermediate[0x05]
intermediate[0x1D] = intermediate[0x05]
intermediate[0x25] = intermediate[0x05]
intermediate[0x2D] = intermediate[0x05]
intermediate[0x35] = intermediate[0x05]
intermediate[0x3D] = intermediate[0x05]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x15]) ~mod* (this.quant_tables[args.q][0x15] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x35]) ~mod* (this.quant_tables[args.q][0x35] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x05]) ~mod* (this.quant_tables[args.q][0x05] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x25]) ~mod* (this.quant_tables[args.q][0x25] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x0D]) ~mod* (this.quant_tables[args.q][0x0D] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x1D]) ~mod* (this.quant_tables[args.q][0x1D] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x2D]) ~mod* (this.quant_tables[args.q][0x2D] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x3D]) ~mod* (this.quant_tables[args.q][0x3D] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x05] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x3D] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x0D] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x35] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x15] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x2D] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x1D] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x25] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== First pass, column 6.
if (0 == (
this.mcu_blocks[0][0x0E] |
this.mcu_blocks[0][0x16] |
this.mcu_blocks[0][0x1E] |
this.mcu_blocks[0][0x26] |
this.mcu_blocks[0][0x2E] |
this.mcu_blocks[0][0x36] |
this.mcu_blocks[0][0x3E])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x06] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x06]) ~mod*
(this.quant_tables[args.q][0x06] as base.u32)) ~mod<< 2
intermediate[0x0E] = intermediate[0x06]
intermediate[0x16] = intermediate[0x06]
intermediate[0x1E] = intermediate[0x06]
intermediate[0x26] = intermediate[0x06]
intermediate[0x2E] = intermediate[0x06]
intermediate[0x36] = intermediate[0x06]
intermediate[0x3E] = intermediate[0x06]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x16]) ~mod* (this.quant_tables[args.q][0x16] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x36]) ~mod* (this.quant_tables[args.q][0x36] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x06]) ~mod* (this.quant_tables[args.q][0x06] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x26]) ~mod* (this.quant_tables[args.q][0x26] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x0E]) ~mod* (this.quant_tables[args.q][0x0E] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x1E]) ~mod* (this.quant_tables[args.q][0x1E] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x2E]) ~mod* (this.quant_tables[args.q][0x2E] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x3E]) ~mod* (this.quant_tables[args.q][0x3E] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x06] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x3E] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x0E] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x36] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x16] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x2E] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x1E] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x26] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== First pass, column 7.
if (0 == (
this.mcu_blocks[0][0x0F] |
this.mcu_blocks[0][0x17] |
this.mcu_blocks[0][0x1F] |
this.mcu_blocks[0][0x27] |
this.mcu_blocks[0][0x2F] |
this.mcu_blocks[0][0x37] |
this.mcu_blocks[0][0x3F])) {
// Fast path when the 1-dimensional AC terms are all zero.
intermediate[0x07] =
(this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x07]) ~mod*
(this.quant_tables[args.q][0x07] as base.u32)) ~mod<< 2
intermediate[0x0F] = intermediate[0x07]
intermediate[0x17] = intermediate[0x07]
intermediate[0x1F] = intermediate[0x07]
intermediate[0x27] = intermediate[0x07]
intermediate[0x2F] = intermediate[0x07]
intermediate[0x37] = intermediate[0x07]
intermediate[0x3F] = intermediate[0x07]
} else {
// Even rows.
bq2 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x17]) ~mod* (this.quant_tables[args.q][0x17] as base.u32)
bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x37]) ~mod* (this.quant_tables[args.q][0x37] as base.u32)
// This code...
ca = (bq2 ~mod+ bq6) ~mod* 0x0000_1151
cb2 = ca ~mod+ (bq2 ~mod* 0x0000_187E)
cb6 = ca ~mod- (bq6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
bq0 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x07]) ~mod* (this.quant_tables[args.q][0x07] as base.u32)
bq4 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x27]) ~mod* (this.quant_tables[args.q][0x27] as base.u32)
ccp = (bq0 ~mod+ bq4) ~mod<< 13
ccm = (bq0 ~mod- bq4) ~mod<< 13
cd0 = ccp ~mod+ cb2
cd1 = ccm ~mod+ cb6
cd2 = ccm ~mod- cb6
cd3 = ccp ~mod- cb2
// Odd rows.
bq1 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x0F]) ~mod* (this.quant_tables[args.q][0x0F] as base.u32)
bq3 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x1F]) ~mod* (this.quant_tables[args.q][0x1F] as base.u32)
bq5 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x2F]) ~mod* (this.quant_tables[args.q][0x2F] as base.u32)
bq7 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][0x3F]) ~mod* (this.quant_tables[args.q][0x3F] as base.u32)
ci51 = bq5 ~mod+ bq1
ci53 = bq5 ~mod+ bq3
ci71 = bq7 ~mod+ bq1
ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* 0x0000_25A1
ck1 = bq1 ~mod* 0x0000_300B
ck3 = bq3 ~mod* 0x0000_6254
ck5 = bq5 ~mod* 0x0000_41B3
ck7 = bq7 ~mod* 0x0000_098E
ci51 ~mod*= 0xFFFF_F384
ci53 ~mod*= 0xFFFF_ADFD
ci71 ~mod*= 0xFFFF_E333
ci73 ~mod*= 0xFFFF_C13B
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
// Combine rows.
intermediate[0x07] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x3F] = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
intermediate[0x0F] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x37] = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
intermediate[0x17] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x2F] = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
intermediate[0x1F] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
intermediate[0x27] = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
}
// ==== Second pass, row 0.
if (0 == (
intermediate[0x01] |
intermediate[0x02] |
intermediate[0x03] |
intermediate[0x04] |
intermediate[0x05] |
intermediate[0x06] |
intermediate[0x07])) {
// Fast path when the 1-dimensional AC terms are all zero.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x00] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
} else {
// Even columns.
in2 = intermediate[0x02]
in6 = intermediate[0x06]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x00]
in4 = intermediate[0x04]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x01]
in3 = intermediate[0x03]
in5 = intermediate[0x05]
in7 = intermediate[0x07]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
}
// ==== Second pass, row 1.
if (0 == (
intermediate[0x09] |
intermediate[0x0A] |
intermediate[0x0B] |
intermediate[0x0C] |
intermediate[0x0D] |
intermediate[0x0E] |
intermediate[0x0F])) {
// Fast path when the 1-dimensional AC terms are all zero.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x08] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
} else {
// Even columns.
in2 = intermediate[0x0A]
in6 = intermediate[0x0E]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x08]
in4 = intermediate[0x0C]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x09]
in3 = intermediate[0x0B]
in5 = intermediate[0x0D]
in7 = intermediate[0x0F]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
}
// ==== Second pass, row 2.
if (0 == (
intermediate[0x11] |
intermediate[0x12] |
intermediate[0x13] |
intermediate[0x14] |
intermediate[0x15] |
intermediate[0x16] |
intermediate[0x17])) {
// Fast path when the 1-dimensional AC terms are all zero.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x10] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
} else {
// Even columns.
in2 = intermediate[0x12]
in6 = intermediate[0x16]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x10]
in4 = intermediate[0x14]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x11]
in3 = intermediate[0x13]
in5 = intermediate[0x15]
in7 = intermediate[0x17]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
}
// ==== Second pass, row 3.
if (0 == (
intermediate[0x19] |
intermediate[0x1A] |
intermediate[0x1B] |
intermediate[0x1C] |
intermediate[0x1D] |
intermediate[0x1E] |
intermediate[0x1F])) {
// Fast path when the 1-dimensional AC terms are all zero.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x18] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
} else {
// Even columns.
in2 = intermediate[0x1A]
in6 = intermediate[0x1E]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x18]
in4 = intermediate[0x1C]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x19]
in3 = intermediate[0x1B]
in5 = intermediate[0x1D]
in7 = intermediate[0x1F]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
}
// ==== Second pass, row 4.
if (0 == (
intermediate[0x21] |
intermediate[0x22] |
intermediate[0x23] |
intermediate[0x24] |
intermediate[0x25] |
intermediate[0x26] |
intermediate[0x27])) {
// Fast path when the 1-dimensional AC terms are all zero.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x20] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
} else {
// Even columns.
in2 = intermediate[0x22]
in6 = intermediate[0x26]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x20]
in4 = intermediate[0x24]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x21]
in3 = intermediate[0x23]
in5 = intermediate[0x25]
in7 = intermediate[0x27]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
}
// ==== Second pass, row 5.
if (0 == (
intermediate[0x29] |
intermediate[0x2A] |
intermediate[0x2B] |
intermediate[0x2C] |
intermediate[0x2D] |
intermediate[0x2E] |
intermediate[0x2F])) {
// Fast path when the 1-dimensional AC terms are all zero.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x28] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
} else {
// Even columns.
in2 = intermediate[0x2A]
in6 = intermediate[0x2E]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x28]
in4 = intermediate[0x2C]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x29]
in3 = intermediate[0x2B]
in5 = intermediate[0x2D]
in7 = intermediate[0x2F]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
}
// ==== Second pass, row 6.
if (0 == (
intermediate[0x31] |
intermediate[0x32] |
intermediate[0x33] |
intermediate[0x34] |
intermediate[0x35] |
intermediate[0x36] |
intermediate[0x37])) {
// Fast path when the 1-dimensional AC terms are all zero.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x30] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
} else {
// Even columns.
in2 = intermediate[0x32]
in6 = intermediate[0x36]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x30]
in4 = intermediate[0x34]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x31]
in3 = intermediate[0x33]
in5 = intermediate[0x35]
in7 = intermediate[0x37]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer = args.dst_buffer[args.dst_stride ..]
}
// ==== Second pass, row 7.
if (0 == (
intermediate[0x39] |
intermediate[0x3A] |
intermediate[0x3B] |
intermediate[0x3C] |
intermediate[0x3D] |
intermediate[0x3E] |
intermediate[0x3F])) {
// Fast path when the 1-dimensional AC terms are all zero.
if 8 > args.dst_buffer.length() {
return nothing
}
args.dst_buffer[0] = BIAS_AND_CLAMP[((intermediate[0x38] ~mod+ (1 << 4)) >> 5) & 1023]
args.dst_buffer[1] = args.dst_buffer[0]
args.dst_buffer[2] = args.dst_buffer[0]
args.dst_buffer[3] = args.dst_buffer[0]
args.dst_buffer[4] = args.dst_buffer[0]
args.dst_buffer[5] = args.dst_buffer[0]
args.dst_buffer[6] = args.dst_buffer[0]
args.dst_buffer[7] = args.dst_buffer[0]
} else {
// Even columns.
in2 = intermediate[0x3A]
in6 = intermediate[0x3E]
// This code...
ra = (in2 ~mod+ in6) ~mod* 0x0000_1151
rb2 = ra ~mod+ (in2 ~mod* 0x0000_187E)
rb6 = ra ~mod- (in6 ~mod* 0x0000_3B21)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
in0 = intermediate[0x38]
in4 = intermediate[0x3C]
rcp = (in0 ~mod+ in4) ~mod<< 13
rcm = (in0 ~mod- in4) ~mod<< 13
rd0 = rcp ~mod+ rb2
rd1 = rcm ~mod+ rb6
rd2 = rcm ~mod- rb6
rd3 = rcp ~mod- rb2
// Odd columns.
in1 = intermediate[0x39]
in3 = intermediate[0x3B]
in5 = intermediate[0x3D]
in7 = intermediate[0x3F]
ri51 = in5 ~mod+ in1
ri53 = in5 ~mod+ in3
ri71 = in7 ~mod+ in1
ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* 0x0000_25A1
rk1 = in1 ~mod* 0x0000_300B
rk3 = in3 ~mod* 0x0000_6254
rk5 = in5 ~mod* 0x0000_41B3
rk7 = in7 ~mod* 0x0000_098E
ri51 ~mod*= 0xFFFF_F384
ri53 ~mod*= 0xFFFF_ADFD
ri71 ~mod*= 0xFFFF_E333
ri73 ~mod*= 0xFFFF_C13B
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
// Combine columns.
if 8 > args.dst_buffer.length() {
return nothing
}
args.dst_buffer[0] = BIAS_AND_CLAMP[(((rd0 ~mod+ rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[7] = BIAS_AND_CLAMP[(((rd0 ~mod- rk1) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[1] = BIAS_AND_CLAMP[(((rd1 ~mod+ rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[6] = BIAS_AND_CLAMP[(((rd1 ~mod- rk3) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[2] = BIAS_AND_CLAMP[(((rd2 ~mod+ rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[5] = BIAS_AND_CLAMP[(((rd2 ~mod- rk5) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[3] = BIAS_AND_CLAMP[(((rd3 ~mod+ rk7) ~mod+ (1 << 17)) >> 18) & 1023]
args.dst_buffer[4] = BIAS_AND_CLAMP[(((rd3 ~mod- rk7) ~mod+ (1 << 17)) >> 18) & 1023]
}
// -------- END generated by script/print-jpeg-idct-code.go
}
+928
View File
@@ -0,0 +1,928 @@
// 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.
pri func decoder.decode_idct_x86_avx2!(dst_buffer: slice base.u8, dst_stride: base.u64, q: base.u32[..= 3]),
choose cpu_arch >= x86_avx2,
{
var sse42_util : base.x86_sse42_utility
var util : base.x86_avx2_utility
// SIMD constants.
var k_0000 : base.x86_m256i
var k_8080 : base.x86_m256i
var k_0000_0002 : base.x86_m256i
var k_0001_FFFF : base.x86_m256i
var k_0400_0000 : base.x86_m256i
var k_29CF_1151_D630_1151 : base.x86_m256i
var k_E333_133E_ADFD_1051 : base.x86_m256i
var k_E6DC_25A1_1925_25A1 : base.x86_m256i
var k_ECC1_E333_EFB0_ADFD : base.x86_m256i
// "Are the AC terms zero" variable names start with "az_".
var az_coeffs : base.x86_m128i
var az_ah00 : base.x86_m256i
var az_ad00 : base.x86_m256i
var az_eh00 : base.x86_m256i
var az_adeh : base.x86_m256i
// Set up variables.
var rows01 : base.x86_m256i
var rows23 : base.x86_m256i
var rows45 : base.x86_m256i
var rows67 : base.x86_m256i
var quants01 : base.x86_m256i
var quants23 : base.x86_m256i
var quants45 : base.x86_m256i
var quants67 : base.x86_m256i
var rows04 : base.x86_m256i
var rows31 : base.x86_m256i
var rows26 : base.x86_m256i
var rows75 : base.x86_m256i
// First pass variable names start with "fp_".
var fp_rows62 : base.x86_m256i
var fp_bq2662ad : base.x86_m256i
var fp_bq2662eh : base.x86_m256i
var fp_cb26ad : base.x86_m256i
var fp_cb26eh : base.x86_m256i
var fp_rows40pos : base.x86_m256i
var fp_rows04neg : base.x86_m256i
var fp_rows0pm4 : base.x86_m256i
var fp_ccpmad : base.x86_m256i
var fp_ccpmeh : base.x86_m256i
var fp_cd01ad : base.x86_m256i
var fp_cd01eh : base.x86_m256i
var fp_cd32ad : base.x86_m256i
var fp_cd32eh : base.x86_m256i
var fp_sums7351 : base.x86_m256i
var fp_sums5173 : base.x86_m256i
var fp_ci73515173ad : base.x86_m256i
var fp_ci73515173eh : base.x86_m256i
var fp_cl7351ad : base.x86_m256i
var fp_cl7351eh : base.x86_m256i
var fp_rows13 : base.x86_m256i
var fp_bq7153ad : base.x86_m256i
var fp_bq7153eh : base.x86_m256i
var fp_ck75ad : base.x86_m256i
var fp_ck75eh : base.x86_m256i
var fp_cl5173ad : base.x86_m256i
var fp_cl5173eh : base.x86_m256i
var fp_ck13ad : base.x86_m256i
var fp_ck13eh : base.x86_m256i
// Intermediate variables between first and second pass.
var intermediate01ad : base.x86_m256i
var intermediate01eh : base.x86_m256i
var intermediate01 : base.x86_m256i
var intermediate32ad : base.x86_m256i
var intermediate32eh : base.x86_m256i
var intermediate32 : base.x86_m256i
var intermediate45ad : base.x86_m256i
var intermediate45eh : base.x86_m256i
var intermediate45 : base.x86_m256i
var intermediate76ad : base.x86_m256i
var intermediate76eh : base.x86_m256i
var intermediate76 : base.x86_m256i
var ita0a1e0e1 : base.x86_m256i
var ita2a3e2e3 : base.x86_m256i
var ita4a5e4e5 : base.x86_m256i
var ita6a7e6e7 : base.x86_m256i
var ita0c0e0g0 : base.x86_m256i
var ita1c1e1g1 : base.x86_m256i
var ita4c4e4g4 : base.x86_m256i
var ita5c5e5g5 : base.x86_m256i
var ita0b0e0f0 : base.x86_m256i
var ita4b4e4f4 : base.x86_m256i
var itc0d0g0h0 : base.x86_m256i
var itc4d4g4h4 : base.x86_m256i
var intermediateae : base.x86_m256i
var intermediatebf : base.x86_m256i
var intermediatecg : base.x86_m256i
var intermediatedh : base.x86_m256i
var intermediatedb : base.x86_m256i
var intermediatehf : base.x86_m256i
// Second pass variable names start with "sp_".
var sp_cols62 : base.x86_m256i
var sp_bq2662ad : base.x86_m256i
var sp_bq2662eh : base.x86_m256i
var sp_rb26ad : base.x86_m256i
var sp_rb26eh : base.x86_m256i
var sp_cols40pos : base.x86_m256i
var sp_cols04neg : base.x86_m256i
var sp_cols0pm4 : base.x86_m256i
var sp_rcpmad : base.x86_m256i
var sp_rcpmeh : base.x86_m256i
var sp_rd01ad : base.x86_m256i
var sp_rd01eh : base.x86_m256i
var sp_rd32ad : base.x86_m256i
var sp_rd32eh : base.x86_m256i
var sp_sums7351 : base.x86_m256i
var sp_sums5173 : base.x86_m256i
var sp_ri73515173ad : base.x86_m256i
var sp_ri73515173eh : base.x86_m256i
var sp_rl7351ad : base.x86_m256i
var sp_rl7351eh : base.x86_m256i
var sp_cols13 : base.x86_m256i
var sp_bq7153ad : base.x86_m256i
var sp_bq7153eh : base.x86_m256i
var sp_rk75ad : base.x86_m256i
var sp_rk75eh : base.x86_m256i
var sp_rl5173ad : base.x86_m256i
var sp_rl5173eh : base.x86_m256i
var sp_rk13ad : base.x86_m256i
var sp_rk13eh : base.x86_m256i
// Final variables.
var final01ad : base.x86_m256i
var final01eh : base.x86_m256i
var final01 : base.x86_m256i
var final32ad : base.x86_m256i
var final32eh : base.x86_m256i
var final32 : base.x86_m256i
var final45ad : base.x86_m256i
var final45eh : base.x86_m256i
var final45 : base.x86_m256i
var final76ad : base.x86_m256i
var final76eh : base.x86_m256i
var final76 : base.x86_m256i
var fta0a1e0e1 : base.x86_m256i
var fta2a3e2e3 : base.x86_m256i
var fta4a5e4e5 : base.x86_m256i
var fta6a7e6e7 : base.x86_m256i
var fta0c0e0g0 : base.x86_m256i
var fta1c1e1g1 : base.x86_m256i
var fta4c4e4g4 : base.x86_m256i
var fta5c5e5g5 : base.x86_m256i
var fta0b0e0f0 : base.x86_m256i
var ftc0d0g0h0 : base.x86_m256i
var fta4b4e4f4 : base.x86_m256i
var ftc4d4g4h4 : base.x86_m256i
var finalae : base.x86_m256i
var finalbf : base.x86_m256i
var finalcg : base.x86_m256i
var finaldh : base.x86_m256i
var final0145 : base.x86_m256i
var final2367 : base.x86_m256i
var final0 : base.u64
var final1 : base.u64
var final2 : base.u64
var final3 : base.u64
var final4 : base.u64
var final5 : base.u64
var final6 : base.u64
var final7 : base.u64
var remaining : slice base.u8
// ----
if 8 > args.dst_stride {
return nothing
}
k_0000 = util.make_m256i_multiple_u16(
a00: 0x0000, a01: 0x0000, a02: 0x0000, a03: 0x0000,
a04: 0x0000, a05: 0x0000, a06: 0x0000, a07: 0x0000,
a08: 0x0000, a09: 0x0000, a10: 0x0000, a11: 0x0000,
a12: 0x0000, a13: 0x0000, a14: 0x0000, a15: 0x0000)
k_8080 = util.make_m256i_multiple_u16(
a00: 0x8080, a01: 0x8080, a02: 0x8080, a03: 0x8080,
a04: 0x8080, a05: 0x8080, a06: 0x8080, a07: 0x8080,
a08: 0x8080, a09: 0x8080, a10: 0x8080, a11: 0x8080,
a12: 0x8080, a13: 0x8080, a14: 0x8080, a15: 0x8080)
k_0000_0002 = util.make_m256i_multiple_u16(
a00: 0x0000, a01: 0x0002, a02: 0x0000, a03: 0x0002,
a04: 0x0000, a05: 0x0002, a06: 0x0000, a07: 0x0002,
a08: 0x0000, a09: 0x0002, a10: 0x0000, a11: 0x0002,
a12: 0x0000, a13: 0x0002, a14: 0x0000, a15: 0x0002)
k_0001_FFFF = util.make_m256i_multiple_u16(
a00: 0x0001, a01: 0x0001, a02: 0x0001, a03: 0x0001,
a04: 0x0001, a05: 0x0001, a06: 0x0001, a07: 0x0001,
a08: 0xFFFF, a09: 0xFFFF, a10: 0xFFFF, a11: 0xFFFF,
a12: 0xFFFF, a13: 0xFFFF, a14: 0xFFFF, a15: 0xFFFF)
k_0400_0000 = util.make_m256i_multiple_u16(
a00: 0x0400, a01: 0x0000, a02: 0x0400, a03: 0x0000,
a04: 0x0400, a05: 0x0000, a06: 0x0400, a07: 0x0000,
a08: 0x0400, a09: 0x0000, a10: 0x0400, a11: 0x0000,
a12: 0x0400, a13: 0x0000, a14: 0x0400, a15: 0x0000)
k_29CF_1151_D630_1151 = util.make_m256i_multiple_u16(
a00: 0x29CF, a01: 0x1151, a02: 0x29CF, a03: 0x1151,
a04: 0x29CF, a05: 0x1151, a06: 0x29CF, a07: 0x1151,
a08: 0xD630, a09: 0x1151, a10: 0xD630, a11: 0x1151,
a12: 0xD630, a13: 0x1151, a14: 0xD630, a15: 0x1151)
k_E333_133E_ADFD_1051 = util.make_m256i_multiple_u16(
a00: 0xE333, a01: 0x133E, a02: 0xE333, a03: 0x133E,
a04: 0xE333, a05: 0x133E, a06: 0xE333, a07: 0x133E,
a08: 0xADFD, a09: 0x1051, a10: 0xADFD, a11: 0x1051,
a12: 0xADFD, a13: 0x1051, a14: 0xADFD, a15: 0x1051)
k_E6DC_25A1_1925_25A1 = util.make_m256i_multiple_u16(
a00: 0xE6DC, a01: 0x25A1, a02: 0xE6DC, a03: 0x25A1,
a04: 0xE6DC, a05: 0x25A1, a06: 0xE6DC, a07: 0x25A1,
a08: 0x1925, a09: 0x25A1, a10: 0x1925, a11: 0x25A1,
a12: 0x1925, a13: 0x25A1, a14: 0x1925, a15: 0x25A1)
k_ECC1_E333_EFB0_ADFD = util.make_m256i_multiple_u16(
a00: 0xECC1, a01: 0xE333, a02: 0xECC1, a03: 0xE333,
a04: 0xECC1, a05: 0xE333, a06: 0xECC1, a07: 0xE333,
a08: 0xEFB0, a09: 0xADFD, a10: 0xEFB0, a11: 0xADFD,
a12: 0xEFB0, a13: 0xADFD, a14: 0xEFB0, a15: 0xADFD)
// ----
while.goto_do_second_pass true,
inv 8 <= args.dst_stride,
{{
// Name the columns a ..= h and the rows 0 ..= 7.
//
// Check if the AC terms are zero. First, a relative cheap check of the
// (a1, b1, c1, d1, a2, b2, c2, d2) coefficients - two half-rows.
if 0 == (util.make_u64_slice_u16lex4(a: this.mcu_blocks[0][0x08 .. 0x0C]) |
util.make_u64_slice_u16lex4(a: this.mcu_blocks[0][0x10 .. 0x14])) {
// A more thorough check of every coefficient in rows 1 ..= 7.
az_coeffs = sse42_util.make_m128i_slice_u16lex8(a: this.mcu_blocks[0][0x08 .. 0x10])._mm_or_si128(b:
sse42_util.make_m128i_slice_u16lex8(a: this.mcu_blocks[0][0x10 .. 0x18]))._mm_or_si128(b:
sse42_util.make_m128i_slice_u16lex8(a: this.mcu_blocks[0][0x18 .. 0x20]))._mm_or_si128(b:
sse42_util.make_m128i_slice_u16lex8(a: this.mcu_blocks[0][0x20 .. 0x28]))._mm_or_si128(b:
sse42_util.make_m128i_slice_u16lex8(a: this.mcu_blocks[0][0x28 .. 0x30]))._mm_or_si128(b:
sse42_util.make_m128i_slice_u16lex8(a: this.mcu_blocks[0][0x30 .. 0x38]))._mm_or_si128(b:
sse42_util.make_m128i_slice_u16lex8(a: this.mcu_blocks[0][0x38 .. 0x40]))
// Pack u16x8 into u8x8 in the low 64 bits (using signed saturation)
// and bulk-compare to zero. Only "zero versus non-zero" matters.
if 0 == az_coeffs._mm_packs_epi16(b: az_coeffs).truncate_u64() {
// Dequantize, similar to the "Set up" code path below.
rows01 = util.make_m256i_slice_u16lex16(a: this.mcu_blocks[0][0x00 .. 0x10])
quants01 = util.make_m256i_slice_u16lex16(a: this.quant_tables[args.q][0x00 .. 0x10])
rows01 = rows01._mm256_mullo_epi16(b: quants01)
// az_ah00 = i16x16 [a b c d e f g h 0 0 0 0 0 0 0 0]
// az_ad00 = i16x16 [a a b b c c d d 0 0 0 0 0 0 0 0]
// az_eh00 = i16x16 [e e f f g g h h 0 0 0 0 0 0 0 0]
// az_adeh = i16x16 [a a b b c c d d e e f f g g h h]
az_ah00 = rows01._mm256_slli_epi16(imm8: 2) // PASS1_BITS is 2.
az_ad00 = az_ah00._mm256_unpacklo_epi16(b: az_ah00)
az_eh00 = az_ah00._mm256_unpackhi_epi16(b: az_ah00)
az_adeh = az_ad00._mm256_inserti128_si256(b: az_eh00._mm256_castsi256_si128(), imm8: 1)
// intermediateae = i16x16 [a a a a a a a a e e e e e e e e]
// intermediatebf = i16x16 [b b b b b b b b f f f f f f f f]
// intermediatecg = i16x16 [c c c c c c c c g g g g g g g g]
// intermediatedh = i16x16 [d d d d d d d d h h h h h h h h]
intermediateae = az_adeh._mm256_shuffle_epi32(imm8: 0x00)
intermediatebf = az_adeh._mm256_shuffle_epi32(imm8: 0x55)
intermediatecg = az_adeh._mm256_shuffle_epi32(imm8: 0xAA)
intermediatedh = az_adeh._mm256_shuffle_epi32(imm8: 0xFF)
break.goto_do_second_pass
}
}
// ----
// Set up.
// Dequantize:
//
// rows01 = i16x16 [a0 b0 .. g0 h0
// a1 b1 .. g1 h1]
// rows23 = i16x16 [a2 b2 .. g2 e2
// a3 b3 .. g3 h3]
// rows45 = i16x16 [a4 b4 .. g4 h4
// a5 b5 .. g5 h5]
// rows67 = i16x16 [a6 b6 .. g6 h6
// a7 b7 .. g7 h7]
rows01 = util.make_m256i_slice_u16lex16(a: this.mcu_blocks[0][0x00 .. 0x10])
rows23 = util.make_m256i_slice_u16lex16(a: this.mcu_blocks[0][0x10 .. 0x20])
rows45 = util.make_m256i_slice_u16lex16(a: this.mcu_blocks[0][0x20 .. 0x30])
rows67 = util.make_m256i_slice_u16lex16(a: this.mcu_blocks[0][0x30 .. 0x40])
quants01 = util.make_m256i_slice_u16lex16(a: this.quant_tables[args.q][0x00 .. 0x10])
quants23 = util.make_m256i_slice_u16lex16(a: this.quant_tables[args.q][0x10 .. 0x20])
quants45 = util.make_m256i_slice_u16lex16(a: this.quant_tables[args.q][0x20 .. 0x30])
quants67 = util.make_m256i_slice_u16lex16(a: this.quant_tables[args.q][0x30 .. 0x40])
rows01 = rows01._mm256_mullo_epi16(b: quants01)
rows23 = rows23._mm256_mullo_epi16(b: quants23)
rows45 = rows45._mm256_mullo_epi16(b: quants45)
rows67 = rows67._mm256_mullo_epi16(b: quants67)
// Permute:
//
// rows04 = i16x16 [a0 b0 .. g0 h0
// a4 b4 .. g4 h4]
// rows31 = i16x16 [a3 b3 .. g3 e3
// a1 b1 .. g1 h1]
// rows26 = i16x16 [a2 b2 .. g2 h2
// a6 b6 .. g6 h6]
// rows75 = i16x16 [a7 b7 .. g7 h7
// a5 b5 .. g5 h5]
rows04 = rows01._mm256_permute2x128_si256(b: rows45, imm8: 0x20)
rows31 = rows23._mm256_permute2x128_si256(b: rows01, imm8: 0x31)
rows26 = rows23._mm256_permute2x128_si256(b: rows67, imm8: 0x20)
rows75 = rows67._mm256_permute2x128_si256(b: rows45, imm8: 0x31)
// ----
// First pass (even rows).
// This non-SIMD code:
//
// cb2 = (bq2 ~mod* 0x0000_29CF) ~mod+ (bq6 ~mod* 0x0000_1151)
// cb6 = (bq2 ~mod* 0x0000_1151) ~mod+ (bq6 ~mod* 0xFFFF_D630)
//
// becomes:
//
// fp_rows62 = i16x16 [a6 b6 .. g6 h6
// a2 b2 .. g2 h2]
// fp_bq2662ad = i16x16 [a2 a6 .. d2 d6
// a6 a2 .. d6 d2]
// fp_bq2662eh = i16x16 [e2 e6 .. h2 h6
// e6 e2 .. h6 h2]
// fp_cb26ad = i32x8 [cb2.a .. cb2.d
// cb6.a .. cb6.d]
// = i32x8 [a2*0x29CF+a6*0x1151 .. d2*0x29CF+d6*0x1151
// a6*0xD630+a2*0x1151 .. d6*0xD630+d2*0x1151]
// fp_cb26eh = i32x8 [cb2.e .. cb2.h
// cb6.e .. cb6.h]
// = i32x8 [e2*0x29CF+e6*0x1151 .. h2*0x29CF+h6*0x1151
// e6*0xD630+e2*0x1151 .. h6*0xD630+h2*0x1151]
fp_rows62 = rows26._mm256_permute2x128_si256(b: rows26, imm8: 0x01)
fp_bq2662ad = rows26._mm256_unpacklo_epi16(b: fp_rows62)
fp_bq2662eh = rows26._mm256_unpackhi_epi16(b: fp_rows62)
fp_cb26ad = fp_bq2662ad._mm256_madd_epi16(b: k_29CF_1151_D630_1151)
fp_cb26eh = fp_bq2662eh._mm256_madd_epi16(b: k_29CF_1151_D630_1151)
// This non-SIMD code:
//
// ccp = (bq0 ~mod+ bq4) ~mod<< 13
// ccm = (bq0 ~mod- bq4) ~mod<< 13
//
// becomes:
//
// fp_rows40pos = i16x16 [+a4 +b4 .. +g4 +h4
// +a0 +b0 .. +g0 +h0]
// fp_rows04neg = i16x16 [+a0 +b0 .. +g0 +h0
// -a4 -b4 .. -g4 -h4]
// fp_rows0pm4 = i16x16 [a0+a4 b0+b4 .. g0+g4 h0+h4
// a0-a4 b0-b4 .. g0-g4 h0-h4]
// fp_ccpmad = i32x8 [ccp.a .. ccp.d
// ccm.a .. ccm.d]
// = i32x8 [(a0+a4)<<13 .. (d0+d4)<<13
// (a0-a4)<<13 .. (d0-d4)<<13]
// fp_ccpmeh = i32x8 [ccp.e .. ccp.h
// ccm.e .. ccm.h]
// = i32x8 [(e0+e4)<<13 .. (h0+h4)<<13
// (e0-e4)<<13 .. (h0-h4)<<13]
fp_rows40pos = rows04._mm256_permute2x128_si256(b: rows04, imm8: 0x01)
fp_rows04neg = rows04._mm256_sign_epi16(b: k_0001_FFFF)
fp_rows0pm4 = fp_rows40pos._mm256_add_epi16(b: fp_rows04neg)
fp_ccpmad = k_0000._mm256_unpacklo_epi16(b: fp_rows0pm4)._mm256_srai_epi32(imm8: 16 - 13)
fp_ccpmeh = k_0000._mm256_unpackhi_epi16(b: fp_rows0pm4)._mm256_srai_epi32(imm8: 16 - 13)
// This non-SIMD code:
//
// cd0 = ccp ~mod+ cb2
// cd1 = ccm ~mod+ cb6
// cd2 = ccm ~mod- cb6
// cd3 = ccp ~mod- cb2
//
// becomes:
//
// fp_cd01ad = i32x8 [cd0.a .. cd0.d
// cd1.a .. cd1.d]
// = i32x8 [ccp.a+cb2.a .. ccp.d+cb2.d
// ccm.a+cb6.a .. ccm.d+cb6.d]
// fp_cd01eh = i32x8 [cd0.e .. cd0.h
// cd1.e .. cd1.h]
// = i32x8 [ccp.e+cb2.e .. ccp.h+cb2.h
// ccm.e+cb6.e .. ccm.h+cb6.h]
// fp_cd32ad = i32x8 [cd3.a .. cd3.d
// cd2.a .. cd2.d]
// = i32x8 [ccp.a-cb2.a .. ccp.d-cb2.d
// ccm.a-cb6.a .. ccm.d-cb6.d]
// fp_cd32eh = i32x8 [cd3.e .. cd3.h
// cd2.e .. cd2.h]
// = i32x8 [ccp.e-cb2.e .. ccp.h-cb2.h
// ccm.e-cb6.e .. ccm.h-cb6.h]
fp_cd01ad = fp_ccpmad._mm256_add_epi32(b: fp_cb26ad)
fp_cd01eh = fp_ccpmeh._mm256_add_epi32(b: fp_cb26eh)
fp_cd32ad = fp_ccpmad._mm256_sub_epi32(b: fp_cb26ad)
fp_cd32eh = fp_ccpmeh._mm256_sub_epi32(b: fp_cb26eh)
// ----
// First pass (odd rows).
// This non-SIMD code:
//
// ci73 = bq7 ~mod+ bq3
// ci51 = bq5 ~mod+ bq1
// cl73 = (ci73 ~mod* 0xFFFF_E6DC) ~mod+ (ci51 ~mod* 0x0000_25A1)
// cl51 = (ci73 ~mod* 0x0000_25A1) ~mod+ (ci51 ~mod* 0x0000_1925)
//
// becomes:
//
// fp_sums7351 = i16x16 [a7+a3 b7+b3 .. g7+g3 h7+h3
// a5+a1 b5+b1 .. g5+g1 h5+h1]
// fp_sums5173 = i16x16 [a5+a1 b5+b1 .. g5+g1 h5+h1
// a7+a3 b7+b3 .. g7+g3 h7+h3]
// fp_ci73515173ad = i16x16 [a7+a3 a5+a1 .. d7+d3 d5+d1
// a5+a1 a7+a3 .. d5+d1 d7+d3]
// fp_ci73515173eh = i16x16 [e7+e3 e5+e1 .. h7+h3 h5+d1
// e5+e1 e7+e3 .. h5+h1 h7+d3]
// fp_cl7351ad = i32x8 [cl73.a .. cl73.d
// cl51.a .. cl51.d]
// = i32x8 [(a7+a3)*0xE6DC+(a5+a1)*0x25A1 .. (d7+d3)*0xE6DC+(d5+d1)*0x25A1
// (a5+a1)*0x1925+(a7+a3)*0x25A1 .. (d5+d1)*0x1925+(d7+d3)*0x25A1]
// fp_cl7351eh = i32x8 [cl73.e .. cl73.h
// cl51.e .. cl51.h]
// = i32x8 [(e7+e3)*0xE6DC+(e5+e1)*0x25A1 .. (h7+h3)*0xE6DC+(h5+h1)*0x25A1
// (e5+e1)*0x1925+(e7+e3)*0x25A1 .. (h5+h1)*0x1925+(h7+h3)*0x25A1]
fp_sums7351 = rows75._mm256_add_epi16(b: rows31)
fp_sums5173 = fp_sums7351._mm256_permute2x128_si256(b: fp_sums7351, imm8: 0x01)
fp_ci73515173ad = fp_sums7351._mm256_unpacklo_epi16(b: fp_sums5173)
fp_ci73515173eh = fp_sums7351._mm256_unpackhi_epi16(b: fp_sums5173)
fp_cl7351ad = fp_ci73515173ad._mm256_madd_epi16(b: k_E6DC_25A1_1925_25A1)
fp_cl7351eh = fp_ci73515173eh._mm256_madd_epi16(b: k_E6DC_25A1_1925_25A1)
// This non-SIMD code:
//
// ck5 = cl51 ~mod+ ((bq3 ~mod* 0xFFFF_ADFD) ~mod+ (bq5 ~mod* 0xFFFF_EFB0))
// ck7 = cl73 ~mod+ ((bq1 ~mod* 0xFFFF_E333) ~mod+ (bq7 ~mod* 0xFFFF_ECC1))
//
// becomes:
//
// fp_rows13 = i16x16 [a1 b1 .. g1 e1 a3 b3 .. g3 h3]
// fp_bq7153ad = i16x16 [a7 a1 .. d7 d1 a5 a3 .. d5 d3]
// fp_bq7153eh = i16x16 [e7 e1 .. h7 h1 e5 e3 .. h5 h3]
// fp_ck75ad = i32x8 [ck7.a .. ck7.d
// ck5.a .. ck5.d]
// = i32x8 [cl73.a+a7*0xECC1+a1*0xE333 .. cl73.d+d7*0xECC1+d1*0xE333
// cl51.a+a5*0xEFB0+a3*0xADFD .. cl51.d+d5*0xEFB0+d3*0xADFD]
// fp_ck75eh = i32x8 [ck7.e .. ck7.h
// ck5.e .. ck5.h]
// = i32x8 [cl73.e+e7*0xECC1+e1*0xE333 .. cl73.h+h7*0xECC1+h1*0xE333
// cl51.e+e5*0xEFB0+e3*0xADFD .. cl51.h+h5*0xEFB0+h3*0xADFD]
fp_rows13 = rows31._mm256_permute2x128_si256(b: rows31, imm8: 0x01)
fp_bq7153ad = rows75._mm256_unpacklo_epi16(b: fp_rows13)
fp_bq7153eh = rows75._mm256_unpackhi_epi16(b: fp_rows13)
fp_ck75ad = fp_bq7153ad._mm256_madd_epi16(b: k_ECC1_E333_EFB0_ADFD)._mm256_add_epi32(b: fp_cl7351ad)
fp_ck75eh = fp_bq7153eh._mm256_madd_epi16(b: k_ECC1_E333_EFB0_ADFD)._mm256_add_epi32(b: fp_cl7351eh)
// This non-SIMD code:
//
// ck1 = cl51 ~mod+ ((bq1 ~mod* 0x0000_133E) ~mod+ (bq7 ~mod* 0xFFFF_E333))
// ck3 = cl73 ~mod+ ((bq3 ~mod* 0x0000_1051) ~mod+ (bq5 ~mod* 0xFFFF_ADFD))
//
// becomes:
//
// fp_cl5173ad = i32x8 [cl51.a .. cl51.d
// cl73.a .. cl73.d]
// fp_cl5173eh = i32x8 [cl51.e .. cl51.h
// cl73.e .. cl73.h]
// fp_ck13ad = i32x8 [ck1.a .. ck1.d
// ck3.a .. ck3.d]
// = i32x8 [cl51.a+a7*0xE333+a1*0x133E .. cl51.d+d7*0xE333+d1*0x133E
// cl73.a+a5*0xADFD+a3*0x1051 .. cl73.d+d5*0xADFD+d3*0x1051]
// fp_ck13eh = i32x8 [ck1.e .. ck3.h
// ck3.e .. ck1.h]
// = i32x8 [cl51.e+e7*0xE333+e1*0x133E .. cl51.h+h7*0xE333+h1*0x133E
// cl73.e+e5*0xADFD+e3*0x1051 .. cl73.h+h5*0xADFD+h3*0x1051]
fp_cl5173ad = fp_cl7351ad._mm256_permute2x128_si256(b: fp_cl7351ad, imm8: 0x01)
fp_cl5173eh = fp_cl7351eh._mm256_permute2x128_si256(b: fp_cl7351eh, imm8: 0x01)
fp_ck13ad = fp_cl5173ad._mm256_add_epi32(b: fp_bq7153ad._mm256_madd_epi16(b: k_E333_133E_ADFD_1051))
fp_ck13eh = fp_cl5173eh._mm256_add_epi32(b: fp_bq7153eh._mm256_madd_epi16(b: k_E333_133E_ADFD_1051))
// ----
// First pass (combine rows).
// We have now calculated:
//
// fp_ck13ad = i32x8 [ck1.a .. ck1.d ck3.a .. ck3.d]
// fp_ck13eh = i32x8 [ck1.e .. ck1.h ck3.e .. ck3.h]
// fp_ck75ad = i32x8 [ck7.a .. ck7.d ck5.a .. ck5.d]
// fp_ck75eh = i32x8 [ck7.e .. ck7.h ck5.e .. ck5.h]
// fp_cd01ad = i32x8 [cd0.a .. cd0.d cd1.a .. cd1.d]
// fp_cd01eh = i32x8 [cd0.e .. cd0.h cd1.e .. cd1.h]
// fp_cd32ad = i32x8 [cd3.a .. cd3.d cd2.a .. cd2.d]
// fp_cd32eh = i32x8 [cd3.e .. cd3.h cd2.e .. cd2.h]
//
// This non-SIMD code:
//
// intermediate0 = this.util.sign_extend_rshift_u32(a: (cd0 ~mod+ ck1) ~mod+ (1 << 10), n: 11)
// intermediate1 = this.util.sign_extend_rshift_u32(a: (cd1 ~mod+ ck3) ~mod+ (1 << 10), n: 11)
// intermediate2 = this.util.sign_extend_rshift_u32(a: (cd2 ~mod+ ck5) ~mod+ (1 << 10), n: 11)
// intermediate3 = this.util.sign_extend_rshift_u32(a: (cd3 ~mod+ ck7) ~mod+ (1 << 10), n: 11)
// intermediate4 = this.util.sign_extend_rshift_u32(a: (cd3 ~mod- ck7) ~mod+ (1 << 10), n: 11)
// intermediate5 = this.util.sign_extend_rshift_u32(a: (cd2 ~mod- ck5) ~mod+ (1 << 10), n: 11)
// intermediate6 = this.util.sign_extend_rshift_u32(a: (cd1 ~mod- ck3) ~mod+ (1 << 10), n: 11)
// intermediate7 = this.util.sign_extend_rshift_u32(a: (cd0 ~mod- ck1) ~mod+ (1 << 10), n: 11)
//
// becomes a mix of adds, subtracts, shifts and packs.
intermediate01ad = fp_cd01ad._mm256_add_epi32(b: fp_ck13ad)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate01eh = fp_cd01eh._mm256_add_epi32(b: fp_ck13eh)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate01 = intermediate01ad._mm256_packs_epi32(b: intermediate01eh)
intermediate32ad = fp_cd32ad._mm256_add_epi32(b: fp_ck75ad)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate32eh = fp_cd32eh._mm256_add_epi32(b: fp_ck75eh)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate32 = intermediate32ad._mm256_packs_epi32(b: intermediate32eh)
intermediate45ad = fp_cd32ad._mm256_sub_epi32(b: fp_ck75ad)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate45eh = fp_cd32eh._mm256_sub_epi32(b: fp_ck75eh)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate45 = intermediate45ad._mm256_packs_epi32(b: intermediate45eh)
intermediate76ad = fp_cd01ad._mm256_sub_epi32(b: fp_ck13ad)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate76eh = fp_cd01eh._mm256_sub_epi32(b: fp_ck13eh)._mm256_add_epi32(b: k_0400_0000)._mm256_srai_epi32(imm8: 11)
intermediate76 = intermediate76ad._mm256_packs_epi32(b: intermediate76eh)
// ----
// Transpose/re-order the intermediate rows and columns. We start with:
//
// intermediate01 = i16x16 [in.a0 .. in.d0 in.e0 .. in.h0 in.a1 .. in.d1 in.e1 .. in.h1]
// intermediate32 = i16x16 [in.a3 .. in.d3 in.e3 .. in.h3 in.a2 .. in.d2 in.e2 .. in.h2]
// intermediate45 = i16x16 [in.a4 .. in.d4 in.e4 .. in.h4 in.a5 .. in.d5 in.e5 .. in.h5]
// intermediate76 = i16x16 [in.a7 .. in.d7 in.e7 .. in.h7 in.a6 .. in.d6 in.e6 .. in.h6]
ita0a1e0e1 = intermediate01._mm256_permute4x64_epi64(imm8: 0xD8)
ita2a3e2e3 = intermediate32._mm256_permute4x64_epi64(imm8: 0x72)
ita4a5e4e5 = intermediate45._mm256_permute4x64_epi64(imm8: 0xD8)
ita6a7e6e7 = intermediate76._mm256_permute4x64_epi64(imm8: 0x72)
// We now have:
//
// ita0a1e0e1 = i16x16 [in.a0 .. in.d0 in.a1 .. in.d1 in.e0 .. in.h0 in.e1 .. in.h1]
// ita2a3e2e3 = i16x16 [in.a2 .. in.d2 in.a3 .. in.d3 in.e2 .. in.h2 in.e3 .. in.h3]
// ita4a5e4e5 = i16x16 [in.a4 .. in.d4 in.a5 .. in.d5 in.e4 .. in.h4 in.e5 .. in.h5]
// ita6a7e6e7 = i16x16 [in.a6 .. in.d6 in.a7 .. in.d7 in.e6 .. in.h6 in.e7 .. in.h7]
ita0c0e0g0 = ita0a1e0e1._mm256_unpacklo_epi16(b: ita2a3e2e3)
ita1c1e1g1 = ita0a1e0e1._mm256_unpackhi_epi16(b: ita2a3e2e3)
ita4c4e4g4 = ita4a5e4e5._mm256_unpacklo_epi16(b: ita6a7e6e7)
ita5c5e5g5 = ita4a5e4e5._mm256_unpackhi_epi16(b: ita6a7e6e7)
// We now have:
//
// ita0c0e0g0 = i16x16 [in.a0 in.a2 .. in.d0 in.d2 in.e0 in.e2 .. in.h0 in.h2]
// ita1c1e1g1 = i16x16 [in.a1 in.a3 .. in.d1 in.d3 in.e1 in.e3 .. in.h1 in.h3]
// ita4c4e4g4 = i16x16 [in.a4 in.a6 .. in.d4 in.d6 in.e4 in.e6 .. in.h4 in.h6]
// ita5c5e5g5 = i16x16 [in.a5 in.a7 .. in.d5 in.d7 in.e5 in.e7 .. in.h5 in.h7]
ita0b0e0f0 = ita0c0e0g0._mm256_unpacklo_epi16(b: ita1c1e1g1)
itc0d0g0h0 = ita0c0e0g0._mm256_unpackhi_epi16(b: ita1c1e1g1)
ita4b4e4f4 = ita4c4e4g4._mm256_unpacklo_epi16(b: ita5c5e5g5)
itc4d4g4h4 = ita4c4e4g4._mm256_unpackhi_epi16(b: ita5c5e5g5)
// We now have:
//
// ita0b0e0f0 = i16x16 [in.a0 .. in.a3 in.b0 .. in.b3 in.e0 .. in.e3 in.f0 .. in.f3]
// itc0d0g0h0 = i16x16 [in.c0 .. in.c3 in.d0 .. in.d3 in.g0 .. in.g3 in.h0 .. in.h3]
// ita4b4e4f4 = i16x16 [in.a4 .. in.a7 in.b4 .. in.b7 in.e4 .. in.e7 in.f4 .. in.f7]
// itc4d4g4h4 = i16x16 [in.c4 .. in.c7 in.d4 .. in.d7 in.g4 .. in.g7 in.h4 .. in.h7]
intermediateae = ita0b0e0f0._mm256_unpacklo_epi64(b: ita4b4e4f4)
intermediatebf = ita0b0e0f0._mm256_unpackhi_epi64(b: ita4b4e4f4)
intermediatecg = itc0d0g0h0._mm256_unpacklo_epi64(b: itc4d4g4h4)
intermediatedh = itc0d0g0h0._mm256_unpackhi_epi64(b: itc4d4g4h4)
// We now have:
//
// intermediateae = i16x16 [in.a0 .. in.a3 in.a4 .. in.a7 in.e0 .. in.e3 in.e4 .. in.e7]
// intermediatebf = i16x16 [in.b0 .. in.b3 in.b4 .. in.b7 in.f0 .. in.f4 in.f5 .. in.f7]
// intermediatecg = i16x16 [in.c0 .. in.c3 in.c4 .. in.c7 in.g0 .. in.g3 in.g4 .. in.g7]
// 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
// ----
// To recap, we have:
//
// intermediateae = i16x16 [in.a0 in.a1 .. in.a6 in.a7
// in.e0 in.e1 .. in.e6 in.e7]
// intermediatebf = i16x16 [in.b0 in.b1 .. in.b6 in.b7
// in.f0 in.f1 .. in.f6 in.f7]
// intermediatecg = i16x16 [in.c0 in.c1 .. in.c6 in.c7
// in.g0 in.g1 .. in.g6 in.g7]
// intermediatedh = i16x16 [in.d0 in.d1 .. in.d6 in.d7
// in.h0 in.h1 .. in.h6 in.h7]
//
// Which is similar to this, but note the transposition and re-ordering:
//
// rows01 = i16x16 [a0 b0 .. g0 h0
// a1 b1 .. g1 h1]
// rows23 = i16x16 [a2 b2 .. g2 e2
// a3 b3 .. g3 h3]
// rows45 = i16x16 [a4 b4 .. g4 h4
// a5 b5 .. g5 h5]
// rows67 = i16x16 [a6 b6 .. g6 h6
// a7 b7 .. g7 h7]
// Permute:
//
// intermediatedb = i16x16 [in.d0 in.d1 .. in.d6 in.d7
// in.b0 in.b1 .. in.b6 in.b7]
// intermediatehf = i16x16 [in.h0 in.h1 .. in.h6 in.h7
// in.f0 in.f1 .. in.f6 in.f7]
//
// The row/column analogies are:
//
// [a0 .. h0 a4 .. h4] = rows04 <=> intermediateae = [in.a0 .. in.a7 in.e0 .. in.e7]
// [a3 .. h3 a1 .. h1] = rows31 <=> intermediatedb = [in.d0 .. in.d7 in.b0 .. in.b7]
// [a2 .. h2 a6 .. h6] = rows26 <=> intermediatecg = [in.c0 .. in.c7 in.g0 .. in.g7]
// [a7 .. h7 a5 .. h5] = rows75 <=> intermediatehf = [in.h0 .. in.h7 in.f0 .. in.f7]
intermediatedb = intermediatedh._mm256_permute2x128_si256(b: intermediatebf, imm8: 0x20)
intermediatehf = intermediatedh._mm256_permute2x128_si256(b: intermediatebf, imm8: 0x31)
// ----
// Second pass (even columns).
// This non-SIMD code:
//
// rb2 = (in2 ~mod* 0x0000_29CF) ~mod+ (in6 ~mod* 0x0000_1151)
// rb6 = (in2 ~mod* 0x0000_1151) ~mod+ (in6 ~mod* 0xFFFF_D630)
//
// becomes:
//
// sp_rb26ad = i32x8 [rb2.a .. rb2.d rb6.a .. rb6.d] transposed
// sp_rb26eh = i32x8 [rb2.e .. rb2.h rb6.e .. rb6.h] transposed
//
// 'Tranposed' means that the rows and column names should be swapped.
// rb2.a, rb6.h, etc should really be rbc.0, rbg.7, etc but the former
// notation lines up closer with the first pass' comments.
sp_cols62 = intermediatecg._mm256_permute2x128_si256(b: intermediatecg, imm8: 0x01)
sp_bq2662ad = intermediatecg._mm256_unpacklo_epi16(b: sp_cols62)
sp_bq2662eh = intermediatecg._mm256_unpackhi_epi16(b: sp_cols62)
sp_rb26ad = sp_bq2662ad._mm256_madd_epi16(b: k_29CF_1151_D630_1151)
sp_rb26eh = sp_bq2662eh._mm256_madd_epi16(b: k_29CF_1151_D630_1151)
// This non-SIMD code:
//
// rcp = (in0 ~mod+ in4) ~mod<< 13
// rcm = (in0 ~mod- in4) ~mod<< 13
//
// becomes:
//
// sp_rcpmad = i32x8 [rcp.a .. rcp.d rcm.a .. rcm.d] transposed
// sp_rcpmeh = i32x8 [rcp.e .. rcp.h rcm.e .. rcm.h] transposed
sp_cols40pos = intermediateae._mm256_permute2x128_si256(b: intermediateae, imm8: 0x01)
sp_cols04neg = intermediateae._mm256_sign_epi16(b: k_0001_FFFF)
sp_cols0pm4 = sp_cols40pos._mm256_add_epi16(b: sp_cols04neg)
sp_rcpmad = k_0000._mm256_unpacklo_epi16(b: sp_cols0pm4)._mm256_srai_epi32(imm8: 16 - 13)
sp_rcpmeh = k_0000._mm256_unpackhi_epi16(b: sp_cols0pm4)._mm256_srai_epi32(imm8: 16 - 13)
// This non-SIMD code:
//
// rd0 = rcp ~mod+ rb2
// rd1 = rcm ~mod+ rb6
// rd2 = rcm ~mod- rb6
// rd3 = rcp ~mod- rb2
//
// becomes:
//
// sp_rd01ad = i32x8 [rd0.a .. rd0.d rd1.a .. rd1.d] transposed
// sp_rd01eh = i32x8 [rd0.e .. rd0.h rd1.e .. rd1.h] transposed
// sp_rd32ad = i32x8 [rd3.a .. rd3.d rd2.a .. rd2.d] transposed
// sp_rd32eh = i32x8 [rd3.e .. rd3.h rd2.e .. rd2.h] transposed
sp_rd01ad = sp_rcpmad._mm256_add_epi32(b: sp_rb26ad)
sp_rd01eh = sp_rcpmeh._mm256_add_epi32(b: sp_rb26eh)
sp_rd32ad = sp_rcpmad._mm256_sub_epi32(b: sp_rb26ad)
sp_rd32eh = sp_rcpmeh._mm256_sub_epi32(b: sp_rb26eh)
// ----
// Second pass (odd columns).
// This non-SIMD code:
//
// ri73 = in7 ~mod+ in3
// ri51 = in5 ~mod+ in1
// rl73 = (ri73 ~mod* 0xFFFF_E6DC) ~mod+ (ri51 ~mod* 0x0000_25A1)
// rl51 = (ri73 ~mod* 0x0000_25A1) ~mod+ (ri51 ~mod* 0x0000_1925)
//
// becomes:
//
// sp_rl7351ad = i32x8 [rl73.a .. rl73.d rl51.a .. rl51.d] transposed
// sp_rl7351eh = i32x8 [rl73.e .. rl73.h rl51.e .. rl51.h] transposed
sp_sums7351 = intermediatehf._mm256_add_epi16(b: intermediatedb)
sp_sums5173 = sp_sums7351._mm256_permute2x128_si256(b: sp_sums7351, imm8: 0x01)
sp_ri73515173ad = sp_sums7351._mm256_unpacklo_epi16(b: sp_sums5173)
sp_ri73515173eh = sp_sums7351._mm256_unpackhi_epi16(b: sp_sums5173)
sp_rl7351ad = sp_ri73515173ad._mm256_madd_epi16(b: k_E6DC_25A1_1925_25A1)
sp_rl7351eh = sp_ri73515173eh._mm256_madd_epi16(b: k_E6DC_25A1_1925_25A1)
// This non-SIMD code:
//
// rk5 = rl51 ~mod+ ((in3 ~mod* 0xFFFF_ADFD) ~mod+ (in5 ~mod* 0xFFFF_EFB0))
// rk7 = rl73 ~mod+ ((in1 ~mod* 0xFFFF_E333) ~mod+ (in7 ~mod* 0xFFFF_ECC1))
//
// becomes:
//
// sp_rk75ad = i32x8 [rk7.a .. rk7.d rk5.a .. rk5.d] transposed
// sp_rk75eh = i32x8 [rk7.e .. rk7.h rk5.e .. rk5.h] transposed
sp_cols13 = intermediatedb._mm256_permute2x128_si256(b: intermediatedb, imm8: 0x01)
sp_bq7153ad = intermediatehf._mm256_unpacklo_epi16(b: sp_cols13)
sp_bq7153eh = intermediatehf._mm256_unpackhi_epi16(b: sp_cols13)
sp_rk75ad = sp_bq7153ad._mm256_madd_epi16(b: k_ECC1_E333_EFB0_ADFD)._mm256_add_epi32(b: sp_rl7351ad)
sp_rk75eh = sp_bq7153eh._mm256_madd_epi16(b: k_ECC1_E333_EFB0_ADFD)._mm256_add_epi32(b: sp_rl7351eh)
// This non-SIMD code:
//
// rk1 = rl51 ~mod+ ((in1 ~mod* 0x0000_133E) ~mod+ (in7 ~mod* 0xFFFF_E333))
// rk3 = rl73 ~mod+ ((in3 ~mod* 0x0000_1051) ~mod+ (in5 ~mod* 0xFFFF_ADFD))
//
// becomes:
//
// sp_rk13ad = i32x8 [rk1.a .. rk1.d rk3.a .. rk3.d] transposed
// sp_rk13eh = i32x8 [rk1.e .. rk3.h rk3.e .. rk1.h] transposed
sp_rl5173ad = sp_rl7351ad._mm256_permute2x128_si256(b: sp_rl7351ad, imm8: 0x01)
sp_rl5173eh = sp_rl7351eh._mm256_permute2x128_si256(b: sp_rl7351eh, imm8: 0x01)
sp_rk13ad = sp_rl5173ad._mm256_add_epi32(b: sp_bq7153ad._mm256_madd_epi16(b: k_E333_133E_ADFD_1051))
sp_rk13eh = sp_rl5173eh._mm256_add_epi32(b: sp_bq7153eh._mm256_madd_epi16(b: k_E333_133E_ADFD_1051))
// ----
// Second pass (combine columns).
// We have now calculated:
//
// sp_rk13ad = i32x8 [rk1.a .. rk1.d rk3.a .. rk3.d] transposed
// sp_rk13eh = i32x8 [rk1.e .. rk1.h rk3.e .. rk3.h] transposed
// sp_rk75ad = i32x8 [rk7.a .. rk7.d rk5.a .. rk5.d] transposed
// sp_rk75eh = i32x8 [rk7.e .. rk7.h rk5.e .. rk5.h] transposed
// sp_rd01ad = i32x8 [rd0.a .. rd0.d rd1.a .. rd1.d] transposed
// sp_rd01eh = i32x8 [rd0.e .. rd0.h rd1.e .. rd1.h] transposed
// sp_rd32ad = i32x8 [rd3.a .. rd3.d rd2.a .. rd2.d] transposed
// sp_rd32eh = i32x8 [rd3.e .. rd3.h rd2.e .. rd2.h] transposed
//
// This non-SIMD code:
//
// final0 = this.util.sign_extend_rshift_u32(a: (rd0 ~mod+ rk1) ~mod+ (1 << 17), n: 18)
// final1 = this.util.sign_extend_rshift_u32(a: (rd1 ~mod+ rk3) ~mod+ (1 << 17), n: 18)
// final2 = this.util.sign_extend_rshift_u32(a: (rd2 ~mod+ rk5) ~mod+ (1 << 17), n: 18)
// final3 = this.util.sign_extend_rshift_u32(a: (rd3 ~mod+ rk7) ~mod+ (1 << 17), n: 18)
// final4 = this.util.sign_extend_rshift_u32(a: (rd3 ~mod- rk7) ~mod+ (1 << 17), n: 18)
// final5 = this.util.sign_extend_rshift_u32(a: (rd2 ~mod- rk5) ~mod+ (1 << 17), n: 18)
// final6 = this.util.sign_extend_rshift_u32(a: (rd1 ~mod- rk3) ~mod+ (1 << 17), n: 18)
// final7 = this.util.sign_extend_rshift_u32(a: (rd0 ~mod- rk1) ~mod+ (1 << 17), n: 18)
//
// becomes a mix of adds, subtracts, shifts and packs.
final01ad = sp_rd01ad._mm256_add_epi32(b: sp_rk13ad)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final01eh = sp_rd01eh._mm256_add_epi32(b: sp_rk13eh)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final01 = final01ad._mm256_packs_epi32(b: final01eh)
final32ad = sp_rd32ad._mm256_add_epi32(b: sp_rk75ad)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final32eh = sp_rd32eh._mm256_add_epi32(b: sp_rk75eh)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final32 = final32ad._mm256_packs_epi32(b: final32eh)
final45ad = sp_rd32ad._mm256_sub_epi32(b: sp_rk75ad)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final45eh = sp_rd32eh._mm256_sub_epi32(b: sp_rk75eh)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final45 = final45ad._mm256_packs_epi32(b: final45eh)
final76ad = sp_rd01ad._mm256_sub_epi32(b: sp_rk13ad)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final76eh = sp_rd01eh._mm256_sub_epi32(b: sp_rk13eh)._mm256_add_epi32(b: k_0000_0002)._mm256_srai_epi32(imm8: 18)
final76 = final76ad._mm256_packs_epi32(b: final76eh)
// ----
// Transpose/re-order the final rows and columns.
fta0a1e0e1 = final01._mm256_permute4x64_epi64(imm8: 0xD8)
fta2a3e2e3 = final32._mm256_permute4x64_epi64(imm8: 0x72)
fta4a5e4e5 = final45._mm256_permute4x64_epi64(imm8: 0xD8)
fta6a7e6e7 = final76._mm256_permute4x64_epi64(imm8: 0x72)
fta0c0e0g0 = fta0a1e0e1._mm256_unpacklo_epi16(b: fta2a3e2e3)
fta1c1e1g1 = fta0a1e0e1._mm256_unpackhi_epi16(b: fta2a3e2e3)
fta4c4e4g4 = fta4a5e4e5._mm256_unpacklo_epi16(b: fta6a7e6e7)
fta5c5e5g5 = fta4a5e4e5._mm256_unpackhi_epi16(b: fta6a7e6e7)
fta0b0e0f0 = fta0c0e0g0._mm256_unpacklo_epi16(b: fta1c1e1g1)
ftc0d0g0h0 = fta0c0e0g0._mm256_unpackhi_epi16(b: fta1c1e1g1)
fta4b4e4f4 = fta4c4e4g4._mm256_unpacklo_epi16(b: fta5c5e5g5)
ftc4d4g4h4 = fta4c4e4g4._mm256_unpackhi_epi16(b: fta5c5e5g5)
finalae = fta0b0e0f0._mm256_unpacklo_epi64(b: fta4b4e4f4)
finalbf = fta0b0e0f0._mm256_unpackhi_epi64(b: fta4b4e4f4)
finalcg = ftc0d0g0h0._mm256_unpacklo_epi64(b: ftc4d4g4h4)
finaldh = ftc0d0g0h0._mm256_unpackhi_epi64(b: ftc4d4g4h4)
// ----
// Pack i16x16 into i8x32 (using signed saturation; i8 ranges from -128 ..=
// +127), bias by +0x80 (u8 ranges from 0 ..= 255) and extract the rows.
//
// We also drop the "'Tranposed' means that the rows and column names
// should be swapped". Rows are back to 0 ..= 7 and columns are a ..= h.
final0145 = finalae._mm256_packs_epi16(b: finalbf)._mm256_add_epi8(b: k_8080)
final2367 = finalcg._mm256_packs_epi16(b: finaldh)._mm256_add_epi8(b: k_8080)
final0 = final0145._mm256_extract_epi64(index: 0)
final1 = final0145._mm256_extract_epi64(index: 1)
final2 = final2367._mm256_extract_epi64(index: 0)
final3 = final2367._mm256_extract_epi64(index: 1)
final4 = final0145._mm256_extract_epi64(index: 2)
final5 = final0145._mm256_extract_epi64(index: 3)
final6 = final2367._mm256_extract_epi64(index: 2)
final7 = final2367._mm256_extract_epi64(index: 3)
// ----
// Write to the args.dst_buffer.
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
remaining = args.dst_buffer[args.dst_stride ..]
args.dst_buffer.poke_u64le!(a: final0)
args.dst_buffer = remaining
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
remaining = args.dst_buffer[args.dst_stride ..]
args.dst_buffer.poke_u64le!(a: final1)
args.dst_buffer = remaining
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
remaining = args.dst_buffer[args.dst_stride ..]
args.dst_buffer.poke_u64le!(a: final2)
args.dst_buffer = remaining
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
remaining = args.dst_buffer[args.dst_stride ..]
args.dst_buffer.poke_u64le!(a: final3)
args.dst_buffer = remaining
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
remaining = args.dst_buffer[args.dst_stride ..]
args.dst_buffer.poke_u64le!(a: final4)
args.dst_buffer = remaining
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
remaining = args.dst_buffer[args.dst_stride ..]
args.dst_buffer.poke_u64le!(a: final5)
args.dst_buffer = remaining
if args.dst_stride > args.dst_buffer.length() {
return nothing
}
assert 8 <= args.dst_buffer.length() via "a <= b: a <= c; c <= b"(c: args.dst_stride)
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
remaining = args.dst_buffer[args.dst_stride ..]
args.dst_buffer.poke_u64le!(a: final6)
args.dst_buffer = remaining
if 8 > args.dst_buffer.length() {
return nothing
}
assert args.dst_buffer.length() >= 8 via "a >= b: b <= a"()
args.dst_buffer.poke_u64le!(a: final7)
}
+2116
View File
@@ -0,0 +1,2116 @@
// 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.
pub status "#bad DHT marker"
pub status "#bad DQT marker"
pub status "#bad DRI marker"
pub status "#bad SOF marker"
pub status "#bad SOS marker"
pub status "#bad header"
pub status "#bad marker"
pub status "#missing Huffman table"
pub status "#missing Quantization table"
pub status "#truncated input"
pub status "#unsupported arithmetic coding"
pub status "#unsupported color model"
pub status "#unsupported fractional sampling"
pub status "#unsupported hierarchical coding"
pub status "#unsupported implicit height"
pub status "#unsupported lossless coding"
pub status "#unsupported marker"
pub status "#unsupported precision (12 bits)"
pub status "#unsupported precision (16 bits)"
pub status "#unsupported precision"
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 struct decoder? implements base.image_decoder(
width : base.u32[..= 0xFFFF],
height : base.u32[..= 0xFFFF],
width_in_mcus : base.u32[..= 0x2000],
height_in_mcus : base.u32[..= 0x2000],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
call_sequence : base.u8,
test_only_interrupt_decode_mcu : base.bool,
is_jfif : base.bool,
is_adobe : base.u8, // 0: no, 1: yes+RGB/CMYK, 2:yes+YCC/YCCK.
is_rgb_or_cmyk : base.bool,
sof_marker : base.u8,
next_restart_marker : base.u8[..= 7],
max_incl_components_h : base.u8[..= 4],
max_incl_components_v : base.u8[..= 4],
num_components : base.u32[..= 4],
components_c : array[4] base.u8,
components_h : array[4] base.u8[..= 4],
components_v : array[4] base.u8[..= 4],
components_tq : array[4] base.u8[..= 3],
// components_workbuf_offsets[0 .. 5], indexed by (csel) and (csel +
// 1), is the i and j bounds in the workbuf[i .. j] slice holding 8-bit
// samples (post-IDCT values) for the csel'th component. The row width
// is components_workbuf_widths[csel], which is also the row stride.
// There is no slack.
//
// For example, a 4:2:0 chroma-subsampled, 36 pixels wide × 28 pixels
// high image has 6 blocks (4 Y, 1 Cb, 1 Cr; 8×8 samples each) per MCU.
// Each MCU is 16×16 pixels. The image is 3 MCUs wide × 2 MCUs high.
// The post-IDCT image dimensions round up to 48 × 32 pixels.
//
// The components_workbuf_widths array is:
// 0: 0x30 = 48 // Y
// 1: 0x18 = 24 // Cb
// 2: 0x18 = 24 // Cr
// 3: 0x00 = 0 // Unused
//
// The head of the components_workbuf_offsets array is:
// 0: 0x0000 = 0
// 1: 0x0600 = 1536 = previous + (48 * 32)
// 2: 0x0780 = 1920 = previous + (24 * 16)
// 3: 0x0900 = 2304 = previous + (24 * 16)
// 4: 0x0900 = 2304 = previous + ( 0 * 0)
//
// That's components_workbuf_offsets[0 .. 5], for to a csel ranging in
// [0 .. 4]. For sequential JPEGs, components_workbuf_offsets[5 .. 9]
// are all equal to components_workbuf_offsets[4]. The four tail
// elements are unused, other than components_workbuf_offsets[8] (equal
// to components_workbuf_offsets[4]) being the workbuf_len.
//
// For progressive JPEGs, these hold the pre-IDCT pre-dequantization
// coefficients that persist between and are incrementally built by
// multiple Scans. There are 64 16-bit coefficients per block, just
// like there are 64 8-bit samples per block, but 16-bit coefficients
// obviously occupy twice as many bytes. Hence, the deltas between the
// components_workbuf_offsets tail elements are twice the deltas
// between its head elements.
//
// A block's 64 coefficients also have a different workbuf layout
// (placed in 128 consecutive bytes), compared to a block's 64 samples
// (placed in 8 rows; the stride is components_workbuf_widths[csel]).
// The 16-bit coefficients are stored little-endian.
//
// Continuing our 36 × 28 image example, if it was sequential encoded,
// the remaining four elements would all be 0x0900. If progressive
// encoded, the tail of the components_workbuf_offsets array is:
// 5: 0x1500 = 5376 = previous + (48 * 64)
// 6: 0x1800 = 6144 = previous + (24 * 32)
// 7: 0x1B00 = 6912 = previous + (24 * 32)
// 8: 0x1B00 = 6912 = previous + ( 0 * 0)
//
// The workbuf_len would be 0x0900 (baseline) or 0x1B00 (progressive).
components_workbuf_widths : array[4] base.u32[..= 0x1_0008],
components_workbuf_heights : array[4] base.u32[..= 0x1_0008],
components_workbuf_offsets : array[9] base.u64[..= 0xC_00C0_0300], // 12 * 0x1_0008 * 0x1_0008.
scan_count : base.u32,
scan_num_components : base.u32[..= 4],
scan_comps_cselector : array[4] base.u8[..= 3],
scan_comps_td : array[4] base.u8[..= 3],
scan_comps_ta : array[4] base.u8[..= 3],
// Every JPEG has a single SOI (Start Of Image) marker. Hierarchical
// JPEG images can have multiple Frames but this decoder does not
// support those. We thus expect a single SOF (Start Of Frame) for the
// single SOI.
//
// Sequential JPEGs have a single SOS (Start Of Scan) for the SOF.
// Their (Ss, Se, Ah, Al) below are effectively (0, 63, 0, 0).
//
// Progressive JPEGs have muliple Scans, incrementally building the 64
// coefficients (1 DC coefficient and 63 AC coefficients) of each
// pre-IDCT block. There are two independent aspects of progression.
//
// Spectral selection (the Ss and Se parameters) is when a subset of a
// 64 coefficients are in the scan. For example, three scans could hold
// coefficient 0 (the DC coefficient), coefficients 1 ..= 5 and then
// coefficients 6 ..= 63, in zig-zag order.
//
// Successive approximation (the Ah and Al parameters) is when a subset
// of the spectral-selected coefficients' 8 bits are in the scan
// (assuming 8-bit and not 12-bit or 16-bit JPEGs). For example, three
// scans could hold the 6 most significant bits, the second-least
// significant bit and then the least significant bit. A zero Ah value
// is a special case, meaning the scan holds (8 - Al) bits.
//
// The test/data/peacock.progressive.jpeg file has 10 scans:
// 0: Ss = 0 Se = 0 Ah = 0 Al = 1 3 components (Y, Cb, Cr)
// 1: Ss = 1 Se = 5 Ah = 0 Al = 2 1 component (Y)
// 2: Ss = 1 Se = 63 Ah = 0 Al = 1 1 component (Cr)
// 3: Ss = 1 Se = 63 Ah = 0 Al = 1 1 component (Cb)
// 4: Ss = 6 Se = 63 Ah = 0 Al = 2 1 component (Y)
// 5: Ss = 1 Se = 63 Ah = 2 Al = 1 1 component (Y)
// 6: Ss = 0 Se = 0 Ah = 1 Al = 0 3 components (Y, Cb, Cr)
// 7: Ss = 1 Se = 63 Ah = 1 Al = 0 1 component (Cr)
// 8: Ss = 1 Se = 63 Ah = 1 Al = 0 1 component (Cb)
// 9: Ss = 1 Se = 63 Ah = 1 Al = 0 1 component (Y)
//
// This matches /usr/bin/cjpeg's default script for progressive YCbCr:
// https://github.com/libjpeg-turbo/libjpeg-turbo/blob/2192560d74e6e6cf99dd05928885573be00a8208/jcparam.c#L517-L535
//
// The first scan holds the high 7 bits of all components' DC
// coefficients.
//
// The second scan holds the high 6 bits of the 1 ..= 5 AC coefficients
// of the Y component.
//
// The third and fourth scan give the high 7 bits of all of the AC
// coefficients of the Cr and Cb components.
//
// The fifth scan is like the second scan, but for the Y component's
// remaining AC coefficients.
//
// The sixth scan holds the second-least significant bit for the Y
// component's AC coefficients.
//
// The seventh scan holds the least significant bit for all components'
// DC coefficients.
//
// The last three scans hold the least significant bit for components'
// AC coefficients.
scan_ss : base.u8[..= 63],
scan_se : base.u8[..= 63],
scan_ah : base.u8[..= 14],
scan_al : base.u8[..= 13],
// These fields, the mx and my loop bounds in decode_sos, are usually
// measured "in MCUs" but, for progressive JPEGs' single-component
// scans, they're measured in blocks.
scan_width_in_mcus : base.u32[..= 0x2000],
scan_height_in_mcus : base.u32[..= 0x2000],
// The block's position within the MCU. For example, a 4:2:0 chroma-
// subsampled image has 6 blocks (4 Y, 1 Cb, 1 Cr) per MCU:
// 0: by = 0 bx = 0 Y
// 1: by = 0 bx = 1 Y
// 2: by = 1 bx = 0 Y
// 3: by = 1 bx = 1 Y
// 4: by = 0 bx = 0 Cb
// 5: by = 0 bx = 0 Cr
//
// The remaining (16 - mcu_num_blocks) elements are unused.
scan_comps_bx_offset : array[16] base.u8[..= 3],
scan_comps_by_offset : array[16] base.u8[..= 3],
mcu_num_blocks : base.u32[..= 10],
mcu_current_block : base.u32[..= 10],
mcu_zig_index : base.u32[..= 63],
mcu_blocks_sselector : array[16] base.u8[..= 3],
// (offset[b] + (mx_mul[b] * mx) + (my_mul[b] * my)) is the workbuf
// offset of the top-left sample of the b'th block in the (mx, my) MCU.
// The block's 64 samples are arranged in 8 rows, each separated by a
// stride equal to components_workbuf_widths[csel].
//
// For single-component scans, its calculation depends on:
// - components_workbuf_offsets
// - components_workbuf_widths
//
// For multi-component scans, its calculation depends on:
// - components_workbuf_offsets
// - components_workbuf_widths
// - scan_comps_bx_offset
// - scan_comps_by_offset
// - components_h
// - components_v
//
// Continuing our 4:2:0 chroma-subsampled, 36 × 28 sequential example:
// 0: my_mul = 768 mx_mul = 16 offset = 0x0000 + 0x0000 = 0
// 1: my_mul = 768 mx_mul = 16 offset = 0x0000 + 0x0008 = 8
// 2: my_mul = 768 mx_mul = 16 offset = 0x0000 + 0x0180 = 384
// 3: my_mul = 768 mx_mul = 16 offset = 0x0000 + 0x0188 = 392
// 4: my_mul = 192 mx_mul = 8 offset = 0x0600 + 0x0000 = 1536
// 5: my_mul = 192 mx_mul = 8 offset = 0x0780 + 0x0000 = 1920
mcu_blocks_offset : array[10] base.u64[..= 0xC_00D8_03D8], // (8 * 3 * (0x1_0008 + 1)) + 0xC_00C0_0300
mcu_blocks_mx_mul : array[10] base.u32[..= 0x00_0020], // 8 * 4.
mcu_blocks_my_mul : array[10] base.u32[..= 0x20_0100], // 8 * 4 * 0x1_0008.
mcu_blocks_dc_hselector : array[10] base.u8[..= 3],
mcu_blocks_ac_hselector : array[10] base.u8[..= 7],
mcu_previous_dc_values : array[4] base.u16,
block_smoothing_lowest_scan_al : array[4] array[10] base.u8[..= 16],
block_smoothing_dc_values : array[5] array[5] base.u16,
block_smoothing_mx_max_incl : base.u32[..= 0x1FFF],
block_smoothing_my_max_incl : base.u32[..= 0x1FFF],
restart_interval : base.u16,
saved_restart_interval : base.u16,
restarts_remaining : base.u16,
// End-Of-Band run count, per Section G.1.2.2: "Progressive encoding of
// AC coefficients with Huffman coding... An EOB run of length 5 means
// that the current block and the next four blocks have an end-of-band
// with no intervening non-zero coefficients".
eob_run : base.u16,
frame_config_io_position : base.u64,
payload_length : base.u32[..= 0xFFFF],
seen_dqt : array[4] base.bool,
saved_seen_dqt : array[4] base.bool,
seen_dht : array[8] base.bool,
// These fields yield bitstream bits in Most Significant Bits order.
bitstream_bits : base.u64,
bitstream_n_bits : base.u32,
bitstream_ri : base.u32[..= 0x800],
bitstream_wi : base.u32[..= 0x800],
bitstream_is_closed : base.bool,
// bitstream_padding is the number (per restart) of implicit zeroes
// remaining at the end of the bitstream. Its initial 12345 value is
// arbitrary.
bitstream_padding : base.u32[..= 12345],
quant_tables : array[4] array[64] base.u16[..= 0xFF],
saved_quant_tables : array[4] array[64] base.u16[..= 0xFF],
// huff_tables_symbols[(tc*4)|th][i] is the i'th Huffman code's symbol.
huff_tables_symbols : array[8] array[256] base.u8,
// huff_tables_slow[(tc*4)|th][n] is a u32 such that:
// - the high 24 bits hold the maximum (exclusive) bit-string of the
// codes of bit-length (n+1).
// - the low 8 bits hold a huff_tables_symbols[(tc*4)|th] index bias.
huff_tables_slow : array[8] array[16] base.u32,
// huff_tables_fast[(tc*4)|th][b] is a u16 that decodes the bit-length
// and symbol when the MSB-first bit-stream starts with b.
// - the high 8 bits hold the bit-length. Zero means no fast path.
// - the low 8 bits hold the symbol.
huff_tables_fast : array[8] array[256] base.u16,
swizzler : base.pixel_swizzler,
util : base.utility,
) + (
bitstream_buffer : array[0x800] base.u8, // 0x800 = 2048.
// Decoding sequential JPEGs only uses the first element of this array,
// since sequential decode_mcu calls decode_idct straight away.
// Decoding progressive JPEGs can use all of it.
mcu_blocks : array[10] array[64] base.u16,
swizzle_ycck_scratch_buffer_2k : array[2048] base.u8,
// The dht_temp_etc fields are decode_dht temporary values.
// dht_temp_counts[n] is the number of codes with bit-length (n+1).
dht_temp_counts : array[16] base.u8,
// dht_temp_bit_lengths[i] is the bit-length of the i'th code.
dht_temp_bit_lengths : array[256] base.u8,
// dht_temp_bit_strings[i] is the bit-string of the i'th code.
dht_temp_bit_strings : array[256] base.u16,
dst_palette : array[4 * 256] 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
} endwhile
}
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var c : base.u8
var marker : base.u8
var pixfmt : base.u32
if this.call_sequence <> 0x00 {
return base."#bad call sequence"
}
c = args.src.read_u8?()
if c <> 0xFF {
return "#bad header"
}
c = args.src.read_u8?()
if c <> 0xD8 { // SOI (Start Of Image).
return "#bad header"
}
// Process chunks (markers and their payloads).
while true {
// Read the marker (a two-byte 0xFF 0x?? sequence).
while true {
c = args.src.read_u8?()
if c == 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
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.
continue
} else if (0xD0 <= marker) and (marker <= 0xD9) {
// RSTn (Restart), SOI and EOI markers have no payload.
if marker <= 0xD7 {
continue
}
} else {
this.payload_length = args.src.read_u16be_as_u32?()
// Payload length includes the 2 bytes for the u16be just read.
if this.payload_length < 2 {
return "#bad marker"
}
this.payload_length -= 2
}
// Switch on the marker.
if marker < 0xC0 {
return "#unsupported marker"
} else if marker < 0xD0 { // SOFn (Start of Frame) and friends.
if marker <= 0xC2 {
if this.sof_marker <> 0 {
return "#bad SOF marker"
}
this.sof_marker = marker
this.decode_sof?(src: args.src)
break
} else if marker == 0xC3 {
return "#unsupported lossless coding"
} else if marker == 0xC4 { // DHT (Define Huffman Table).
// We shouldn't see DHT before SOF.
return "#bad DHT marker"
} else if (0xC5 <= marker) and (marker <= 0xC7) {
return "#unsupported hierarchical coding"
} else if marker == 0xC8 { // JPG (JPEG extension).
return "#unsupported marker"
} else {
return "#unsupported arithmetic coding"
}
} else if marker < 0xE0 {
if marker < 0xDA {
// RSTn markers are already handled above. We either have 0xD8
// (SOI: Start Of Image) or 0xD9 (EOI: End Of Image), neither
// of which are valid here.
return "#bad marker"
} else if marker == 0xDA { // SOS (Start Of Scan).
// We shouldn't see SOS before SOF.
return "#bad SOS marker"
} else if marker == 0xDB { // DQT (Define Quantization Table).
this.decode_dqt?(src: args.src)
continue
} else if marker == 0xDD { // DRI (Define Restart Interval).
this.decode_dri?(src: args.src)
continue
} else {
// 0xDC (DNL: Define Number of Lines).
// 0xDE (DHP: Define Hierarchical Progression).
// 0xDF (EXP: Expand Reference Components).
return "#unsupported marker"
}
} else if marker < 0xF0 { // APPn (Application specific).
this.decode_appn?(src: args.src, marker: marker)
continue
} else {
if marker == 0xFE { // COM (Comment).
// No-op.
} else {
return "#unsupported marker"
}
}
args.src.skip_u32?(n: this.payload_length)
this.payload_length = 0
} endwhile
choose decode_idct = [
// TODO: decode_idct_arm_neon,
decode_idct_x86_avx2]
this.frame_config_io_position = args.src.position()
if args.dst <> nullptr {
pixfmt = base.PIXEL_FORMAT__Y
if this.num_components > 1 {
// TODO: base.PIXEL_FORMAT__YCBCR is probably more correct,
// although possibly less convenient for the caller.
pixfmt = base.PIXEL_FORMAT__BGRX
}
args.dst.set!(
pixfmt: pixfmt,
pixsub: 0,
width: this.width,
height: this.height,
first_frame_io_position: this.frame_config_io_position,
first_frame_is_opaque: true)
}
this.call_sequence = 0x20
}
pri func decoder.decode_dqt?(src: base.io_reader) {
var c : 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 {
return "#bad DQT marker"
}
q = c & 0x0F
if (c >> 4) == 1 {
return "#unsupported precision"
} else if ((c >> 4) > 1) or (this.payload_length < 64) {
return "#bad DQT marker"
}
this.payload_length -= 64
i = 0
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 {
i = 0
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) {
if this.payload_length <> 2 {
return "#bad DRI marker"
}
this.payload_length = 0
this.restart_interval = args.src.read_u16be?()
if this.sof_marker == 0 {
this.saved_restart_interval = this.restart_interval
}
}
// APPn tags are listed at https://exiftool.org/TagNames/JPEG.html
pri func decoder.decode_appn?(src: base.io_reader, marker: base.u8) {
var c8 : base.u8
var c32 : base.u32
while.goto_done true {{
if args.marker == 0xE0 { // APP0.
if this.payload_length >= 5 {
this.payload_length -= 5
c32 = args.src.read_u32le?()
if c32 <> 'JFIF'le {
this.payload_length = 0xFFFF & (this.payload_length + 1)
break.goto_done
}
c8 = args.src.read_u8?()
this.is_jfif = (c8 == 0)
}
} else if args.marker == 0xEE { // APP14.
if this.payload_length >= 12 {
this.payload_length -= 12
c32 = args.src.read_u32le?()
if c32 <> 'Adob'le {
this.payload_length = 0xFFFF & (this.payload_length + 8)
break.goto_done
}
c32 = args.src.read_u32le?()
if (0xFF & c32) <> 'e' {
this.payload_length = 0xFFFF & (this.payload_length + 4)
break.goto_done
}
// After the 5 bytes of "Adobe" come 2 bytes of DCTEncodeVersion
// and 4 bytes of flags. The 12th byte is the color transform.
// Technically, 0=Unknown, 1=YCbCr and 2=YCbCrK. In practice, per
// libjpeg-turbo, treat 0=RGB/CMYK and NonZero=YCbCr/YCbCrK.
//
// https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe
c32 = args.src.read_u32le?()
if (c32 >> 24) == 0 {
this.is_adobe = 1
} else {
this.is_adobe = 2
}
}
}
break.goto_done
}} endwhile.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 comp_h : base.u8
var comp_v : base.u8
var i : base.u32
var j : base.u32
var has_h24 : base.bool
var has_h3 : base.bool
var has_v24 : base.bool
var has_v3 : base.bool
var upper_bound : base.u32[..= 0x1_0008]
var wh0 : base.u64[..= 0x1_0010_0040] // 0x1_0008 * 0x1_0008.
var wh1 : base.u64[..= 0x1_0010_0040] // 0x1_0008 * 0x1_0008.
var wh2 : base.u64[..= 0x1_0010_0040] // 0x1_0008 * 0x1_0008.
var wh3 : base.u64[..= 0x1_0010_0040] // 0x1_0008 * 0x1_0008.
var progressive : base.u64[..= 2]
if this.payload_length < 6 {
return "#bad SOF marker"
}
this.payload_length -= 6
c = args.src.read_u8?()
if c == 8 {
// No-op.
} else if c == 12 {
return "#unsupported precision (12 bits)"
} else if c == 16 {
return "#unsupported precision (16 bits)"
} else {
return "#unsupported precision"
}
this.height = args.src.read_u16be_as_u32?()
if this.height == 0 {
return "#unsupported implicit height"
}
this.width = args.src.read_u16be_as_u32?()
if this.width == 0 {
return base."#unsupported image dimension"
}
c = args.src.read_u8?()
if (c == 0) or (c > 4) {
return "#bad SOF marker"
} else if c == 2 {
return "#unsupported color model"
}
this.num_components = c as base.u32
if this.payload_length <> (3 * this.num_components) {
return "#bad SOF marker"
}
this.payload_length = 0
i = 0
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
if (comp_h == 0) or (comp_h > 4) or (comp_v == 0) or (comp_v > 4) {
return "#bad SOF marker"
}
this.components_h[i] = comp_h
if this.max_incl_components_h < this.components_h[i] {
this.max_incl_components_h = this.components_h[i]
}
this.components_v[i] = comp_v
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 {
return "#bad SOF marker"
}
this.components_tq[i] = c
// Section B.2.2: "the value of C_i shall be different from the values
// of C_1 through C_(i-1)".
j = 0
while j < i,
inv i < 4,
{
assert j < 4 via "a < b: a < c; c < b"(c: i)
if this.components_c[j] == this.components_c[i] {
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
// always 1. Section A.2.2: "When Ns = 1 (where Ns is the number of
// components in a scan), the order of data units [8x8 blocks] within a
// scan shall be left-to-right and top-to-bottom... regardless of the
// values of H1 and V1.".
this.max_incl_components_h = 1
this.max_incl_components_v = 1
this.components_h[0] = 1
this.components_v[0] = 1
} else {
has_h24 = false
has_h3 = false
has_v24 = false
has_v3 = false
i = 0
while i < this.num_components {
assert i < 4 via "a < b: a < c; c <= b"(c: this.num_components)
has_h24 = has_h24 or (this.components_h[i] == 2) or (this.components_h[i] == 4)
has_h3 = has_h3 or (this.components_h[i] == 3)
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"
}
// Match the behavior of libjpeg-turbo's jdapimin.c.
if this.num_components == 4 {
this.is_rgb_or_cmyk = this.is_adobe < 2
} else { // this.num_components == 3
if this.is_jfif {
this.is_rgb_or_cmyk = false
} else if this.is_adobe > 0 {
this.is_rgb_or_cmyk = this.is_adobe == 1
} else {
this.is_rgb_or_cmyk =
(this.components_c[0] == 'R') and
(this.components_c[1] == 'G') and
(this.components_c[2] == 'B')
}
}
}
this.width_in_mcus = this.quantize_dimension(
width: this.width, h: 1, max_incl_h: this.max_incl_components_h)
this.height_in_mcus = this.quantize_dimension(
width: this.height, h: 1, max_incl_h: this.max_incl_components_v)
upper_bound = 0x1_0008
this.components_workbuf_widths[0] = upper_bound.min(no_more_than:
8 * this.width_in_mcus * (this.components_h[0] as base.u32))
this.components_workbuf_widths[1] = upper_bound.min(no_more_than:
8 * this.width_in_mcus * (this.components_h[1] as base.u32))
this.components_workbuf_widths[2] = upper_bound.min(no_more_than:
8 * this.width_in_mcus * (this.components_h[2] as base.u32))
this.components_workbuf_widths[3] = upper_bound.min(no_more_than:
8 * this.width_in_mcus * (this.components_h[3] as base.u32))
this.components_workbuf_heights[0] = upper_bound.min(no_more_than:
8 * this.height_in_mcus * (this.components_v[0] as base.u32))
this.components_workbuf_heights[1] = upper_bound.min(no_more_than:
8 * this.height_in_mcus * (this.components_v[1] as base.u32))
this.components_workbuf_heights[2] = upper_bound.min(no_more_than:
8 * this.height_in_mcus * (this.components_v[2] as base.u32))
this.components_workbuf_heights[3] = upper_bound.min(no_more_than:
8 * this.height_in_mcus * (this.components_v[3] as base.u32))
wh0 = (this.components_workbuf_widths[0] as base.u64) * (this.components_workbuf_heights[0] as base.u64)
wh1 = (this.components_workbuf_widths[1] as base.u64) * (this.components_workbuf_heights[1] as base.u64)
wh2 = (this.components_workbuf_widths[2] as base.u64) * (this.components_workbuf_heights[2] as base.u64)
wh3 = (this.components_workbuf_widths[3] as base.u64) * (this.components_workbuf_heights[3] as base.u64)
progressive = 0
if this.sof_marker >= 0xC2 {
// Pre-IDCT block coefficients (mcu_blocks elements) are 2 bytes each.
progressive = 2
i = 0
while i < 4 {
j = 0
while j < 10,
inv i < 4,
{
this.block_smoothing_lowest_scan_al[i][j] = 16
j += 1
} endwhile
i += 1
} endwhile
}
this.components_workbuf_offsets[0] = 0
this.components_workbuf_offsets[1] = this.components_workbuf_offsets[0] + wh0
this.components_workbuf_offsets[2] = this.components_workbuf_offsets[1] + wh1
this.components_workbuf_offsets[3] = this.components_workbuf_offsets[2] + wh2
this.components_workbuf_offsets[4] = this.components_workbuf_offsets[3] + wh3
this.components_workbuf_offsets[5] = this.components_workbuf_offsets[4] + (wh0 * progressive)
this.components_workbuf_offsets[6] = this.components_workbuf_offsets[5] + (wh1 * progressive)
this.components_workbuf_offsets[7] = this.components_workbuf_offsets[6] + (wh2 * progressive)
this.components_workbuf_offsets[8] = this.components_workbuf_offsets[7] + (wh3 * progressive)
}
pri func decoder.quantize_dimension(width: base.u32[..= 0xFFFF], h: base.u8[..= 4], max_incl_h: base.u8[..= 4]) base.u32[..= 0x2000] {
var ratio : base.u32
ratio = 0
if args.h > 0 {
ratio = (args.max_incl_h / args.h) as base.u32
}
if ratio == 1 {
return (args.width + 0x07) / 0x08
} else if ratio == 2 {
return (args.width + 0x0F) / 0x10
} else if ratio == 3 {
return (args.width + 0x17) / 0x18
}
return (args.width + 0x1F) / 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
} endwhile
}
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: true,
overwrite_instead_of_blend: false,
background_color: 0xFF00_0000)
}
this.call_sequence = 0x40
}
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var ddf_status : base.status
var swizzle_status : base.status
var scan_count : base.u32
while true {
scan_count = this.scan_count
ddf_status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
if (ddf_status == base."$short read") and args.src.is_closed() {
ddf_status = "#truncated input"
}
if 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)
} else {
swizzle_status = this.swizzle_colorful!(dst: args.dst, workbuf: args.workbuf)
}
if ddf_status.is_error() {
return ddf_status
} else if swizzle_status.is_error() {
return swizzle_status
}
}
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 marker : base.u8
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"
}
pixfmt = base.PIXEL_FORMAT__Y
if this.num_components > 1 {
pixfmt = base.PIXEL_FORMAT__BGRX
}
status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
src_pixfmt: this.util.make_pixel_format(repr: pixfmt),
src_palette: this.util.empty_slice_u8(),
blend: args.blend)
if not status.is_ok() {
return status
}
// 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.
if this.components_workbuf_offsets[8] > args.workbuf.length() {
return base."#bad workbuf length"
} 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)
}
// For both sequential and progressive JPEGs, biased-zero-initialize the
// samples, in case the scans are incomplete (in terms of covering all
// components) or the input is truncated. 0x80 is the same post-IDCT bias
// as per BIAS_AND_CLAMP. For YCbCr, (0x80, 0x80, 0x80) is a medium gray
// but (0x00, 0x00, 0x00) is a dark green.
if this.components_workbuf_offsets[4] <= args.workbuf.length() {
args.workbuf[.. this.components_workbuf_offsets[4]].bulk_memset!(byte_value: 0x80)
}
// Process chunks (markers and their payloads).
while true {
// Read the marker (a two-byte 0xFF 0x?? sequence).
while true {
c = args.src.read_u8?()
if c == 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
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.
continue
} else if (0xD0 <= marker) and (marker <= 0xD9) {
// RSTn (Restart), SOI and EOI markers have no payload.
if marker <= 0xD7 {
continue
}
} else {
this.payload_length = args.src.read_u16be_as_u32?()
// Payload length includes the 2 bytes for the u16be just read.
if this.payload_length < 2 {
return "#bad marker"
}
this.payload_length -= 2
}
// Switch on the marker.
if marker < 0xC0 {
return "#unsupported marker"
} else if marker < 0xD0 { // SOFn (Start of Frame) and friends.
if marker == 0xC4 { // DHT (Define Huffman Table).
this.decode_dht?(src: args.src)
continue
} else if marker == 0xC8 { // JPG (JPEG extension).
return "#unsupported marker"
}
return "#bad SOF marker"
} else if marker < 0xE0 {
if marker < 0xD9 {
// RSTn markers are already handled above. We have 0xD8 (SOI:
// Start Of Image), which is invalid here.
return "#bad marker"
} else if marker == 0xD9 { // EOI (End Of Image).
break
} else if marker == 0xDA { // SOS (Start Of Scan).
this.decode_sos?(src: args.src, workbuf: args.workbuf)
continue
} else if marker == 0xDB { // DQT (Define Quantization Table).
this.decode_dqt?(src: args.src)
continue
} else if marker == 0xDD { // DRI (Define Restart Interval).
this.decode_dri?(src: args.src)
continue
} else {
// 0xDC (DNL: Define Number of Lines).
// 0xDE (DHP: Define Hierarchical Progression).
// 0xDF (EXP: Expand Reference Components).
return "#unsupported marker"
}
} else if marker < 0xF0 { // APPn (Application specific).
// No-op.
} else {
if marker == 0xFE { // COM (Comment).
// No-op.
} else {
return "#unsupported marker"
}
}
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 tc : base.u8[..= 1]
var th : base.u8[..= 3]
var tc4_th : base.u8[..= 7]
var working_total_count : base.u32[..= 0xFFFF]
var total_count : base.u32[..= 256]
var i : base.u32
var failed : base.bool
if this.sof_marker == 0 {
return "#bad DHT marker"
}
while this.payload_length > 0 {
if this.payload_length < 17 {
return "#bad DHT marker"
}
this.payload_length -= 17
c = args.src.read_u8?()
if ((c >> 4) > 1) or ((c & 0x0F) > 3) {
return "#bad DHT marker"
}
tc = c >> 4
th = c & 0x0F
tc4_th = ((tc * 4) | th) as base.u8
// SOF0 (which is 0xC0) means a baseline JPEG. The baseline (th <= 1)
// restriction is specified in table B.5.
if (this.sof_marker == 0xC0) and ((tc4_th & 3) > 1) {
return "#bad DHT marker"
}
// Read dht_temp_counts.
i = 0
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"
}
total_count = working_total_count
// Read huff_tables_symbols[tc4_th].
if this.payload_length < total_count {
return "#bad DHT marker"
}
this.payload_length -= total_count
i = 0
while i < total_count {
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.
if (tc4_th & 4) == 0 {
i = 0
while i < total_count {
assert i < 256 via "a < b: a < c; c <= b"(c: total_count)
if this.huff_tables_symbols[tc4_th][i] > 15 {
return "#bad DHT marker"
}
i += 1
} endwhile
}
failed = this.calculate_huff_tables!(tc4_th: tc4_th, total_count: total_count)
if failed {
return "#bad DHT marker"
}
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 {
var i : base.u32
var j : base.u8
var k : base.u8
var bit_length_minus_one : base.u32[..= 15]
var bit_length : base.u8[..= 16]
var bit_string : base.u32
var slow : base.u32
var prefix : base.u8
var fast : base.u16
var reps : base.u32
// Calculate dht_temp_bit_lengths.
i = 0
k = 0
bit_length_minus_one = 0
while i < args.total_count {
assert i < 256 via "a < b: a < c; c <= b"(c: args.total_count)
while k >= this.dht_temp_counts[bit_length_minus_one],
inv i < 256,
post k < this.dht_temp_counts[bit_length_minus_one],
{
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
bit_string = 0
i = 0
while i < args.total_count {
assert i < 256 via "a < b: a < c; c <= b"(c: args.total_count)
while bit_length < this.dht_temp_bit_lengths[i],
inv i < 256,
{
if bit_length >= 16 {
return true
}
bit_length += 1
bit_string ~mod<<= 1
} endwhile
this.dht_temp_bit_strings[i] = (bit_string & 0xFFFF) as base.u16
bit_string ~mod+= 1
// Check the bit_string just assigned to dht_temp_bit_strings[i].
// Section C: "the codes shall be generated such that the
// all-1-bits code word of any length is reserved".
if (bit_string >> bit_length) > 0 {
return true
}
i += 1
} endwhile
// Calculate huff_tables_slow[args.tc4_th].
k = 0
bit_length_minus_one = 0
while true {
if this.dht_temp_counts[bit_length_minus_one] == 0 {
this.huff_tables_slow[args.tc4_th][bit_length_minus_one] = 0
} else {
slow = 0xFF & ((k as base.u32) ~mod-
(this.dht_temp_bit_strings[k] as base.u32))
k ~mod+= this.dht_temp_counts[bit_length_minus_one]
this.huff_tables_slow[args.tc4_th][bit_length_minus_one] = slow |
(((this.dht_temp_bit_strings[k ~mod- 1] as base.u32) + 1) << 8)
}
bit_length_minus_one = (bit_length_minus_one + 1) & 15
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 {
k = 0
while k < this.dht_temp_counts[bit_length_minus_one],
inv bit_length_minus_one < 8,
{
assert k < 255 via "a < b: a < c; c <= b"(c: this.dht_temp_counts[bit_length_minus_one])
prefix = (((this.dht_temp_bit_strings[j] as base.u32) <<
(7 - bit_length_minus_one)) & 0xFF) as base.u8
fast = ((((bit_length_minus_one + 1) as base.u32) << 8) |
(this.huff_tables_symbols[args.tc4_th][j] as base.u32)) as base.u16
reps = (1 as base.u32) << (7 - bit_length_minus_one)
while reps > 0,
inv bit_length_minus_one < 8,
inv k < 255,
{
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) {
var my : base.u32
var mx : base.u32
var decode_mcu_result : base.u32
var bitstream_length : base.u32
if this.scan_count >= 64 {
return "#unsupported scan count"
}
this.prepare_scan?(src: args.src)
// Reset.
this.next_restart_marker = 0
this.mcu_previous_dc_values[0] = 0
this.mcu_previous_dc_values[1] = 0
this.mcu_previous_dc_values[2] = 0
this.mcu_previous_dc_values[3] = 0
this.restarts_remaining = this.restart_interval
this.eob_run = 0
this.bitstream_bits = 0
this.bitstream_n_bits = 0
this.bitstream_ri = 0
this.bitstream_wi = 0
this.bitstream_padding = 12345
this.fill_bitstream!(src: args.src)
my = 0
while my < this.scan_height_in_mcus {
assert my < 0x2000 via "a < b: a < c; c <= b"(c: this.scan_height_in_mcus)
mx = 0
while mx < this.scan_width_in_mcus,
inv my < 0x2000,
{
assert mx < 0x2000 via "a < b: a < c; c <= b"(c: this.scan_width_in_mcus)
this.mcu_current_block = 0
this.mcu_zig_index = this.scan_ss as base.u32
if this.sof_marker >= 0xC2 {
this.load_mcu_blocks!(mx: mx, my: my, workbuf: args.workbuf)
}
while.decode_mcu true,
inv my < 0x2000,
inv mx < 0x2000,
{
decode_mcu_result = this.decode_mcu!(workbuf: args.workbuf, mx: mx, my: my)
if decode_mcu_result == 0 {
break.decode_mcu
} else if decode_mcu_result <> 1 {
return "#internal error: inconsistent decoder state"
}
while.fill_bitstream true,
inv my < 0x2000,
inv mx < 0x2000,
{
bitstream_length = this.bitstream_wi ~mod- this.bitstream_ri
this.fill_bitstream!(src: args.src)
if bitstream_length < (this.bitstream_wi ~mod- this.bitstream_ri) {
break.fill_bitstream
} else if this.bitstream_padding == 0 {
return "#bad SOS marker"
} else if args.src.is_closed() and (not this.bitstream_is_closed) {
if this.bitstream_wi < (0x800 / 2) {
assert this.bitstream_wi <= (this.bitstream_wi + 264) via "a <= (a + b): 0 <= b"()
this.bitstream_buffer[this.bitstream_wi .. (this.bitstream_wi + 264)].bulk_memset!(byte_value: 0)
this.bitstream_wi += 264
this.bitstream_is_closed = true
}
break.fill_bitstream
}
yield? base."$short read"
} endwhile.fill_bitstream
} endwhile.decode_mcu
if this.sof_marker >= 0xC2 {
this.save_mcu_blocks!(mx: mx, my: my, workbuf: args.workbuf)
}
// Check for a restart.
if this.restarts_remaining > 0 {
this.restarts_remaining -= 1
if this.restarts_remaining == 0 {
this.skip_past_the_next_restart_marker?(src: args.src)
// Reset.
this.mcu_previous_dc_values[0] = 0
this.mcu_previous_dc_values[1] = 0
this.mcu_previous_dc_values[2] = 0
this.mcu_previous_dc_values[3] = 0
this.restarts_remaining = this.restart_interval
this.eob_run = 0
this.bitstream_bits = 0
this.bitstream_n_bits = 0
this.bitstream_ri = 0
this.bitstream_wi = 0
this.bitstream_padding = 12345
}
}
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 i : base.u32
var j : base.u32
var j_max_incl : base.u32[..= 9]
var failed : base.bool
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) {
return "#bad SOS marker"
}
this.scan_num_components = c 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"
}
this.payload_length = 0
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?()
j = 0
while true,
inv i < 4,
{
if j >= this.num_components {
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 not this.seen_dqt[this.components_tq[j]] {
return "#missing Quantization table"
}
this.scan_comps_cselector[i] = j as base.u8
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".
j = 0
while j < i,
inv i < 4,
{
assert j < 4 via "a < b: a < c; c < b"(c: i)
if this.scan_comps_cselector[i] == this.scan_comps_cselector[j] {
return "#bad SOS marker"
}
j += 1
} endwhile
c = args.src.read_u8?()
if ((c >> 4) > 3) or ((c & 0x0F) > 3) {
return "#bad SOS marker"
}
this.scan_comps_td[i] = c >> 4
this.scan_comps_ta[i] = c & 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 {
if (this.scan_comps_td[i] > 1) or (this.scan_comps_ta[i] > 1) {
return "#bad SOS marker"
}
}
i += 1
} endwhile
if this.sof_marker < 0xC2 {
// At this point, for sequential (not progressive) JPEGs, we should
// check that (Ss, Se, Ah, Al) is (0, 63, 0, 0) but libjpeg treats
// otherwise as a warning (JWRN_NOT_SEQUENTIAL), not an error.
args.src.skip_u32?(n: 3)
this.scan_ss = 0
this.scan_se = 63
this.scan_ah = 0
this.scan_al = 0
} else {
c = args.src.read_u8?()
if c > 63 {
return "#bad SOS marker"
}
this.scan_ss = c
c = args.src.read_u8?()
if (c > 63) or (c < this.scan_ss) {
return "#bad SOS marker"
}
this.scan_se = c
c = args.src.read_u8?()
if ((c >> 4) > 14) or ((c & 0x0F) > 13) {
return "#bad SOS marker"
}
this.scan_ah = c >> 4
this.scan_al = c & 0x0F
if this.scan_ah > 0 {
if (this.scan_ah - 1) <> this.scan_al {
return "#bad SOS marker"
}
}
if this.scan_ss == 0 {
// Progressive DC scans can have only one spectral element.
if this.scan_se <> 0 {
return "#bad SOS marker"
} else if this.scan_ah == 0 {
choose decode_mcu = [decode_mcu_progressive_dc_high_bits]
} else {
choose decode_mcu = [decode_mcu_progressive_dc_low_bit]
}
} else {
// Progressive AC scans can have only one component.
if this.scan_num_components <> 1 {
return "#bad SOS marker"
} else if this.scan_ah == 0 {
choose decode_mcu = [decode_mcu_progressive_ac_high_bits]
} else {
choose decode_mcu = [decode_mcu_progressive_ac_low_bit]
}
}
}
i = 0
while i < this.scan_num_components {
assert i < 4 via "a < b: a < c; c <= b"(c: this.scan_num_components)
if (this.scan_ss == 0) and (not this.seen_dht[0 | this.scan_comps_td[i]]) {
this.use_default_huffman_table?(tc4_th: 0 | this.scan_comps_td[i])
}
if (this.scan_se <> 0) and (not this.seen_dht[4 | this.scan_comps_ta[i]]) {
this.use_default_huffman_table?(tc4_th: 4 | this.scan_comps_ta[i])
}
j = this.scan_ss as base.u32
j_max_incl = (this.scan_se.min(no_more_than: 9)) as base.u32
while j <= j_max_incl,
inv i < 4,
{
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!()
} else {
failed = this.calculate_multiple_component_scan_fields!()
if failed {
return "#bad SOS marker"
}
}
}
pri func decoder.use_default_huffman_table?(tc4_th: base.u8[..= 7]) {
var data : roslice base.u8
var r : base.io_reader
var status : base.status
if args.tc4_th == 0 {
data = DEFAULT_HUFF_TABLE_DC_LUMA[..]
} else if args.tc4_th == 1 {
data = DEFAULT_HUFF_TABLE_DC_CHROMA[..]
} else if args.tc4_th == 4 {
data = DEFAULT_HUFF_TABLE_AC_LUMA[..]
} else if args.tc4_th == 5 {
data = DEFAULT_HUFF_TABLE_AC_CHROMA[..]
} else {
return "#missing Huffman table"
}
io_bind (io: r, data: data, history_position: 0) {
this.payload_length = (data.length() & 0xFFFF) as base.u32
status =? this.decode_dht?(src: r)
}
return status
}
pri func decoder.calculate_single_component_scan_fields!() {
var csel : base.u8[..= 3]
this.scan_comps_bx_offset[0] = 0
this.scan_comps_by_offset[0] = 0
this.mcu_num_blocks = 1
this.mcu_blocks_sselector[0] = 0
csel = this.scan_comps_cselector[0]
this.mcu_blocks_offset[0] = this.components_workbuf_offsets[csel]
this.mcu_blocks_mx_mul[0] = 8
this.mcu_blocks_my_mul[0] = 8 * this.components_workbuf_widths[csel]
this.mcu_blocks_dc_hselector[0] = 0 | this.scan_comps_td[0]
this.mcu_blocks_ac_hselector[0] = 4 | this.scan_comps_ta[0]
this.scan_width_in_mcus = this.quantize_dimension(
width: this.width, h: this.components_h[csel], max_incl_h: this.max_incl_components_h)
this.scan_height_in_mcus = this.quantize_dimension(
width: this.height, h: this.components_v[csel], max_incl_h: this.max_incl_components_v)
}
pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
var i : base.u32
var h : base.u32[..= 4]
var v : base.u32[..= 4]
var hv : base.u32[..= 16]
var total_hv : base.u32
var b : base.u32
var bx_offset : base.u32
var by_offset : base.u32
var ssel : base.u8[..= 3]
var csel : base.u8[..= 3]
total_hv = 0
i = 0
b = 0
bx_offset = 0
by_offset = 0
while i < this.scan_num_components {
assert i < 4 via "a < b: a < c; c <= b"(c: this.scan_num_components)
h = this.components_h[this.scan_comps_cselector[i]] as base.u32
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))
total_hv ~mod+= hv
while hv > 0,
inv i < 4,
{
this.scan_comps_bx_offset[b & 15] = (bx_offset & 3) as base.u8
this.scan_comps_by_offset[b & 15] = (by_offset & 3) as base.u8
this.mcu_blocks_sselector[b & 15] = i as base.u8
b ~mod+= 1
bx_offset ~mod+= 1
if bx_offset == h {
bx_offset = 0
by_offset ~mod+= 1
if by_offset == v {
by_offset = 0
}
}
hv -= 1
} endwhile
i += 1
} endwhile
if total_hv > 10 {
return true
}
this.mcu_num_blocks = total_hv
b = 0
while b < this.mcu_num_blocks {
assert b < 10 via "a < b: a < c; c <= b"(c: this.mcu_num_blocks)
ssel = this.mcu_blocks_sselector[b]
csel = this.scan_comps_cselector[ssel]
this.mcu_blocks_offset[b] = this.components_workbuf_offsets[csel] +
(8 * (this.scan_comps_bx_offset[b] as base.u64)) +
(8 * (this.scan_comps_by_offset[b] as base.u64) * (this.components_workbuf_widths[csel] as base.u64))
this.mcu_blocks_mx_mul[b] = 8 * (this.components_h[csel] as base.u32)
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]
b += 1
} endwhile
this.scan_width_in_mcus = this.width_in_mcus
this.scan_height_in_mcus = this.height_in_mcus
return false
}
pri func decoder.fill_bitstream!(src: base.io_reader) {
var wi : base.u32[..= 0x800]
var c : base.u8
var new_wi : base.u32[..= 0x800]
// Compact unread bytes to the start of the buffer.
if this.bitstream_ri <= 0 {
// No-op.
} else if this.bitstream_ri >= this.bitstream_wi {
this.bitstream_ri = 0
this.bitstream_wi = 0
} else {
assert this.bitstream_wi > this.bitstream_ri via "a > b: b < a"()
wi = this.bitstream_wi - this.bitstream_ri
this.bitstream_buffer[..].copy_from_slice!(s: this.bitstream_buffer[this.bitstream_ri .. this.bitstream_wi])
this.bitstream_ri = 0
this.bitstream_wi = wi
}
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
wi += 1
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
continue
} else if args.src.length() <= 1 {
break
} else if (args.src.peek_u16le() >> 8) > 0 {
break
} else {
this.bitstream_buffer[wi] = 0xFF
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
// this method can insert even more.
if args.src.length() > 1 {
if (args.src.peek_u8() >= 0xFF) and ((args.src.peek_u16le() >> 8) > 0) {
new_wi = wi.min(no_more_than: 0x800 - 264) + 264
new_wi = new_wi.min(no_more_than: wi + this.bitstream_padding)
if wi < new_wi {
assert new_wi > wi via "a > b: b < a"()
this.bitstream_padding ~sat-= new_wi - wi
this.bitstream_buffer[wi .. new_wi].bulk_memset!(byte_value: 0)
wi = new_wi
}
}
}
this.bitstream_wi = wi
}
pri func decoder.load_mcu_blocks_for_single_component!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2000], workbuf: slice base.u8, csel: base.u32[..= 3]),
choosy,
{
var stride16 : base.u64[..= 0x10_0080]
var offset : base.u64
stride16 = (this.components_workbuf_widths[args.csel] * 16) as base.u64
offset = this.components_workbuf_offsets[args.csel | 4] +
((args.mx as base.u64) * 128) +
((args.my as base.u64) * stride16)
if offset <= args.workbuf.length() {
this.mcu_blocks[.. 1].bulk_load_host_endian!(src: args.workbuf[offset ..])
}
}
pri func decoder.load_mcu_blocks!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2000], workbuf: slice base.u8) {
var b : base.u32
var csel : base.u8[..= 3]
var h : base.u64[..= 4]
var v : base.u64[..= 4]
var stride16 : base.u64[..= 0x10_0080]
var offset : base.u64
h = 1
v = 1
b = 0
while b < this.mcu_num_blocks {
assert b < 10 via "a < b: a < c; c <= b"(c: this.mcu_num_blocks)
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[b]]
if this.scan_num_components > 1 {
h = this.components_h[csel] as base.u64
v = this.components_v[csel] as base.u64
}
stride16 = (this.components_workbuf_widths[csel] * 16) as base.u64
offset = this.components_workbuf_offsets[csel | 4] +
(((h * (args.mx as base.u64)) + (this.scan_comps_bx_offset[b] as base.u64)) * 128) +
(((v * (args.my as base.u64)) + (this.scan_comps_by_offset[b] as base.u64)) * stride16)
if offset <= args.workbuf.length() {
assert b <= (b + 1) via "a <= (a + b): 0 <= b"()
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) {
var b : base.u32
var csel : base.u8[..= 3]
var h : base.u64[..= 4]
var v : base.u64[..= 4]
var stride16 : base.u64[..= 0x10_0080]
var offset : base.u64
h = 1
v = 1
b = 0
while b < this.mcu_num_blocks {
assert b < 10 via "a < b: a < c; c <= b"(c: this.mcu_num_blocks)
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[b]]
if this.scan_num_components > 1 {
h = this.components_h[csel] as base.u64
v = this.components_v[csel] as base.u64
}
stride16 = (this.components_workbuf_widths[csel] * 16) as base.u64
offset = this.components_workbuf_offsets[csel | 4] +
(((h * (args.mx as base.u64)) + (this.scan_comps_bx_offset[b] as base.u64)) * 128) +
(((v * (args.my as base.u64)) + (this.scan_comps_by_offset[b] as base.u64)) * stride16)
if offset <= args.workbuf.length() {
assert b <= (b + 1) via "a <= (a + b): 0 <= b"()
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
while true {
if args.src.length() < 2 {
yield? base."$short read"
continue
} else if args.src.peek_u8() < 0xFF {
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
continue
}
c = (args.src.peek_u16le() >> 8) as base.u8
if c < 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) {
// 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)) {
// 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)) {
// A lagging RSTn marker. Consume it and continue.
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
continue
} else {
// The RSTn marker is either the expected one or far away from the
// expected one (neither leading or lagging). Consume it and break.
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
break
}
} endwhile
this.next_restart_marker = (this.next_restart_marker ~mod+ 1) & 7
}
pri func decoder.apply_progressive_idct!(workbuf: slice base.u8) {
var csel : base.u32
var block_smoothing_applicable : base.bool
var scan_width_in_mcus : base.u32[..= 0x2000]
var scan_height_in_mcus : base.u32[..= 0x2000]
var mcu_blocks_mx_mul_0 : base.u32[..= 0x00_0020]
var mcu_blocks_my_mul_0 : base.u32[..= 0x20_0100]
var my : base.u32
var mx : base.u32
var stride : base.u64[..= 0x1_0008]
var offset : base.u64
// Copies mcu_blocks[0], which load_mcu_blocks_for_single_component might
// overwrite, as decode_mcu may be suspended (due to a "$short read").
var stashed_mcu_blocks_0 : array[128] base.u8
this.mcu_blocks[.. 1].bulk_save_host_endian!(dst: stashed_mcu_blocks_0[..])
block_smoothing_applicable = true
csel = 0
while csel < this.num_components {
assert csel < 4 via "a < b: a < c; c <= b"(c: this.num_components)
if (this.block_smoothing_lowest_scan_al[csel][0] >= 16) or
this.top_left_quants_has_zero(q: this.components_tq[csel] as base.u32) {
block_smoothing_applicable = false
}
csel += 1
} endwhile
csel = 0
while csel < this.num_components {
assert csel < 4 via "a < b: a < c; c <= b"(c: this.num_components)
// Fake a single-component scan.
scan_width_in_mcus = this.quantize_dimension(
width: this.width, h: this.components_h[csel], max_incl_h: this.max_incl_components_h)
scan_height_in_mcus = this.quantize_dimension(
width: this.height, h: this.components_v[csel], max_incl_h: this.max_incl_components_v)
mcu_blocks_mx_mul_0 = 8
mcu_blocks_my_mul_0 = 8 * this.components_workbuf_widths[csel]
// For partially loaded progressive JPEGs, apply what libjpeg-turbo
// calls "block smoothing".
if block_smoothing_applicable and (0 <> (
this.block_smoothing_lowest_scan_al[csel][1] |
this.block_smoothing_lowest_scan_al[csel][2] |
this.block_smoothing_lowest_scan_al[csel][3] |
this.block_smoothing_lowest_scan_al[csel][4] |
this.block_smoothing_lowest_scan_al[csel][5] |
this.block_smoothing_lowest_scan_al[csel][6] |
this.block_smoothing_lowest_scan_al[csel][8] |
this.block_smoothing_lowest_scan_al[csel][8] |
this.block_smoothing_lowest_scan_al[csel][9])) {
choose load_mcu_blocks_for_single_component = [load_mcu_blocks_for_single_component_smooth]
this.block_smoothing_mx_max_incl = scan_width_in_mcus ~sat- 1
this.block_smoothing_my_max_incl = scan_height_in_mcus ~sat- 1
} else {
choose load_mcu_blocks_for_single_component = [load_mcu_blocks_for_single_component]
}
// Apply IDCT to the MCU blocks in the csel'th component.
my = 0
while my < scan_height_in_mcus,
inv csel < 4,
{
assert my < 0x2000 via "a < b: a < c; c <= b"(c: scan_height_in_mcus)
mx = 0
while mx < scan_width_in_mcus,
inv csel < 4,
inv my < 0x2000,
{
assert mx < 0x2000 via "a < b: a < c; c <= b"(c: scan_width_in_mcus)
this.load_mcu_blocks_for_single_component!(mx: mx, my: my, workbuf: args.workbuf, csel: csel)
stride = this.components_workbuf_widths[csel] as base.u64
offset = this.components_workbuf_offsets[csel] +
((mcu_blocks_mx_mul_0 as base.u64) * (mx as base.u64)) +
((mcu_blocks_my_mul_0 as base.u64) * (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)
}
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 {
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 tab : table base.u8
var dst : slice base.u8
var y : base.u32
var stride : base.u64[..= 0x4_0000]
// 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_length = (dst_bytes_per_pixel * 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)
dst = tab.row_u32(y: y)
if dst_length < dst.length() {
dst = dst[.. dst_length]
}
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 ..]
} 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
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.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]]
}
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]]
}
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]]
}
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,
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],
h0: this.components_h[0],
h1: this.components_h[1],
h2: this.components_h[2],
h3: this.components_h[3],
v0: this.components_v[0],
v1: this.components_v[1],
v2: this.components_v[2],
v3: this.components_v[3],
is_rgb_or_cmyk: this.is_rgb_or_cmyk,
triangle_filter_for_2to1: true,
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
return status
}
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 {
var i : base.u32
var j : base.u32
if this.call_sequence < 0x20 {
return base."#bad call sequence"
}
if args.index <> 0 {
return base."#bad argument"
}
this.call_sequence = 0x28
this.bitstream_is_closed = false
this.frame_config_io_position = args.io_position
this.scan_count = 0
this.restart_interval = this.saved_restart_interval
i = 0
while i < 4 {
this.seen_dqt[i] = this.saved_seen_dqt[i]
j = 0
while j < 64,
inv i < 4,
{
this.quant_tables[i][j] = this.saved_quant_tables[i][j]
j += 1
} endwhile
i += 1
} endwhile
i = 0
while i < 4 {
j = 0
while j < 10,
inv i < 4,
{
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
}
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
// TODO: implement.
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
return base."#no more information"
}
pub func decoder.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.components_workbuf_offsets[8],
max_incl: this.components_workbuf_offsets[8])
}
+886
View File
@@ -0,0 +1,886 @@
// 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.
// ----
// 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
// this.mcu_blocks[0] array are:
//
// 0x00 0x01 0x02 0x03 .... .... .... .... // 0x00 is the DC coefficient.
// 0x08 0x09 0x0A .... .... .... .... ....
// 0x10 0x11 .... .... .... .... .... ....
// 0x18 .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
//
// These are the first 10 coefficients (in zig-zag order), the 10 elements of
// each this.block_smoothing_lowest_scan_al[csel] array:
//
// zig0 zig1 zig5 zig6 .... .... .... .... // zig0 is the DC coefficient.
// zig2 zig4 zig7 .... .... .... .... ....
// zig3 zig8 .... .... .... .... .... ....
// zig9 .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
// .... .... .... .... .... .... .... ....
pri func decoder.top_left_quants_has_zero(q: base.u32[..= 3]) base.bool {
// Examine the top-left 10 of the 8×8 = 64 quantization factors.
return (this.quant_tables[args.q][0x00] == 0) or
(this.quant_tables[args.q][0x01] == 0) or
(this.quant_tables[args.q][0x02] == 0) or
(this.quant_tables[args.q][0x03] == 0) or
(this.quant_tables[args.q][0x08] == 0) or
(this.quant_tables[args.q][0x09] == 0) or
(this.quant_tables[args.q][0x0A] == 0) or
(this.quant_tables[args.q][0x10] == 0) or
(this.quant_tables[args.q][0x11] == 0) or
(this.quant_tables[args.q][0x18] == 0)
}
pri func decoder.load_mcu_blocks_for_single_component_smooth!(mx: base.u32[..= 0x2000], my: base.u32[..= 0x2000], workbuf: slice base.u8, csel: base.u32[..= 3]) {
var stride16 : base.u64[..= 0x10_0080]
var offset : base.u64
var dx : base.u32
var dy : base.u32
var mx : base.u32[..= 0x1FFF]
var my : base.u32[..= 0x1FFF]
var q : base.u8[..= 3]
var q_00 : base.u32
var q_xy : base.u32
var al : base.u8[..= 16]
var scratch : base.u32
var limit : base.u32
stride16 = (this.components_workbuf_widths[args.csel] * 16) as base.u64
offset = this.components_workbuf_offsets[args.csel | 4] +
((args.mx as base.u64) * 128) +
((args.my as base.u64) * stride16)
if offset <= args.workbuf.length() {
this.mcu_blocks[.. 1].bulk_load_host_endian!(src: args.workbuf[offset ..])
}
dy = 0
while dy < 5 {
my = this.block_smoothing_my_max_incl.min(no_more_than: (args.my + dy) ~sat- 2)
dx = 0
while dx < 5,
inv dy < 5,
{
mx = this.block_smoothing_mx_max_incl.min(no_more_than: (args.mx + dx) ~sat- 2)
offset = this.components_workbuf_offsets[args.csel | 4] +
((mx as base.u64) * 128) +
((my as base.u64) * stride16)
if offset <= args.workbuf.length() {
assert dx <= (dx + 1) via "a <= (a + b): 0 <= b"()
this.block_smoothing_dc_values[dy][dx .. (dx + 1)].bulk_load_host_endian!(src: args.workbuf[offset ..])
}
dx += 1
} endwhile
dy += 1
} endwhile
q = this.components_tq[args.csel]
q_00 = this.quant_tables[q][0x00] as base.u32
if q_00 <= 0 {
return nothing
}
// See "Consider the 8×8" above.
//
// There are two sets of formulae, adjusting 10 or 5 coefficients:
// - Major: 0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x18.
// zig0, zig1, zig5, zig6, zig2, zig4, zig7, zig3, zig8, zig9.
// - Minor: 0x01, 0x02, 0x08, 0x09, 0x10.
// zig1, zig5, zig2, zig4, zig3.
//
// We only do major smoothing (including DC interpolation) if no AC
// coefficients are available.
if 0 <> (16 &
this.block_smoothing_lowest_scan_al[args.csel][1] &
this.block_smoothing_lowest_scan_al[args.csel][2] &
this.block_smoothing_lowest_scan_al[args.csel][3] &
this.block_smoothing_lowest_scan_al[args.csel][4] &
this.block_smoothing_lowest_scan_al[args.csel][5] &
this.block_smoothing_lowest_scan_al[args.csel][6] &
this.block_smoothing_lowest_scan_al[args.csel][7] &
this.block_smoothing_lowest_scan_al[args.csel][8] &
this.block_smoothing_lowest_scan_al[args.csel][9]) {
// Major smoothing.
// Offset=0x00 DC coefficient. Weights total to +256:
//
// -2 -6 -8 -6 -2
// -6 +6 +42 +6 -6
// -8 +42 +152 +42 -8
// -6 +6 +42 +6 -6
// -2 -6 -8 -6 -2
if true {
scratch = 0
scratch ~mod+= 0xFFFF_FFFE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0xFFFF_FFF8 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0xFFFF_FFFE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0006 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_002A ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0006 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0xFFFF_FFF8 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_002A ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0098 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_002A ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0xFFFF_FFF8 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0006 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_002A ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0006 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0xFFFF_FFFE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0xFFFF_FFF8 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0xFFFF_FFFA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0xFFFF_FFFE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (1 << 7)) / (1 << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (1 << 7)) / (1 << 8))
}
this.mcu_blocks[0][0x00] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x01 AC coefficient. Weights total to zero:
//
// -1 -1 0 +1 +1
// -3 +13 0 -13 +3
// -3 +38 0 -38 +3
// -3 +13 0 -13 +3
// -1 -1 0 +1 +1
q_xy = this.quant_tables[q][0x01] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x01] == 0) {
scratch = 0
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0xFFFF_FFF3 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0026 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0xFFFF_FFDA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0xFFFF_FFF3 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x01] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x02 AC coefficient. Weights total to zero:
//
// 0 0 0 0 0
// 0 +2 -5 +2 0
// +1 +7 -14 +7 +1
// 0 +2 -5 +2 0
// 0 0 0 0 0
q_xy = this.quant_tables[q][0x02] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x02] == 0) {
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0xFFFF_FFFB ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0007 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0xFFFF_FFF2 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0007 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0xFFFF_FFFB ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x02] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x03 AC coefficient. Weights total to zero:
//
// 0 0 0 0 0
// 0 +1 0 -1 0
// 0 +2 0 -2 0
// 0 +1 0 -1 0
// 0 0 0 0 0
q_xy = this.quant_tables[q][0x03] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x03] == 0) {
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0xFFFF_FFFE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x03] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x08 AC coefficient. Weights total to zero:
//
// -1 -3 -3 -3 -1
// -1 +13 +38 +13 -1
// 0 0 0 0 0
// +1 -13 -38 -13 +1
// +1 +3 +3 +3 +1
q_xy = this.quant_tables[q][0x08] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x08] == 0) {
scratch = 0
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0026 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0xFFFF_FFF3 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0xFFFF_FFDA ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0xFFFF_FFF3 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x08] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x09 AC coefficient. Weights total to zero:
//
// -1 0 0 0 +1
// 0 +9 0 -9 0
// 0 0 0 0 0
// 0 -9 0 +9 0
// +1 0 0 0 -1
q_xy = this.quant_tables[q][0x09] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x09] == 0) {
scratch = 0
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0009 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0xFFFF_FFF7 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0xFFFF_FFF7 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0009 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x09] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x0A AC coefficient. Weights total to zero:
//
// 0 0 0 0 0
// 0 +1 -3 +1 0
// 0 0 0 0 0
// 0 -1 +3 -1 0
// 0 0 0 0 0
q_xy = this.quant_tables[q][0x0A] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x0A] == 0) {
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x0A] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x10 AC coefficient. Weights total to zero:
//
// 0 0 +1 0 0
// 0 +2 +7 +2 0
// 0 -5 -14 -5 0
// 0 +2 +7 +2 0
// 0 0 +1 0 0
q_xy = this.quant_tables[q][0x10] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x10] == 0) {
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0007 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0xFFFF_FFFB ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0xFFFF_FFF2 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0xFFFF_FFFB ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0007 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x10] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x11 AC coefficient. Weights total to zero:
//
// 0 0 0 0 0
// 0 +1 0 -1 0
// 0 -3 0 +3 0
// 0 +1 0 -1 0
// 0 0 0 0 0
q_xy = this.quant_tables[q][0x11] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x11] == 0) {
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0xFFFF_FFFD ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0003 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x11] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x18 AC coefficient. Weights total to zero:
//
// 0 0 0 0 0
// 0 +1 +2 +1 0
// 0 0 0 0 0
// 0 -1 -2 -1 0
// 0 0 0 0 0
q_xy = this.quant_tables[q][0x18] as base.u32
if (q_xy > 0) and (this.mcu_blocks[0][0x18] == 0) {
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0002 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0xFFFF_FFFE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
} else {
scratch = 0 ~mod- (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8))
}
this.mcu_blocks[0][0x18] = (scratch & 0xFFFF) as base.u16
}
} else {
// Minor smoothing.
// Offset=0x01 AC coefficient. Weights total to zero:
//
// 0 0 0 0 0
// 0 0 0 0 0
// -7 +50 0 -50 +7
// 0 0 0 0 0
// 0 0 0 0 0
al = this.block_smoothing_lowest_scan_al[args.csel][1]
q_xy = this.quant_tables[q][0x01] as base.u32
if (al > 0) and (q_xy > 0) and (this.mcu_blocks[0][0x01] == 0) {
limit = ((1 as base.u32) << al) - 1
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0xFFFF_FFF9 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0032 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0xFFFF_FFCE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0007 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ limit.min(no_more_than: (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
} else {
scratch = 0 ~mod- limit.min(no_more_than: (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
}
this.mcu_blocks[0][0x01] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x02 AC coefficient. Weights total to zero:
//
// 0 0 0 0 0
// 0 0 0 0 0
// -1 +13 -24 +13 -1
// 0 0 0 0 0
// 0 0 0 0 0
al = this.block_smoothing_lowest_scan_al[args.csel][5]
q_xy = this.quant_tables[q][0x02] as base.u32
if (al > 0) and (q_xy > 0) and (this.mcu_blocks[0][0x02] == 0) {
limit = ((1 as base.u32) << al) - 1
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0xFFFF_FFE8 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ limit.min(no_more_than: (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
} else {
scratch = 0 ~mod- limit.min(no_more_than: (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
}
this.mcu_blocks[0][0x02] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x08 AC coefficient. Weights total to zero:
//
// 0 0 -7 0 0
// 0 0 +50 0 0
// 0 0 0 0 0
// 0 0 -50 0 0
// 0 0 +7 0 0
al = this.block_smoothing_lowest_scan_al[args.csel][2]
q_xy = this.quant_tables[q][0x08] as base.u32
if (al > 0) and (q_xy > 0) and (this.mcu_blocks[0][0x08] == 0) {
limit = ((1 as base.u32) << al) - 1
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0xFFFF_FFF9 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0032 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0xFFFF_FFCE ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0007 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ limit.min(no_more_than: (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
} else {
scratch = 0 ~mod- limit.min(no_more_than: (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
}
this.mcu_blocks[0][0x08] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x09 AC coefficient. Weights total to zero:
//
// 0 -1 0 +1 0
// -1 +10 0 -10 +1
// 0 0 0 0 0
// +1 -10 0 +10 -1
// 0 +1 0 -1 0
al = this.block_smoothing_lowest_scan_al[args.csel][4]
q_xy = this.quant_tables[q][0x09] as base.u32
if (al > 0) and (q_xy > 0) and (this.mcu_blocks[0][0x09] == 0) {
limit = ((1 as base.u32) << al) - 1
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_000A ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0xFFFF_FFF6 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0xFFFF_FFF6 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_000A ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0001 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ limit.min(no_more_than: (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
} else {
scratch = 0 ~mod- limit.min(no_more_than: (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
}
this.mcu_blocks[0][0x09] = (scratch & 0xFFFF) as base.u16
}
// Offset=0x10 AC coefficient. Weights total to zero:
//
// 0 0 -1 0 0
// 0 0 +13 0 0
// 0 0 -24 0 0
// 0 0 +13 0 0
// 0 0 -1 0 0
al = this.block_smoothing_lowest_scan_al[args.csel][3]
q_xy = this.quant_tables[q][0x10] as base.u32
if (al > 0) and (q_xy > 0) and (this.mcu_blocks[0][0x10] == 0) {
limit = ((1 as base.u32) << al) - 1
scratch = 0
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][1])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[0][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][1])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[1][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][1])
scratch ~mod+= 0xFFFF_FFE8 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[2][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][1])
scratch ~mod+= 0x0000_000D ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[3][4])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][0])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][1])
scratch ~mod+= 0xFFFF_FFFF ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][2])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][3])
scratch ~mod+= 0x0000_0000 ~mod* this.util.sign_extend_convert_u16_u32(a: this.block_smoothing_dc_values[4][4])
scratch ~mod*= q_00
if scratch < 0x8000_0000 {
scratch = 0 ~mod+ limit.min(no_more_than: (((0 ~mod+ scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
} else {
scratch = 0 ~mod- limit.min(no_more_than: (((0 ~mod- scratch) ~mod+ (q_xy << 7)) / (q_xy << 8)))
}
this.mcu_blocks[0][0x10] = (scratch & 0xFFFF) as base.u16
}
}
}
+297
View File
@@ -0,0 +1,297 @@
// 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.
pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32,
choosy,
{
var ret : base.u32
var bits : base.u64
var n_bits : base.u32
var csel : base.u8[..= 3]
var r : base.io_reader
var pos : base.u32
// etc_bl and etc_blm1 are the Huffman code's "bit length" and "bit length
// minus 1" for the DC (first) and AC (later) components.
var dc_h : base.u8[..= 3]
var dc_symbol : base.u32[..= 0x0F]
var dc_ht_fast : base.u32
var dc_bl : base.u32
var dc_code : base.u32
var dc_blm1 : base.u32[..= 15]
var dc_ht_slow : base.u32
var dc_value : base.u16
var dc_extend : base.u16
var ac_huff_table_fast : nptr roarray[256] base.u16
var ac_h : base.u8[..= 7]
var ac_symbol : base.u32[..= 0xFF]
var ac_ht_fast : base.u32
var ac_bl : base.u32
var ac_code : base.u32
var ac_blm1 : base.u32[..= 15]
var ac_ht_slow : base.u32
var ac_value : base.u16
var ac_extend : base.u16
var ac_rrrr : base.u32[..= 15]
var ac_ssss : base.u32[..= 15]
var z : base.u32[..= 79] // 79 = 63 + 15 + 1.
var mcb : base.u32[..= 9]
var stride : base.u64[..= 0x1_0008]
var offset : base.u64
bits = this.bitstream_bits
n_bits = this.bitstream_n_bits
if this.bitstream_ri > this.bitstream_wi {
return 2 // Internal error.
}
io_bind (io: r, data: this.bitstream_buffer[this.bitstream_ri .. this.bitstream_wi], history_position: this.bitstream_ri as base.u64) {
while.goto_done true {{
while.block this.mcu_current_block < this.mcu_num_blocks {
assert this.mcu_current_block < 10 via "a < b: a < c; c <= b"(c: this.mcu_num_blocks)
while.dc_component this.mcu_zig_index <= 0,
inv this.mcu_current_block < 10,
{
this.mcu_blocks[.. 1].bulk_memset!(byte_value: 0)
// Load at least 56 bits. We only need 8 bytes (for the
// peek_u64be call), but ask for 264 to be consistent with the
// other "another fill_bitstream call" requests, in this method
// (decode_mcu) and its other variants.
if r.length() < 264 {
ret = 1 // Request another fill_bitstream call.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
// Read the Huffman-encoded dc_symbol, up to 16 bits long.
dc_h = this.mcu_blocks_dc_hselector[this.mcu_current_block]
dc_ht_fast = this.huff_tables_fast[dc_h][bits >> 56] as base.u32
dc_bl = dc_ht_fast >> 8
if n_bits >= dc_bl {
dc_symbol = 0x0F & dc_ht_fast
dc_extend = EXTEND[dc_symbol]
bits ~mod<<= (dc_bl & 63)
n_bits -= dc_bl
} else {
dc_code = (bits >> 55) as base.u32
dc_blm1 = 8
bits ~mod<<= 9
n_bits ~mod-= 9
while true,
inv this.mcu_current_block < 10,
{
dc_ht_slow = this.huff_tables_slow[dc_h][dc_blm1]
if dc_code < (dc_ht_slow >> 8) {
dc_symbol = 0x0F & (this.huff_tables_symbols[dc_h][0xFF & (dc_code ~mod+ dc_ht_slow)] as base.u32)
dc_extend = EXTEND[dc_symbol]
break
}
dc_code = (dc_code ~mod<< 1) | ((bits >> 63) as base.u32)
bits ~mod<<= 1
n_bits ~mod-= 1
dc_blm1 = (dc_blm1 + 1) & 15
if dc_blm1 == 0 {
dc_symbol = 0
dc_extend = EXTEND[dc_symbol]
break
}
} endwhile
}
// Process the dc_value in the next dc_symbol (up to 15) bits.
//
// The dc_value is shifted by (64 - dc_symbol) in two steps,
// because we want to shift by 64 (not 0) when dc_symbol is 0.
dc_value = (((bits >> 32) >> (32 - dc_symbol)) & 0xFFFF) as base.u16
dc_value ~mod+= dc_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= dc_symbol
n_bits ~mod-= dc_symbol
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[this.mcu_current_block]]
this.mcu_previous_dc_values[csel] ~mod+= dc_value
this.mcu_blocks[0][0] =
this.mcu_previous_dc_values[csel]
this.mcu_zig_index = 1
break.dc_component
} endwhile.dc_component
// Ensure that we have enough bits for this iteration of the
// while.block loop body. Worst case, there are 64 components and
// each one needs (16 + 15) bits (round that up to 4 bytes), so we
// need (64 * 4) = 256 bytes available. 8 more bytes of slack means
// that we can always call peek_u64be.
if r.length() < 264 {
ret = 1 // Request another fill_bitstream call.
break.goto_done
}
// Ensure the informal "the lower bound on the number of loaded
// bits is at least 16" loop pre-condition below.
if n_bits < 16 {
bits |= r.peek_u64be() >> (n_bits & 63)
// Skip these lines that are normally part of "load more bits".
// It's unnecessary, just for the informal (NB > 16) below, and
// skipping it avoids a small but negative performance impact.
//
// r.skip_u32_fast!( etc )
// n_bits |= 56
}
z = 1
this.mcu_zig_index = 0
ac_h = this.mcu_blocks_ac_hselector[this.mcu_current_block]
ac_huff_table_fast = this.huff_tables_fast[ac_h][..] as ptr array[256] base.u16
while.ac_components z < 64,
inv this.mcu_current_block < 10,
inv ac_huff_table_fast <> nullptr,
{
// Use the high bits of the bits variable to look up the
// Huffman table. Conceptually, we should do this *after*
// "Load at least 56 bits" below (at "LOOK-UP" further below),
// but it is noticably faster to do it beforehand:
// https://github.com/google/wuffs/commit/d9c7740ea6c4a450401c393787838436895b87bb
//
// Earlier look-up is OK because there is a informal loop
// pre-condition (informal means not enforced by the Wuffs
// compiler) that (NB >= 16) here, where NB is "the number of
// loaded bits in the bits variable". It is literally n_bits
// for almost all loop iterations, but it can be higher on the
// first iteration, set up by "Ensure the informal" above.
//
// For subsequent iterations, the "Load at least 56 bits" below
// does what it says. The Huffman code consumes up to 16 bits
// and processing the Huffman symbol's ssss nibble consumes up
// to 15 bits. (56 - 16 - 15) = 25 >= 16 so at the end of the
// loop body, (n_bits >= 16).
//
// This 16 bound has some slack, as (NB >= 8) is all we need
// when ac_huff_table_fast has (1 << 8) entries, but a bound of
// 16 (the longest JPEG Huffman code bit length) won't need to
// change even if, in the future, the look-up table size grows.
ac_ht_fast = ac_huff_table_fast[bits >> 56] as base.u32
// Load at least 56 bits.
//
// TODO: eliminate this bounds check entirely.
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
//
// LOOK-UP: "ac_ht_fast = etc" conceptually happens here, just
// before deriving ac_bl from ac_ht_fast.
ac_bl = ac_ht_fast >> 8
if n_bits >= ac_bl {
ac_symbol = 0xFF & ac_ht_fast
bits ~mod<<= (ac_bl & 63)
n_bits -= ac_bl
} else {
ac_code = (bits >> 55) as base.u32
ac_blm1 = 8
bits ~mod<<= 9
n_bits ~mod-= 9
while true,
inv this.mcu_current_block < 10,
inv ac_huff_table_fast <> nullptr,
inv z < 64,
{
ac_ht_slow = this.huff_tables_slow[ac_h][ac_blm1]
if ac_code < (ac_ht_slow >> 8) {
ac_symbol = this.huff_tables_symbols[ac_h][0xFF & (ac_code ~mod+ ac_ht_slow)] as base.u32
break
}
ac_code = (ac_code ~mod<< 1) | ((bits >> 63) as base.u32)
bits ~mod<<= 1
n_bits ~mod-= 1
ac_blm1 = (ac_blm1 + 1) & 15
if ac_blm1 == 0 {
ac_symbol = 0
break
}
} endwhile
}
// Split the 8-bit ac_symbol into two 4-bit halves, per section
// F.2.2.2 "Decoding procedure for AC coefficients".
ac_rrrr = ac_symbol >> 4
z += ac_rrrr + 1
ac_ssss = ac_symbol & 15
ac_extend = EXTEND[ac_ssss]
// Process the ac_value in the next ac_ssss (up to 15) bits.
if ac_ssss > 0 {
ac_value = ((bits >> (64 - ac_ssss)) & 0xFFFF) as base.u16
ac_value ~mod+= ac_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= ac_ssss
n_bits ~mod-= ac_ssss
this.mcu_blocks[0][UNZIG[z]] =
ac_value
} else if ac_rrrr < 15 {
break.ac_components
}
} endwhile.ac_components
assert this.mcu_current_block < 10
mcb = this.mcu_current_block
this.mcu_current_block += 1
if this.test_only_interrupt_decode_mcu {
break.goto_done
}
// 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() {
this.decode_idct!(
dst_buffer: args.workbuf[offset ..],
dst_stride: stride,
q: this.components_tq[csel] as base.u32)
}
} endwhile.block
this.mcu_current_block = 0
break.goto_done
}} endwhile.goto_done
pos = (r.position() & 0xFFFF_FFFF) as base.u32
if pos > this.bitstream_wi {
ret = 2 // Internal error.
} else {
assert pos <= 0x800 via "a <= b: a <= c; c <= b"(c: this.bitstream_wi)
this.bitstream_ri = pos
}
}
this.bitstream_bits = bits
this.bitstream_n_bits = n_bits
return ret
}
@@ -0,0 +1,197 @@
// 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.
pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
var ret : base.u32
var bits : base.u64
var n_bits : base.u32
var r : base.io_reader
var pos : base.u32
var ac_huff_table_fast : nptr roarray[256] base.u16
var ac_h : base.u8[..= 7]
var ac_symbol : base.u32[..= 0xFF]
var ac_ht_fast : base.u32
var ac_bl : base.u32
var ac_code : base.u32
var ac_blm1 : base.u32[..= 15]
var ac_ht_slow : base.u32
var ac_value : base.u16
var ac_extend : base.u16
var ac_rrrr : base.u32[..= 15]
var ac_ssss : base.u32[..= 15]
var z : base.u32[..= 79] // 79 = 63 + 15 + 1.
if this.eob_run > 0 {
this.eob_run -= 1
return 0
}
bits = this.bitstream_bits
n_bits = this.bitstream_n_bits
if this.bitstream_ri > this.bitstream_wi {
return 2 // Internal error.
}
io_bind (io: r, data: this.bitstream_buffer[this.bitstream_ri .. this.bitstream_wi], history_position: this.bitstream_ri as base.u64) {
while.goto_done true {{
while.block true {
// Ensure that we have enough bits for this iteration of the
// while.block loop body. Worst case, there are 64 components and
// each one needs (16 + 15) bits (round that up to 4 bytes), so we
// need (64 * 4) = 256 bytes available. 8 more bytes of slack means
// that we can always call peek_u64be.
if r.length() < 264 {
ret = 1 // Request another fill_bitstream call.
break.goto_done
}
// Ensure the informal "the lower bound on the number of loaded
// bits is at least 16" loop pre-condition below.
if n_bits < 16 {
bits |= r.peek_u64be() >> (n_bits & 63)
// Skip these lines that are normally part of "load more bits".
// It's unnecessary, just for the informal (NB > 16) below, and
// skipping it avoids a small but negative performance impact.
//
// r.skip_u32_fast!( etc )
// n_bits |= 56
}
z = this.mcu_zig_index
this.mcu_zig_index = 0
ac_h = this.mcu_blocks_ac_hselector[0]
ac_huff_table_fast = this.huff_tables_fast[ac_h][..] as ptr array[256] base.u16
while.ac_components z <= (this.scan_se as base.u32),
inv ac_huff_table_fast <> nullptr,
{
assert z < 64 via "a < b: a <= c; c < b"(c: (this.scan_se as base.u32))
// Use the high bits of the bits variable to look up the
// Huffman table. Conceptually, we should do this *after*
// "Load at least 56 bits" below (at "LOOK-UP" further below),
// but it is noticably faster to do it beforehand:
// https://github.com/google/wuffs/commit/d9c7740ea6c4a450401c393787838436895b87bb
//
// Earlier look-up is OK because there is a informal loop
// pre-condition (informal means not enforced by the Wuffs
// compiler) that (NB >= 16) here, where NB is "the number of
// loaded bits in the bits variable". It is literally n_bits
// for almost all loop iterations, but it can be higher on the
// first iteration, set up by "Ensure the informal" above.
//
// For subsequent iterations, the "Load at least 56 bits" below
// does what it says. The Huffman code consumes up to 16 bits
// and processing the Huffman symbol's ssss nibble consumes up
// to 15 bits. (56 - 16 - 15) = 25 >= 16 so at the end of the
// loop body, (n_bits >= 16).
//
// This 16 bound has some slack, as (NB >= 8) is all we need
// when ac_huff_table_fast has (1 << 8) entries, but a bound of
// 16 (the longest JPEG Huffman code bit length) won't need to
// change even if, in the future, the look-up table size grows.
ac_ht_fast = ac_huff_table_fast[bits >> 56] as base.u32
// Load at least 56 bits.
//
// TODO: eliminate this bounds check entirely.
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
//
// LOOK-UP: "ac_ht_fast = etc" conceptually happens here, just
// before deriving ac_bl from ac_ht_fast.
ac_bl = ac_ht_fast >> 8
if n_bits >= ac_bl {
ac_symbol = 0xFF & ac_ht_fast
bits ~mod<<= (ac_bl & 63)
n_bits -= ac_bl
} else {
ac_code = (bits >> 55) as base.u32
ac_blm1 = 8
bits ~mod<<= 9
n_bits ~mod-= 9
while true,
inv ac_huff_table_fast <> nullptr,
inv z < 64,
{
ac_ht_slow = this.huff_tables_slow[ac_h][ac_blm1]
if ac_code < (ac_ht_slow >> 8) {
ac_symbol = this.huff_tables_symbols[ac_h][0xFF & (ac_code ~mod+ ac_ht_slow)] as base.u32
break
}
ac_code = (ac_code ~mod<< 1) | ((bits >> 63) as base.u32)
bits ~mod<<= 1
n_bits ~mod-= 1
ac_blm1 = (ac_blm1 + 1) & 15
if ac_blm1 == 0 {
ac_symbol = 0
break
}
} endwhile
}
// Split the 8-bit ac_symbol into two 4-bit halves, per section
// F.2.2.2 "Decoding procedure for AC coefficients".
ac_rrrr = ac_symbol >> 4
z += ac_rrrr + 1
ac_ssss = ac_symbol & 15
ac_extend = EXTEND[ac_ssss]
// Process the ac_value in the next ac_ssss (up to 15) bits or
// the eob_run in the next ac_rrrr (up to 15) bits.
if ac_ssss > 0 {
ac_value = ((bits >> (64 - ac_ssss)) & 0xFFFF) as base.u16
ac_value ~mod+= ac_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= ac_ssss
n_bits ~mod-= ac_ssss
this.mcu_blocks[0][UNZIG[z]] =
((ac_value ~mod<< this.scan_al) & 0xFFFF) as base.u16
} else if ac_rrrr < 15 {
this.eob_run = (((1 as base.u16) << ac_rrrr) - 1) as base.u16
if ac_rrrr > 0 {
this.eob_run ~mod+= ((bits >> (64 - ac_rrrr)) & 0xFFFF) as base.u16
bits ~mod<<= ac_rrrr
n_bits ~mod-= ac_rrrr
}
break.ac_components
}
} endwhile.ac_components
break.block
} endwhile.block
break.goto_done
}} endwhile.goto_done
pos = (r.position() & 0xFFFF_FFFF) as base.u32
if pos > this.bitstream_wi {
ret = 2 // Internal error.
} else {
assert pos <= 0x800 via "a <= b: a <= c; c <= b"(c: this.bitstream_wi)
this.bitstream_ri = pos
}
}
this.bitstream_bits = bits
this.bitstream_n_bits = n_bits
return ret
}
@@ -0,0 +1,245 @@
// 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.
pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
var ret : base.u32
var bits : base.u64
var n_bits : base.u32
var one_lshift_scan_al : base.u16[..= 0x2000]
var r : base.io_reader
var pos : base.u32
var ac_huff_table_fast : nptr roarray[256] base.u16
var ac_h : base.u8[..= 7]
var ac_symbol : base.u32[..= 0xFF]
var ac_ht_fast : base.u32
var ac_bl : base.u32
var ac_code : base.u32
var ac_blm1 : base.u32[..= 15]
var ac_ht_slow : base.u32
var ac_value : base.u16
var ac_rrrr : base.u32[..= 15]
var ac_ssss : base.u32[..= 15]
var unzig : base.u8[..= 63]
var bit : base.bool
bits = this.bitstream_bits
n_bits = this.bitstream_n_bits
one_lshift_scan_al = (1 as base.u16) << this.scan_al
if this.bitstream_ri > this.bitstream_wi {
return 2 // Internal error.
}
io_bind (io: r, data: this.bitstream_buffer[this.bitstream_ri .. this.bitstream_wi], history_position: this.bitstream_ri as base.u64) {
while.goto_done true {{
while.block true {
// Ensure that we have enough bits for this iteration of the
// while.block loop body. Worst case, there are 64 components and
// each one needs (16 + 15) bits (round that up to 4 bytes), so we
// need (64 * 4) = 256 bytes available. 8 more bytes of slack means
// that we can always call peek_u64be.
if r.length() < 264 {
ret = 1 // Request another fill_bitstream call.
break.goto_done
}
while.goto_do_eob true {{
if this.eob_run > 0 {
break.goto_do_eob
}
ac_h = this.mcu_blocks_ac_hselector[0]
ac_huff_table_fast = this.huff_tables_fast[ac_h][..] as ptr array[256] base.u16
while.ac_components true,
inv ac_huff_table_fast <> nullptr,
{
// Load at least 56 bits.
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
ac_ht_fast = ac_huff_table_fast[bits >> 56] as base.u32
ac_bl = ac_ht_fast >> 8
if n_bits >= ac_bl {
ac_symbol = 0xFF & ac_ht_fast
bits ~mod<<= (ac_bl & 63)
n_bits -= ac_bl
} else {
ac_code = (bits >> 55) as base.u32
ac_blm1 = 8
bits ~mod<<= 9
n_bits ~mod-= 9
while true,
inv ac_huff_table_fast <> nullptr,
{
ac_ht_slow = this.huff_tables_slow[ac_h][ac_blm1]
if ac_code < (ac_ht_slow >> 8) {
ac_symbol = this.huff_tables_symbols[ac_h][0xFF & (ac_code ~mod+ ac_ht_slow)] as base.u32
break
}
ac_code = (ac_code ~mod<< 1) | ((bits >> 63) as base.u32)
bits ~mod<<= 1
n_bits ~mod-= 1
ac_blm1 = (ac_blm1 + 1) & 15
if ac_blm1 == 0 {
ac_symbol = 0
break
}
} endwhile
}
// Split the 8-bit ac_symbol into two 4-bit halves, per section
// F.2.2.2 "Decoding procedure for AC coefficients".
ac_rrrr = ac_symbol >> 4
ac_ssss = ac_symbol & 15
// Process the ac_value in the next ac_ssss (up to 15) bits or
// the eob_run in the next ac_rrrr (up to 15) bits.
ac_value = 0
if ac_ssss > 0 {
ac_value = (0x0001 as base.u16) << this.scan_al
if (bits >> 63) == 0 {
ac_value = (0xFFFF as base.u16) ~mod<< this.scan_al
}
bits ~mod<<= 1
n_bits ~mod-= 1
} else if ac_rrrr < 15 {
this.eob_run = (1 as base.u16) << ac_rrrr
if ac_rrrr > 0 {
this.eob_run ~mod+= ((bits >> (64 - ac_rrrr)) & 0xFFFF) as base.u16
bits ~mod<<= ac_rrrr
n_bits ~mod-= ac_rrrr
}
break.goto_do_eob
}
// Consume 1 bit per non-zero AC coefficient, up to 63 bits.
while.refine_non_zeroes true,
inv ac_huff_table_fast <> nullptr,
{
unzig = UNZIG[1 + this.mcu_zig_index]
if this.mcu_blocks[0][unzig] <> 0 {
if n_bits == 0 {
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
}
bit = (bits >> 63) > 0
bits ~mod<<= 1
n_bits ~mod-= 1
if bit {
if this.mcu_blocks[0][unzig] < 0x8000 {
this.mcu_blocks[0][unzig] += one_lshift_scan_al
} else {
this.mcu_blocks[0][unzig] -= one_lshift_scan_al
}
}
} else if ac_rrrr <= 0 {
break.refine_non_zeroes
} else {
ac_rrrr -= 1
}
if this.mcu_zig_index >= (this.scan_se as base.u32) {
break.refine_non_zeroes
}
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
if ac_value <> 0 {
this.mcu_blocks[0][UNZIG[1 + this.mcu_zig_index]] = ac_value
}
if this.mcu_zig_index >= (this.scan_se as base.u32) {
break.ac_components
}
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
break.block
}} endwhile.goto_do_eob
if this.eob_run <= 0 {
ret = 2 // Internal error.
break.goto_done
}
while.refine_eob_non_zeroes true,
inv this.eob_run > 0,
{
unzig = UNZIG[1 + this.mcu_zig_index]
if this.mcu_blocks[0][unzig] <> 0 {
if n_bits == 0 {
// Load at least 56 bits.
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
}
bit = (bits >> 63) > 0
bits ~mod<<= 1
n_bits ~mod-= 1
if bit {
if this.mcu_blocks[0][unzig] < 0x8000 {
this.mcu_blocks[0][unzig] += one_lshift_scan_al
} else {
this.mcu_blocks[0][unzig] -= one_lshift_scan_al
}
}
}
if this.mcu_zig_index >= (this.scan_se as base.u32) {
break.refine_eob_non_zeroes
}
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
this.eob_run -= 1
break.block
} endwhile.block
break.goto_done
}} endwhile.goto_done
pos = (r.position() & 0xFFFF_FFFF) as base.u32
if pos > this.bitstream_wi {
ret = 2 // Internal error.
} else {
assert pos <= 0x800 via "a <= b: a <= c; c <= b"(c: this.bitstream_wi)
this.bitstream_ri = pos
}
}
this.bitstream_bits = bits
this.bitstream_n_bits = n_bits
return ret
}
@@ -0,0 +1,136 @@
// 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.
pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
var ret : base.u32
var bits : base.u64
var n_bits : base.u32
var csel : base.u8[..= 3]
var r : base.io_reader
var pos : base.u32
var dc_h : base.u8[..= 3]
var dc_symbol : base.u32[..= 0x0F]
var dc_ht_fast : base.u32
var dc_bl : base.u32
var dc_code : base.u32
var dc_blm1 : base.u32[..= 15]
var dc_ht_slow : base.u32
var dc_value : base.u16
var dc_extend : base.u16
bits = this.bitstream_bits
n_bits = this.bitstream_n_bits
if this.bitstream_ri > this.bitstream_wi {
return 2 // Internal error.
}
io_bind (io: r, data: this.bitstream_buffer[this.bitstream_ri .. this.bitstream_wi], history_position: this.bitstream_ri as base.u64) {
while.goto_done true {{
while.block this.mcu_current_block < this.mcu_num_blocks {
assert this.mcu_current_block < 10 via "a < b: a < c; c <= b"(c: this.mcu_num_blocks)
// Ensure that we have enough bits for this iteration of the
// while.block loop body. Worst case, there are 64 components and
// each one needs (16 + 15) bits (round that up to 4 bytes), so we
// need (64 * 4) = 256 bytes available. 8 more bytes of slack means
// that we can always call peek_u64be.
if r.length() < 264 {
ret = 1 // Request another fill_bitstream call.
break.goto_done
}
while.dc_component true,
inv this.mcu_current_block < 10,
{
// Load at least 56 bits.
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
// Read the Huffman-encoded dc_symbol, up to 16 bits long.
dc_h = this.mcu_blocks_dc_hselector[this.mcu_current_block]
dc_ht_fast = this.huff_tables_fast[dc_h][bits >> 56] as base.u32
dc_bl = dc_ht_fast >> 8
if n_bits >= dc_bl {
dc_symbol = 0x0F & dc_ht_fast
dc_extend = EXTEND[dc_symbol]
bits ~mod<<= (dc_bl & 63)
n_bits -= dc_bl
} else {
dc_code = (bits >> 55) as base.u32
dc_blm1 = 8
bits ~mod<<= 9
n_bits ~mod-= 9
while true,
inv this.mcu_current_block < 10,
{
dc_ht_slow = this.huff_tables_slow[dc_h][dc_blm1]
if dc_code < (dc_ht_slow >> 8) {
dc_symbol = 0x0F & (this.huff_tables_symbols[dc_h][0xFF & (dc_code ~mod+ dc_ht_slow)] as base.u32)
dc_extend = EXTEND[dc_symbol]
break
}
dc_code = (dc_code ~mod<< 1) | ((bits >> 63) as base.u32)
bits ~mod<<= 1
n_bits ~mod-= 1
dc_blm1 = (dc_blm1 + 1) & 15
if dc_blm1 == 0 {
dc_symbol = 0
dc_extend = EXTEND[dc_symbol]
break
}
} endwhile
}
// Process the dc_value in the next dc_symbol (up to 15) bits.
//
// The dc_value is shifted by (64 - dc_symbol) in two steps,
// because we want to shift by 64 (not 0) when dc_symbol is 0.
dc_value = (((bits >> 32) >> (32 - dc_symbol)) & 0xFFFF) as base.u16
dc_value ~mod+= dc_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= dc_symbol
n_bits ~mod-= dc_symbol
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[this.mcu_current_block]]
this.mcu_previous_dc_values[csel] ~mod+= dc_value
this.mcu_blocks[this.mcu_current_block][0] =
this.mcu_previous_dc_values[csel] ~mod<< this.scan_al
break.dc_component
} endwhile.dc_component
assert this.mcu_current_block < 10
this.mcu_current_block += 1
} endwhile.block
this.mcu_current_block = 0
break.goto_done
}} endwhile.goto_done
pos = (r.position() & 0xFFFF_FFFF) as base.u32
if pos > this.bitstream_wi {
ret = 2 // Internal error.
} else {
assert pos <= 0x800 via "a <= b: a <= c; c <= b"(c: this.bitstream_wi)
this.bitstream_ri = pos
}
}
this.bitstream_bits = bits
this.bitstream_n_bits = n_bits
return ret
}
@@ -0,0 +1,86 @@
// 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.
pri func decoder.decode_mcu_progressive_dc_low_bit!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], my: base.u32[..= 0x1FFF]) base.u32 {
var ret : base.u32
var bits : base.u64
var n_bits : base.u32
var one_lshift_scan_al : base.u16[..= 0x2000]
var r : base.io_reader
var pos : base.u32
bits = this.bitstream_bits
n_bits = this.bitstream_n_bits
one_lshift_scan_al = (1 as base.u16) << this.scan_al
if this.bitstream_ri > this.bitstream_wi {
return 2 // Internal error.
}
io_bind (io: r, data: this.bitstream_buffer[this.bitstream_ri .. this.bitstream_wi], history_position: this.bitstream_ri as base.u64) {
while.goto_done true {{
while.block this.mcu_current_block < this.mcu_num_blocks {
assert this.mcu_current_block < 10 via "a < b: a < c; c <= b"(c: this.mcu_num_blocks)
// Ensure that we have enough bits for this iteration of the
// while.block loop body. Worst case, there are 64 components and
// each one needs (16 + 15) bits (round that up to 4 bytes), so we
// need (64 * 4) = 256 bytes available. 8 more bytes of slack means
// that we can always call peek_u64be.
if r.length() < 264 {
ret = 1 // Request another fill_bitstream call.
break.goto_done
}
while.dc_component true,
inv this.mcu_current_block < 10,
{
// Load at least 56 bits.
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
r.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
n_bits |= 56
// Refine a bit.
if (bits >> 63) <> 0 {
this.mcu_blocks[this.mcu_current_block][0] |= one_lshift_scan_al
}
bits ~mod<<= 1
n_bits ~mod-= 1
break.dc_component
} endwhile.dc_component
assert this.mcu_current_block < 10
this.mcu_current_block += 1
} endwhile.block
this.mcu_current_block = 0
break.goto_done
}} endwhile.goto_done
pos = (r.position() & 0xFFFF_FFFF) as base.u32
if pos > this.bitstream_wi {
ret = 2 // Internal error.
} else {
assert pos <= 0x800 via "a <= b: a <= c; c <= b"(c: this.bitstream_wi)
this.bitstream_ri = pos
}
}
this.bitstream_bits = bits
this.bitstream_n_bits = n_bits
return ret
}
+16 -18
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad C0 control code"
pub status "#bad UTF-8"
@@ -25,6 +19,10 @@ 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
@@ -84,7 +82,7 @@ pri const DECODER_NUMBER_LENGTH_MAX_INCL : base.u64 = 99
//
// If the element is zero then "\i" is invalid, or it is a special case, the
// start of "\x12", "\u1234" or "\U12345678".
pri const LUT_BACKSLASHES : array[256] base.u8 = [
pri const LUT_BACKSLASHES : roarray[256] base.u8 = [
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07.
@@ -129,7 +127,7 @@ pri const LUT_BACKSLASHES : array[256] base.u8 = [
// LUT_QUIRKY_BACKSLASHES_QUIRKS is discussed in the LUT_BACKSLASHES comment.
// The first element (index 0) is not used, but 8 is a round power of 2, so
// enforcing index-in-bounds is a simple "&7" operation.
pri const LUT_QUIRKY_BACKSLASHES_QUIRKS : array[8] base.u8[..= 0x0A] = [
pri const LUT_QUIRKY_BACKSLASHES_QUIRKS : roarray[8] base.u8[..= 0x0A] = [
0,
// Uncommenting the following lines requires being able to define consts in
// terms of other consts, which could be non-trivial to specify and
@@ -146,7 +144,7 @@ pri const LUT_QUIRKY_BACKSLASHES_QUIRKS : array[8] base.u8[..= 0x0A] = [
// LUT_QUIRKY_BACKSLASHES_CHARS is discussed in the LUT_BACKSLASHES comment.
// The first element (index 0) is not used, but 8 is a round power of 2, so
// enforcing index-in-bounds is a simple "&7" operation.
pri const LUT_QUIRKY_BACKSLASHES_CHARS : array[8] base.u8 = [
pri const LUT_QUIRKY_BACKSLASHES_CHARS : roarray[8] base.u8 = [
0x00, 0x07, 0x1B, 0x0A, 0x3F, 0x27, 0x0B, 0x00,
]
@@ -169,7 +167,7 @@ pri const LUT_QUIRKY_BACKSLASHES_CHARS : array[8] base.u8 = [
// UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
// %xF4 %x80-8F 2( UTF8-tail )
// UTF8-tail = %x80-BF
pri const LUT_CHARS : array[256] base.u8 = [
pri const LUT_CHARS : roarray[256] base.u8 = [
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, // 0x00 ..= 0x07. C0 control codes.
@@ -269,7 +267,7 @@ pri const EXPECT_CLOSE_SQUARE_BRACKET : base.u32 = 0x1100
//
// The bitmasks are used by the "expect" variable: what the next character
// class can be. See EXPECT_ETC above.
pri const LUT_CLASSES : array[256] base.u8[..= 0x0F] = [
pri const LUT_CLASSES : roarray[256] base.u8[..= 0x0F] = [
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x00 ..= 0x07.
@@ -311,7 +309,7 @@ pri const LUT_CLASSES : array[256] base.u8[..= 0x0F] = [
// 8 9 A B C D E F
]
pri const LUT_DECIMAL_DIGITS : array[256] base.u8 = [
pri const LUT_DECIMAL_DIGITS : roarray[256] base.u8 = [
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07.
@@ -353,7 +351,7 @@ pri const LUT_DECIMAL_DIGITS : array[256] base.u8 = [
// 8 9 A B C D E F
]
pri const LUT_HEXADECIMAL_DIGITS : array[256] base.u8 = [
pri const LUT_HEXADECIMAL_DIGITS : roarray[256] base.u8 = [
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07.
+31 -17
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub struct decoder? implements base.token_decoder(
quirks : array[QUIRKS_COUNT] base.bool,
@@ -29,7 +23,7 @@ pub struct decoder? implements base.token_decoder(
comment_type : base.u8,
util : base.utility,
)(
) + (
// stack is conceptually an array of bits, implemented as an array of u32.
// The N'th bit being 0 or 1 means that we're in an array or object, where
// N is the recursion depth.
@@ -61,13 +55,33 @@ pub struct decoder? implements base.token_decoder(
stack : array[1024 / 32] base.u32,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
if args.quirk >= QUIRKS_BASE {
args.quirk -= QUIRKS_BASE
if args.quirk < QUIRKS_COUNT {
this.quirks[args.quirk] = args.enabled
pub func decoder.get_quirk(key: base.u32) base.u64 {
var key : base.u32
if args.key >= QUIRKS_BASE {
key = args.key - QUIRKS_BASE
if key < QUIRKS_COUNT {
if this.quirks[key] {
return 1
}
}
}
return 0
}
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
if args.key >= QUIRKS_BASE {
args.key -= QUIRKS_BASE
if args.key < QUIRKS_COUNT {
this.quirks[args.key] = args.value > 0
return ok
}
}
return base."#unsupported option"
}
pub func decoder.history_retain_length() base.u64 {
return 0
}
pub func decoder.workbuf_len() base.range_ii_u64 {
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
+47 -28
View File
@@ -1,22 +1,18 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad code"
pub status "#truncated input"
pri status "#internal error: inconsistent I/O"
pub const DECODER_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
// decoding all but the smallest GIFs. See these git commits for numbers:
@@ -28,11 +24,11 @@ pri status "#internal error: inconsistent I/O"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.io_transformer(
// set_literal_width_arg is 1 plus the saved argument passed to
// set_literal_width. This is assigned to the literal_width field at the
// start of transform_io. During that method, calling set_literal_width
// will change set_literal_width_arg but not literal_width.
set_literal_width_arg : base.u32[..= 9],
// pending_literal_width_plus_one is 1 plus the saved argument passed
// to set_quirk. This is assigned to the literal_width field at the
// start of transform_io. During that method, calling set_quirk will
// change pending_literal_width_plus_one but not literal_width.
pending_literal_width_plus_one : base.u32[..= 9],
// read_from state that does not change during a decode call.
literal_width : base.u32[..= 8],
@@ -58,7 +54,7 @@ pub struct decoder? implements base.io_transformer(
prefixes : array[4096] base.u16[..= 4095],
util : base.utility,
)(
) + (
// read_from per-code state.
suffixes : array[4096] array[8] base.u8,
// lm1s is the "length minus 1"s of the values for the implicit key-value
@@ -70,11 +66,26 @@ pub struct decoder? implements base.io_transformer(
output : array[8192 + 7] base.u8,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
pub func decoder.get_quirk(key: base.u32) base.u64 {
if args.key == QUIRK_LITERAL_WIDTH_PLUS_ONE {
return this.pending_literal_width_plus_one as base.u64
}
return 0
}
pub func decoder.set_literal_width!(lw: base.u32[..= 8]) {
this.set_literal_width_arg = args.lw + 1
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
if args.key == QUIRK_LITERAL_WIDTH_PLUS_ONE {
if args.value > 9 {
return base."#bad argument"
}
this.pending_literal_width_plus_one = args.value as base.u32
return ok
}
return base."#unsupported option"
}
pub func decoder.history_retain_length() base.u64 {
return 0
}
pub func decoder.workbuf_len() base.range_ii_u64 {
@@ -86,8 +97,8 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
// Initialize read_from state.
this.literal_width = 8
if this.set_literal_width_arg > 0 {
this.literal_width = this.set_literal_width_arg - 1
if this.pending_literal_width_plus_one > 0 {
this.literal_width = this.pending_literal_width_plus_one - 1
}
this.clear_code = (1 as base.u32) << this.literal_width
this.end_code = this.clear_code + 1
@@ -364,13 +375,21 @@ pri func decoder.write_to?(dst: base.io_writer) {
} endwhile
}
pub func decoder.flush!() slice base.u8 {
var s : slice base.u8
// Deprecated. Use transform_io and an io_writer instead.
//
// We'd like to deprecate (and eventually remove) methods that return anything
// pointer-y (including slices).
pub func decoder.flush!() roslice base.u8 {
var ri : base.u32[..= 8191]
var wi : base.u32[..= 8191]
if this.output_ri <= this.output_wi {
s = this.output[this.output_ri .. this.output_wi]
}
ri = this.output_ri
wi = this.output_wi
this.output_ri = 0
this.output_wi = 0
return s
if ri <= wi {
return this.output[ri .. wi]
}
return this.output[.. 0]
}
+22
View File
@@ -0,0 +1,22 @@
// 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.
// --------
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "lzw " is 0x1417A8. Left shifting by 10 gives
// 0x505E_A000.
pri const QUIRKS_BASE : base.u32 = 0x505E_A000
// --------
// When this quirk is set (to a value in the range 0 ..= 9), a positive value
// is one more than the initial number of bits of a literal code. Zero means to
// use the default literal width, 8.
pub const QUIRK_LITERAL_WIDTH_PLUS_ONE : base.u32 = 0x505E_A000 | 0x00
+436
View File
@@ -0,0 +1,436 @@
// 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.
pub status "#bad header"
pub status "#truncated input"
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 struct decoder? implements base.image_decoder(
pixfmt : base.u32,
width : base.u32[..= 0xFF_FFFF],
height : base.u32[..= 0xFF_FFFF],
max_value : base.u32[..= 0xFF_FFFF],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
call_sequence : base.u8,
frame_config_io_position : base.u64,
dst_x : base.u32,
dst_y : base.u32,
swizzler : base.pixel_swizzler,
util : base.utility,
)
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
} 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
if this.call_sequence <> 0x00 {
return base."#bad call sequence"
}
c = args.src.read_u8?()
if c <> 'P' {
return "#bad header"
}
c = args.src.read_u8?()
if (c < '1') or ('7' < c) {
return "#bad header"
} else if c == '5' {
this.pixfmt = base.PIXEL_FORMAT__Y
} else if c == '6' {
this.pixfmt = base.PIXEL_FORMAT__RGB
} else {
return "#unsupported Netpbm file"
}
c = args.src.read_u8?()
if c <> 0x0A {
return "#bad header"
}
// Decode width.
while true {
c = args.src.read_u8?()
if (c == ' ') or (c == 0x09) {
continue
} else if c == '#' {
// Consume a "#...\n" comment.
while true {
c = args.src.read_u8?()
if c == 0x0A {
break
}
} endwhile
continue
} else if (c < '0') or ('9' < c) {
return "#bad header"
}
this.width = ((c - '0') as base.u32)
break
} endwhile
while true {
c = args.src.read_u8?()
if (c == ' ') or (c == 0x09) {
break
} else if (c < '0') or ('9' < c) {
return "#bad header"
}
n = (10 * this.width) + ((c - '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) {
continue
} else if c == '#' {
// Consume a "#...\n" comment.
while true {
c = args.src.read_u8?()
if c == 0x0A {
break
}
} endwhile
continue
} else if (c < '0') or ('9' < c) {
return "#bad header"
}
this.height = ((c - '0') as base.u32)
break
} endwhile
while true {
c = args.src.read_u8?()
if (c == ' ') or (c == 0x09) or (c == 0x0D) {
continue
} else if c == 0x0A {
break
} else if (c < '0') or ('9' < c) {
return "#bad header"
}
n = (10 * this.height) + ((c - '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) {
continue
} else if c == '#' {
// Consume a "#...\n" comment.
while true {
c = args.src.read_u8?()
if c == 0x0A {
break
}
} endwhile
continue
} else if (c < '0') or ('9' < c) {
return "#bad header"
}
this.max_value = ((c - '0') as base.u32)
break
} endwhile
while true {
c = args.src.read_u8?()
if (c == ' ') or (c == 0x09) or (c == 0x0D) {
continue
} else if c == 0x0A {
break
} else if (c < '0') or ('9' < c) {
return "#bad header"
}
n = (10 * this.max_value) + ((c - '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"
}
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
}
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
} endwhile
}
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
} 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 status : base.status
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.dst_x = 0
this.dst_y = 0
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
}
while true {
status = this.swizzle!(dst: args.dst, src: args.src)
if status.is_ok() {
break
} else if status <> "@internal note: short read" {
return status
}
yield? base."$short read"
} endwhile
this.call_sequence = 0x60
}
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) 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 src_bytes_per_pixel : base.u32[..= 8]
var tab : table base.u8
var dst : slice base.u8
var i : base.u64
var j : base.u64
var n : 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 true {
if this.dst_x == this.width {
this.dst_x = 0
this.dst_y ~mod+= 1
if this.dst_y >= this.height {
break
}
}
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)
if i >= dst.length() {
src_bytes_per_pixel = 1
assert src_bytes_per_pixel > 0
if this.pixfmt == base.PIXEL_FORMAT__RGB {
src_bytes_per_pixel = 3
assert src_bytes_per_pixel > 0
}
n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(no_more_than: (this.width ~mod- this.dst_x) as base.u64)
j = n
while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
args.src.skip_u32_fast!(
actual: src_bytes_per_pixel * 8,
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!(
actual: src_bytes_per_pixel * 1,
worst_case: src_bytes_per_pixel * 1)
}
j -= 1
} endwhile
} else {
n = this.swizzler.swizzle_interleaved_from_reader!(
dst: dst[i ..],
dst_palette: args.dst.palette(),
src: args.src)
}
if n == 0 {
return "@internal note: short read"
}
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
} endwhile
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. Netpbm 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.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)
}
+29 -21
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad header"
pub status "#truncated input"
@@ -18,12 +12,13 @@ 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 struct decoder? implements base.image_decoder(
pixfmt : base.u32,
width : base.u32[..= 0x7FFF_FFFF],
height : base.u32[..= 0x7FFF_FFFF],
width : base.u32[..= 0xFF_FFFF],
height : base.u32[..= 0xFF_FFFF],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
@@ -36,7 +31,12 @@ pub struct decoder? implements base.image_decoder(
util : base.utility,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
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) {
@@ -77,14 +77,18 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
}
a = args.src.read_u32le?()
if a >= 0x8000_0000 {
if a > 0x7FFF_FFFF {
return "#bad header"
} else if a > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.width = a
a = args.src.read_u32le?()
if a >= 0x8000_0000 {
if a > 0x7FFF_FFFF {
return "#bad header"
} else if a > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.height = a
@@ -199,7 +203,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var src_bytes_per_pixel : base.u32[..= 8]
var tab : table base.u8
@@ -215,8 +219,8 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
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 true {
@@ -232,7 +236,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
if i >= dst.length() {
src_bytes_per_pixel = 4
assert src_bytes_per_pixel > 0
@@ -241,7 +245,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
assert src_bytes_per_pixel > 0
}
n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
n = n.min(no_more_than: (this.width ~mod- this.dst_x) as base.u64)
j = n
while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
@@ -319,6 +323,10 @@ 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)
}
-2
View File
@@ -5,8 +5,6 @@ image compression format for still images. APNG ([Animated
PNG](https://wiki.mozilla.org/APNG_Specification)) is an unofficial extension
for animated images.
Wuffs does not currently implement the APNG extension.
## File Structure
+11 -16
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad animation sequence number"
pub status "#bad checksum"
@@ -30,6 +24,7 @@ pri status "#internal error: inconsistent frame bounds"
pri status "#internal error: inconsistent workbuf length"
pri status "#internal error: zlib decoder did not exhaust its input"
pub const DECODER_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
// DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL is the minimum length of the src
@@ -57,7 +52,7 @@ pri const ANCILLARY_BIT : base.u32 = 0x0000_0020
// 3: log2(y_stride)
// 4: y_stride - y_offset - 1
// 5: y_offset
pri const INTERLACING : array[8] array[6] base.u8[..= 7] = [
pri const INTERLACING : roarray[8] roarray[6] base.u8[..= 7] = [
[0, 0, 0, 0, 0, 0], // non-interlaced; xy_stride=1, xy_offset=0
[3, 7, 0, 3, 7, 0], // interlace_pass == 1
[3, 3, 4, 3, 7, 0], // interlace_pass == 2
@@ -70,7 +65,7 @@ pri const INTERLACING : array[8] array[6] base.u8[..= 7] = [
// LOW_BIT_DEPTH_MULTIPLIERS holds multipliers that convert D-bit values into
// 8-bit values, for depth D.
pri const LOW_BIT_DEPTH_MULTIPLIERS : array[8] base.u8 = [
pri const LOW_BIT_DEPTH_MULTIPLIERS : roarray[8] base.u8 = [
0,
0b1111_1111, // depth == 1
0b0101_0101, // depth == 2
@@ -83,7 +78,7 @@ pri const LOW_BIT_DEPTH_MULTIPLIERS : array[8] base.u8 = [
// LOW_BIT_DEPTH_NUM_PACKS holds the number of smaller-than-1-byte units that
// are packed into each byte.
pri const LOW_BIT_DEPTH_NUM_PACKS : array[8] base.u8 = [
pri const LOW_BIT_DEPTH_NUM_PACKS : roarray[8] base.u8 = [
0,
8, // depth == 1
4, // depth == 2
@@ -95,7 +90,7 @@ pri const LOW_BIT_DEPTH_NUM_PACKS : array[8] base.u8 = [
]
// NUM_CHANNELS holds the number of channels for each valid color type.
pri const NUM_CHANNELS : array[8] base.u8[..= 4] = [
pri const NUM_CHANNELS : roarray[8] base.u8[..= 4] = [
1, // color_type == 0: Y
0,
3, // color_type == 2: RGB
@@ -108,7 +103,7 @@ pri const NUM_CHANNELS : array[8] base.u8[..= 4] = [
// LATIN_1 converts from printable Latin-1 (ISO/IEC 8859-1) to UTF-8 (encoded
// as little-endian u16). It was created by script/print-png-latin-1.go.
pri const LATIN_1 : array[256] base.u16 = [
pri const LATIN_1 : roarray[256] base.u16 = [
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
+8 -14
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
@@ -84,7 +78,7 @@ pri func decoder.filter_2!(curr: slice base.u8, prev: slice base.u8) {
var n : base.u64
var i : base.u64
n = args.curr.length().min(a: args.prev.length())
n = args.curr.length().min(no_more_than: args.prev.length())
i = 0
while i < n,
inv n <= args.curr.length(),
@@ -122,7 +116,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
} endwhile
} else {
n = args.curr.length().min(a: args.prev.length())
n = args.curr.length().min(no_more_than: args.prev.length())
i = 0
while (i < n) and (i < filter_distance),
inv n <= args.curr.length(),
@@ -238,7 +232,7 @@ pri func decoder.filter_4!(curr: slice base.u8, prev: slice base.u8),
var pc : base.u32
filter_distance = this.filter_distance as base.u64
n = args.curr.length().min(a: args.prev.length())
n = args.curr.length().min(no_more_than: args.prev.length())
i = 0
while (i < n) and (i < filter_distance),
inv n <= args.curr.length(),
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
+31 -26
View File
@@ -1,23 +1,15 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
use "std/crc32"
use "std/zlib"
pub struct decoder? implements base.image_decoder(
// The 0x00FF_FFFF limit is arbitrary (the PNG spec says 0x7FFF_FFFF) but
// it means that (width * height * bytes_per_pixel) doesn't overflow a u64.
width : base.u32[..= 0x00FF_FFFF],
height : base.u32[..= 0x00FF_FFFF],
@@ -143,7 +135,7 @@ pub struct decoder? implements base.image_decoder(
swizzler : base.pixel_swizzler,
util : base.utility,
)(
) + (
crc32 : crc32.ieee_hasher,
zlib : zlib.decoder,
@@ -155,11 +147,20 @@ pub struct decoder? implements base.image_decoder(
src_palette : array[4 * 256] base.u8,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
this.ignore_checksum = args.enabled
this.zlib.set_quirk_enabled!(quirk: args.quirk, enabled: args.enabled)
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
this.zlib.set_quirk!(key: args.key, value: args.value)
return ok
}
return base."#unsupported option"
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
@@ -334,18 +335,18 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
var a8 : base.u8
a32 = args.src.read_u32be?()
if (a32 == 0) or (a32 >= 0x8000_0000) {
if (a32 == 0) or (a32 > 0x7FFF_FFFF) {
return "#bad header"
} else if a32 >= 0x0100_0000 {
return "#unsupported PNG file"
} else if a32 > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.width = a32
a32 = args.src.read_u32be?()
if (a32 == 0) or (a32 >= 0x8000_0000) {
if (a32 == 0) or (a32 > 0x7FFF_FFFF) {
return "#bad header"
} else if a32 >= 0x0100_0000 {
return "#unsupported PNG file"
} else if a32 > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.height = a32
@@ -1184,7 +1185,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
if this.zlib_is_dirty {
this.zlib.reset!()
if this.ignore_checksum {
this.zlib.set_quirk_enabled!(quirk: base.QUIRK_IGNORE_CHECKSUM, enabled: true)
this.zlib.set_quirk!(key: base.QUIRK_IGNORE_CHECKSUM, value: 1)
}
}
this.zlib_is_dirty = true
@@ -1463,7 +1464,7 @@ pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inf
if this.zlib_is_dirty {
this.zlib.reset!()
if this.ignore_checksum {
this.zlib.set_quirk_enabled!(quirk: base.QUIRK_IGNORE_CHECKSUM, enabled: true)
this.zlib.set_quirk!(key: base.QUIRK_IGNORE_CHECKSUM, value: 1)
}
}
this.zlib_is_dirty = true
@@ -1716,6 +1717,10 @@ 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,
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func decoder.filter_and_swizzle!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) base.status,
choosy,
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) base.status {
var dst_pixfmt : base.pixel_format
+19 -15
View File
@@ -1,22 +1,17 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
pub status "#bad header"
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 struct decoder? implements base.image_decoder(
@@ -46,13 +41,18 @@ pub struct decoder? implements base.image_decoder(
swizzler : base.pixel_swizzler,
util : base.utility,
)(
) + (
dst_palette : array[4 * 256] base.u8,
src_palette : array[4 * 256] base.u8,
scratch : array[4] base.u8,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
pub func decoder.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) {
@@ -307,7 +307,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
var dst_palette : slice base.u8
var dst : slice base.u8
var dst_start : base.u64
var src_palette : slice base.u8
var src_palette : roslice base.u8
var mark : base.u64
var num_pixels64 : base.u64
var num_pixels32 : base.u32[..= 0xFFFF]
@@ -377,7 +377,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
if lit_length > 0 {
mark = args.src.mark()
num_pixels64 = args.src.length() / (this.src_bytes_per_pixel as base.u64)
num_pixels32 = num_pixels64.min(a: lit_length as base.u64) as base.u32
num_pixels32 = num_pixels64.min(no_more_than: lit_length as base.u64) as base.u32
num_dst_bytes = (num_pixels32 as base.u64) * dst_bytes_per_pixel
num_src_bytes = num_pixels32 * this.src_bytes_per_pixel
args.src.skip_u32?(n: num_src_bytes)
@@ -610,6 +610,10 @@ 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)
}
+31 -30
View File
@@ -1,25 +1,20 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
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 struct decoder? implements base.image_decoder(
width : base.u32,
height : base.u32,
width : base.u32[..= 0xFF_FFFF],
height : base.u32[..= 0xFF_FFFF],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
@@ -31,7 +26,12 @@ pub struct decoder? implements base.image_decoder(
util : base.utility,
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
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) {
@@ -49,8 +49,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
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 x32 : base.u32
var x64 : base.u64
var p : base.u32[..= 0xFF_FFFF]
if this.call_sequence <> 0x00 {
return base."#bad call sequence"
@@ -69,27 +68,25 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
// Width, height.
i = 0
while i < 2 {
x32 = 0
p = 0
while true,
inv i < 2,
{
c = args.src.read_u8?()
x32 |= (c & 0x7F) as base.u32
p |= (c & 0x7F) as base.u32
if (c >> 7) == 0 {
break
} else if p > 0x1_FFFF {
return base."#unsupported image dimension"
}
x64 = (x32 as base.u64) << 7
if x64 > 0xFFFF_FFFF {
return "#bad header"
}
x32 = x64 as base.u32
p <<= 7
} endwhile
if i == 0 {
this.width = x32
this.width = p
} else {
this.height = x32
this.height = p
}
i += 1
} endwhile
@@ -211,19 +208,19 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
if this.width > 0 {
tab = args.dst.plane(p: 0)
while dst_y < this.height {
assert dst_y < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: this.height)
assert dst_y < 0xFF_FFFF via "a < b: a < c; c <= b"(c: this.height)
dst = tab.row_u32(y: dst_y)
dst_x = 0
while dst_x < this.width,
inv dst_y < 0xFFFF_FFFF,
inv dst_y < 0xFF_FFFF,
{
assert dst_x < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: this.width)
assert dst_x < 0xFF_FFFF via "a < b: a < c; c <= b"(c: this.width)
if (dst_x & 7) == 0 {
while args.src.length() <= 0,
inv dst_x < 0xFFFF_FFFF,
inv dst_y < 0xFFFF_FFFF,
inv dst_x < 0xFF_FFFF,
inv dst_y < 0xFF_FFFF,
post args.src.length() > 0,
{
yield? base."$short read"
@@ -311,6 +308,10 @@ 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)
}
+259
View File
@@ -0,0 +1,259 @@
// 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.
pri const XXH_PRIME32_1 : base.u32 = 0x9E37_79B1
pri const XXH_PRIME32_2 : base.u32 = 0x85EB_CA77
pri const XXH_PRIME32_3 : base.u32 = 0xC2B2_AE3D
pri const XXH_PRIME32_4 : base.u32 = 0x27D4_EB2F
pri const XXH_PRIME32_5 : base.u32 = 0x1656_67B1
pri const INITIAL_V0 : base.u32 = 0x2423_4428 // 0 + XXH_PRIME32_1 + XXH_PRIME32_2
pri const INITIAL_V1 : base.u32 = 0x85EB_CA77 // 0 + XXH_PRIME32_2
pri const INITIAL_V2 : base.u32 = 0x0000_0000 // 0
pri const INITIAL_V3 : base.u32 = 0x61C8_864F // 0 - XXH_PRIME32_1
pub struct hasher? implements base.hasher_u32(
length_modulo_u32 : base.u32,
length_overflows_u32 : base.bool,
padding0 : base.u8,
padding1 : base.u8,
buf_len : base.u8[..= 16],
buf_data : array[16] base.u8,
v0 : base.u32,
v1 : base.u32,
v2 : base.u32,
v3 : base.u32,
)
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 remaining : roslice base.u8
if (this.length_modulo_u32 == 0) and not this.length_overflows_u32 {
this.v0 = INITIAL_V0
this.v1 = INITIAL_V1
this.v2 = INITIAL_V2
this.v3 = INITIAL_V3
// In theory, we could "choose up" here to pick SIMD versions. In
// practice, non-SIMD versions are faster (and simpler). For example,
// see commit b9b28dbe "std/xxhash32: add hasher.up_x86_sse42".
}
// Slicing at 0x100_0000 is arbitrary but ensures that the subslice's
// length (used in hasher.up) doesn't overflow a u32.
while args.x.length() > 0 {
remaining = args.x[.. 0]
if args.x.length() > 0x100_0000 {
remaining = args.x[0x100_0000 ..]
args.x = args.x[.. 0x100_0000]
}
this.up!(x: args.x)
args.x = remaining
} endwhile
}
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
this.update!(x: args.x)
return this.checksum_u32()
}
pri func hasher.up!(x: roslice base.u8) {
var new_lmu : base.u32
var buf_u32 : base.u32
var buf_len : base.u32[..= 15]
var v0 : base.u32
var v1 : base.u32
var v2 : base.u32
var v3 : base.u32
var p : roslice base.u8
new_lmu = this.length_modulo_u32 ~mod+ ((args.x.length() & 0xFFFF_FFFF) as base.u32)
this.length_overflows_u32 = (new_lmu < this.length_modulo_u32) or this.length_overflows_u32
this.length_modulo_u32 = new_lmu
while true {
if this.buf_len >= 16 {
buf_u32 = (this.buf_data[0x00] as base.u32) |
((this.buf_data[0x01] as base.u32) << 8) |
((this.buf_data[0x02] as base.u32) << 16) |
((this.buf_data[0x03] as base.u32) << 24)
v0 = this.v0 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v0 = (v0 ~mod<< 13) | (v0 >> 19)
this.v0 = v0 ~mod* XXH_PRIME32_1
buf_u32 = (this.buf_data[0x04] as base.u32) |
((this.buf_data[0x05] as base.u32) << 8) |
((this.buf_data[0x06] as base.u32) << 16) |
((this.buf_data[0x07] as base.u32) << 24)
v1 = this.v1 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v1 = (v1 ~mod<< 13) | (v1 >> 19)
this.v1 = v1 ~mod* XXH_PRIME32_1
buf_u32 = (this.buf_data[0x08] as base.u32) |
((this.buf_data[0x09] as base.u32) << 8) |
((this.buf_data[0x0A] as base.u32) << 16) |
((this.buf_data[0x0B] as base.u32) << 24)
v2 = this.v2 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v2 = (v2 ~mod<< 13) | (v2 >> 19)
this.v2 = v2 ~mod* XXH_PRIME32_1
buf_u32 = (this.buf_data[0x0C] as base.u32) |
((this.buf_data[0x0D] as base.u32) << 8) |
((this.buf_data[0x0E] as base.u32) << 16) |
((this.buf_data[0x0F] as base.u32) << 24)
v3 = this.v3 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v3 = (v3 ~mod<< 13) | (v3 >> 19)
this.v3 = v3 ~mod* XXH_PRIME32_1
this.buf_len = 0
break
}
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 ..]
} endwhile
buf_len = (this.buf_len & 15) as base.u32
v0 = this.v0
v1 = this.v1
v2 = this.v2
v3 = this.v3
iterate (p = args.x)(length: 16, advance: 16, unroll: 1) {
buf_u32 = (p[0x00] as base.u32) |
((p[0x01] as base.u32) << 8) |
((p[0x02] as base.u32) << 16) |
((p[0x03] as base.u32) << 24)
v0 = v0 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v0 = (v0 ~mod<< 13) | (v0 >> 19)
v0 = v0 ~mod* XXH_PRIME32_1
buf_u32 = (p[0x04] as base.u32) |
((p[0x05] as base.u32) << 8) |
((p[0x06] as base.u32) << 16) |
((p[0x07] as base.u32) << 24)
v1 = v1 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v1 = (v1 ~mod<< 13) | (v1 >> 19)
v1 = v1 ~mod* XXH_PRIME32_1
buf_u32 = (p[0x08] as base.u32) |
((p[0x09] as base.u32) << 8) |
((p[0x0A] as base.u32) << 16) |
((p[0x0B] as base.u32) << 24)
v2 = v2 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v2 = (v2 ~mod<< 13) | (v2 >> 19)
v2 = v2 ~mod* XXH_PRIME32_1
buf_u32 = (p[0x0C] as base.u32) |
((p[0x0D] as base.u32) << 8) |
((p[0x0E] as base.u32) << 16) |
((p[0x0F] as base.u32) << 24)
v3 = v3 ~mod+ (buf_u32 ~mod* XXH_PRIME32_2)
v3 = (v3 ~mod<< 13) | (v3 >> 19)
v3 = v3 ~mod* XXH_PRIME32_1
} else (length: 1, advance: 1, unroll: 1) {
this.buf_data[buf_len] = p[0]
buf_len = (buf_len + 1) & 15
}
this.buf_len = buf_len as base.u8
this.v0 = v0
this.v1 = v1
this.v2 = v2
this.v3 = v3
}
pub func hasher.checksum_u32() base.u32 {
var ret : base.u32
var i : base.u32[..= 16]
var n : base.u32[..= 16]
var buf_u32 : base.u32
if (this.length_modulo_u32 >= 16) or this.length_overflows_u32 {
ret ~mod+= (this.v0 ~mod<< 1) | (this.v0 >> 31)
ret ~mod+= (this.v1 ~mod<< 7) | (this.v1 >> 25)
ret ~mod+= (this.v2 ~mod<< 12) | (this.v2 >> 20)
ret ~mod+= (this.v3 ~mod<< 18) | (this.v3 >> 14)
ret ~mod+= this.length_modulo_u32
} else {
ret ~mod+= XXH_PRIME32_5
ret ~mod+= this.length_modulo_u32
}
n = 16
n = n.min(no_more_than: this.buf_len as base.u32)
if 0x04 <= n {
buf_u32 = (this.buf_data[0x00] as base.u32) |
((this.buf_data[0x01] as base.u32) << 8) |
((this.buf_data[0x02] as base.u32) << 16) |
((this.buf_data[0x03] as base.u32) << 24)
ret ~mod+= buf_u32 ~mod* XXH_PRIME32_3
ret = (ret ~mod<< 17) | (ret >> 15)
ret ~mod*= XXH_PRIME32_4
i = 0x04
}
if 0x08 <= n {
buf_u32 = (this.buf_data[0x04] as base.u32) |
((this.buf_data[0x05] as base.u32) << 8) |
((this.buf_data[0x06] as base.u32) << 16) |
((this.buf_data[0x07] as base.u32) << 24)
ret ~mod+= buf_u32 ~mod* XXH_PRIME32_3
ret = (ret ~mod<< 17) | (ret >> 15)
ret ~mod*= XXH_PRIME32_4
i = 0x08
}
if 0x0C <= n {
buf_u32 = (this.buf_data[0x08] as base.u32) |
((this.buf_data[0x09] as base.u32) << 8) |
((this.buf_data[0x0A] as base.u32) << 16) |
((this.buf_data[0x0B] as base.u32) << 24)
ret ~mod+= buf_u32 ~mod* XXH_PRIME32_3
ret = (ret ~mod<< 17) | (ret >> 15)
ret ~mod*= XXH_PRIME32_4
i = 0x0C
}
while i < n {
assert i < 16 via "a < b: a < c; c <= b"(c: n)
ret ~mod+= (this.buf_data[i] as base.u32) ~mod* XXH_PRIME32_5
ret = (ret ~mod<< 11) | (ret >> 21)
ret ~mod*= XXH_PRIME32_1
i += 1
} endwhile
ret ^= ret >> 15
ret ~mod*= XXH_PRIME32_2
ret ^= ret >> 13
ret ~mod*= XXH_PRIME32_3
ret ^= ret >> 16
return ret
}
+340
View File
@@ -0,0 +1,340 @@
// 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.
pri const XXH_PRIME64_1 : base.u64 = 0x9E37_79B1_85EB_CA87
pri const XXH_PRIME64_2 : base.u64 = 0xC2B2_AE3D_27D4_EB4F
pri const XXH_PRIME64_3 : base.u64 = 0x1656_67B1_9E37_79F9
pri const XXH_PRIME64_4 : base.u64 = 0x85EB_CA77_C2B2_AE63
pri const XXH_PRIME64_5 : base.u64 = 0x27D4_EB2F_1656_67C5
pri const INITIAL_V0 : base.u64 = 0x60EA_27EE_ADC0_B5D6 // 0 + XXH_PRIME64_1 + XXH_PRIME64_2
pri const INITIAL_V1 : base.u64 = 0xC2B2_AE3D_27D4_EB4F // 0 + XXH_PRIME64_2
pri const INITIAL_V2 : base.u64 = 0x0000_0000_0000_0000 // 0
pri const INITIAL_V3 : base.u64 = 0x61C8_864E_7A14_3579 // 0 - XXH_PRIME64_1
pub struct hasher? implements base.hasher_u64(
length_modulo_u64 : base.u64,
length_overflows_u64 : base.bool,
padding0 : base.u8,
padding1 : base.u8,
padding2 : base.u8,
buf_len : base.u32[..= 32],
buf_data : array[32] base.u8,
v0 : base.u64,
v1 : base.u64,
v2 : base.u64,
v3 : base.u64,
)
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) {
if (this.length_modulo_u64 == 0) and not this.length_overflows_u64 {
this.v0 = INITIAL_V0
this.v1 = INITIAL_V1
this.v2 = INITIAL_V2
this.v3 = INITIAL_V3
// In theory, we could "choose up" here to pick SIMD versions. In
// practice, non-SIMD versions are faster (and simpler). For example,
// see commit b9b28dbe "std/xxhash32: add hasher.up_x86_sse42".
}
this.up!(x: args.x)
}
pub func hasher.update_u64!(x: roslice base.u8) base.u64 {
this.update!(x: args.x)
return this.checksum_u64()
}
pri func hasher.up!(x: roslice base.u8) {
var new_lmu : base.u64
var buf_u64 : base.u64
var buf_len : base.u32[..= 31]
var v0 : base.u64
var v1 : base.u64
var v2 : base.u64
var v3 : base.u64
var p : roslice base.u8
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
while true {
if this.buf_len >= 32 {
buf_u64 = (this.buf_data[0x00] as base.u64) |
((this.buf_data[0x01] as base.u64) << 8) |
((this.buf_data[0x02] as base.u64) << 16) |
((this.buf_data[0x03] as base.u64) << 24) |
((this.buf_data[0x04] as base.u64) << 32) |
((this.buf_data[0x05] as base.u64) << 40) |
((this.buf_data[0x06] as base.u64) << 48) |
((this.buf_data[0x07] as base.u64) << 56)
v0 = this.v0 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v0 = (v0 ~mod<< 31) | (v0 >> 33)
this.v0 = v0 ~mod* XXH_PRIME64_1
buf_u64 = (this.buf_data[0x08] as base.u64) |
((this.buf_data[0x09] as base.u64) << 8) |
((this.buf_data[0x0A] as base.u64) << 16) |
((this.buf_data[0x0B] as base.u64) << 24) |
((this.buf_data[0x0C] as base.u64) << 32) |
((this.buf_data[0x0D] as base.u64) << 40) |
((this.buf_data[0x0E] as base.u64) << 48) |
((this.buf_data[0x0F] as base.u64) << 56)
v1 = this.v1 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v1 = (v1 ~mod<< 31) | (v1 >> 33)
this.v1 = v1 ~mod* XXH_PRIME64_1
buf_u64 = (this.buf_data[0x10] as base.u64) |
((this.buf_data[0x11] as base.u64) << 8) |
((this.buf_data[0x12] as base.u64) << 16) |
((this.buf_data[0x13] as base.u64) << 24) |
((this.buf_data[0x14] as base.u64) << 32) |
((this.buf_data[0x15] as base.u64) << 40) |
((this.buf_data[0x16] as base.u64) << 48) |
((this.buf_data[0x17] as base.u64) << 56)
v2 = this.v2 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v2 = (v2 ~mod<< 31) | (v2 >> 33)
this.v2 = v2 ~mod* XXH_PRIME64_1
buf_u64 = (this.buf_data[0x18] as base.u64) |
((this.buf_data[0x19] as base.u64) << 8) |
((this.buf_data[0x1A] as base.u64) << 16) |
((this.buf_data[0x1B] as base.u64) << 24) |
((this.buf_data[0x1C] as base.u64) << 32) |
((this.buf_data[0x1D] as base.u64) << 40) |
((this.buf_data[0x1E] as base.u64) << 48) |
((this.buf_data[0x1F] as base.u64) << 56)
v3 = this.v3 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v3 = (v3 ~mod<< 31) | (v3 >> 33)
this.v3 = v3 ~mod* XXH_PRIME64_1
this.buf_len = 0
break
}
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 ..]
} endwhile
buf_len = this.buf_len & 31
v0 = this.v0
v1 = this.v1
v2 = this.v2
v3 = this.v3
iterate (p = args.x)(length: 32, advance: 32, unroll: 1) {
buf_u64 = (p[0x00] as base.u64) |
((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)
v0 = v0 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v0 = (v0 ~mod<< 31) | (v0 >> 33)
v0 = v0 ~mod* XXH_PRIME64_1
buf_u64 = (p[0x08] as base.u64) |
((p[0x09] as base.u64) << 8) |
((p[0x0A] as base.u64) << 16) |
((p[0x0B] as base.u64) << 24) |
((p[0x0C] as base.u64) << 32) |
((p[0x0D] as base.u64) << 40) |
((p[0x0E] as base.u64) << 48) |
((p[0x0F] as base.u64) << 56)
v1 = v1 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v1 = (v1 ~mod<< 31) | (v1 >> 33)
v1 = v1 ~mod* XXH_PRIME64_1
buf_u64 = (p[0x10] as base.u64) |
((p[0x11] as base.u64) << 8) |
((p[0x12] as base.u64) << 16) |
((p[0x13] as base.u64) << 24) |
((p[0x14] as base.u64) << 32) |
((p[0x15] as base.u64) << 40) |
((p[0x16] as base.u64) << 48) |
((p[0x17] as base.u64) << 56)
v2 = v2 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v2 = (v2 ~mod<< 31) | (v2 >> 33)
v2 = v2 ~mod* XXH_PRIME64_1
buf_u64 = (p[0x18] as base.u64) |
((p[0x19] as base.u64) << 8) |
((p[0x1A] as base.u64) << 16) |
((p[0x1B] as base.u64) << 24) |
((p[0x1C] as base.u64) << 32) |
((p[0x1D] as base.u64) << 40) |
((p[0x1E] as base.u64) << 48) |
((p[0x1F] as base.u64) << 56)
v3 = v3 ~mod+ (buf_u64 ~mod* XXH_PRIME64_2)
v3 = (v3 ~mod<< 31) | (v3 >> 33)
v3 = v3 ~mod* XXH_PRIME64_1
} else (length: 1, advance: 1, unroll: 1) {
this.buf_data[buf_len] = p[0]
buf_len = (buf_len + 1) & 31
}
this.buf_len = buf_len
this.v0 = v0
this.v1 = v1
this.v2 = v2
this.v3 = v3
}
pub func hasher.checksum_u64() base.u64 {
var ret : base.u64
var v0 : base.u64
var v1 : base.u64
var v2 : base.u64
var v3 : base.u64
var i : base.u32[..= 32]
var i8 : base.u32[..= 24]
var n : base.u32[..= 32]
var buf_u32 : base.u32
var buf_u64 : base.u64
if (this.length_modulo_u64 >= 32) or this.length_overflows_u64 {
ret ~mod+= (this.v0 ~mod<< 1) | (this.v0 >> 63)
ret ~mod+= (this.v1 ~mod<< 7) | (this.v1 >> 57)
ret ~mod+= (this.v2 ~mod<< 12) | (this.v2 >> 52)
ret ~mod+= (this.v3 ~mod<< 18) | (this.v3 >> 46)
v0 = this.v0 ~mod* XXH_PRIME64_2
v0 = (v0 ~mod<< 31) | (v0 >> 33)
v0 ~mod*= XXH_PRIME64_1
v1 = this.v1 ~mod* XXH_PRIME64_2
v1 = (v1 ~mod<< 31) | (v1 >> 33)
v1 ~mod*= XXH_PRIME64_1
v2 = this.v2 ~mod* XXH_PRIME64_2
v2 = (v2 ~mod<< 31) | (v2 >> 33)
v2 ~mod*= XXH_PRIME64_1
v3 = this.v3 ~mod* XXH_PRIME64_2
v3 = (v3 ~mod<< 31) | (v3 >> 33)
v3 ~mod*= XXH_PRIME64_1
ret = ((ret ^ v0) ~mod* XXH_PRIME64_1) ~mod+ XXH_PRIME64_4
ret = ((ret ^ v1) ~mod* XXH_PRIME64_1) ~mod+ XXH_PRIME64_4
ret = ((ret ^ v2) ~mod* XXH_PRIME64_1) ~mod+ XXH_PRIME64_4
ret = ((ret ^ v3) ~mod* XXH_PRIME64_1) ~mod+ XXH_PRIME64_4
ret ~mod+= this.length_modulo_u64
} else {
ret ~mod+= XXH_PRIME64_5
ret ~mod+= this.length_modulo_u64
}
n = 32
n = n.min(no_more_than: this.buf_len)
if 0x08 <= n {
buf_u64 = (this.buf_data[0x00] as base.u64) |
((this.buf_data[0x01] as base.u64) << 8) |
((this.buf_data[0x02] as base.u64) << 16) |
((this.buf_data[0x03] as base.u64) << 24) |
((this.buf_data[0x04] as base.u64) << 32) |
((this.buf_data[0x05] as base.u64) << 40) |
((this.buf_data[0x06] as base.u64) << 48) |
((this.buf_data[0x07] as base.u64) << 56)
buf_u64 ~mod*= XXH_PRIME64_2
buf_u64 = (buf_u64 ~mod<< 31) | (buf_u64 >> 33)
buf_u64 ~mod*= XXH_PRIME64_1
ret ^= buf_u64
ret = (ret ~mod<< 27) | (ret >> 37)
ret ~mod*= XXH_PRIME64_1
ret ~mod+= XXH_PRIME64_4
i = 0x08
}
if 0x10 <= n {
buf_u64 = (this.buf_data[0x08] as base.u64) |
((this.buf_data[0x09] as base.u64) << 8) |
((this.buf_data[0x0A] as base.u64) << 16) |
((this.buf_data[0x0B] as base.u64) << 24) |
((this.buf_data[0x0C] as base.u64) << 32) |
((this.buf_data[0x0D] as base.u64) << 40) |
((this.buf_data[0x0E] as base.u64) << 48) |
((this.buf_data[0x0F] as base.u64) << 56)
buf_u64 ~mod*= XXH_PRIME64_2
buf_u64 = (buf_u64 ~mod<< 31) | (buf_u64 >> 33)
buf_u64 ~mod*= XXH_PRIME64_1
ret ^= buf_u64
ret = (ret ~mod<< 27) | (ret >> 37)
ret ~mod*= XXH_PRIME64_1
ret ~mod+= XXH_PRIME64_4
i = 0x10
}
if 0x18 <= n {
buf_u64 = (this.buf_data[0x10] as base.u64) |
((this.buf_data[0x11] as base.u64) << 8) |
((this.buf_data[0x12] as base.u64) << 16) |
((this.buf_data[0x13] as base.u64) << 24) |
((this.buf_data[0x14] as base.u64) << 32) |
((this.buf_data[0x15] as base.u64) << 40) |
((this.buf_data[0x16] as base.u64) << 48) |
((this.buf_data[0x17] as base.u64) << 56)
buf_u64 ~mod*= XXH_PRIME64_2
buf_u64 = (buf_u64 ~mod<< 31) | (buf_u64 >> 33)
buf_u64 ~mod*= XXH_PRIME64_1
ret ^= buf_u64
ret = (ret ~mod<< 27) | (ret >> 37)
ret ~mod*= XXH_PRIME64_1
ret ~mod+= XXH_PRIME64_4
i = 0x18
}
if (n & 4) <> 0 {
i8 = i & 24
buf_u32 = (this.buf_data[i8 + 0x00] as base.u32) |
((this.buf_data[i8 + 0x01] as base.u32) << 8) |
((this.buf_data[i8 + 0x02] as base.u32) << 16) |
((this.buf_data[i8 + 0x03] as base.u32) << 24)
ret ^= (buf_u32 as base.u64) ~mod* XXH_PRIME64_1
ret = (ret ~mod<< 23) | (ret >> 41)
ret ~mod*= XXH_PRIME64_2
ret ~mod+= XXH_PRIME64_3
i = i8 + 4
}
while i < n {
assert i < 32 via "a < b: a < c; c <= b"(c: n)
ret ^= (this.buf_data[i] as base.u64) ~mod* XXH_PRIME64_5
ret = (ret ~mod<< 11) | (ret >> 53)
ret ~mod*= XXH_PRIME64_1
i += 1
} endwhile
ret ^= ret >> 33
ret ~mod*= XXH_PRIME64_2
ret ^= ret >> 29
ret ~mod*= XXH_PRIME64_3
ret ^= ret >> 32
return ret as base.u64
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// --------
+38 -18
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
use "std/adler32"
use "std/deflate"
@@ -24,6 +18,8 @@ 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
// TODO: reference deflate.DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE.
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
@@ -62,17 +58,41 @@ pub func decoder.add_dictionary!(dict: slice base.u8) {
this.got_dictionary = true
}
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
pub func decoder.get_quirk(key: base.u32) base.u64 {
var key : base.u32
if (args.key == base.QUIRK_IGNORE_CHECKSUM) and this.ignore_checksum {
return 1
} else if args.key >= QUIRKS_BASE {
key = args.key - QUIRKS_BASE
if key < QUIRKS_COUNT {
if this.quirks[key] {
return 1
}
}
}
return 0
}
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
if this.header_complete {
this.bad_call_sequence = true
} else if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
this.ignore_checksum = args.enabled
} else if args.quirk >= QUIRKS_BASE {
args.quirk -= QUIRKS_BASE
if args.quirk < QUIRKS_COUNT {
this.quirks[args.quirk] = args.enabled
return base."#bad call sequence"
} else if args.key == base.QUIRK_IGNORE_CHECKSUM {
this.ignore_checksum = args.value > 0
return ok
} else if args.key >= QUIRKS_BASE {
args.key -= QUIRKS_BASE
if args.key < QUIRKS_COUNT {
this.quirks[args.key] = args.value > 0
return ok
}
}
return base."#unsupported option"
}
pub func decoder.history_retain_length() base.u64 {
return 0
}
pub func decoder.workbuf_len() base.range_ii_u64 {
+2 -3
View File
@@ -1,5 +1,4 @@
# Ignore everything without a dot.
# Ignore everything ending in "suite".
#
# This ignores "pngsuite" but not "fetch-pngsuite.sh".
*
!*.*
*suite
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

+28
View File
@@ -0,0 +1,28 @@
#!/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.
# ----------------
# This script fetches Blink's web_tests/images/resources 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 June 2023).
git clone --quiet --depth=1 https://github.com/nigeltao/blink-web-tests-images-resources.git
cd blink-web-tests-images-resources
git reset --quiet --hard 9c5a6768184e5b45eaddad8f83ffd87dc5dc8f15
cd ..
# Copy out the resources directory.
rm -rf blinksuite
mv blink-web-tests-images-resources/resources blinksuite
rm -rf blink-web-tests-images-resources
+22
View File
@@ -0,0 +1,22 @@
#!/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.
# ----------------
# This script fetches the BMPSuite collection of BMP images.
if [ ! -e ../../wuffs-root-directory.txt ]; then
echo "$0 should be run from the Wuffs test/3pdata directory."
exit 1
fi
curl --silent -O http://entropymine.com/jason/bmpsuite/releases/bmpsuite-2.7.zip
unzip bmpsuite-2.7.zip
mv bmpsuite-2.7 bmpsuite
rm bmpsuite-2.7.zip
+28
View File
@@ -0,0 +1,28 @@
#!/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.
# ----------------
# This script fetches golang/go's src/image/testdata 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 June 2023).
git clone --quiet --depth=1 https://github.com/nigeltao/golang-go-src-image-testdata.git
cd golang-go-src-image-testdata
git reset --quiet --hard f2f7970f9054b910148be4e0dbda94b392c58700
cd ..
# Copy out the testdata directory.
rm -rf golangsuite
mv golang-go-src-image-testdata/testdata golangsuite
rm -rf golang-go-src-image-testdata
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2021 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2022 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
@@ -0,0 +1,258 @@
# JPEG Images
`script/confirm-matches-djpeg.sh test/3pdata/blinksuite | grep Differ` gives 5
test files for which Wuffs' `example/convert-to-nia` and libjpeg-turbo's
`djpeg` do not match:
```
Differ (other) test/3pdata/blinksuite/182.jpg
Differ (other) test/3pdata/blinksuite/large-size-image-crash.jpeg
Differ (trunc) test/3pdata/blinksuite/missing-eoi.jpg
Differ (trunc) test/3pdata/blinksuite/non-interleaved_progressive-1.jpg
Differ (trunc) test/3pdata/blinksuite/non-interleaved_progressive.jpg
```
We'll discuss these in simple to complex order, which happens to be the
opposite of the alphabetical order they're listed above.
---
The last three are truncated JPEG files. Like most image file format
specifications, the JPEG specification doesn't mandate exactly how to decode
*invalid* input (including truncated input), and it's reasonable for Wuffs and
libjpeg-turbo to produce slightly different outputs here. Wuffs' [commit
a3cecef6](https://github.com/google/wuffs/commit/a3cecef69aa04f1145f0c84b92481e8abd51c2c3)
"std/jpeg: decode truncated JPEGs on MCU boundaries" discusses some of the
performance trade-offs if Wuffs were to try to exactly match on all input, not
just on well-formed JPEGs.
As pointed out by the a3cecef6 commit message, matching libjpeg-turbo exactly
doesn't necessarily give better output. Here's two JPEG images (one sequential,
one progressive, both truncated to 1 KiB) decoded by Wuffs:
![Decoding by Wuffs](../data/peacock.default.truncated.decoded-by-wuffs.png)
![Decoding by Wuffs](../data/peacock.progressive.truncated.decoded-by-wuffs.png)
Here's the same input, this time decoded by libjpeg-turbo:
![Decoding by djpeg](../data/peacock.default.truncated.decoded-by-djpeg.png)
![Decoding by djpeg](../data/peacock.progressive.truncated.decoded-by-djpeg.png)
Zoom in on all four images (in four different tabs, if viewing in a browser),
and the first pair isn't obviously better or worse than the second pair.
---
`test/3pdata/blinksuite/large-size-image-crash.jpeg` is simply a very large
image (in terms of pixels: 48010 × 16173), even though the file itself is
merely 347 bytes. At 4 bytes per pixel, 48010 × 16173 × 4 ≈ 2962 MiB exceeds
`example/convert-to-nia` maximum pixel buffer size.
```
$ file test/3pdata/blinksuite/large-size-image-crash.jpeg
test/3pdata/blinksuite/large-size-image-crash.jpeg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 48010x16173, components 3
$ grep define.PIXBUF_ARRAY_SIZE example/convert-to-nia/convert-to-nia.c
#define PIXBUF_ARRAY_SIZE (256 * 1024 * 1024)
```
The file itself is merely 347 bytes long. Even if we patched
`example/convert-to-nia` to allow larger pixel buffers, it's a truncated image
like the first three we discussed, above.
```
$ djpeg test/3pdata/blinksuite/large-size-image-crash.jpeg > /dev/null
Premature end of JPEG file
```
That file is in the test suite presumably to check that decoders don't crash or
trigger buffer overflows, and `example/convert-to-nia` does neither here.
---
`test/3pdata/blinksuite/182.jpg` is our final example (first in alphabetical
order but last in discussion order) of where Wuffs and libjpeg-turbo differ.
Once again, different JPEG implementations have some leeway on how to treat
*invalid* JPEGs, and this JPEG is invalid.
```
$ djpeg test/3pdata/blinksuite/182.jpg > /dev/null
Corrupt JPEG data: 29 extraneous bytes before marker 0xc4
```
As of Wuffs' [commit
186bdc5f](https://github.com/google/wuffs/commit/186bdc5fe2eedaa2869123aa7954ed9a4582e895)
"Roll back 'decode truncated... on MCU boundaries'" and libjpeg-turbo v3.0.1,
here are the two decodings (Wuffs' and djpeg's):
![Wuffs decoding of 0-original](./asset/182.0-original.wuffs.png)
![djpeg decoding of 0-original](./asset/182.0-original.djpeg.png)
When zooming in, the two are indeed different, but both decodings look like
garbage and it's not clear that one is better than the other (although djpeg's
output seems to have more 'detail' that Wuffs' output is missing).
Let's look at the hex dump of the `test/3pdata/blinksuite/182.jpg` file, copied
into this repo as `test/3pdata/asset/182.0-original.jpg`
```
$ hd test/3pdata/asset/182.0-original.jpg
00000000 ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 48 |......JFIF.....H|
00000010 00 48 00 00 ff db 00 43 00 10 0b 0c 0e 0c 0a 10 |.H.....C........|
00000020 0e 0d 0e 12 11 10 13 18 28 1a 18 16 16 18 31 23 |........(.....1#|
00000030 25 1d 28 3a 33 3d 3c 39 33 38 37 40 48 5c 4e 40 |%.(:3=<9387@H\N@|
00000040 44 57 45 37 38 50 6d 51 57 5f 62 67 68 67 3e 4d |DWE78PmQW_bghg>M|
00000050 71 79 70 64 78 5c 65 67 63 ff db 00 43 01 11 12 |qypdx\egc...C...|
00000060 12 18 15 18 2f 1a 1a 2f 63 42 38 42 63 63 63 63 |..../../cB8Bcccc|
00000070 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |cccccccccccccccc|
*
00000090 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ff c0 |cccccccccccccc..|
000000a0 00 11 08 00 1d 00 20 03 01 22 00 02 11 01 03 11 |...... .."......|
000000b0 01 ff c4 00 18 00 00 03 01 01 00 00 00 00 00 00 |................|
000000c0 00 00 00 00 00 00 02 03 04 05 01 ff c4 00 16 01 |................|
000000d0 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000e0 00 02 03 fe da 00 0c 03 01 00 02 10 03 10 00 00 |................|
000000f0 01 d9 02 69 93 7c 61 3a d3 4b 91 59 76 77 50 7f |...i.|a:.K.YvwP.|
00000100 ff c4 00 1e 10 00 02 01 05 00 03 00 00 00 00 00 |................|
00000110 00 00 00 00 00 01 02 03 00 04 11 12 13 10 22 31 |.............."1|
00000120 ff da 00 08 01 01 00 01 05 02 66 21 8c 85 55 2f |..........f!..U/|
00000130 09 68 df 63 f6 62 36 57 b3 5c 5b 27 19 5b 11 ce |.h.c.b6W.\['.[..|
00000140 06 a9 ae 40 f7 9a b9 25 72 4f 1f ff c4 00 19 11 |...@...%rO......|
00000150 00 01 05 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000160 01 00 02 10 12 21 ff da 00 08 01 03 01 01 3f 01 |.....!........?.|
00000170 4e a1 d1 3f ff c4 00 17 11 00 03 01 00 00 00 00 |N..?............|
00000180 00 00 00 00 00 00 00 00 00 00 01 10 11 ff da 00 |................|
00000190 08 01 02 01 01 3f 01 16 df ff c4 00 23 10 00 01 |.....?......#...|
000001a0 03 02 05 05 00 00 00 00 00 00 00 00 00 00 01 00 |................|
000001b0 11 21 02 71 10 12 22 41 51 03 31 32 61 62 ff da |.!.q.."AQ.12ab..|
000001c0 00 08 01 01 00 06 3f 02 14 d2 1c 9e 4a 24 f4 ea |......?.....J$..|
000001d0 8b 26 a8 52 15 41 e9 2d c2 1f 21 10 7b 15 a0 b1 |.&.R.A.-..!.{...|
000001e0 f6 b5 90 e4 44 ac cd 1b ad 25 ee 86 63 22 61 66 |....D....%..c"af|
000001f0 1e 22 1f 63 84 06 b1 65 21 ee 5f 0f ff c4 00 23 |.".c...e!._....#|
00000200 10 01 00 02 01 03 02 07 00 00 00 00 00 00 00 00 |................|
00000210 00 01 00 11 21 31 41 71 b1 d1 10 51 61 81 a1 f0 |....!1Aq...Qa...|
00000220 f1 ff da 00 08 01 01 00 01 3f 21 28 00 5d 0c 15 |.........?!(.]..|
00000230 de 08 25 2d a7 ba 66 38 d1 ba 0e 60 dc 5d f2 9f |..%-..f8...`.]..|
00000240 43 9f c8 60 ac 29 8e c8 f7 17 16 a2 7c 92 51 55 |C..`.)......|.QU|
00000250 62 a8 5a 7a ae db c7 42 da a8 bb d6 2a f8 26 a5 |b.Zz...B....*.&.|
00000260 13 76 68 00 3e 67 4f 0c d9 39 dd 13 36 4e 77 54 |.vh.>gO..9..6NwT|
00000270 31 a4 ff da 00 0c 03 01 00 02 00 03 00 00 00 10 |1...............|
00000280 41 c3 28 ff c4 00 18 11 01 00 03 01 00 00 00 00 |A.(.............|
00000290 00 00 00 00 00 00 00 00 01 00 10 11 61 ff da 00 |............a...|
000002a0 08 01 03 01 01 3f 10 80 95 ce 5f ff c4 00 18 11 |.....?...._.....|
000002b0 00 02 03 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000002c0 00 01 10 11 21 ff da 00 08 01 02 01 01 3f 10 29 |....!........?.)|
000002d0 c7 3f fe c4 00 22 10 01 01 00 02 01 03 04 03 00 |.?..."..........|
000002e0 00 00 00 00 00 00 00 01 11 00 21 41 31 61 71 10 |..........!A1aq.|
000002f0 51 81 91 a1 b1 f0 ff da 00 08 01 01 00 01 3f 10 |Q.............?.|
00000300 db 2f 88 48 1d 83 ba 38 c3 8a 32 a0 00 aa 28 b8 |./.H...8..2...(.|
00000310 dc 83 de bb 15 bb e7 59 72 c8 db a8 9c 95 8d 13 |.......Yr.......|
00000320 2f 6a 51 63 2d c0 f1 bf e3 2d 98 0a ca 24 71 35 |/jQc-....-...$q5|
00000330 70 8b a3 d8 76 f3 fb c5 8f d0 00 f4 16 fd 93 e7 |p...v...........|
00000340 0f 59 3c 5d 9d 21 82 a3 fb 49 0a 23 cd ac a7 1b |.Y<].!...I.#....|
00000350 d6 49 65 a5 91 38 7b 76 c5 aa 60 a8 1a 3b 4b c0 |.Ie..8{v..`..;K.|
00000360 bd 2d 2f a6 e6 cf a8 7b f0 8c 5c 78 f3 fe 93 80 |.-/....{..\x....|
00000370 00 00 34 1e d9 ff d9 |..4....|
00000377
```
The JPEG markers within this (including a corrupted one) are:
```
pos = 0x00000000 = 0 marker = 0xFF 0xD8 SOI
pos = 0x00000002 = 2 marker = 0xFF 0xE0 APP0
pos = 0x00000014 = 20 marker = 0xFF 0xDB DQT
pos = 0x00000059 = 89 marker = 0xFF 0xDB DQT
pos = 0x0000009E = 158 marker = 0xFF 0xC0 SOF0 (Sequential/Baseline)
pos = 0x000000B1 = 177 marker = 0xFF 0xC4 DHT
pos = 0x000000CB = 203 marker = 0xFF 0xC4 DHT
pos = 0x000000E3 = 227 marker = 0xFE 0xDA SOS *** corrupted ***
pos = 0x00000100 = 256 marker = 0xFF 0xC4 DHT
pos = 0x00000120 = 288 marker = 0xFF 0xDA SOS
pos = 0x0000014B = 331 marker = 0xFF 0xC4 DHT
pos = 0x00000166 = 358 marker = 0xFF 0xDA SOS
pos = 0x00000174 = 372 marker = 0xFF 0xC4 DHT
pos = 0x0000018D = 397 marker = 0xFF 0xDA SOS
pos = 0x00000199 = 409 marker = 0xFF 0xC4 DHT
pos = 0x000001BE = 446 marker = 0xFF 0xDA SOS
pos = 0x000001FC = 508 marker = 0xFF 0xC4 DHT
pos = 0x00000221 = 545 marker = 0xFF 0xDA SOS
pos = 0x00000272 = 626 marker = 0xFF 0xDA SOS
pos = 0x00000283 = 643 marker = 0xFF 0xC4 DHT
pos = 0x0000029D = 669 marker = 0xFF 0xDA SOS
pos = 0x000002AB = 683 marker = 0xFF 0xC4 DHT
pos = 0x000002C5 = 709 marker = 0xFF 0xDA SOS
pos = 0x000002F6 = 758 marker = 0xFF 0xDA SOS
pos = 0x00000375 = 885 marker = 0xFF 0xD9 EOI
```
Note that this JPEG has multiple `0xFF 0xDA` Start Of Scan markers, but the
`0xFF 0xC0` at position `0x0000009E` denotes a *sequential* JPEG, not a
*progressive* JPEG. It's highly unusual for a non-progressive JPEG to have
multiple scans.
At position `0x000000E3` there are the two bytes `0xFE 0xDA` which is *not* a
Start of Scan (because it's `0xFE`, not `0xFF`). This (continuing up to but
excluding the `0xFF 0xC4` Define Huffman Table marker at position `0x00000100`)
causes the "Corrupt JPEG data: 29 extraneous bytes before marker 0xc4" error
message seen above.
The first recognized `0xFF 0xDA` Start of Scan is actually at position
`0x00000120` and the `0x01` byte at position `0x00000124` means that the *scan*
has only one component. In contrast, the `0x03` byte at position `0x000000A7`
means that the *frame* has three components (the typical Y, Cb, Cr).
Thus, we have a *sequential* JPEG with multiple scans, but also whose first
scan doesn't cover all of the components. Highly, highly unusual, and the cause
of why Wuffs and libjpeg-turbo differ in its output.
Specifically, decoding progressive JPEGs require more memory than decoding
sequential JPEGs, since decoding progressive JPEGs needs somewhere to store 'in
progress' (partially reconstructed) pre-IDCT coefficients. Wuffs-the-language
doesn't allow Wuffs code to allocate memory at arbitrary times. Instead, for
Wuffs image decoding, there is only one point in time where the Wuffs-callee
can advise its caller how much memory it will need for its "work buffer". This
point in time is after the image configuration (width, height, color model,
etc) has been decoded but before actual pixels have been decoded. For the JPEG
file format, "decode the image configuration" corresponds to parsing the `0xFF
0xC0` Start of Frame (Baseline Sequential) marker.
When Wuffs decodes `182.jpg`, the JPEG file's Start Of Frame says "I'm a
*sequential* JPEG", so Wuffs *doesn't* ask its caller for that extra memory.
Even though it turns out that the JPEG file has multiple scans, those scans
*aren't* accumulated (in that non-existent extra memory).
When libjpeg-turbo decodes `182.jpg`, it sees "I'm a *sequential* JPEG" but,
when it also sees that the first scan has incomplete component coverage, it
goes ahead and allocates that extra memory. The multiple scans *are*
accumulated and the final pixel output is different (and more 'detailed').
In theory, it'd be possible to modify Wuffs' JPEG decoder so that "decode the
image configuration" actually peeked ahead to the first scan. But that adds
complexity to the implementation. It's hard to justify that additional cost
just to handle highly, highly unusual JPEGs like the invalid (corrupted)
`182.jpg` differently, especially just to produce different *garbage*.
A final remark: sequential versus progressive JPEGs also differ in how to
handle the Huffman data in each scan. If we modify only 1 byte in
`182.0-original.jpg` to give `182.1-byte-change.jpg`, changing the byte at
position `0x0000009F` from `0xC0` to `0xC2`:
```diff
- 00000090 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ff c0 |cccccccccccccc..|
+ 00000090 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ff c2 |cccccccccccccc..|
```
This changes the JPEG from sequential to progressive. After doing that, Wuffs
and libjpeg-turbo agree *exactly* on what its decoding is (as both ask for and
use that extra memory). It also no longer looks like garbage. It looks like a
kitty!
![Decoding of 1-byte-change](./asset/182.1-byte-change.png)
If we also fix the corruption by changing the `0xFE` to `0xFF` at position
`0x000000E3`, so that we've changed 2 bytes overall, it looks like an even
better kitty (and both decoders still agree).
![Decoding of 2-byte-change](./asset/182.2-byte-change.png)
+189
View File
@@ -0,0 +1,189 @@
# 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
+130
View File
@@ -0,0 +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
@@ -0,0 +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
+1 -1
View File
@@ -157,7 +157,7 @@ f2457b64 test/3pdata/pngsuite/tp0n0g08.png
05846c5f test/3pdata/pngsuite/tp0n2c08.png
3d7708a8 test/3pdata/pngsuite/tp0n3p08.png
46deef3b test/3pdata/pngsuite/tp1n3p08.png
f286cbfc test/3pdata/pngsuite/xcsn0g01.png
926d3aa2 test/3pdata/pngsuite/xcsn0g01.png
9098c4d8 test/3pdata/pngsuite/z00n2c08.png
9098c4d8 test/3pdata/pngsuite/z03n2c08.png
9098c4d8 test/3pdata/pngsuite/z06n2c08.png
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#include "bzlib.h"
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#include "gif_lib.h"
+99
View File
@@ -0,0 +1,99 @@
// 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.
// ----------------
// Uncomment one of these #define lines to test and bench alternative mimic
// libraries (stb_image) instead of libjpeg.
//
// These are collectively referred to as
// WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBJPEG.
//
// #define WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBJPEG 1
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBJPEG
#if defined(WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBJPEG)
#define WUFFS_MIMICLIB_JPEG_DOES_NOT_EXACTLY_MATCH_LIBJPEG 1
#define mimic_jpeg_decode mimic_stb_decode
#include "./stb.c"
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBJPEG
#else
#include "jpeglib.h"
const char* //
mimic_jpeg_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;
}
const char* ret = NULL;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, wuffs_base__io_buffer__reader_pointer(src),
wuffs_base__io_buffer__reader_length(src));
if (jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK) {
ret = "mimic_jpeg_decode: jpeg_read_header failed";
goto cleanup0;
}
switch (pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
cinfo.out_color_space = JCS_GRAYSCALE;
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
cinfo.out_color_space = JCS_EXT_BGRA;
break;
default:
ret = "mimic_jpeg_decode: unsupported pixfmt";
goto cleanup0;
}
jpeg_start_decompress(&cinfo);
size_t stride =
cinfo.output_width *
((size_t)(wuffs_base__pixel_format__bits_per_pixel(&pixfmt) / 8u));
while (cinfo.output_scanline < cinfo.output_height) {
if (wuffs_base__io_buffer__writer_length(dst) < stride) {
ret = "mimic_jpeg_decode: image is too large";
goto cleanup0;
}
JSAMPLE* scanlines[1] = {(void*)wuffs_base__io_buffer__writer_pointer(dst)};
if (jpeg_read_scanlines(&cinfo, scanlines, 1)) {
dst->meta.wi += stride;
if (n_bytes_out) {
*n_bytes_out += stride;
}
}
}
jpeg_finish_decompress(&cinfo);
cleanup0:;
jpeg_destroy_decompress(&cinfo);
return ret;
}
#endif
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBJPEG
+7 -91
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -228,11 +222,6 @@ cleanup0:;
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBPNG
#elif defined(WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBPNG)
// We #include a foo.cpp file, not a foo.h file, as stb_image is a "single file
// C library".
#define STB_IMAGE_IMPLEMENTATION
#include "/path/to/your/copy/of/github.com/nothings/stb/stb_image.h"
// We deliberately do not define the
// WUFFS_MIMICLIB_PNG_DOES_NOT_SUPPORT_QUIRK_IGNORE_CHECKSUM macro. The
// stb_image library always ignores checksums.
@@ -242,81 +231,8 @@ cleanup0:;
// We deliberately do not define the
// WUFFS_MIMICLIB_PNG_DOES_NOT_VERIFY_FINAL_IDAT_CHECKSUMS macro.
const char* //
mimic_png_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;
}
uint64_t n = 0;
bool swap_bgra_rgba = false;
switch (pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
n = 1;
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
n = 4;
// stb_image doesn't do BGRA8. RGBA8 is the closest approximation. We'll
// fix it up later.
swap_bgra_rgba = true;
break;
default:
return "mimic_png_decode: unsupported pixfmt";
}
int width = 0;
int height = 0;
int channels_in_file = 0;
unsigned char* output =
stbi_load_from_memory(wuffs_base__io_buffer__reader_pointer(src), //
wuffs_base__io_buffer__reader_length(src), //
&width, &height, &channels_in_file, n);
if (!output) {
return "mimic_png_decode: could not load image";
}
const char* ret = NULL;
if ((width > 0xFFFF) || (height > 0xFFFF)) {
ret = "mimic_png_decode: image is too large";
goto cleanup0;
}
n *= ((uint64_t)width) * ((uint64_t)height);
if (n > wuffs_base__io_buffer__writer_length(dst)) {
ret = "mimic_png_decode: image is too large";
goto cleanup0;
}
// Copy from the mimic library's output buffer to Wuffs' dst buffer.
uint8_t* dst_ptr = wuffs_base__io_buffer__writer_pointer(dst);
memcpy(dst_ptr, output, n);
dst->meta.wi += n;
if (n_bytes_out) {
*n_bytes_out += n;
}
// Fix up BGRA8 vs RGBA8.
if (swap_bgra_rgba) {
for (; n >= 4; n -= 4) {
uint8_t swap = dst_ptr[0];
dst_ptr[0] = dst_ptr[2];
dst_ptr[2] = swap;
dst_ptr += 4;
}
}
cleanup0:;
stbi_image_free(output);
return ret;
}
#define mimic_png_decode mimic_stb_decode
#include "./stb.c"
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBPNG
#else
+92
View File
@@ -0,0 +1,92 @@
// 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.
// We #include a foo.cpp file, not a foo.h file, as stb_image is a "single file
// C library".
//
// Consider also #define'ing STBI_NO_SIMD.
#define STBI_NO_HDR
#define STBI_NO_LINEAR
#define STB_IMAGE_IMPLEMENTATION
#include "/path/to/your/copy/of/github.com/nothings/stb/stb_image.h"
const char* //
mimic_stb_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;
}
uint64_t n = 0;
bool swap_bgra_rgba = false;
switch (pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
n = 1;
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
n = 4;
// stb_image doesn't do BGRA8. RGBA8 is the closest approximation. We'll
// fix it up later.
swap_bgra_rgba = true;
break;
default:
return "mimic_stb_decode: unsupported pixfmt";
}
int width = 0;
int height = 0;
int channels_in_file = 0;
unsigned char* output =
stbi_load_from_memory(wuffs_base__io_buffer__reader_pointer(src), //
wuffs_base__io_buffer__reader_length(src), //
&width, &height, &channels_in_file, n);
if (!output) {
return "mimic_stb_decode: could not load image";
}
const char* ret = NULL;
if ((width > 0xFFFF) || (height > 0xFFFF)) {
ret = "mimic_stb_decode: image is too large";
goto cleanup0;
}
n *= ((uint64_t)width) * ((uint64_t)height);
if (n > wuffs_base__io_buffer__writer_length(dst)) {
ret = "mimic_stb_decode: image is too large";
goto cleanup0;
}
// Copy from the mimic library's output buffer to Wuffs' dst buffer.
uint8_t* dst_ptr = wuffs_base__io_buffer__writer_pointer(dst);
memcpy(dst_ptr, output, n);
dst->meta.wi += n;
if (n_bytes_out) {
*n_bytes_out += n;
}
// Fix up BGRA8 vs RGBA8.
if (swap_bgra_rgba) {
for (; n >= 4; n -= 4) {
uint8_t swap = dst_ptr[0];
dst_ptr[0] = dst_ptr[2];
dst_ptr[2] = swap;
dst_ptr += 4;
}
}
cleanup0:;
stbi_image_free(output);
return ret;
}
+92
View File
@@ -0,0 +1,92 @@
// 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.
#include "xxhash.h"
uint32_t global_mimiclib_xxhash32_unused_u32;
uint64_t global_mimiclib_xxhash64_unused_u64;
const char* //
mimic_bench_xxhash32(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
XXH32_state_t* hasher = XXH32_createState();
if (!hasher) {
return "libxxhash: XXH32_createState failed";
} else if (XXH_OK != XXH32_reset(hasher, 0)) {
return "libxxhash: XXH32_reset failed";
}
global_mimiclib_xxhash32_unused_u32 = 0;
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 (XXH_OK != XXH32_update(hasher, ptr, len)) {
return "libxxhash: XXH32_update failed";
}
src->meta.ri += len;
}
global_mimiclib_xxhash32_unused_u32 = XXH32_digest(hasher);
if (XXH_OK != XXH32_freeState(hasher)) {
return "libxxhash: XXH32_freeState failed";
}
return NULL;
}
const char* //
mimic_bench_xxhash64(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
XXH64_state_t* hasher = XXH64_createState();
if (!hasher) {
return "libxxhash: XXH64_createState failed";
} else if (XXH_OK != XXH64_reset(hasher, 0)) {
return "libxxhash: XXH64_reset failed";
}
global_mimiclib_xxhash64_unused_u64 = 0;
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 (XXH_OK != XXH64_update(hasher, ptr, len)) {
return "libxxhash: XXH64_update failed";
}
src->meta.ri += len;
}
global_mimiclib_xxhash64_unused_u64 = XXH64_digest(hasher);
if (XXH_OK != XXH64_freeState(hasher)) {
return "libxxhash: XXH64_freeState failed";
}
return NULL;
}
uint32_t //
mimic_xxhash32_one_shot_checksum_u32(wuffs_base__slice_u8 data) {
return XXH32(data.ptr, data.len, 0);
}
uint64_t //
mimic_xxhash64_one_shot_checksum_u64(wuffs_base__slice_u8 data) {
return XXH64(data.ptr, data.len, 0);
}
+7 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -215,7 +209,7 @@ test_wuffs_adler32_pi() {
uint32_t have = wuffs_adler32__hasher__update_u32(
&checksum, ((wuffs_base__slice_u8){
.ptr = (uint8_t*)(digits),
.len = i,
.len = (size_t)(i),
}));
if (have != wants[i]) {
RETURN_FAIL("i=%d: have 0x%08" PRIX32 ", want 0x%08" PRIX32, i, have,
@@ -239,7 +233,7 @@ wuffs_bench_adler32(wuffs_base__io_buffer* dst,
if (rlimit) {
len = wuffs_base__u64__min(len, rlimit);
}
wuffs_adler32__hasher checksum;
wuffs_adler32__hasher checksum = {0};
CHECK_STATUS("initialize", wuffs_adler32__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
wuffs_initialize_flags));
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+9 -15
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -131,7 +125,7 @@ test_wuffs_cbor_decode_invalid() {
// test/data/cbor-rfc-7049-examples.cbor) contain valid examples.
//
// This suite contains invalid examples, which should be rejected.
char* test_cases[] = {
const char* test_cases[] = {
// Truncated (integer; major type 0) value.
"\x18",
// Tag in array, immediately before an 0xFF stop code. Some discussion is
@@ -155,7 +149,7 @@ test_wuffs_cbor_decode_invalid() {
&tok_array[0], WUFFS_TESTLIB_ARRAY_SIZE(tok_array)));
const bool closed = true;
wuffs_base__io_buffer io_buf = wuffs_base__slice_u8__reader(
wuffs_base__make_slice_u8((uint8_t*)(test_cases[tc]),
wuffs_base__make_slice_u8((uint8_t*)(void*)(test_cases[tc]),
strlen(test_cases[tc])),
closed);
@@ -180,7 +174,7 @@ test_wuffs_cbor_decode_valid() {
// This suite contains valid examples, similar to the
// test_wuffs_cbor_decode_invalid examples, but they should be accepted.
char* test_cases[] = {
const char* test_cases[] = {
// Map with 2 elements (an even number).
"\xA1\x01\x02",
// Tag immediately before an empty array.
@@ -196,7 +190,7 @@ test_wuffs_cbor_decode_valid() {
&tok_array[0], WUFFS_TESTLIB_ARRAY_SIZE(tok_array)));
const bool closed = true;
wuffs_base__io_buffer io_buf = wuffs_base__slice_u8__reader(
wuffs_base__make_slice_u8((uint8_t*)(test_cases[tc]),
wuffs_base__make_slice_u8((uint8_t*)(void*)(test_cases[tc]),
strlen(test_cases[tc])),
closed);
+7 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -208,7 +202,7 @@ do_test_xxxxx_crc32_ieee_pi(bool mimic) {
uint32_t have;
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
.ptr = (uint8_t*)(digits),
.len = i,
.len = (size_t)(i),
});
if (mimic) {
@@ -276,7 +270,7 @@ wuffs_bench_crc32_ieee(wuffs_base__io_buffer* dst,
if (rlimit) {
len = wuffs_base__u64__min(len, rlimit);
}
wuffs_crc32__ieee_hasher checksum;
wuffs_crc32__ieee_hasher checksum = {0};
CHECK_STATUS("initialize", wuffs_crc32__ieee_hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
wuffs_initialize_flags));
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+23 -49
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -57,7 +51,6 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
@@ -148,25 +141,6 @@ test_basic_status_is_error() {
return NULL;
}
const char* //
test_basic_sub_struct_initializer() {
CHECK_FOCUS(__func__);
wuffs_gif__decoder dec;
CHECK_STATUS("initialize",
wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
if (dec.private_impl.magic != WUFFS_BASE__MAGIC) {
RETURN_FAIL("outer magic: have %" PRIu32 ", want %" PRIu32 "",
dec.private_impl.magic, WUFFS_BASE__MAGIC);
}
if (dec.private_data.f_lzw.private_impl.magic != WUFFS_BASE__MAGIC) {
RETURN_FAIL("inner magic: have %" PRIu32 ", want %" PRIu32,
dec.private_data.f_lzw.private_impl.magic, WUFFS_BASE__MAGIC);
}
return NULL;
}
// ---------------- GIF Tests
const char* //
@@ -469,7 +443,7 @@ do_test_wuffs_gif_decode_expecting(wuffs_base__io_buffer src,
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
if (quirk) {
wuffs_gif__decoder__set_quirk_enabled(&dec, quirk, true);
wuffs_gif__decoder__set_quirk(&dec, quirk, 1);
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
@@ -720,8 +694,8 @@ test_wuffs_gif_decode_delay_num_frames_decoded() {
wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES, q);
wuffs_gif__decoder__set_quirk(&dec,
WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES, q);
while (true) {
wuffs_base__status status =
@@ -756,8 +730,8 @@ test_wuffs_gif_decode_empty_palette() {
wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE, q);
wuffs_gif__decoder__set_quirk(&dec, WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE,
q);
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__status status =
@@ -822,8 +796,8 @@ test_wuffs_gif_decode_background_color() {
wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR, q);
wuffs_gif__decoder__set_quirk(&dec, WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR,
q);
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__status status =
@@ -860,8 +834,8 @@ test_wuffs_gif_decode_first_frame_is_opaque() {
wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR, q);
wuffs_gif__decoder__set_quirk(&dec, WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR,
q);
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__status status =
@@ -897,8 +871,8 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT, q);
wuffs_gif__decoder__set_quirk(&dec,
WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT, q);
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__status status =
@@ -1072,13 +1046,13 @@ test_wuffs_gif_decode_zero_width_frame() {
break;
case 1:
want = NULL;
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, true);
wuffs_gif__decoder__set_quirk(
&dec, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, 1);
break;
case 2:
want = wuffs_gif__error__bad_frame_size;
wuffs_gif__decoder__set_quirk_enabled(
&dec, WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME, true);
wuffs_gif__decoder__set_quirk(&dec, WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME,
1);
break;
}
@@ -1373,7 +1347,8 @@ do_test_wuffs_gif_decode_metadata(bool full) {
}
wuffs_base__range_ie_u64 r =
wuffs_base__more_information__metadata__range(&minfo);
wuffs_base__more_information__metadata_raw_passthrough__range(
&minfo);
uint64_t n = wuffs_base__range_ie_u64__length(&r);
if ((n > 100) || (n + have_length > 100)) {
RETURN_FAIL(
@@ -1636,7 +1611,7 @@ test_wuffs_gif_decode_pixel_data_too_much_sans_quirk() {
CHECK_STRING(read_file(
&src, "test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif"));
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
src, 0, wuffs_lzw__error__bad_code, false));
src, 0, wuffs_gif__error__bad_lzw_code, false));
src.meta = wuffs_base__empty_io_buffer_meta();
CHECK_STRING(read_file(
@@ -2350,7 +2325,6 @@ proc g_tests[] = {
test_basic_bad_wuffs_version,
test_basic_initialize_not_called,
test_basic_status_is_error,
test_basic_sub_struct_initializer,
test_wuffs_gif_call_interleaved,
test_wuffs_gif_call_sequence,
+7 -13
View File
@@ -1,16 +1,10 @@
// Copyright 2018 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -183,8 +177,8 @@ do_test_wuffs_gzip_checksum(bool ignore_checksum, uint32_t bad_checksum) {
wuffs_gzip__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_gzip__decoder__set_quirk_enabled(
&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, ignore_checksum);
wuffs_gzip__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
(uint64_t)ignore_checksum);
have.meta.wi = 0;
src.meta.ri = 0;
+1033
View File
@@ -0,0 +1,1033 @@
// 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.
// ----------------
/*
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 jpeg.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 -ljpeg
// 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__JPEG
// 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/jpeg.c"
#endif
// ---------------- JPEG Tests
const char* //
wuffs_jpeg_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_jpeg__decoder dec;
CHECK_STATUS("initialize",
wuffs_jpeg__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
wuffs_initialize_flags));
return do_run__wuffs_base__image_decoder(
wuffs_jpeg__decoder__upcast_as__wuffs_base__image_decoder(&dec),
n_bytes_out, dst, pixfmt, quirks_ptr, quirks_len, src);
}
const char* //
test_wuffs_jpeg_decode_interface() {
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));
return 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);
}
const char* //
test_wuffs_jpeg_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_jpeg__decoder dec;
CHECK_STATUS("initialize",
wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_jpeg__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_jpeg__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_jpeg__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_jpeg__error__truncated_input);
}
return NULL;
}
const char* //
do_test_wuffs_jpeg_decode_dht(wuffs_base__io_buffer* src,
const uint32_t arg_bits,
const uint32_t arg_n_bits,
const int32_t* want_dst_ptr,
const size_t want_dst_len,
const uint8_t (*want_symbols)[256],
const uint32_t (*want_slow)[16],
const uint16_t (*want_fast)[256]) {
wuffs_jpeg__decoder dec;
memset(&dec, 0xAB, sizeof dec); // 0xAB is arbitrary, non-zero junk.
CHECK_STATUS("initialize",
wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
// Decode that DHT payload.
if (wuffs_base__io_buffer__reader_length(src) <= 0) {
return "empty src";
}
uint32_t tc4_th = ((src->data.ptr[src->meta.ri] >> 2) & 0x04) |
((src->data.ptr[src->meta.ri] >> 0) & 0x03);
dec.private_impl.f_sof_marker = 0xC0;
dec.private_impl.f_payload_length =
((uint32_t)(wuffs_base__io_buffer__reader_length(src)));
CHECK_STATUS("decode_dht", wuffs_jpeg__decoder__decode_dht(&dec, src));
if (memcmp(dec.private_impl.f_huff_tables_symbols[tc4_th], want_symbols,
sizeof(*want_symbols))) {
RETURN_FAIL("unexpected huff_tables_symbols");
} else if (memcmp(dec.private_impl.f_huff_tables_slow[tc4_th], want_slow,
sizeof(*want_slow))) {
RETURN_FAIL("unexpected huff_tables_slow");
} else if (memcmp(dec.private_impl.f_huff_tables_fast[tc4_th], want_fast,
sizeof(*want_fast))) {
RETURN_FAIL("unexpected huff_tables_fast");
}
const int32_t err_not_enough_bits = -1;
const int32_t err_fast_not_applicable = -2;
const int32_t err_invalid_code = -3;
// Check decoding of (arg_bits, arg_n_bits).
for (int use_fast = 0; use_fast < 2; use_fast++) {
uint32_t bits = arg_bits;
uint32_t n_bits = arg_n_bits;
for (size_t i = 0; i < want_dst_len; i++) {
int have = err_fast_not_applicable;
if (use_fast) {
uint16_t x = (*want_fast)[bits >> 24];
uint32_t n = x >> 8;
if (x == 0xFFFF) {
have = err_fast_not_applicable;
} else if (n > n_bits) {
have = err_not_enough_bits;
} else {
bits <<= n;
n_bits -= n;
have = x & 0xFF;
}
}
if (have == err_fast_not_applicable) {
uint32_t code = 0;
for (uint32_t j = 0; true; j++) {
if (n_bits <= 0) {
have = err_not_enough_bits;
break;
} else if (j >= 16) {
have = err_invalid_code;
break;
}
code = (code << 1) | (bits >> 31);
bits <<= 1;
n_bits -= 1;
uint32_t x = (*want_slow)[j];
if (code < (x >> 8)) {
have = (*want_symbols)[(code + x) & 0xFF];
break;
}
}
}
if (have != want_dst_ptr[i]) {
RETURN_FAIL("output symbols: use_fast=%d, i=%zu: have %d, want %d",
use_fast, i, have, want_dst_ptr[i]);
}
}
}
return NULL;
}
const char* //
test_wuffs_jpeg_decode_dht_easy() {
CHECK_FOCUS(__func__);
const uint8_t want_symbols[256] = {
6, 7, 4, 5, 0, 3, 8, 9, 2, 1, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
};
// Set src to this fragment of "hd test/data/bricks-color.jpeg".
// 000000b0 .. ff c4 00 1d 00 00 02 02 03 01 01 01 00 00 00
// 000000c0 00 00 00 00 00 00 06 07 04 05 00 03 08 09 02 01
// The "ff c4" is the DHT marker. The "00 1d" is the payload length. The
// remaining payload has 0x001D - 2 = 0x1B = 17 + 10 bytes.
g_src_array_u8[0x00] = 0x00; // (tc, th) selectors are (0, 0).
g_src_array_u8[0x01] = 0x00; // 0 codes of bit_length 1.
g_src_array_u8[0x02] = 0x02; // 2 codes of bit_length 2.
g_src_array_u8[0x03] = 0x02; // 2 codes of bit_length 3.
g_src_array_u8[0x04] = 0x03; // 3 codes of bit_length 4.
g_src_array_u8[0x05] = 0x01; // 1 codes of bit_length 5.
g_src_array_u8[0x06] = 0x01; // 1 codes of bit_length 6.
g_src_array_u8[0x07] = 0x01; // 1 codes of bit_length 7.
g_src_array_u8[0x08] = 0x00; // 0 codes of bit_length 8.
g_src_array_u8[0x09] = 0x00; // 0 codes of bit_length 9.
g_src_array_u8[0x0A] = 0x00; // etc.
g_src_array_u8[0x0B] = 0x00;
g_src_array_u8[0x0C] = 0x00;
g_src_array_u8[0x0D] = 0x00;
g_src_array_u8[0x0E] = 0x00;
g_src_array_u8[0x0F] = 0x00;
g_src_array_u8[0x10] = 0x00; // 0 codes of bit-length 16. 10 codes total.
g_src_array_u8[0x11] = want_symbols[0]; // The 1st symbol is 0x06.
g_src_array_u8[0x12] = want_symbols[1]; // The 2nd symbol is 0x07.
g_src_array_u8[0x13] = want_symbols[2]; // The 3rd symbol is 0x04.
g_src_array_u8[0x14] = want_symbols[3]; // etc.
g_src_array_u8[0x15] = want_symbols[4];
g_src_array_u8[0x16] = want_symbols[5];
g_src_array_u8[0x17] = want_symbols[6];
g_src_array_u8[0x18] = want_symbols[7];
g_src_array_u8[0x19] = want_symbols[8];
g_src_array_u8[0x1A] = want_symbols[9];
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0x1B, false);
// The Huffman codes are:
// 0b00...... bit_length=2 symbol=6
// 0b01...... bit_length=2 symbol=7
// 0b100..... bit_length=3 symbol=4
// 0b101..... bit_length=3 symbol=5
// 0b1100.... bit_length=4 symbol=0
// 0b1101.... bit_length=4 symbol=3
// 0b1110.... bit_length=4 symbol=8
// 0b11110... bit_length=5 symbol=9
// 0b111110.. bit_length=6 symbol=2
// 0b1111110. bit_length=7 symbol=1
// 0b1111111. invalid
// Running this on "wxyz" input should give these symbols:
// 0x77 'w' 0x78 'x' 0x79 'y' 0x7A 'z'
// 0b0111_0111 0b0111_1000 0b0111_1001 0b0111_1010
// 01 1101 1101 1110 00 01 1110 01 01 1110 10
// s7 s3 s3 s8 s6 s7 s8 s7 s7 s8 err_not_enough_bits
const uint32_t bits = 0x7778797A;
const uint32_t n_bits = 32;
const int32_t want_dst_ptr[11] = {7, 3, 3, 8, 6, 7, 8, 7, 7, 8, -1};
const size_t want_dst_len = 11;
const uint32_t want_slow[16] = {
0x00000000, 0x00000200, 0x000006FE, 0x00000FF8, //
0x00001FE9, 0x00003FCA, 0x00007F8B, 0x00000000, //
0x00000000, 0x00000000, 0x00000000, 0x00000000, //
0x00000000, 0x00000000, 0x00000000, 0x00000000, //
};
const uint16_t want_fast[256] = {
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, 0x0206, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, 0x0207, //
0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, //
0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, //
0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, //
0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, 0x0304, //
0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, //
0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, //
0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, //
0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, 0x0305, //
0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, //
0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, //
0x0403, 0x0403, 0x0403, 0x0403, 0x0403, 0x0403, 0x0403, 0x0403, //
0x0403, 0x0403, 0x0403, 0x0403, 0x0403, 0x0403, 0x0403, 0x0403, //
0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, //
0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, //
0x0509, 0x0509, 0x0509, 0x0509, 0x0509, 0x0509, 0x0509, 0x0509, //
0x0602, 0x0602, 0x0602, 0x0602, 0x0701, 0x0701, 0xFFFF, 0xFFFF, //
};
return do_test_wuffs_jpeg_decode_dht(&src, bits, n_bits, want_dst_ptr,
want_dst_len, &want_symbols, &want_slow,
&want_fast);
}
const char* //
test_wuffs_jpeg_decode_dht_hard() {
CHECK_FOCUS(__func__);
const uint8_t want_symbols[256] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x11, 0x00, 0x06, //
0x07, 0x12, 0x21, 0x31, 0x13, 0x41, 0x51, 0x08, //
0x14, 0x22, 0x61, 0x71, 0x32, 0x42, 0x81, 0x91, //
0xA1, 0xB1, 0x15, 0x23, 0x52, 0x33, 0x82, 0xC1, //
0xD1, 0xF0, 0x16, 0x62, 0x72, 0x92, 0xC2, 0xE1, //
0x17, 0x53, 0x63, 0xA2, 0xA4, 0xB2, 0xF1, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
};
// Set src to this fragment of "hd test/data/bricks-color.jpeg".
// 000000d0 ff c4 00 42 10 00 02 01 03 02 04 03 05 06 03 05
// 000000e0 06 07 00 00 00 01 02 03 04 05 11 00 06 07 12 21
// 000000f0 31 13 41 51 08 14 22 61 71 32 42 81 91 a1 b1 15
// 00000100 23 52 33 82 c1 d1 f0 16 62 72 92 c2 e1 17 53 63
// 00000110 a2 a4 b2 f1 .. .. .. .. .. .. .. .. .. .. .. ..
// The "ff c4" is the DHT marker. The "00 42" is the payload length. The
// remaining payload has 0x0042 - 2 = 0x40 = 17 + 47 bytes.
g_src_array_u8[0x00] = 0x10; // (tc, th) selectors are (1, 0).
g_src_array_u8[0x01] = 0x00; // 0 codes of bit_length 1.
g_src_array_u8[0x02] = 0x02; // 2 codes of bit_length 2.
g_src_array_u8[0x03] = 0x01; // 1 codes of bit_length 3.
g_src_array_u8[0x04] = 0x03; // 3 codes of bit_length 4.
g_src_array_u8[0x05] = 0x02; // 2 codes of bit_length 5.
g_src_array_u8[0x06] = 0x04; // 4 codes of bit_length 6.
g_src_array_u8[0x07] = 0x03; // 3 codes of bit_length 7.
g_src_array_u8[0x08] = 0x05; // 5 codes of bit_length 8.
g_src_array_u8[0x09] = 0x06; // 6 codes of bit_length 9.
g_src_array_u8[0x0A] = 0x03; // etc.
g_src_array_u8[0x0B] = 0x05;
g_src_array_u8[0x0C] = 0x06;
g_src_array_u8[0x0D] = 0x07;
g_src_array_u8[0x0E] = 0x00;
g_src_array_u8[0x0F] = 0x00;
g_src_array_u8[0x10] = 0x00; // 0 codes of bit-length 16. 47 codes total.
memcpy(&g_src_array_u8[0x11], want_symbols, 47);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0x40, false);
// The Huffman codes are:
// 0b00......_........ bit_length=0x02 symbol=0x01
// 0b01......_........ bit_length=0x02 symbol=0x02
// 0b100....._........ bit_length=0x03 symbol=0x03
// 0b1010...._........ bit_length=0x04 symbol=0x04
// 0b1011...._........ bit_length=0x04 symbol=0x05
// 0b1100...._........ bit_length=0x04 symbol=0x11
// 0b11010..._........ bit_length=0x05 symbol=0x00
// 0b11011..._........ bit_length=0x05 symbol=0x06
// 0b111000.._........ bit_length=0x06 symbol=0x07
// 0b111001.._........ bit_length=0x06 symbol=0x12
// 0b111010.._........ bit_length=0x06 symbol=0x21
// 0b111011.._........ bit_length=0x06 symbol=0x31
// 0b1111000._........ bit_length=0x07 symbol=0x13
// 0b1111001._........ bit_length=0x07 symbol=0x41
// 0b1111010._........ bit_length=0x07 symbol=0x51
// 0b11110110_........ bit_length=0x08 symbol=0x08
// 0b11110111_........ bit_length=0x08 symbol=0x14
// 0b11111000_........ bit_length=0x08 symbol=0x22
// 0b11111001_........ bit_length=0x08 symbol=0x61
// 0b11111010_........ bit_length=0x08 symbol=0x71
// 0b11111011_0....... bit_length=0x09 symbol=0x32
// 0b11111011_1....... bit_length=0x09 symbol=0x42
// 0b11111100_0....... bit_length=0x09 symbol=0x81
// 0b11111100_1....... bit_length=0x09 symbol=0x91
// 0b11111101_0....... bit_length=0x09 symbol=0xA1
// 0b11111101_1....... bit_length=0x09 symbol=0xB1
// 0b11111110_00...... bit_length=0x0A symbol=0x15
// 0b11111110_01...... bit_length=0x0A symbol=0x23
// 0b11111110_10...... bit_length=0x0A symbol=0x52
// 0b11111110_110..... bit_length=0x0B symbol=0x33
// 0b11111110_111..... bit_length=0x0B symbol=0x82
// 0b11111111_000..... bit_length=0x0B symbol=0xC1
// 0b11111111_001..... bit_length=0x0B symbol=0xD1
// 0b11111111_010..... bit_length=0x0B symbol=0xF0
// 0b11111111_0110.... bit_length=0x0C symbol=0x16
// 0b11111111_0111.... bit_length=0x0C symbol=0x62
// 0b11111111_1000.... bit_length=0x0C symbol=0x72
// 0b11111111_1001.... bit_length=0x0C symbol=0x92
// 0b11111111_1010.... bit_length=0x0C symbol=0xC2
// 0b11111111_1011.... bit_length=0x0C symbol=0xE1
// 0b11111111_11000... bit_length=0x0D symbol=0x17
// 0b11111111_11001... bit_length=0x0D symbol=0x53
// 0b11111111_11010... bit_length=0x0D symbol=0x63
// 0b11111111_11011... bit_length=0x0D symbol=0xA2
// 0b11111111_11100... bit_length=0x0D symbol=0xA4
// 0b11111111_11101... bit_length=0x0D symbol=0xB2
// 0b11111111_11110... bit_length=0x0D symbol=0xF1
// 0b11111111_11111... invalid
// Running this on "wx\x7Fh" input should give these symbols:
// 0x77 'w' 0x78 'x' 0x7F '\x7F' 0x68 'h'
// 0b0111_0111 0b0111_1000 0b0111_1111 0b0110_1000
// 01 11011 1011 1100 00 11111110110 100 0
// s2 s6 s5 s11 s1 s33 s3 err_not_enough_bits
const uint32_t bits = 0x77787F68;
const uint32_t n_bits = 32;
const int32_t want_dst_ptr[8] = {0x02, 0x06, 0x05, 0x11,
0x01, 0x33, 0x03, -1};
const size_t want_dst_len = 8;
const uint32_t want_slow[16] = {
0x00000000, 0x00000200, 0x000005FE, 0x00000DF9, //
0x00001CEC, 0x00003CD0, 0x00007B94, 0x0000FB19, //
0x0001FC1E, 0x0003FB22, 0x0007FB27, 0x000FFC2C, //
0x001FFF30, 0x00000000, 0x00000000, 0x00000000, //
};
const uint16_t want_fast[256] = {
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, 0x0201, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, //
0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, //
0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, //
0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, //
0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, //
0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, //
0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, //
0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, //
0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, //
0x0411, 0x0411, 0x0411, 0x0411, 0x0411, 0x0411, 0x0411, 0x0411, //
0x0411, 0x0411, 0x0411, 0x0411, 0x0411, 0x0411, 0x0411, 0x0411, //
0x0500, 0x0500, 0x0500, 0x0500, 0x0500, 0x0500, 0x0500, 0x0500, //
0x0506, 0x0506, 0x0506, 0x0506, 0x0506, 0x0506, 0x0506, 0x0506, //
0x0607, 0x0607, 0x0607, 0x0607, 0x0612, 0x0612, 0x0612, 0x0612, //
0x0621, 0x0621, 0x0621, 0x0621, 0x0631, 0x0631, 0x0631, 0x0631, //
0x0713, 0x0713, 0x0741, 0x0741, 0x0751, 0x0751, 0x0808, 0x0814, //
0x0822, 0x0861, 0x0871, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, //
};
return do_test_wuffs_jpeg_decode_dht(&src, bits, n_bits, want_dst_ptr,
want_dst_len, &want_symbols, &want_slow,
&want_fast);
}
const char* //
test_wuffs_jpeg_decode_idct() {
CHECK_FOCUS(__func__);
// This is "test/data/bricks-color.jpeg"'s first MCU's first block, in
// natural (not zig-zag) order.
const uint16_t mcu_block[64] = {
0xFFC9, 0xFFD8, 0x0014, 0xFFF7, 0x0002, 0x0000, 0x0000, 0x0000, //
0x006A, 0xFFE3, 0x001C, 0xFFF9, 0x0002, 0x0000, 0x0000, 0x0000, //
0x0015, 0x0002, 0x0002, 0xFFFE, 0x0001, 0x0000, 0x0000, 0x0001, //
0x000D, 0xFFEC, 0x0005, 0xFFFE, 0x0000, 0x0000, 0x0000, 0x0000, //
0xFFFA, 0xFFFA, 0x0002, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0xFFFD, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
};
// This is "test/data/bricks-color.jpeg"'s first quantization table, in
// natural (not zig-zag) order.
const uint16_t quant_table[64] = {
0x03, 0x02, 0x02, 0x03, 0x04, 0x06, 0x08, 0x0A, //
0x02, 0x02, 0x02, 0x03, 0x04, 0x09, 0x0A, 0x09, //
0x02, 0x02, 0x03, 0x04, 0x06, 0x09, 0x0B, 0x09, //
0x02, 0x03, 0x04, 0x05, 0x08, 0x0E, 0x0D, 0x0A, //
0x03, 0x04, 0x06, 0x09, 0x0B, 0x11, 0x10, 0x0C, //
0x04, 0x06, 0x09, 0x0A, 0x0D, 0x11, 0x12, 0x0F, //
0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x13, 0x13, 0x10, //
0x0C, 0x0F, 0x0F, 0x10, 0x12, 0x10, 0x10, 0x10, //
};
// This is the IDCT's expected result (including dequantization), again in
// natural (not zig-zag) order.
const uint8_t want_array[64] = {
0x81, 0x7E, 0x82, 0x7E, 0x82, 0x92, 0xC5, 0xF2, //
0x81, 0x80, 0x84, 0x85, 0x85, 0x88, 0x9D, 0xB2, //
0x86, 0x81, 0x7A, 0x77, 0x72, 0x75, 0x7E, 0x8A, //
0x54, 0x58, 0x58, 0x5E, 0x5E, 0x6C, 0x79, 0x87, //
0x4D, 0x54, 0x56, 0x5B, 0x59, 0x65, 0x6E, 0x7A, //
0x4A, 0x4D, 0x4F, 0x53, 0x56, 0x5F, 0x67, 0x6E, //
0x4A, 0x4D, 0x54, 0x58, 0x5B, 0x58, 0x56, 0x54, //
0x4C, 0x4C, 0x52, 0x4F, 0x4D, 0x40, 0x3A, 0x35, //
};
for (int f = 0; f < 2; f++) {
wuffs_jpeg__decoder dec;
CHECK_STATUS("initialize", wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
memcpy(&dec.private_data.f_mcu_blocks[0], mcu_block, sizeof(mcu_block));
const uint32_t q = 0;
memcpy(&dec.private_impl.f_quant_tables[q], quant_table,
sizeof(quant_table));
const char* func_name = NULL;
wuffs_base__empty_struct (*func)(
wuffs_jpeg__decoder * self, wuffs_base__slice_u8 a_dst_buffer,
uint64_t a_dst_stride, uint32_t a_q) = NULL;
if (f == 0) {
func_name = "choosy_default";
func = &wuffs_jpeg__decoder__decode_idct__choosy_default;
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
} else if (wuffs_base__cpu_arch__have_x86_avx2()) {
func_name = "x86_avx2";
func = &wuffs_jpeg__decoder__decode_idct_x86_avx2;
#endif
}
if (!func) {
continue;
}
uint8_t dst_array[64] = {0};
(*func)(&dec, wuffs_base__make_slice_u8(&dst_array[0], 64), 8, q);
wuffs_base__io_buffer have =
wuffs_base__ptr_u8__reader(&dst_array[0], 64, true);
wuffs_base__io_buffer want =
wuffs_base__ptr_u8__reader((uint8_t*)(&want_array[0]), 64, true);
char prefix[256];
snprintf(prefix, 256, "f=%d (%s): ", f, func_name);
CHECK_STRING(check_io_buffers_equal(prefix, &have, &want));
}
return NULL;
}
const char* //
test_wuffs_jpeg_decode_mcu() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/bricks-color.jpeg"));
wuffs_jpeg__decoder dec;
CHECK_STATUS("initialize", wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
// Bypass the "#missing Quantization table" check.
dec.private_impl.f_seen_dqt[0] = true;
dec.private_impl.f_seen_dqt[1] = true;
// Decode the 0xC0 SOF marker, four 0xC4 DHT markers and 0xDA SOS marker. The
// SOS marker is only partially processed, since complete SOS processing
// would call wuffs_jpeg__decoder__decode_mcu multiple times.
const uint32_t marker_positions[6] = //
{0x09E, 0x0B1, 0x0D0, 0x114, 0x133, 0x16E};
for (int i = 0; i < WUFFS_TESTLIB_ARRAY_SIZE(marker_positions); i++) {
uint8_t want_marker = (i <= 0) ? 0xC0 : ((i <= 4) ? 0xC4 : 0xDA);
src.meta.ri = marker_positions[i];
if ((src.meta.ri + 4) > src.meta.wi) {
RETURN_FAIL("seek #%d: past EOF", i);
} else if (src.data.ptr[src.meta.ri++] != 0xFF) {
RETURN_FAIL("seek #%d: have 0x%02X, want 0x%02X", i,
src.data.ptr[src.meta.ri - 1], 0xFF);
} else if (src.data.ptr[src.meta.ri++] != want_marker) {
RETURN_FAIL("seek #%d: have 0x%02X, want 0x%02X", i,
src.data.ptr[src.meta.ri - 1], want_marker);
}
dec.private_impl.f_payload_length = 0;
dec.private_impl.f_payload_length |= src.data.ptr[src.meta.ri++];
dec.private_impl.f_payload_length <<= 8;
dec.private_impl.f_payload_length |= src.data.ptr[src.meta.ri++];
dec.private_impl.f_payload_length -= 2;
if (i <= 0) {
dec.private_impl.f_sof_marker = 0xC0;
CHECK_STATUS("decode_sof", wuffs_jpeg__decoder__decode_sof(&dec, &src));
} else if (i <= 4) {
CHECK_STATUS("decode_dht", wuffs_jpeg__decoder__decode_dht(&dec, &src));
} else {
CHECK_STATUS("prepare_scan",
wuffs_jpeg__decoder__prepare_scan(&dec, &src));
wuffs_jpeg__decoder__fill_bitstream(&dec, &src);
}
}
// 4:2:0 chroma subsampling means that the MCU has 4 Y, 1 Cb and 1 Cr blocks.
uint16_t wants[6][64] = {
{
0xFFC9, 0xFFD8, 0x0014, 0xFFF7, 0x0002, 0x0000, 0x0000, 0x0000, //
0x006A, 0xFFE3, 0x001C, 0xFFF9, 0x0002, 0x0000, 0x0000, 0x0000, //
0x0015, 0x0002, 0x0002, 0xFFFE, 0x0001, 0x0000, 0x0000, 0x0001, //
0x000D, 0xFFEC, 0x0005, 0xFFFE, 0x0000, 0x0000, 0x0000, 0x0000, //
0xFFFA, 0xFFFA, 0x0002, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0xFFFD, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
},
{
0xFFAA, 0x0070, 0x003A, 0xFFE0, 0xFFF9, 0x0004, 0x0000, 0x0001, //
0x004F, 0x005E, 0x0022, 0x0006, 0xFFF3, 0xFFFD, 0x0004, 0x0000, //
0xFFF4, 0xFFE8, 0x0002, 0x0012, 0x0003, 0x0000, 0xFFFF, 0x0002, //
0xFFEC, 0xFFF3, 0x000A, 0x000A, 0x0007, 0x0000, 0xFFFF, 0xFFFF, //
0xFFF3, 0xFFFB, 0xFFFD, 0x0002, 0x0002, 0x0000, 0x0001, 0x0000, //
0xFFFC, 0xFFFB, 0xFFFD, 0xFFFF, 0x0000, 0x0002, 0x0001, 0x0001, //
0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0001, 0x0001, 0x0001, //
0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0001, 0x0000, //
},
{
0xFF25, 0x000D, 0x0003, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, //
0x000E, 0x0006, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0005, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0004, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
},
{
0xFF59, 0xFFD6, 0xFFCF, 0x000C, 0x0006, 0xFFFE, 0xFFFE, 0x0002, //
0xFFF3, 0x0013, 0x000C, 0xFFE6, 0x000E, 0x0001, 0xFFFC, 0x0004, //
0x0010, 0xFFF1, 0x0005, 0x0003, 0xFFFA, 0x0002, 0x0001, 0xFFFE, //
0xFFF9, 0x0005, 0x0000, 0xFFFE, 0x0002, 0x0000, 0xFFFE, 0x0002, //
0x0003, 0xFFFF, 0x0000, 0x0001, 0xFFFF, 0x0000, 0x0001, 0xFFFF, //
0xFFFE, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
},
{
0x0077, 0x000F, 0xFFFA, 0x0001, 0x0000, 0xFFFF, 0x0002, 0xFFFF, //
0xFFFA, 0x0020, 0xFFF9, 0x0000, 0x0000, 0xFFFF, 0x0001, 0xFFFF, //
0xFFFA, 0x0008, 0x0000, 0x0000, 0xFFFF, 0x0001, 0x0000, 0x0000, //
0xFFFE, 0x0001, 0x0001, 0x0001, 0xFFFF, 0x0001, 0xFFFF, 0x0000, //
0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
},
{
0xFF88, 0x0003, 0xFFFD, 0x0000, 0x0000, 0x0000, 0xFFFF, 0x0001, //
0xFFE4, 0xFFEC, 0x0001, 0x0001, 0x0000, 0x0001, 0xFFFF, 0x0001, //
0xFFFC, 0xFFFC, 0xFFFE, 0x0000, 0x0001, 0xFFFF, 0x0000, 0x0000, //
0x0001, 0xFFFF, 0xFFFF, 0x0000, 0x0001, 0xFFFF, 0x0000, 0x0000, //
0x0000, 0x0000, 0xFFFE, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, //
},
};
// Decode and compare-to-golden the first MCU (Minimum Coded Unit).
dec.private_impl.f_test_only_interrupt_decode_mcu = true;
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)) {
RETURN_FAIL("decode_mcu failed");
}
wuffs_base__io_buffer have = wuffs_base__ptr_u8__reader( //
(uint8_t*)(void*)(&dec.private_data.f_mcu_blocks[0]), //
sizeof(dec.private_data.f_mcu_blocks[0]), true);
wuffs_base__io_buffer want = wuffs_base__ptr_u8__reader( //
(uint8_t*)(void*)(&wants[b]), //
sizeof(wants[b]), true);
char prefix[64];
snprintf(prefix, 64, "b=%d: ", b);
CHECK_STRING(check_io_buffers_equal(prefix, &have, &want));
}
return NULL;
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
const char* //
do_test_mimic_jpeg_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_jpeg_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_jpeg_decode(
NULL, &want, WUFFS_INITIALIZE__DEFAULT_OPTIONS,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, &src));
#ifdef WUFFS_MIMICLIB_JPEG_DOES_NOT_EXACTLY_MATCH_LIBJPEG
if (have.meta.wi != want.meta.wi) {
RETURN_FAIL("decoded image size (in bytes): have %zu, want %zu.\n",
have.meta.wi, want.meta.wi);
}
return NULL;
#else
return check_io_buffers_equal("", &have, &want);
#endif // WUFFS_MIMICLIB_JPEG_DOES_NOT_EXACTLY_MATCH_LIBJPEG
}
const char* //
test_mimic_jpeg_decode_19k_8bpp() {
CHECK_FOCUS(__func__);
return do_test_mimic_jpeg_decode("test/data/bricks-gray.jpeg");
}
const char* //
test_mimic_jpeg_decode_30k_24bpp_progressive() {
CHECK_FOCUS(__func__);
return do_test_mimic_jpeg_decode("test/data/peacock.progressive.jpeg");
}
const char* //
test_mimic_jpeg_decode_30k_24bpp_sequential() {
CHECK_FOCUS(__func__);
return do_test_mimic_jpeg_decode("test/data/peacock.default.jpeg");
}
const char* //
test_mimic_jpeg_decode_552k_24bpp_420() {
CHECK_FOCUS(__func__);
return do_test_mimic_jpeg_decode("test/data/hibiscus.regular.jpeg");
}
const char* //
test_mimic_jpeg_decode_552k_24bpp_444() {
CHECK_FOCUS(__func__);
return do_test_mimic_jpeg_decode("test/data/hibiscus.primitive.jpeg");
}
#endif // WUFFS_MIMIC
// ---------------- JPEG Benches
const char* //
bench_wuffs_jpeg_decode_19k_8bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__Y), NULL, 0,
"test/data/bricks-gray.jpeg", 0, SIZE_MAX, 100);
}
const char* //
bench_wuffs_jpeg_decode_30k_24bpp_progressive() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/peacock.progressive.jpeg", 0, SIZE_MAX, 50);
}
const char* //
bench_wuffs_jpeg_decode_30k_24bpp_sequential() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/peacock.default.jpeg", 0, SIZE_MAX, 50);
}
const char* //
bench_wuffs_jpeg_decode_77k_24bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/bricks-color.jpeg", 0, SIZE_MAX, 30);
}
const char* //
bench_wuffs_jpeg_decode_552k_24bpp_420() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/hibiscus.regular.jpeg", 0, SIZE_MAX, 5);
}
const char* //
bench_wuffs_jpeg_decode_552k_24bpp_444() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/hibiscus.primitive.jpeg", 0, SIZE_MAX, 5);
}
const char* //
bench_wuffs_jpeg_decode_4002k_24bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/harvesters.jpeg", 0, SIZE_MAX, 1);
}
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
const char* //
bench_mimic_jpeg_decode_19k_8bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&mimic_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__Y), NULL, 0,
"test/data/bricks-gray.jpeg", 0, SIZE_MAX, 100);
}
const char* //
bench_mimic_jpeg_decode_30k_24bpp_progressive() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&mimic_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/peacock.progressive.jpeg", 0, SIZE_MAX, 50);
}
const char* //
bench_mimic_jpeg_decode_30k_24bpp_sequential() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&mimic_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/peacock.default.jpeg", 0, SIZE_MAX, 50);
}
const char* //
bench_mimic_jpeg_decode_77k_24bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&mimic_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/bricks-color.jpeg", 0, SIZE_MAX, 30);
}
const char* //
bench_mimic_jpeg_decode_552k_24bpp_420() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&mimic_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/hibiscus.regular.jpeg", 0, SIZE_MAX, 5);
}
const char* //
bench_mimic_jpeg_decode_552k_24bpp_444() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&mimic_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/hibiscus.primitive.jpeg", 0, SIZE_MAX, 5);
}
const char* //
bench_mimic_jpeg_decode_4002k_24bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&mimic_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/harvesters.jpeg", 0, SIZE_MAX, 1);
}
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_jpeg_decode_dht_easy,
test_wuffs_jpeg_decode_dht_hard,
test_wuffs_jpeg_decode_idct,
test_wuffs_jpeg_decode_mcu,
test_wuffs_jpeg_decode_interface,
test_wuffs_jpeg_decode_truncated_input,
#ifdef WUFFS_MIMIC
test_mimic_jpeg_decode_19k_8bpp,
test_mimic_jpeg_decode_30k_24bpp_progressive,
test_mimic_jpeg_decode_30k_24bpp_sequential,
test_mimic_jpeg_decode_552k_24bpp_420,
test_mimic_jpeg_decode_552k_24bpp_444,
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
bench_wuffs_jpeg_decode_19k_8bpp,
bench_wuffs_jpeg_decode_30k_24bpp_progressive,
bench_wuffs_jpeg_decode_30k_24bpp_sequential,
bench_wuffs_jpeg_decode_77k_24bpp,
bench_wuffs_jpeg_decode_552k_24bpp_420,
bench_wuffs_jpeg_decode_552k_24bpp_444,
bench_wuffs_jpeg_decode_4002k_24bpp,
#ifdef WUFFS_MIMIC
bench_mimic_jpeg_decode_19k_8bpp,
bench_mimic_jpeg_decode_30k_24bpp_progressive,
bench_mimic_jpeg_decode_30k_24bpp_sequential,
bench_mimic_jpeg_decode_77k_24bpp,
bench_mimic_jpeg_decode_552k_24bpp_420,
bench_mimic_jpeg_decode_552k_24bpp_444,
bench_mimic_jpeg_decode_4002k_24bpp,
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/jpeg";
return test_main(argc, argv, g_tests, g_benches);
}
+82 -78
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -343,10 +337,11 @@ 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;
CHECK_STATUS("hpd__parse",
CHECK_STATUS(
"hpd__parse",
wuffs_base__private_implementation__high_prec_dec__parse(
&hpd,
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
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 =
@@ -388,10 +383,11 @@ 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;
CHECK_STATUS("hpd__parse",
CHECK_STATUS(
"hpd__parse",
wuffs_base__private_implementation__high_prec_dec__parse(
&hpd,
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
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;
@@ -408,7 +404,7 @@ test_wuffs_strconv_hpd_shift() {
wuffs_base__private_implementation__high_prec_dec__to_debug_string(
&hpd,
wuffs_base__make_slice_u8(have, WUFFS_TESTLIB_ARRAY_SIZE(have))));
if (strcmp(((void*)(have)), test_cases[tc].want)) {
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) ? ">>" : "<<"),
((shift > 0) ? +shift : -shift), have, test_cases[tc].want);
@@ -672,7 +668,7 @@ test_wuffs_strconv_base_16() {
const char* str = "6A6b7"; // The "7" should cause "#base: bad data".
wuffs_base__slice_u8 dst = g_have_slice_u8;
wuffs_base__slice_u8 src =
wuffs_base__make_slice_u8((void*)str, strlen(str));
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str));
wuffs_base__transform__output have = wuffs_base__base_16__decode2(
dst, src, src_closed, WUFFS_BASE__BASE_16__DEFAULT_OPTIONS);
if (have.status.repr != wuffs_base__error__bad_data) {
@@ -699,7 +695,7 @@ test_wuffs_strconv_base_16() {
const char* str = "\\xa9\\x00\\xFe";
wuffs_base__slice_u8 dst = g_have_slice_u8;
wuffs_base__slice_u8 src =
wuffs_base__make_slice_u8((void*)str, strlen(str));
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str));
wuffs_base__transform__output have = wuffs_base__base_16__decode4(
dst, src, src_closed, WUFFS_BASE__BASE_16__DEFAULT_OPTIONS);
if (have.status.repr) {
@@ -732,7 +728,7 @@ const char* //
test_wuffs_strconv_base_64() {
CHECK_FOCUS(__func__);
char* foobar = "foobar";
const char* foobar = "foobar";
const char* wants[] = {
"", //
"Zg==", //
@@ -747,8 +743,9 @@ test_wuffs_strconv_base_64() {
const bool src_closed = true;
wuffs_base__transform__output e = wuffs_base__base_64__encode(
g_have_slice_u8, wuffs_base__make_slice_u8(((uint8_t*)foobar), tc),
src_closed, WUFFS_BASE__BASE_64__ENCODE_EMIT_PADDING);
g_have_slice_u8,
wuffs_base__make_slice_u8(((uint8_t*)(void*)foobar), tc), src_closed,
WUFFS_BASE__BASE_64__ENCODE_EMIT_PADDING);
if (e.status.repr) {
RETURN_FAIL("tc=%zu: encode: \"%s\"", tc, e.status.repr);
}
@@ -824,7 +821,7 @@ test_wuffs_strconv_parse_number_f64_options() {
for (int o = 0; o < 2; o++) {
const char* str = "001.25";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str)),
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
@@ -854,7 +851,7 @@ test_wuffs_strconv_parse_number_f64_options() {
for (int o = 0; o < 2; o++) {
const char* str = "_1.2__5";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str)),
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
@@ -883,7 +880,7 @@ test_wuffs_strconv_parse_number_f64_options() {
for (int o = 0; o < 2; o++) {
const char* str = "1,75";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str)),
(o ? WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
@@ -913,7 +910,7 @@ test_wuffs_strconv_parse_number_f64_options() {
for (int o = 0; o < 4; o++) {
const char* str = (o & 2) ? "1e999" : "nan";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str)),
((o & 1) ? WUFFS_BASE__PARSE_NUMBER_FXX__REJECT_INF_AND_NAN
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
@@ -1077,7 +1074,7 @@ test_wuffs_strconv_parse_number_f64_regular() {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
wuffs_base__make_slice_u8((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str)),
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES);
uint64_t have =
@@ -1112,7 +1109,7 @@ test_wuffs_strconv_parse_number_i64() {
{.want = -0x0000000000000002, .str = "-2"},
{.want = -0x00000000000000AB, .str = "_-_0x_AB"},
{.want = -0x7FFFFFFFFFFFFFFF, .str = "-9223372036854775807"},
{.want = -0x8000000000000000, .str = "-9223372036854775808"},
{.want = (int64_t)(-0x8000000000000000), .str = "-9223372036854775808"},
{.want = fail, .str = "+ 1"},
{.want = fail, .str = "++1"},
@@ -1129,7 +1126,7 @@ test_wuffs_strconv_parse_number_i64() {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__result_i64 r = wuffs_base__parse_number_i64(
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
wuffs_base__make_slice_u8((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str)),
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES);
int64_t have = (r.status.repr == NULL) ? r.value : fail;
@@ -1215,7 +1212,7 @@ test_wuffs_strconv_parse_number_u64() {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
wuffs_base__make_slice_u8((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str)),
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES);
uint64_t have = (r.status.repr == NULL) ? r.value : fail;
@@ -1230,7 +1227,7 @@ test_wuffs_strconv_parse_number_u64() {
for (int o = 0; o < 2; o++) {
const char* str = "007";
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str)),
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
@@ -1258,7 +1255,7 @@ test_wuffs_strconv_parse_number_u64() {
for (int o = 0; o < 2; o++) {
const char* str = "56_7__8";
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str)),
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
@@ -2251,7 +2248,7 @@ test_wuffs_strconv_render_number_i64() {
{.x = -0x0000000100000000ll, .want = "-4294967296"},
{.x = -0x0123456789ABCDEFll, .want = "-81985529216486895"},
{.x = -0x7FFFFFFFFFFFFFFFll, .want = "-9223372036854775807"},
{.x = -0x8000000000000000ll, .want = "-9223372036854775808"},
{.x = (int64_t)(-0x8000000000000000ll), .want = "-9223372036854775808"},
};
if (g_have_slice_u8.len < WUFFS_BASE__I64__BYTE_LENGTH__MAX_INCL) {
@@ -2461,7 +2458,7 @@ test_wuffs_strconv_utf_8_next() {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__slice_u8 s = wuffs_base__make_slice_u8(
(void*)test_cases[tc].str, strlen(test_cases[tc].str));
(uint8_t*)(void*)test_cases[tc].str, strlen(test_cases[tc].str));
// Override "The <NUL> byte" with "\x00".
if (test_cases[tc].want0 == 0x01000000) {
s = wuffs_base__make_slice_u8(&the_nul_byte[0], 1);
@@ -2583,7 +2580,7 @@ test_wuffs_json_decode_interface() {
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
for (size_t i = 0; quirks[i]; i++) {
wuffs_json__decoder__set_quirk_enabled(&dec, quirks[i], true);
wuffs_json__decoder__set_quirk(&dec, quirks[i], 1);
}
CHECK_STRING(do_test__wuffs_base__token_decoder(
wuffs_json__decoder__upcast_as__wuffs_base__token_decoder(&dec),
@@ -2886,7 +2883,7 @@ test_wuffs_json_decode_prior_valid_utf_8() {
size_t num_preceding = 0;
while (num_preceding < n) {
wuffs_base__utf_8__next__output x = wuffs_base__utf_8__next(
(void*)(test_cases[tc]) + num_preceding, n - num_preceding);
(uint8_t*)(void*)(test_cases[tc]) + num_preceding, n - num_preceding);
if (!wuffs_base__utf_8__next__output__is_valid(&x) ||
(x.code_point < 0x20) || (x.code_point == '\\')) {
break;
@@ -3024,12 +3021,13 @@ test_wuffs_json_decode_quirk_allow_backslash_etc() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(&dec, test_cases[tc].quirk, q);
wuffs_json__decoder__set_quirk(&dec, test_cases[tc].quirk, q);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str), true);
const char* have_status_repr =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
@@ -3106,13 +3104,13 @@ test_wuffs_json_decode_quirk_allow_backslash_x() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS, true);
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS, 1);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__slice_u8 src_slice = wuffs_base__make_slice_u8(
(void*)(test_cases[tc].str), strlen(test_cases[tc].str));
(uint8_t*)(void*)(test_cases[tc].str), strlen(test_cases[tc].str));
wuffs_base__io_buffer src = wuffs_base__slice_u8__reader(src_slice, true);
const char* have_status_repr =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
@@ -3184,13 +3182,14 @@ test_wuffs_json_decode_quirk_allow_extra_comma() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA, q & 1);
wuffs_json__decoder__set_quirk(&dec, WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA,
q & 1);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str), true);
const char* have =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
.repr;
@@ -3257,13 +3256,14 @@ test_wuffs_json_decode_quirk_allow_inf_nan_numbers() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS, q & 1);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str), true);
const char* have =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
.repr;
@@ -3324,15 +3324,16 @@ test_wuffs_json_decode_quirk_allow_comment_etc() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, q & 1);
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, q & 2);
wuffs_json__decoder__set_quirk(&dec, WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE,
q & 2);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str), true);
const char* have =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
.repr;
@@ -3399,15 +3400,16 @@ test_wuffs_json_decode_quirk_allow_leading_etc() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR, q & 1);
wuffs_json__decoder__set_quirk_enabled(
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK, q & 2);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str), true);
const char* have =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
.repr;
@@ -3495,17 +3497,17 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(tc_ptr, tc_len, true);
wuffs_base__ptr_u8__reader((uint8_t*)tc_ptr, tc_len, true);
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK, true);
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE, true);
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER, true);
wuffs_json__decoder__set_quirk(&dec, WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK,
1);
wuffs_json__decoder__set_quirk(&dec, WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE,
1);
wuffs_json__decoder__set_quirk(&dec,
WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER, 1);
const char* have_repr =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
@@ -3539,13 +3541,13 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(tc_ptr, tc_len, true);
wuffs_base__ptr_u8__reader((uint8_t*)tc_ptr, tc_len, true);
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF, true);
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF, 1);
const char* have_repr =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
@@ -3612,15 +3614,16 @@ test_wuffs_json_decode_quirk_allow_trailing_filler() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER, q & 1);
wuffs_json__decoder__set_quirk_enabled(
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF, q & 2);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader((uint8_t*)(void*)test_cases[tc].str,
strlen(test_cases[tc].str), true);
const char* have =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
.repr;
@@ -3709,14 +3712,14 @@ test_wuffs_json_decode_quirk_replace_invalid_unicode() {
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE, true);
wuffs_json__decoder__set_quirk(
&dec, WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE, 1);
wuffs_base__io_buffer have = wuffs_base__slice_u8__writer(g_have_slice_u8);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
(uint8_t*)(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
CHECK_STATUS("decode_tokens", wuffs_json__decoder__decode_tokens(
&dec, &tok, &src, g_work_slice_u8));
@@ -3847,7 +3850,7 @@ test_wuffs_json_decode_unicode4_escapes() {
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
(uint8_t*)(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8);
uint32_t have = fail;
@@ -3924,7 +3927,7 @@ test_wuffs_json_decode_src_io_buffer_length() {
wuffs_base__slice_u8 src_data = ((wuffs_base__slice_u8){
.ptr = &src_array[0],
.len = i,
.len = (size_t)(i),
});
int closed;
@@ -4034,7 +4037,7 @@ test_wuffs_json_decode_string() {
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(
(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
(uint8_t*)(void*)test_cases[tc].str, strlen(test_cases[tc].str), true);
wuffs_base__status have_status =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8);
@@ -4072,7 +4075,8 @@ test_wuffs_json_decode_string() {
const char* //
do_bench_wuffs_strconv_parse_number_f64(const char* str,
uint64_t iters_unscaled) {
wuffs_base__slice_u8 s = wuffs_base__make_slice_u8((void*)str, strlen(str));
wuffs_base__slice_u8 s =
wuffs_base__make_slice_u8((uint8_t*)(void*)str, strlen(str));
bench_start();
uint64_t iters = iters_unscaled * g_flags.iterscale;
+13 -15
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -149,7 +143,8 @@ do_test_wuffs_lzw_decode(const char* src_filename,
wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_lzw__decoder__set_literal_width(&dec, literal_width);
wuffs_lzw__decoder__set_quirk(&dec, WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE,
literal_width + 1);
int num_iters = 0;
while (true) {
num_iters++;
@@ -267,7 +262,8 @@ test_wuffs_lzw_decode_output_bad() {
wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_lzw__decoder__set_literal_width(&dec, 7);
wuffs_lzw__decoder__set_quirk(&dec, WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE,
7 + 1);
wuffs_base__status status =
wuffs_lzw__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
@@ -310,7 +306,8 @@ test_wuffs_lzw_decode_output_empty() {
wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_lzw__decoder__set_literal_width(&dec, 8);
wuffs_lzw__decoder__set_quirk(&dec, WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE,
8 + 1);
CHECK_STATUS("transform_io", wuffs_lzw__decoder__transform_io(
&dec, &have, &src, g_work_slice_u8));
@@ -333,7 +330,8 @@ do_test_wuffs_lzw_decode_width(uint32_t width,
wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_lzw__decoder__set_literal_width(&dec, width);
wuffs_lzw__decoder__set_quirk(&dec, WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE,
width + 1);
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
.data = g_have_slice_u8,
+220
View File
@@ -0,0 +1,220 @@
// 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.
// ----------------
/*
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 netpbm.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__NETPBM
// 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
// ---------------- Netpbm Tests
const char* //
test_wuffs_netpbm_decode_interface() {
CHECK_FOCUS(__func__);
wuffs_netpbm__decoder dec;
CHECK_STATUS("initialize",
wuffs_netpbm__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_netpbm__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/hippopotamus.ppm", 0, SIZE_MAX, 36, 28, 0xFFF5F5F5);
}
const char* //
test_wuffs_netpbm_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_netpbm__decoder dec;
CHECK_STATUS("initialize",
wuffs_netpbm__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_netpbm__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_netpbm__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_netpbm__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_netpbm__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_netpbm_decode_frame_config() {
CHECK_FOCUS(__func__);
wuffs_netpbm__decoder dec;
CHECK_STATUS("initialize",
wuffs_netpbm__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/hippopotamus.pgm"));
CHECK_STATUS("decode_frame_config #0",
wuffs_netpbm__decoder__decode_frame_config(&dec, &fc, &src));
wuffs_base__status status =
wuffs_netpbm__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;
}
const char* //
test_wuffs_netpbm_decode_image_config() {
CHECK_FOCUS(__func__);
wuffs_netpbm__decoder dec;
CHECK_STATUS("initialize",
wuffs_netpbm__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/hippopotamus.pgm"));
CHECK_STATUS("decode_image_config",
wuffs_netpbm__decoder__decode_image_config(&dec, &ic, &src));
uint32_t have_width = wuffs_base__pixel_config__width(&ic.pixcfg);
uint32_t want_width = 36;
if (have_width != want_width) {
RETURN_FAIL("width: have %" PRIu32 ", want %" PRIu32, have_width,
want_width);
}
uint32_t have_height = wuffs_base__pixel_config__height(&ic.pixcfg);
uint32_t want_height = 28;
if (have_height != want_height) {
RETURN_FAIL("height: have %" PRIu32 ", want %" PRIu32, have_height,
want_height);
}
return NULL;
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
// ---------------- Netpbm Benches
// No Netpbm benches.
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_netpbm_decode_frame_config,
test_wuffs_netpbm_decode_image_config,
test_wuffs_netpbm_decode_interface,
test_wuffs_netpbm_decode_truncated_input,
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
// No Netpbm benches.
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/netpbm";
return test_main(argc, argv, g_tests, g_benches);
}
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+5 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2022 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
+138 -11
View File
@@ -1,16 +1,10 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -114,6 +108,97 @@ colors_differ(wuffs_base__color_u32_argb_premul color0,
return false;
}
const char* //
test_wuffs_color_ycc_as_color_u32() {
CHECK_FOCUS(__func__);
struct {
uint8_t yy;
uint8_t cb;
uint8_t cr;
wuffs_base__color_u32_argb_premul want;
} test_cases[] = {
{0x00, 0x00, 0x00, 0xFF008700}, //
{0x00, 0x00, 0x55, 0xFF004B00}, //
{0x00, 0x00, 0xAA, 0xFF3B0E00}, //
{0x00, 0x00, 0xFF, 0xFFB20000}, //
{0x00, 0x55, 0x00, 0xFF006A00}, //
{0x00, 0x55, 0x55, 0xFF002E00}, //
{0x00, 0x55, 0xAA, 0xFF3B0000}, //
{0x00, 0x55, 0xFF, 0xFFB20000}, //
{0x00, 0xAA, 0x00, 0xFF004D4A}, //
{0x00, 0xAA, 0x55, 0xFF00104A}, //
{0x00, 0xAA, 0xAA, 0xFF3B004A}, //
{0x00, 0xAA, 0xFF, 0xFFB2004A}, //
{0x00, 0xFF, 0x00, 0xFF0030E1}, //
{0x00, 0xFF, 0x55, 0xFF0000E1}, //
{0x00, 0xFF, 0xAA, 0xFF3B00E1}, //
{0x00, 0xFF, 0xFF, 0xFFB200E1}, //
{0x55, 0x00, 0x00, 0xFF00DC00}, //
{0x55, 0x00, 0x55, 0xFF19A000}, //
{0x55, 0x00, 0xAA, 0xFF906300}, //
{0x55, 0x00, 0xFF, 0xFFFF2600}, //
{0x55, 0x55, 0x00, 0xFF00BF09}, //
{0x55, 0x55, 0x55, 0xFF198309}, //
{0x55, 0x55, 0xAA, 0xFF904609}, //
{0x55, 0x55, 0xFF, 0xFFFF0909}, //
{0x55, 0xAA, 0x00, 0xFF00A29F}, //
{0x55, 0xAA, 0x55, 0xFF19659F}, //
{0x55, 0xAA, 0xAA, 0xFF90299F}, //
{0x55, 0xAA, 0xFF, 0xFFFF009F}, //
{0x55, 0xFF, 0x00, 0xFF0085FF}, //
{0x55, 0xFF, 0x55, 0xFF1948FF}, //
{0x55, 0xFF, 0xAA, 0xFF900BFF}, //
{0x55, 0xFF, 0xFF, 0xFFFF00FF}, //
{0xAA, 0x00, 0x00, 0xFF00FF00}, //
{0xAA, 0x00, 0x55, 0xFF6EF500}, //
{0xAA, 0x00, 0xAA, 0xFFE5B800}, //
{0xAA, 0x00, 0xFF, 0xFFFF7B00}, //
{0xAA, 0x55, 0x00, 0xFF00FF5E}, //
{0xAA, 0x55, 0x55, 0xFF6ED85E}, //
{0xAA, 0x55, 0xAA, 0xFFE59B5E}, //
{0xAA, 0x55, 0xFF, 0xFFFF5E5E}, //
{0xAA, 0xAA, 0x00, 0xFF00F7F4}, //
{0xAA, 0xAA, 0x55, 0xFF6EBAF4}, //
{0xAA, 0xAA, 0xAA, 0xFFE57EF4}, //
{0xAA, 0xAA, 0xFF, 0xFFFF41F4}, //
{0xAA, 0xFF, 0x00, 0xFF00DAFF}, //
{0xAA, 0xFF, 0x55, 0xFF6E9DFF}, //
{0xAA, 0xFF, 0xAA, 0xFFE560FF}, //
{0xAA, 0xFF, 0xFF, 0xFFFF24FF}, //
{0xFF, 0x00, 0x00, 0xFF4CFF1C}, //
{0xFF, 0x00, 0x55, 0xFFC3FF1C}, //
{0xFF, 0x00, 0xAA, 0xFFFFFF1C}, //
{0xFF, 0x00, 0xFF, 0xFFFFD01C}, //
{0xFF, 0x55, 0x00, 0xFF4CFFB3}, //
{0xFF, 0x55, 0x55, 0xFFC3FFB3}, //
{0xFF, 0x55, 0xAA, 0xFFFFF0B3}, //
{0xFF, 0x55, 0xFF, 0xFFFFB3B3}, //
{0xFF, 0xAA, 0x00, 0xFF4CFFFF}, //
{0xFF, 0xAA, 0x55, 0xFFC3FFFF}, //
{0xFF, 0xAA, 0xAA, 0xFFFFD3FF}, //
{0xFF, 0xAA, 0xFF, 0xFFFF96FF}, //
{0xFF, 0xFF, 0x00, 0xFF4CFFFF}, //
{0xFF, 0xFF, 0x55, 0xFFC3F2FF}, //
{0xFF, 0xFF, 0xAA, 0xFFFFB5FF}, //
{0xFF, 0xFF, 0xFF, 0xFFFF79FF}, //
};
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__color_u32_argb_premul have =
wuffs_base__color_ycc__as__color_u32(
test_cases[tc].yy, test_cases[tc].cb, test_cases[tc].cr);
if (have != test_cases[tc].want) {
RETURN_FAIL(
"wuffs_base__color_ycc__as__color_u32(0x%02X, 0x%02X, 0x%02X): have "
"0x%08" PRIX32 ", want 0x%08" PRIX32,
(int)test_cases[tc].yy, (int)test_cases[tc].cb,
(int)test_cases[tc].cr, have, test_cases[tc].want);
}
}
return NULL;
}
const char* //
test_wuffs_pixel_buffer_fill_rect() {
CHECK_FOCUS(__func__);
@@ -303,6 +388,10 @@ test_wuffs_pixel_swizzler_swizzle() {
.color = 0x80000040,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL,
},
{
.color = 0xFF002233,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__RGB,
},
{
.color = 0x33002233,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL,
@@ -421,6 +510,42 @@ test_wuffs_pixel_swizzler_swizzle() {
return NULL;
}
const char* //
test_wuffs_upsample_inv_h2v1() {
CHECK_FOCUS(__func__);
// src_array0 is "A lovely example".
const uint8_t src_array0[16] = {
0x41, 0x20, 0x6C, 0x6F, 0x76, 0x65, 0x6C, 0x79, //
0x20, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, //
};
const uint8_t want_array[32] = {
// A box filter (nearest neighbor) would look like this:
// 0x41, 0x41, 0x20, 0x20, 0x6C, 0x6C, 0x6F, 0x6F,
// 0x76, 0x76, 0x65, 0x65, 0x6C, 0x6C, 0x79, 0x79,
// 0x20, 0x20, 0x65, 0x65, 0x78, 0x78, 0x61, 0x61,
// 0x6D, 0x6D, 0x70, 0x70, 0x6C, 0x6C, 0x65, 0x65,
// We use a triangle filter instead, matching libjpeg-turbo.
0x41, 0x39, 0x28, 0x33, 0x59, 0x6D, 0x6E, 0x71, //
0x74, 0x72, 0x69, 0x67, 0x6A, 0x6F, 0x76, 0x63, //
0x36, 0x31, 0x54, 0x6A, 0x73, 0x72, 0x67, 0x64, //
0x6A, 0x6E, 0x6F, 0x6F, 0x6D, 0x6A, 0x67, 0x65, //
};
const uint8_t* have_ptr =
wuffs_base__pixel_swizzler__swizzle_ycc__upsample_inv_h2v1_triangle(
g_have_array_u8, src_array0, src_array0, 16, 0, true, true);
const bool closed = true;
wuffs_base__io_buffer have = wuffs_base__ptr_u8__reader( //
(uint8_t*)(void*)have_ptr, 32, closed);
wuffs_base__io_buffer want = wuffs_base__ptr_u8__reader( //
(uint8_t*)(void*)want_array, 32, closed);
return check_io_buffers_equal("", &have, &want);
}
// ---------------- WBMP Tests
const char* //
@@ -675,8 +800,10 @@ proc g_tests[] = {
// These pixel_buffer / pixel_swizzler tests are really testing the Wuffs
// base library. They aren't specific to the std/wbmp code, but putting
// them here is as good as any other place.
test_wuffs_color_ycc_as_color_u32,
test_wuffs_pixel_buffer_fill_rect,
test_wuffs_pixel_swizzler_swizzle,
test_wuffs_upsample_inv_h2v1,
test_wuffs_wbmp_decode_frame_config,
test_wuffs_wbmp_decode_image_config,
+350
View File
@@ -0,0 +1,350 @@
// 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.
// ----------------
/*
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 xxhash32.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 -lxxhash
// 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__XXHASH32
// 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/xxhash.c"
#endif
// ---------------- Golden Tests
golden_test g_xxhash32_midsummer_gt = {
.src_filename = "test/data/midsummer.txt",
};
golden_test g_xxhash32_pi_gt = {
.src_filename = "test/data/pi.txt",
};
// ---------------- XXHash32 Tests
const char* //
test_wuffs_xxhash32_interface() {
CHECK_FOCUS(__func__);
wuffs_xxhash32__hasher h;
CHECK_STATUS("initialize",
wuffs_xxhash32__hasher__initialize(
&h, sizeof h, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__hasher_u32(
wuffs_xxhash32__hasher__upcast_as__wuffs_base__hasher_u32(&h),
"test/data/hat.lossy.webp", 0, SIZE_MAX, 0x1A54B53D);
}
const char* //
test_wuffs_xxhash32_golden() {
CHECK_FOCUS(__func__);
struct {
const char* filename;
// The want values are determined by script/checksum.go.
uint32_t want;
} test_cases[] = {
{
.filename = "test/data/hat.bmp",
.want = 0xCAD975D7,
},
{
.filename = "test/data/hat.gif",
.want = 0x27633229,
},
{
.filename = "test/data/hat.jpeg",
.want = 0xEEF96C12,
},
{
.filename = "test/data/hat.lossless.webp",
.want = 0xA731CF6A,
},
{
.filename = "test/data/hat.lossy.webp",
.want = 0x1A54B53D,
},
{
.filename = "test/data/hat.png",
.want = 0x2EF9D842,
},
{
.filename = "test/data/hat.tiff",
.want = 0x244C2A7F,
},
};
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_xxhash32__hasher checksum;
CHECK_STATUS("initialize",
wuffs_xxhash32__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
uint32_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_xxhash32__hasher__update_u32(&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%08" PRIX32
", want 0x%08" PRIX32 "\n",
tc, j, test_cases[tc].filename, have, test_cases[tc].want);
}
}
}
return NULL;
}
const char* //
do_test_xxxxx_xxhash32_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[i] is the checksum of the first i bytes of the digits string.
uint32_t wants[100] = {
0x02CC5D05, 0x9CEC73C4, 0x8882F465, 0x76EB9891, 0x65EE94C3, 0x1D582EB0,
0x3F23315C, 0xF7876132, 0x5C7905AB, 0xB13CFCB0, 0x249A3696, 0x8DFDDDDE,
0x074C32E3, 0x01832398, 0x342CC9FD, 0x27DAF5DF, 0xA724DADF, 0x82C243CD,
0x058657E3, 0x7702E9E9, 0x0BB1F08C, 0x8663CF29, 0x9EE80972, 0x8072A394,
0x896E216F, 0x2BA14621, 0xC8F505C1, 0xA1E25C52, 0x3775542D, 0x7A89E5C6,
0xACD02748, 0x6C4406C8, 0x260382A6, 0x6AD6D4BD, 0xB3CC8788, 0xF8DCB125,
0xA5BBCDFB, 0x82CC4E8C, 0xCDF34B78, 0xD8D22CCE, 0x64C57168, 0xA8DE94FF,
0x9DD2BAA1, 0x9D44B437, 0x5A136E82, 0x1907E88D, 0x80F7AA44, 0x1DC870E6,
0xD300C657, 0xC6F80CA0, 0xECA7845A, 0xEA33A5CA, 0x6113E405, 0x8D952878,
0x08853159, 0x83AD2241, 0x0B776C22, 0x17B74D73, 0x0A5503C1, 0x4BB9F48F,
0xA044A6F2, 0xC7BD90E6, 0x23B9D53F, 0x512A214F, 0xDA5BF238, 0xCE112793,
0xD6833E33, 0x28911D30, 0x588E359B, 0xC161984D, 0xD87050E1, 0xDBF9126A,
0x676E7A0D, 0xEA6AAC3D, 0x5392F46E, 0xC3851030, 0x3714254B, 0x7136006D,
0xD7683690, 0xDA681B6E, 0x6AE5712A, 0x30CB24D5, 0x9D760EA6, 0x5B0020E6,
0xDC118CC1, 0xFC764944, 0x27163F53, 0x91DFA8D9, 0x2D3B63BA, 0x3790770D,
0x9012C9F0, 0xF0F5377B, 0x624B4744, 0xF376E821, 0x8900258A, 0x5E01F292,
0xE77B80AE, 0x335F4A44, 0x40374C75, 0x7E7BD839,
};
for (int i = 0; i < 100; i++) {
uint32_t have = 0;
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
.ptr = (uint8_t*)(digits),
.len = (size_t)(i),
});
if (mimic) {
#ifdef WUFFS_MIMIC
have = mimic_xxhash32_one_shot_checksum_u32(data);
#endif // WUFFS_MIMIC
} else {
wuffs_xxhash32__hasher checksum;
CHECK_STATUS("initialize",
wuffs_xxhash32__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
have = wuffs_xxhash32__hasher__update_u32(&checksum, data);
}
if (have != wants[i]) {
RETURN_FAIL("i=%d: have 0x%08" PRIX32 ", want 0x%08" PRIX32, i, have,
wants[i]);
}
}
return NULL;
}
const char* //
test_wuffs_xxhash32_pi() {
CHECK_FOCUS(__func__);
return do_test_xxxxx_xxhash32_pi(false);
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
const char* //
test_mimic_xxhash32_pi() {
CHECK_FOCUS(__func__);
return do_test_xxxxx_xxhash32_pi(true);
}
#endif // WUFFS_MIMIC
// ---------------- XXHash32 Benches
uint32_t g_wuffs_xxhash32_unused_u32;
const char* //
wuffs_bench_xxhash32(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_xxhash32__hasher checksum = {0};
CHECK_STATUS("initialize", wuffs_xxhash32__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
wuffs_initialize_flags));
g_wuffs_xxhash32_unused_u32 = wuffs_xxhash32__hasher__update_u32(
&checksum, ((wuffs_base__slice_u8){
.ptr = src->data.ptr + src->meta.ri,
.len = len,
}));
src->meta.ri += len;
return NULL;
}
const char* //
bench_wuffs_xxhash32_10k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(
wuffs_bench_xxhash32,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
&g_xxhash32_midsummer_gt, UINT64_MAX, UINT64_MAX, 5000);
}
const char* //
bench_wuffs_xxhash32_100k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(
wuffs_bench_xxhash32,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
&g_xxhash32_pi_gt, UINT64_MAX, UINT64_MAX, 500);
}
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
const char* //
bench_mimic_xxhash32_10k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(mimic_bench_xxhash32, 0, tcounter_src,
&g_xxhash32_midsummer_gt, UINT64_MAX, UINT64_MAX,
5000);
}
const char* //
bench_mimic_xxhash32_100k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(mimic_bench_xxhash32, 0, tcounter_src,
&g_xxhash32_pi_gt, UINT64_MAX, UINT64_MAX, 500);
}
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_xxhash32_golden,
test_wuffs_xxhash32_interface,
test_wuffs_xxhash32_pi,
#ifdef WUFFS_MIMIC
test_mimic_xxhash32_pi,
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
bench_wuffs_xxhash32_10k,
bench_wuffs_xxhash32_100k,
#ifdef WUFFS_MIMIC
bench_mimic_xxhash32_10k,
bench_mimic_xxhash32_100k,
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/xxhash32";
return test_main(argc, argv, g_tests, g_benches);
}
+367
View File
@@ -0,0 +1,367 @@
// 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.
// ----------------
/*
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 xxhash64.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 -lxxhash
// 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__XXHASH64
// 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/xxhash.c"
#endif
// ---------------- Golden Tests
golden_test g_xxhash64_midsummer_gt = {
.src_filename = "test/data/midsummer.txt",
};
golden_test g_xxhash64_pi_gt = {
.src_filename = "test/data/pi.txt",
};
// ---------------- XXHash64 Tests
const char* //
test_wuffs_xxhash64_interface() {
CHECK_FOCUS(__func__);
wuffs_xxhash64__hasher h;
CHECK_STATUS("initialize",
wuffs_xxhash64__hasher__initialize(
&h, sizeof h, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__hasher_u64(
wuffs_xxhash64__hasher__upcast_as__wuffs_base__hasher_u64(&h),
"test/data/hat.lossy.webp", 0, SIZE_MAX, 0x85D813707FE352B7);
}
const char* //
test_wuffs_xxhash64_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 = 0xA7D576E6A9BAF900,
},
{
.filename = "test/data/hat.gif",
.want = 0x38E8A7CAFE15E5B8,
},
{
.filename = "test/data/hat.jpeg",
.want = 0x6B8E028CE8CC09AD,
},
{
.filename = "test/data/hat.lossless.webp",
.want = 0xCA571B25E75792DA,
},
{
.filename = "test/data/hat.lossy.webp",
.want = 0x85D813707FE352B7,
},
{
.filename = "test/data/hat.png",
.want = 0x6096D53175D9C0B5,
},
{
.filename = "test/data/hat.tiff",
.want = 0x2B7A9E69AEB07DD1,
},
};
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_xxhash64__hasher checksum;
CHECK_STATUS("initialize",
wuffs_xxhash64__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_xxhash64__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_xxhash64_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[i] is the checksum of the first i bytes of the digits string.
uint64_t wants[100] = {
0xEF46DB3751D8E999, 0x26167C2AF5162CA4, 0x05BEDEA4D7DD3935,
0x765F8073D4013B31, 0x3E160875545B6BE3, 0x0BC5FB5031C01569,
0x7F4E574C0FE47F1B, 0xFD47EAC9931E5611, 0x9ECF69693F684A04,
0x71C02736251798B6, 0x6C21272990F120AC, 0xE4727A188A905D0A,
0x259CE02196F0FB6C, 0x5E34060EB8B01C23, 0xD13DA3CBF5A601C2,
0xF127AEAAA3C7373B, 0xDB620698899E4B6D, 0x6E478EE5FA6DD2E9,
0x1AE794F2917D2E95, 0x276ADD06C59EC853, 0x491CE0EDFE9825B0,
0x6E74453240292289, 0x22B769287778C836, 0xBF35609B690EC521,
0x33C6958E166EF7FB, 0xB68BFC69363BA321, 0xF80FA8B7954AEBFA,
0x0BF5ACA4705A6293, 0x0556B78D45BCAAF2, 0xEE2CEF405184E046,
0x73227D21D75B5FE8, 0xD0DF37F5BDB842D2, 0x28EE2A083406DB5A,
0x374E44E23156B38C, 0x2337A79B3AE153E7, 0xF584A7417BA286F4,
0x5E3C84336022F4D8, 0x59399EA49A971651, 0x2B320610ADC6F17F,
0xC36EBC282E7312C2, 0x1C81100B2FE75440, 0x1372BAA075FFF382,
0xE8937E82A1F75179, 0xBAC1E93B15E462CA, 0x562C0E62274601C0,
0x6F4A0CB8ACFF7034, 0xEA51C1C9C8F23049, 0xCA413E3603CBDCCF,
0xA7E5B91D287D545F, 0x1C323C89D01E9460, 0xA6DDEB12F0B41B72,
0x4C4BD80B6559D8D2, 0x9D84AF3AF8CCF566, 0x1DAE74E2D7F65F4F,
0x214AA9F23CF62937, 0xBA95E37E94F03C41, 0x00C40774F9799DE7,
0x623CA815A53DC0A0, 0x2B966F603BAA005A, 0x4A7F01729330A03C,
0x3AA3C3B6AF1ACE45, 0x8EEDAFF7174EBDC5, 0x78005039F4CEA4AA,
0x4D36AAB2FCA2C150, 0xDDE323A66BF337F5, 0x6F7E47861B7A1277,
0xB86088670CA3BAA8, 0x218C45C8727FBAA0, 0x76D3167331343EF7,
0x78DF6DE9AADD9E63, 0x9DD67E3E0CCF388B, 0xB571630663016120,
0x349C904FA4D6AFC9, 0xA4321D9FB73EC5D5, 0xA31CB6B845CF52B1,
0xED771A139FE20B86, 0xC05857A1061CE915, 0xE1C69AF2BA7BE706,
0x88DF0DDA58781E75, 0xBFE6E4B61B923F50, 0x2D1797888A57F9FC,
0x37F0A88CB6BB2317, 0x1E5AF6EBC5D5CD77, 0xBCF0BB798CF609D2,
0x6C74415B840C8F42, 0x5F92AC0AEFBB2A2A, 0xAEA80952AC83CDCC,
0x148E6336080BC9FC, 0x440A9EAC0572D0BC, 0xBB2DCE23A2FCF164,
0xC63F825E6738F990, 0x4F4B89A6AB0C59DF, 0x2B1B23B3AAE125F7,
0x02AFCD3AA9D1B454, 0xFCEF5F3517819564, 0x54B73F4D8F06CD33,
0x9B59C3BAA7819081, 0xF406BAA777860094, 0xC66B599CB8D22647,
0x7DBC5F307AC4DB70,
};
for (int i = 0; i < 100; i++) {
uint64_t have = 0;
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
.ptr = (uint8_t*)(digits),
.len = (size_t)(i),
});
if (mimic) {
#ifdef WUFFS_MIMIC
have = mimic_xxhash64_one_shot_checksum_u64(data);
#endif // WUFFS_MIMIC
} else {
wuffs_xxhash64__hasher checksum;
CHECK_STATUS("initialize",
wuffs_xxhash64__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
have = wuffs_xxhash64__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_xxhash64_pi() {
CHECK_FOCUS(__func__);
return do_test_xxxxx_xxhash64_pi(false);
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
const char* //
test_mimic_xxhash64_pi() {
CHECK_FOCUS(__func__);
return do_test_xxxxx_xxhash64_pi(true);
}
#endif // WUFFS_MIMIC
// ---------------- XXHash64 Benches
uint64_t g_wuffs_xxhash64_unused_u64;
const char* //
wuffs_bench_xxhash64(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_xxhash64__hasher checksum = {0};
CHECK_STATUS("initialize", wuffs_xxhash64__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
wuffs_initialize_flags));
g_wuffs_xxhash64_unused_u64 = wuffs_xxhash64__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_xxhash64_10k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(
wuffs_bench_xxhash64,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
&g_xxhash64_midsummer_gt, UINT64_MAX, UINT64_MAX, 5000);
}
const char* //
bench_wuffs_xxhash64_100k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(
wuffs_bench_xxhash64,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
&g_xxhash64_pi_gt, UINT64_MAX, UINT64_MAX, 500);
}
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
const char* //
bench_mimic_xxhash64_10k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(mimic_bench_xxhash64, 0, tcounter_src,
&g_xxhash64_midsummer_gt, UINT64_MAX, UINT64_MAX,
5000);
}
const char* //
bench_mimic_xxhash64_100k() {
CHECK_FOCUS(__func__);
return do_bench_io_buffers(mimic_bench_xxhash64, 0, tcounter_src,
&g_xxhash64_pi_gt, UINT64_MAX, UINT64_MAX, 500);
}
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_xxhash64_golden,
test_wuffs_xxhash64_interface,
test_wuffs_xxhash64_pi,
#ifdef WUFFS_MIMIC
test_mimic_xxhash64_pi,
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
bench_wuffs_xxhash64_10k,
bench_wuffs_xxhash64_100k,
#ifdef WUFFS_MIMIC
bench_mimic_xxhash64_10k,
bench_mimic_xxhash64_100k,
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/xxhash64";
return test_main(argc, argv, g_tests, g_benches);
}
+10 -17
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
// ----------------
@@ -153,10 +147,9 @@ wuffs_raw_deflate_decode(wuffs_base__io_buffer* dst,
wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
wuffs_initialize_flags));
// This wuffs_zlib__decoder__set_quirk_enabled call is the only difference
// between wuffs_raw_deflate_decode and wuffs_zlib_decode immediately below.
wuffs_zlib__decoder__set_quirk_enabled(
&dec, WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE, true);
// This wuffs_zlib__decoder__set_quirk call is the only difference between
// wuffs_raw_deflate_decode and wuffs_zlib_decode immediately below.
wuffs_zlib__decoder__set_quirk(&dec, WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE, 1);
while (true) {
wuffs_base__io_buffer limited_dst = make_limited_writer(*dst, wlimit);
@@ -234,8 +227,8 @@ do_test_wuffs_zlib_checksum(bool ignore_checksum, uint32_t bad_checksum) {
wuffs_zlib__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_zlib__decoder__set_quirk_enabled(
&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, ignore_checksum);
wuffs_zlib__decoder__set_quirk(&dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
(uint64_t)ignore_checksum);
have.meta.wi = 0;
src.meta.ri = 0;
+27 -12
View File
@@ -1,16 +1,10 @@
// Copyright 2017 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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.
#include <errno.h>
#include <inttypes.h>
@@ -1058,7 +1052,7 @@ do_run__wuffs_base__image_decoder(wuffs_base__image_decoder* b,
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
for (size_t i = 0; i < quirks_len; i++) {
wuffs_base__image_decoder__set_quirk_enabled(b, quirks_ptr[i], true);
wuffs_base__image_decoder__set_quirk(b, quirks_ptr[i], 1);
}
uint32_t bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&pixfmt);
@@ -1167,6 +1161,27 @@ do_test__wuffs_base__hasher_u32(wuffs_base__hasher_u32* b,
return NULL;
}
const char* //
do_test__wuffs_base__hasher_u64(wuffs_base__hasher_u64* b,
const char* src_filename,
size_t src_ri,
size_t src_wi,
uint64_t 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));
uint64_t have = wuffs_base__hasher_u64__update_u64(
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 != want) {
RETURN_FAIL("have 0x%016" PRIX64 ", want 0x%016" PRIX64, have, want);
}
return NULL;
}
const char* //
do_test__wuffs_base__image_decoder(
wuffs_base__image_decoder* b,
+26
View File
@@ -120,6 +120,28 @@ which is in the public domain.
`nobel-prizes.json` was crawled from
[api.nobelprize.org](http://api.nobelprize.org/v1/prize.json).
`peacock.*` is derived from this [peacock (pavo cristatus)
image](https://commons.wikimedia.org/wiki/File:Pavo_Real_Venezolano.jpg),
"available under the Creative Commons CC0 1.0 Universal Public Domain
Dedication":
- `wget --quiet https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Pavo_Real_Venezolano.jpg/1024px-Pavo_Real_Venezolano.jpg`
- `convert 1024px-Pavo_Real_Venezolano.jpg -resize 100x75 peacock.ppm`
- `convert peacock.ppm peacock.png`
- `rm 1024px-Pavo_Real_Venezolano.jpg`
- `cjpeg peacock.ppm > peacock.default.jpeg`
- `cjpeg -optimize peacock.ppm > peacock.optimize.jpeg`
- `cjpeg -grayscale peacock.ppm > peacock.grayscale.jpeg`
- `cjpeg -progressive peacock.ppm > peacock.progressive.jpeg`
- `cjpeg -quality 30 peacock.ppm > peacock.q30.jpeg`
- `cjpeg -quality 99 peacock.ppm > peacock.q99.jpeg`
- `cjpeg -sample 2x2 peacock.ppm > peacock.s2x2-420.jpeg`
- `cjpeg -sample 2x1 peacock.ppm > peacock.s2x1-422.jpeg`
- `cjpeg -sample 1x1 peacock.ppm > peacock.s1x1-444.jpeg`
- `cjpeg -sample 1x3 peacock.ppm > peacock.s1x3.jpeg`
- `cjpeg -sample 2x2,2x1,1x1 peacock.ppm > peacock.s-weird.jpeg`
- `cjpeg -sample 4x1,2x1,2x2 peacock.ppm > peacock.s-very-weird.jpeg`
- `go run ../../script/truncate-progressive-jpeg.go peacock.progressive.jpeg`
`pi.txt` contains the digits of pi.
`pjw-thumbnail.*` are various encodings of an image derived from an iconic,
@@ -134,6 +156,10 @@ Pointer"](https://tools.ietf.org/rfc/rfc6901.txt) specification.
`rgb24png.bmp` comes from [BMP Suite](https://github.com/jsummers/bmpsuite),
which states that its generated images "are in the public domain".
`ridiculously-fast.png` is a screenshot of a [Richard Geldreich
tweet](https://twitter.com/richgel999/status/1481027198530248714) from January
2022. It was lightly edited to darken the non-text areas.
`romeo.txt` is an excerpt of Shakespeare's "Romeo and Juliet", copied from
[shakespeare.mit.edu](http://shakespeare.mit.edu/romeo_juliet/romeo_juliet.2.2.html).
+5 -11
View File
@@ -1,17 +1,11 @@
#!/bin/bash -eu
# Copyright 2021 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
# ----------------
+4
View File
@@ -0,0 +1,4 @@
P5
36 28
255
rtuwxy{{|~~亗們剠唶垐墛妺寣實崕崓帋wxy{|~倎{€€厜唶妺寣崕帍悙悜憫憫拻抾|~€們sruz墠摗槏帍悙憭摀摂敃晻枛枛€€們厒vw僷倖彁槤�洈敁晻枟枟槞殮殮殮儎唸~mew{ru剳��警�摐�殸潪洕潪灋瀲垔`ij坵}z|垝櫇潬�殮湐洤洣⒈櫋  媿峝_a_s`ahqlx敁亗媷}~€棢『鸡漠ぅウ�搑dTOMbVT\\\i噣v恮bimzwzy荒凰畅ī┆敃X\WWTaYXeXJ_lhbnSah^\ICKX幚�mΜ�槈VR_TZ_Q^\VROZedPY[WWQONqK.L�埌氨矟丼S[[]bX^^UPJ`g\RTFCHPUIbpIY纯炒吹盯巇O[UT^Y[ZLMV`dUILHAM`SAik毉鸥婪腹功�^XZUXUYULP[[RWIOMNHHL;U\y�每净技�y[RVSPVeMLNNQNFITR\P?GL`ox懶萍目靠泊�USSRNUIJJIFNLHQY]XDPdnn{勈牙撩哪汉緇XW[UFOMLLTPMMOPMNSCKa倖洷度栏喝寺门圫ERPEPPEKLLFDCDGVhv爳�磷没湧九忧巧梊;+uvFOJKDDCB=:Hey③弢椌缻墯毐谲技緳^</|�&8ESKB@KV'4Ak�揜T`|€崶螺沅�瓧uK2E�1@AiYMGK�(?y烩唰亶�浙珑殚�▓嘼C(E7NCicTPe�%.G埵珏轫铐盱祆眍罡爆俌B@8/?FEdcVVx�38S撪殛腱眍镳痧瘃袂抗唉灆弰ugabc^]r�:Cw幨觌祛镳痱蝌蝮筚姨沤懂�晥ws唲rV/2Xk�珀眍痧蝌篌篝驸哔油凭钒�{|僸Xjnlt姷幼葩骐盹耱篝纛扉玟彷僬淹橇�敧�ゥИ岸救役忤祓蝮躔痫铐礻桤溻噍圪障似粱父焕刃剜尻铖篝赳耩镱铐祀觊珂溷徉捃僬已又坩骊盹耱篝�
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

+41
View File
@@ -25,6 +25,7 @@ f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
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
@@ -33,6 +34,7 @@ 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
@@ -47,33 +49,71 @@ 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
@@ -81,3 +121,4 @@ bf7e8c96 test/data/pjw-thumbnail.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